Hi Kairui,
On 11/20/19 at 11:50pm, Kairui Song wrote:
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(a)redhat.com>
---
mkdumprd | 45 +++++++++++----------------------------------
1 file changed, 11 insertions(+), 34 deletions(-)
diff --git a/mkdumprd b/mkdumprd
index aafd808..76ae7a0 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -17,6 +17,10 @@ SAVE_PATH=$(awk '/^path/ {print $2}' $conf_file)
[ -z "$SAVE_PATH" ] && SAVE_PATH=$DEFAULT_PATH
# strip the duplicated "/"
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() {
local active
@@ -32,40 +36,8 @@ is_wdt_addition_needed() {
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() {
- local arg qarg is_quoted=0
- 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
+ dracut_args="$dracut_args $@"
}
add_dracut_module() {
@@ -390,6 +362,10 @@ if [ "$(uname -m)" = "s390x" ]; then
add_dracut_module "znet"
fi
+if is_wdt_addition_needed; then
+ add_dracut_arg "-a" "watchdog"
+fi
+
while read config_opt config_val;
do
# 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"
fi
-dracut "${dracut_args[@]}" "$@"
+echo "$dracut_args $@" | xargs dracut
+
_rc=$?
sync
exit $_rc
--
2.23.0
It looks much simpler now, looks a good improvement, but I'm not very
familar with the bash tricks. May need some review from other people.
If no other feedback, I think I will trust your knowledge on this, and
feel free to add:
Acked-by: Dave Young <dyoung(a)redhat.com>
Thanks
Dave