Declare and assign separately to avoid masking return values: https://github.com/koalaman/shellcheck/wiki/SC2155
Signed-off-by: Kairui Song kasong@redhat.com --- dracut-module-setup.sh | 22 +++++++++++++++------- kdumpctl | 17 ++++++++++++----- mkdumprd | 21 +++++++++++---------- mkfadumprd | 2 +- 4 files changed, 39 insertions(+), 23 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 46c0087a..7f6a644e 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -321,7 +321,8 @@ kdump_get_mac_addr() { #Bonding or team master modifies the mac address #of its slaves, we should use perm address kdump_get_perm_addr() { - local addr=$(ethtool -P "$1" | sed -e 's/Permanent address: //') + local addr + addr=$(ethtool -P "$1" | sed -e 's/Permanent address: //') if [[ -z "$addr" ]] || [[ "$addr" = "00:00:00:00:00:00" ]] then derror "Can't get the permanent address of $1" @@ -426,10 +427,13 @@ kdump_setup_team() {
kdump_setup_vlan() { local _netdev=$1 - local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")" - local _netmac="$(kdump_get_mac_addr "$_phydev")" + local _phydev + local _netmac local _kdumpdev
+ _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")" + _netmac="$(kdump_get_mac_addr "$_phydev")" + #Just support vlan over bond and team if kdump_is_bridge "$_phydev"; then derror "Vlan over bridge is not supported!" @@ -521,7 +525,8 @@ kdump_get_ip_route_field()
kdump_get_remote_ip() { - local _remote=$(get_remote_host "$1") _remote_temp + local _remote _remote_temp + _remote=$(get_remote_host "$1") if is_hostname "$_remote"; then _remote_temp=$(getent ahosts "$_remote" | grep -v : | head -n 1) if [[ -z "$_remote_temp" ]]; then @@ -875,11 +880,14 @@ get_alias() { }
is_localhost() { - local hostnames=$(hostname -A) - local shortnames=$(hostname -A -s) - local aliasname=$(get_alias) + local hostnames + local shortnames + local aliasname local nodename=$1
+ hostnames=$(hostname -A) + shortnames=$(hostname -A -s) + aliasname=$(get_alias) hostnames="$hostnames $shortnames $aliasname"
for name in ${hostnames}; do diff --git a/kdumpctl b/kdumpctl index ecfe3d77..f6cde221 100755 --- a/kdumpctl +++ b/kdumpctl @@ -690,6 +690,8 @@ load_kdump()
check_ssh_config() { + local SSH_TARGET + while read -r config_opt config_val; do case "$config_opt" in sshkey) @@ -713,7 +715,7 @@ check_ssh_config() done <<< "$(kdump_read_conf)"
#make sure they've configured kdump.conf for ssh dumps - local SSH_TARGET=$(echo -n "$DUMP_TARGET" | sed -n '/.*@/p') + SSH_TARGET=$(echo -n "$DUMP_TARGET" | sed -n '/.*@/p') if [[ -z "$SSH_TARGET" ]]; then return 1 fi @@ -725,13 +727,14 @@ check_ssh_config() # by the return val of 'ssh' check_and_wait_network_ready() { - local start_time=$(date +%s) + local start_time local warn_once=1 local cur local diff local retval local errmsg
+ start_time=$(date +%s) while true; do errmsg=$(ssh -i "$SSH_KEY_LOCATION" -o BatchMode=yes "$DUMP_TARGET" mkdir -p "$SAVE_PATH" 2>&1) retval=$? @@ -935,9 +938,13 @@ selinux_relabel()
check_fence_kdump_config() { - local hostname=$(hostname) - local ipaddrs=$(hostname -I) - local nodes=$(kdump_get_conf_val "fence_kdump_nodes") + local hostname + local ipaddrs + local nodes + + hostname=$(hostname) + ipaddrs=$(hostname -I) + nodes=$(kdump_get_conf_val "fence_kdump_nodes")
for node in $nodes; do if [[ "$node" = "$hostname" ]]; then diff --git a/mkdumprd b/mkdumprd index a2c6ed29..9c8ba232 100644 --- a/mkdumprd +++ b/mkdumprd @@ -29,9 +29,9 @@ OVERRIDE_RESETTABLE=0 extra_modules="" dracut_args=( --add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth dash resume ifcfg earlykdump" )
-readonly MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)" +MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)" [ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed." -readonly MKDUMPRD_TMPMNT="$MKDUMPRD_TMPDIR/target" +MKDUMPRD_TMPMNT="$MKDUMPRD_TMPDIR/target"
trap ' ret=$?; @@ -195,9 +195,11 @@ mount_failure() check_user_configured_target() { local _target=$1 _cfg_fs_type=$2 _mounted - local _mnt=$(get_mntpoint_from_target "$_target") - local _opt=$(get_mntopt_from_target "$_target") - local _fstype=$(get_fs_type_from_target "$_target") + local _mnt _opt _fstype + + _mnt=$(get_mntpoint_from_target "$_target") + _opt=$(get_mntopt_from_target "$_target") + _fstype=$(get_fs_type_from_target "$_target")
if [[ -n "$_fstype" ]]; then # In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf @@ -314,14 +316,13 @@ for_each_block_target() #return false if unresettable. is_unresettable() { - local path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/(cciss[0-9]+/).*/\1/g' -e 's//block/.*$//')/resettable" - local resettable=1 + local path device resettable=1
- if [[ -f "$path" ]] - then + path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/(cciss[0-9]+/).*/\1/g' -e 's//block/.*$//')/resettable" + if [[ -f "$path" ]]; then resettable="$(<"$path")" [[ $resettable -eq 0 ]] && [[ "$OVERRIDE_RESETTABLE" -eq 0 ]] && { - local device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}') + device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}') derror "Error: Can not save vmcore because device $device is unresettable" return 0 } diff --git a/mkfadumprd b/mkfadumprd index ca9f362c..5c96ee75 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -17,7 +17,7 @@ if ! dlog_init; then exit 1 fi
-readonly MKFADUMPRD_TMPDIR="$(mktemp -d -t mkfadumprd.XXXXXX)" +MKFADUMPRD_TMPDIR="$(mktemp -d -t mkfadumprd.XXXXXX)" [ -d "$MKFADUMPRD_TMPDIR" ] || perror_exit "mkfadumprd: mktemp -d -t mkfadumprd.XXXXXX failed." trap ' ret=$?;