kdump-lib-initramfs: rewrite kdump_get_conf_val
Resolves: RHEL-115464
Upstream: kdump-utils
Conflict: None
commit d81109cf9291250b42434fc51798c93b613c4ee2
Author: Philipp Rudo <prudo@redhat.com>
Date: Thu Nov 6 15:07:42 2025 +0100
kdump-lib-initramfs: rewrite kdump_get_conf_val
Previously, kdump_get_conf_val() relied on a "magic" regular
expression to parse kdump.conf, making maintenance and
extension difficult. This patch rewrites the parsing logic
to be more human-readable.
The '\|' needs to be changed to a single '|' because after
the rewrite we will use another tool to parse the options to
find.
Furthermore, kdump_read_conf() has been refactored to invoke
kdump_get_conf_val(), as their logic is functionally identical.
Signed-off-by: Philipp Rudo <prudo@redhat.com>
Signed-off-by: Lichen Liu <lichliu@redhat.com>
Signed-off-by: Lichen Liu <lichliu@redhat.com>
This commit is contained in:
parent
fa23321644
commit
d2709ce157
@ -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()
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user