Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions kdump-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump/registered"
FADUMP_APPEND_ARGS_SYS_NODE="/sys/kernel/fadump/bootargs_append"
# shellcheck disable=SC2034
FENCE_KDUMP_CONFIG_FILE="/etc/sysconfig/fence_kdump"
# shellcheck disable=SC2034
KDUMP_SYSCONFIG_FILE="/etc/sysconfig/kdump"

is_fadump_capable()
{
Expand Down Expand Up @@ -974,6 +976,27 @@ _crashkernel_add()
echo "${ret%,}"
}

get_dump_commandline()
{
local _dump_mode=$1
local _cmdline_append

if ! [ -e "$KDUMP_SYSCONFIG_FILE" ]; then
derror "No $KDUMP_SYSCONFIG_FILE yet"
return 1
fi

if [ "$_dump_mode" = "fadump" ]; then
_cmdline_append=$(grep '^\s*FADUMP_COMMANDLINE_APPEND\s*=' "$KDUMP_SYSCONFIG_FILE" | \
sed 's/^\s*FADUMP_COMMANDLINE_APPEND\s*=\s*"\(.*\)".*$/\1/')
else
_cmdline_append=$(grep '^\s*KDUMP_COMMANDLINE_APPEND\s*=' "$KDUMP_SYSCONFIG_FILE" | \
sed 's/^\s*KDUMP_COMMANDLINE_APPEND\s*=\s*"\(.*\)".*$/\1/')
fi

echo "$_cmdline_append"
}
Comment on lines +979 to +998
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of using grep and sed to parse the sysconfig file, it's simpler and more robust to source the file in a subshell. This avoids potential parsing issues and aligns with how shell configuration files are typically handled. The subshell ensures that the sourced variables do not pollute the main script's environment.

get_dump_commandline()
{
	local _dump_mode=$1

	if ! [ -e "$KDUMP_SYSCONFIG_FILE" ]; then
		derror "No $KDUMP_SYSCONFIG_FILE yet"
		return 1
	fi

	(
		# shellcheck source=/dev/null
		. "$KDUMP_SYSCONFIG_FILE"

		if [ "$_dump_mode" = "fadump" ]; then
			# shellcheck disable=SC2153
			echo "$FADUMP_COMMANDLINE_APPEND"
		else
			# shellcheck disable=SC2153
			echo "$KDUMP_COMMANDLINE_APPEND"
		fi
	)
}


# Parses the kdump or fadump command line to extract a valid
# positive nr_cpus=<N> value, defaulting to 1 if none is found.
find_nr_cpus()
Expand All @@ -983,9 +1006,9 @@ find_nr_cpus()

# shellcheck disable=SC2153
if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then
_cmdline_append="$FADUMP_COMMANDLINE_APPEND"
_cmdline_append=$(get_dump_commandline "fadump")
else
_cmdline_append="$KDUMP_COMMANDLINE_APPEND"
_cmdline_append=$(get_dump_commandline "kdump")
fi

for arg in $_cmdline_append; do
Expand Down
5 changes: 4 additions & 1 deletion kdumpctl
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,10 @@ fadump_bootargs_append()

# shellcheck disable=SC2153
if output=$({
echo "${FADUMP_COMMANDLINE_APPEND}" > "$FADUMP_APPEND_ARGS_SYS_NODE"
local _fadump_append

_fadump_append=$(get_dump_commandline fadump) || exit
echo "$_fadump_append" > "$FADUMP_APPEND_ARGS_SYS_NODE"
} 2>&1); then
output=$(cat "$FADUMP_APPEND_ARGS_SYS_NODE")
dinfo "fadump: additional parameters for capture kernel: '$output'"
Expand Down
Loading