diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 27d6cce..1fc0aa2 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -16,19 +16,52 @@ LUKS_KEY_PRFIX="kdump-cryptsetup:vk-" # Read kdump config in well formated style kdump_read_conf() { - # Following steps are applied in order: strip trailing comment, strip trailing space, - # strip heading space, match non-empty line, remove duplicated spaces between conf name and value - [ -f "$KDUMP_CONFIG_FILE" ] && sed -n -e "s/#.*//;s/\s*$//;s/^\s*//;s/\(\S\+\)\s*\(.*\)/\1 \2/p" $KDUMP_CONFIG_FILE + kdump_get_conf_val "" } # Retrieves config value defined in kdump.conf -# $1: config name, sed regexp compatible +# $1: config name, if empty print full config kdump_get_conf_val() { - # For lines matching "^\s*$1\s+", remove matched part (config name including space), - # remove tailing comment, space, then store in hold space. Print out the hold buffer on last line. - [ -f "$KDUMP_CONFIG_FILE" ] && - sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;h};\${x;p}" $KDUMP_CONFIG_FILE + _to_find="$1" + _found="" + + [ -f "$KDUMP_CONFIG_FILE" ] || return + while read -r _line; do + _line="$(echo "$_line" | tr -s "[:blank:]" " ")" + case "$_line" in + "" | \#*) + continue + ;; + *\#*) + _line="${_line%%\#*}" + _line="${_line% }" + ;; + esac + + _opt=${_line%% *} + _val=${_line#* } + + case "$_val" in + \"*\") + # Remove quotes + _val="${_val#\"}" + _val="${_val%\"}" + ;; + esac + + if [ -z "$_to_find" ]; then + echo "$_opt $_val" + elif echo "$_opt" | grep -q -E "^($_to_find)$"; then + # make sure to only return the last match to mirror the + # old behavior + _found="$_val" + fi + done < "$KDUMP_CONFIG_FILE" + [ -n "$_found" ] && echo "$_found" + + # make sure we return 0 even when a option isn't set + return 0 } is_mounted() diff --git a/kdump-lib.sh b/kdump-lib.sh index a8c5ca5..fabdbe7 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -101,7 +101,7 @@ to_dev_name() is_user_configured_dump_target() { - [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|nfs\|ssh\|virtiofs") ]] || is_mount_in_dracut_args + [[ $(kdump_get_conf_val "ext[234]|xfs|btrfs|minix|raw|nfs|ssh|virtiofs") ]] || is_mount_in_dracut_args } get_block_dump_target() @@ -112,7 +112,7 @@ get_block_dump_target() return fi - _target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|virtiofs") + _target=$(kdump_get_conf_val "ext[234]|xfs|btrfs|minix|raw|virtiofs") [[ -n $_target ]] && to_dev_name "$_target" && return _target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")") @@ -130,7 +130,7 @@ get_block_dump_target() is_dump_to_rootfs() { - [[ $(kdump_get_conf_val 'failure_action\|default') == dump_to_rootfs ]] + [[ $(kdump_get_conf_val 'failure_action|default') == dump_to_rootfs ]] } is_lvm2_thinp_dump_target()