mkdumprd: make dracut_args an array again

To make arguments list work as expected, array is preferred.

Use xargs only to parse the "dracut_args" config value, and pass the
array directly to dracut.

Check following link for details:
https://github.com/koalaman/shellcheck/wiki/SC2089

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
Kairui Song 2021-08-04 03:50:04 +08:00
parent 075e62252e
commit 227fc2bc7d

View File

@ -28,7 +28,7 @@ SAVE_PATH=$(get_save_path)
OVERRIDE_RESETTABLE=0 OVERRIDE_RESETTABLE=0
extra_modules="" extra_modules=""
dracut_args="--add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o \"plymouth dash resume ifcfg earlykdump\"" 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)" readonly MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)"
[ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed." [ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed."
@ -45,15 +45,15 @@ trap '
trap 'exit 1;' SIGINT trap 'exit 1;' SIGINT
add_dracut_arg() { add_dracut_arg() {
dracut_args="$dracut_args $@" dracut_args+=( "$@" )
} }
add_dracut_mount() { add_dracut_mount() {
add_dracut_arg "--mount" "\"$1\"" add_dracut_arg "--mount" "$1"
} }
add_dracut_sshkey() { add_dracut_sshkey() {
add_dracut_arg "--sshkey" "\"$1\"" add_dracut_arg "--sshkey" "$1"
} }
# caller should ensure $1 is valid and mounted in 1st kernel # caller should ensure $1 is valid and mounted in 1st kernel
@ -428,7 +428,9 @@ do
verify_core_collector "$config_val" verify_core_collector "$config_val"
;; ;;
dracut_args) dracut_args)
add_dracut_arg $config_val while read -r dracut_arg; do
add_dracut_arg "$dracut_arg"
done <<< "$(echo "$config_val" | xargs -n 1 echo)"
;; ;;
*) *)
;; ;;
@ -439,7 +441,7 @@ handle_default_dump_target
if [ -n "$extra_modules" ] if [ -n "$extra_modules" ]
then then
add_dracut_arg "--add-drivers" \"$extra_modules\" add_dracut_arg "--add-drivers" "$extra_modules"
fi fi
# TODO: The below check is not needed anymore with the introduction of # TODO: The below check is not needed anymore with the introduction of
@ -455,7 +457,7 @@ if ! is_fadump_capable; then
add_dracut_arg "--no-hostonly-default-device" add_dracut_arg "--no-hostonly-default-device"
fi fi
echo "$dracut_args $@" | xargs dracut dracut "${dracut_args[@]}" "$@"
_rc=$? _rc=$?
sync sync