On Thu, 19 Aug 2021 19:39:38 +0800
Kairui Song <kasong(a)redhat.com> wrote:
POSIX doesn't support keyword `local`, so this commit reduced
varible usage.
s/varible/variable/
Heredoc ("<<<") operation is also not supported,
so kdump.conf is now pre-parse
into a temp file. Also fixes many POSIX syntax errors.
Signed-off-by: Kairui Song <kasong(a)redhat.com>
---
dracut-kdump.sh | 262 ++++++++++++++++++++++--------------------------
1 file changed, 122 insertions(+), 140 deletions(-)
diff --git a/dracut-kdump.sh b/dracut-kdump.sh
index 3c1b080a..0330ec02 100755
--- a/dracut-kdump.sh
+++ b/dracut-kdump.sh
[...]
+# $1: dump path
+# $2: ssh opts
+# $3: ssh address in <user>@<host> format
+# $4: scp address, similiar with ssh address but IPv6 addresses are quoted
s/similiar with/similar to/
Thanks
Philipp
save_opalcore_ssh() {
- local _path=$1
- local _opts="$2"
- local _location=$3
- local _scp_address=$4
-
- ddebug "_path=$_path _opts=$_opts _location=$_location"
-
if [ ! -f $OPALCORE ]; then
# Check if we are on an old kernel that uses a different path
if [ -f /sys/firmware/opal/core ]; then
@@ -460,31 +442,26 @@ save_opalcore_ssh() {
fi
fi
- dinfo "saving opalcore:$OPALCORE to $_location:$_path"
+ dinfo "saving opalcore:$OPALCORE to $3:$1"
- scp $_opts $OPALCORE $_scp_address:$_path/opalcore-incomplete
- if [ $? -ne 0 ]; then
+ if ! scp $2 $OPALCORE "$4:$1/opalcore-incomplete"; then
derror "saving opalcore failed"
- return 1
+ return 1
fi
- ssh $_opts $_location mv $_path/opalcore-incomplete $_path/opalcore
+ ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore"
dinfo "saving opalcore complete"
return 0
}
+# $1: dmesg collector
+# $2: dump path
+# $3: ssh opts
+# $4: ssh address in <user>@<host> format
save_vmcore_dmesg_ssh() {
- local _dmesg_collector=$1
- local _path=$2
- local _opts="$3"
- local _location=$4
-
- dinfo "saving vmcore-dmesg.txt to $_location:$_path"
- $_dmesg_collector /proc/vmcore | ssh $_opts $_location "umask 0077 &&
dd of=$_path/vmcore-dmesg-incomplete.txt"
- _exitcode=$?
-
- if [ $_exitcode -eq 0 ]; then
- ssh -q $_opts $_location mv $_path/vmcore-dmesg-incomplete.txt
$_path/vmcore-dmesg.txt
+ dinfo "saving vmcore-dmesg.txt to $4:$2"
+ if $1 /proc/vmcore | ssh $3 "$4" "umask 0077 && dd
of='$2/vmcore-dmesg-incomplete.txt'"; then
+ ssh -q $3 "$4" mv "$2/vmcore-dmesg-incomplete.txt"
"$2/vmcore-dmesg.txt"
dinfo "saving vmcore-dmesg.txt complete"
else
derror "saving vmcore-dmesg.txt failed"
@@ -493,17 +470,24 @@ save_vmcore_dmesg_ssh() {
get_host_ip()
{
- local _host
if is_nfs_dump_target || is_ssh_dump_target
then
kdumpnic=$(getarg kdumpnic=)
- [ -z "$kdumpnic" ] && derror "failed to get
kdumpnic!" && return 1
- _host=`ip addr show dev $kdumpnic|grep '[ ]*inet'`
- [ $? -ne 0 ] && derror "wrong kdumpnic: $kdumpnic" &&
return 1
- _host=`echo $_host | head -n 1 | cut -d' ' -f2`
- _host="${_host%%/*}"
- [ -z "$_host" ] && derror "wrong kdumpnic:
$kdumpnic" && return 1
- HOST_IP=$_host
+ if [ -z "$kdumpnic" ]; then
+ derror "failed to get kdumpnic!"
+ return 1
+ fi
+ if ! kdumphost=$(ip addr show dev "$kdumpnic" | grep '[
]*inet'); then
+ derror "wrong kdumpnic: $kdumpnic"
+ return 1
+ fi
+ kdumphost=$(echo "$kdumphost" | head -n 1 | awk '{print $2}')
+ kdumphost="${kdumphost%%/*}"
+ if [ -z "$kdumphost" ]; then
+ derror "wrong kdumpnic: $kdumpnic"
+ return 1
+ fi
+ HOST_IP=$kdumphost
fi
return 0
}
@@ -518,7 +502,7 @@ read_kdump_confs()
get_kdump_confs
# rescan for add code for dump target
- while read config_opt config_val;
+ while read -r config_opt config_val;
do
# remove inline comments after the end of a directive.
case "$config_opt" in
@@ -540,12 +524,13 @@ read_kdump_confs()
DUMP_INSTRUCTION="dump_ssh $SSH_KEY_LOCATION $config_val"
;;
esac
- done <<< "$(kdump_read_conf)"
+ done < "$KDUMP_CONF_PARSED"
}
fence_kdump_notify()
{
if [ -n "$FENCE_KDUMP_NODES" ]; then
+ # shellcheck disable=SC2086
$FENCE_KDUMP_SEND $FENCE_KDUMP_ARGS $FENCE_KDUMP_NODES &
fi
}
@@ -566,8 +551,7 @@ fi
read_kdump_confs
fence_kdump_notify
-get_host_ip
-if [ $? -ne 0 ]; then
+if ! get_host_ip; then
derror "get_host_ip exited with non-zero status!"
exit 1
fi
@@ -576,8 +560,7 @@ if [ -z "$DUMP_INSTRUCTION" ]; then
DUMP_INSTRUCTION="dump_fs $NEWROOT"
fi
-do_kdump_pre
-if [ $? -ne 0 ]; then
+if ! do_kdump_pre; then
derror "kdump_pre script exited with non-zero status!"
do_final_action
# During systemd service to reboot the machine, stop this shell script running
@@ -587,8 +570,7 @@ make_trace_mem "kdump saving vmcore" '1:shortmem'
'2+:mem' '3+:slab'
do_dump
DUMP_RETVAL=$?
-do_kdump_post $DUMP_RETVAL
-if [ $? -ne 0 ]; then
+if ! do_kdump_post $DUMP_RETVAL; then
derror "kdump_post script exited with non-zero status!"
fi