mkdumprd: simplify dracut args parsing

Previously dracut_args is stored as an array in the shell code,
so we can just pass this array as argument to dracut.
But when trying to append new dracut argument, we have to manually
handle the quotes and spaces to ensure the appended argument is
splitted into array elements in the right way.

This is complex and hard to read or maintain. Instead, just store the
dracut_args as a plain string, and let xargs help parse it and call
dracut.

Simply passing $dracut_args or "$dracut_args" will either let dracut
consider the whole string as a single argument, or loss all the
quotes. xargs can handle it well and cover more corner cases.

Eg. one corner case before, if we have:
dracut_args --mount "/dev/sda1 /mnt/test xfs rw"

Kdump will fail, because the function add_dracut_arg() will wrongly
change the arguments into: (Notice the extra space.)
dracut_args --mount " /dev/sda1 /mnt/test xfs rw"

Instead of fixing it just use xargs instead. Tested with above config
and multiple other dracut_args values.

Resolves: bz1700136
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
This commit is contained in:
Kairui Song 2019-11-20 22:58:10 +08:00
parent 5633e83318
commit f13eab60cb

View File

@ -17,6 +17,10 @@ SAVE_PATH=$(awk '/^path/ {print $2}' $conf_file)
[ -z "$SAVE_PATH" ] && SAVE_PATH=$DEFAULT_PATH [ -z "$SAVE_PATH" ] && SAVE_PATH=$DEFAULT_PATH
# strip the duplicated "/" # strip the duplicated "/"
SAVE_PATH=$(echo $SAVE_PATH | tr -s /) SAVE_PATH=$(echo $SAVE_PATH | tr -s /)
OVERRIDE_RESETTABLE=0
extra_modules=""
dracut_args="--quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o \"plymouth dash resume ifcfg earlykdump\""
is_wdt_addition_needed() { is_wdt_addition_needed() {
local active local active
@ -32,40 +36,8 @@ is_wdt_addition_needed() {
return 1 return 1
} }
WDTCFG=""
is_wdt_addition_needed
[[ $? -eq 0 ]] && WDTCFG="-a watchdog"
extra_modules=""
dracut_args=("--quiet" "--hostonly" "--hostonly-cmdline" "--hostonly-i18n" "--hostonly-mode" "strict" "-o" "plymouth dash resume ifcfg earlykdump" $WDTCFG)
OVERRIDE_RESETTABLE=0
add_dracut_arg() { add_dracut_arg() {
local arg qarg is_quoted=0 dracut_args="$dracut_args $@"
while [ $# -gt 0 ];
do
arg="${1//\'/\"}"
#Handle quoted substring properly for passing it to dracut_args array.
if [ $is_quoted -eq 0 ]; then
if [[ "$arg" == "\"" ]] || [[ $arg != ${arg#\"} ]]; then
is_quoted=1
arg=${arg#\"}
fi
fi
if [ $is_quoted -eq 1 ]; then
qarg="$qarg $arg"
if [[ "$arg" == "\"" ]] || [[ $arg != ${arg%\"} ]]; then
is_quoted=0
arg=${qarg%\"}
qarg=""
else
shift
continue
fi
fi
dracut_args+=("$arg")
shift
done
} }
add_dracut_module() { add_dracut_module() {
@ -390,6 +362,10 @@ if [ "$(uname -m)" = "s390x" ]; then
add_dracut_module "znet" add_dracut_module "znet"
fi fi
if is_wdt_addition_needed; then
add_dracut_arg "-a" "watchdog"
fi
while read config_opt config_val; while read config_opt config_val;
do do
# remove inline comments after the end of a directive. # remove inline comments after the end of a directive.
@ -463,7 +439,8 @@ if ! is_fadump_capable; then
add_dracut_arg "--no-hostonly-default-device" add_dracut_arg "--no-hostonly-default-device"
fi fi
dracut "${dracut_args[@]}" "$@" echo "$dracut_args $@" | xargs dracut
_rc=$? _rc=$?
sync sync
exit $_rc exit $_rc