From 60b42830dd320eef60e654d40c08e0ac57ca4699 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 20 Nov 2025 17:01:18 +0800 Subject: [PATCH 1/2] Don't let logger functions turn off xtrace Resolves: https://github.com/rhkdump/kdump-utils/issues/108 Functions like dwarn in kdump-logger.sh disable xtrace temporarily and only re-enable xtrace when debug is set. Automatically set debug environment variable to resolve this issue. Signed-off-by: Coiby Xu --- kdump-logger.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kdump-logger.sh b/kdump-logger.sh index 4c3b486e..506d20a3 100755 --- a/kdump-logger.sh +++ b/kdump-logger.sh @@ -37,6 +37,14 @@ # The code in this file might be run in an environment without bash. # Any code added must be POSIX compliant. +# When xtrace is enabled, set debug to prevent logger functions from turning +# off xtrace +case "$-" in +*"x"*) + debug=1 + ;; +esac + # Define vairables for the log levels in this module. kdump_stdloglvl="" kdump_sysloglvl="" From ee4227f3e5f365e75dec27ef5463eee488e335a2 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 20 Nov 2025 17:15:52 +0800 Subject: [PATCH 2/2] Enable xtrace in mkdumprd, mkfadumprd and dracut when kdumpctl enables xtrace Resolves: https://github.com/rhkdump/kdump-utils/issues/118 Since dracut commit 5042681("fix(dracut.sh): initialize variables that get exported"), debug=1 won't enable xtrace in dracut. Let's call dracut with --debug explicitly in mkdumprd and mkfadumprd. Also enable xtrace in mkdumprd and mkfadumprd by passing --debug argument when kdumpctl enables xtrace. Signed-off-by: Coiby Xu --- kdump-lib.sh | 2 ++ kdumpctl | 10 +++++++++- mkdumprd | 12 ++++++++++-- mkfadumprd | 15 +++++++++++++-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 816a6ff6..74eb8dec 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -778,6 +778,8 @@ prepare_cmdline() # (if at all) and add it explicitly. out+="rd.systemd.gpt_auto=no " + shopt -q -o xtrace && out+="rd.debug " + # Trim unnecessary whitespaces echo "$out" | sed -e "s/^ *//g" -e "s/ *$//g" -e "s/ \+/ /g" } diff --git a/kdumpctl b/kdumpctl index dd617f60..e7723c4d 100755 --- a/kdumpctl +++ b/kdumpctl @@ -4,8 +4,16 @@ KEXEC=/sbin/kexec KDUMP_KERNELVER="" KDUMP_KERNEL="" KEXEC_ARGS="" -MKDUMPRD="/sbin/mkdumprd -f" +MKDUMPRD="/sbin/mkdumprd" MKFADUMPRD="/sbin/mkfadumprd" +if shopt -q -o xtrace; then + # shells running as root don't inherit PS4 + PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]-}): ' + MKDUMPRD+=" --debug" + MKFADUMPRD+=" --debug" +fi +MKDUMPRD+=" -f" + DRACUT_MODULES_FILE="/usr/lib/dracut/modules.txt" # Path to the initrd used for normal boot. Used to determine the naming diff --git a/mkdumprd b/mkdumprd index f1116d16..d78f3715 100644 --- a/mkdumprd +++ b/mkdumprd @@ -6,7 +6,11 @@ # Written by Cong Wang # -[[ -n $debug ]] && set -x +if [[ $1 == --debug ]]; then + set -x + PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]-}): ' + shift +fi if [[ -f /etc/sysconfig/kdump ]]; then # shellcheck source=/dev/null @@ -32,7 +36,11 @@ SSH_KEY_LOCATION=$DEFAULT_SSHKEY SAVE_PATH=$(get_save_path) declare -a dracut_args -dracut_args+=(--quiet) +if [[ -n $debug ]]; then + dracut_args+=(--debug) +else + dracut_args+=(--quiet) +fi dracut_args+=(--hostonly) dracut_args+=(--hostonly-cmdline) dracut_args+=(--hostonly-i18n) diff --git a/mkfadumprd b/mkfadumprd index 948f1cf7..e992c02c 100755 --- a/mkfadumprd +++ b/mkfadumprd @@ -2,6 +2,18 @@ # Generate an initramfs image that isolates dump capture capability within # the default initramfs using zz-fadumpinit dracut module. +MKDUMPRD="/sbin/mkdumprd" +if [[ $1 == --debug ]]; then + set -x + PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]-}): ' + shift + MKDUMPRD+=" --debug" + debug_dracut=--debug +else + debug_dracut=--quiet +fi +MKDUMPRD+=" -f" + if [[ -f /etc/sysconfig/kdump ]]; then # shellcheck source=/dev/null . /etc/sysconfig/kdump @@ -33,7 +45,6 @@ trap ' # clean up after ourselves no matter how we die. trap 'exit 1;' SIGINT -MKDUMPRD="/sbin/mkdumprd -f" # Default boot initramfs to be rebuilt REBUILD_INITRD="$1" && shift TARGET_INITRD="$1" && shift @@ -74,6 +85,6 @@ if ! have_compression_in_dracut_args; then fi fi -if ! dracut --force --quiet "${_dracut_isolate_args[@]}" "$@" "$TARGET_INITRD"; then +if ! dracut "$debug_dracut" --force "${_dracut_isolate_args[@]}" "$@" "$TARGET_INITRD"; then perror_exit "mkfadumprd: failed to setup '$TARGET_INITRD' with dump capture capability" fi