Skip to content
Open
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ install: dracut-modules kdump-conf kdump-sysconfig manpages
mkdir -p $(DESTDIR)$(pkglibdir)/dracut.conf.d
mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/pre.d
mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/post.d
mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/emergency.d
mkdir -p -m755 $(DESTDIR)$(localstatedir)/crash
mkdir -p -m755 $(DESTDIR)$(udevrulesdir)
mkdir -p -m755 $(DESTDIR)$(sharedstatedir)/kdump
Expand Down
24 changes: 24 additions & 0 deletions dracut/99kdumpbase/kdump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ DD_BLKSIZE=512
FINAL_ACTION="systemctl reboot -f"
KDUMP_PRE=""
KDUMP_POST=""
KDUMP_EMERGENCY=""
NEWROOT="/sysroot"
OPALCORE="/sys/firmware/opal/mpipl/core"
KDUMP_CONF_PARSED="/tmp/kdump.conf.$$"
Expand Down Expand Up @@ -66,6 +67,9 @@ get_kdump_confs() {
kdump_post)
KDUMP_POST="$config_val"
;;
kdump_emergency)
KDUMP_EMERGENCY="$config_val"
;;
fence_kdump_args)
FENCE_KDUMP_ARGS="$config_val"
;;
Expand Down Expand Up @@ -374,6 +378,25 @@ do_kdump_post() {
fi
}

do_kdump_emergency() {
if [ -d /etc/kdump/emergency.d ]; then
for file in /etc/kdump/emergency.d/*; do
"$file"
_ret=$?
if [ $_ret -ne 0 ]; then
derror "$file exited with $_ret status"
fi
done
fi

if [ -n "$KDUMP_EMERGENCY" ]; then
"$KDUMP_EMERGENCY"
_ret=$?
if [ $_ret -ne 0 ]; then
derror "$KDUMP_EMERGENCY exited with $_ret status"
fi
fi
Comment on lines +381 to +398
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The do_kdump_emergency function does not have any error handling for the directory iteration. If /etc/kdump/emergency.d does not exist or is not a directory, the script will continue without any warning. This could lead to unexpected behavior if the administrator expects the emergency scripts to be executed.

do_kdump_emergency() {
    if [ ! -d /etc/kdump/emergency.d ]; then
        derror "/etc/kdump/emergency.d is not a directory or does not exist"
        return 1 # Indicate failure to the caller
    fi

    for file in /etc/kdump/emergency.d/*; do
        "$file"
        _ret=$?
        if [ $_ret -ne 0 ]; then
            derror "$file exited with $_ret status"
        fi
    done

    if [ -n "$KDUMP_EMERGENCY" ]; then
        "$KDUMP_EMERGENCY"
        _ret=$?
        if [ $_ret -ne 0 ]; then
            derror "$KDUMP_EMERGENCY exited with $_ret status"
        fi
    fi
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is implemented exactly the same way as pre.d and post.d, if we fix this, we also need to apply the same fix to those as well.
I think it would be better to bundle the changes for pre.d and post.d into a separate pull request.

}
# $1: block target, eg. /dev/sda
dump_raw() {
[ -b "$1" ] || return 1
Expand Down Expand Up @@ -641,6 +664,7 @@ kdump_test_init() {

if [ "$1" = "--error-handler" ]; then
get_kdump_confs
do_kdump_emergency
do_failure_action
save_log
do_final_action
Expand Down
14 changes: 12 additions & 2 deletions dracut/99kdumpbase/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ kdump_install_net() {
fi
}

# install etc/kdump/pre.d and /etc/kdump/post.d
# install etc/kdump/pre.d and /etc/kdump/post.d /etc/kdump/emergency.d
kdump_install_pre_post_conf() {
if [[ -d /etc/kdump/pre.d ]]; then
for file in /etc/kdump/pre.d/*; do
Expand All @@ -681,6 +681,16 @@ kdump_install_pre_post_conf() {
fi
done
fi

if [[ -d /etc/kdump/emergency.d ]]; then
for file in /etc/kdump/emergency.d/*; do
if [[ -x $file ]]; then
dracut_install "$file"
elif [[ $file != "/etc/kdump/emergency.d/*" ]]; then
echo "$file is not executable"
Comment on lines +689 to +690
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The echo statement does not redirect to standard error, so the message will not be visible in logs. This could make it difficult to diagnose issues with the emergency scripts.

Suggested change
elif [[ $file != "/etc/kdump/emergency.d/*" ]]; then
echo "$file is not executable"
echo "$file is not executable" >&2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn’t an emergency-time message; it can be logged during initramfs generation when kdump.service starts.
We’ve confirmed it appears in the journal log under kdump.service, consistent with pre.d/post.d.

fi
done
fi
}

default_dump_target_install_conf() {
Expand Down Expand Up @@ -743,7 +753,7 @@ kdump_install_conf() {
kdump_collect_netif_usage "$(get_dracut_args_target "$_val")"
fi
;;
kdump_pre | kdump_post | extra_bins)
kdump_pre | kdump_post | kdump_emergency | extra_bins)
# shellcheck disable=SC2086
dracut_install $_val
;;
Expand Down
8 changes: 8 additions & 0 deletions gen-kdump-conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ generate()
# For core_collector format details, you can refer to
# kexec-kdump-howto.txt or kdump.conf manpage.
#
# kdump_emergency <binary | script>
# - This directive allows you to run a specified executable
# in emergency mode within the kdump capture kernel,
# prior to the dump process.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find the prior to the dump process a bit confusing. When kdump.sh end up in the error handler there is no more dump process (unless you specify failure_action dump_to_rootfs). Should that be prior to executing the failure_action.?
Same for the man page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you pointed out, once the kdump capture kernel enters the error handler, the dump process will never be started.
Therefore, I am considering revising the description to state that the executable runs in the emergency mode that the kdump capture kernel transitions into before the dump capture process is executed.
How about wording it as follows?

--- a/kdump.conf.5
+++ b/kdump.conf.5
@@ -133,8 +133,9 @@ than the system's RAM.
 .B kdump_emergency <binary | script>
 .RS
 This directive allows you to run a specified executable
-in emergency mode within the kdump capture kernel,
-prior to the dump process.
+in the emergency mode entered due to an error that occurs
+before the dump collection process is executed in the
+kdump capture kernel.
 .PP
 All files under /etc/kdump/emergency.d are collectively sorted
 and executed in lexical order, before binary or script

Copy link
Collaborator

Choose a reason for hiding this comment

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

@nishibem,

sorry for nit picking, but my understanding is that the emergency mode is entered for any error, including but not exclusively for those that occur before the dump process starts. Personally I would phrase it like this

This directive allows you to run a specified executable in emergency mode after an error in the kdump environment occurs.

Would that be ok with you?

# All files under /etc/kdump/emergency.d are collectively sorted
# and executed in lexical order, before binary or script
# specified kdump_emergency parameter is executed.
#
# kdump_post <binary | script>
# - This directive allows you to run a executable binary
# or script after the vmcore dump process terminates.
Expand Down
1 change: 1 addition & 0 deletions kdump-utils.spec
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ fi
%dir %{_sysconfdir}/kdump
%dir %{_sysconfdir}/kdump/pre.d
%dir %{_sysconfdir}/kdump/post.d
%dir %{_sysconfdir}/kdump/emergency.d
%dir %{_sharedstatedir}/kdump
%{_mandir}/man8/kdumpctl.8*
%{_mandir}/man8/mkdumprd.8*
Expand Down
17 changes: 17 additions & 0 deletions kdump.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ than the system's RAM.

.RE

.B kdump_emergency <binary | script>
.RS
This directive allows you to run a specified executable
in emergency mode within the kdump capture kernel,
prior to the dump process.
.PP
All files under /etc/kdump/emergency.d are collectively sorted
and executed in lexical order, before binary or script
specified kdump_emergency parameter is executed.
.PP
Note that scripts written for use with this directive must use the /bin/bash
interpreter. And since these scripts run in kdump enviroment, the reference to
the storage or network device in the scripts should adhere to the section
'Supported dump target types and requirements' in kexec-kdump-howto.txt.

.RE

.B kdump_post <binary | script>
.RS
This directive allows you to run a specified executable
Expand Down
18 changes: 10 additions & 8 deletions kdumpctl
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ parse_config()
dwarn "Please update $KDUMP_CONFIG_FILE to use option 'failure_action' instead."
_set_config failure_action "$config_val" || return 1
;;
path | core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;;
path | core_collector | kdump_post | kdump_pre | kdump_emergency | extra_bins | extra_modules | failure_action | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;;

net | options | link_delay | disk_timeout | debug_mem_level | blacklist)
derror "Deprecated kdump config option: $config_opt. Refer to kdump.conf manpage for alternatives."
Expand Down Expand Up @@ -461,9 +461,6 @@ check_files_modified()
#also rebuild when Pacemaker cluster conf is changed and fence kdump is enabled.
modified_files=$(get_pcs_cluster_modified_files "$image_time")

EXTRA_BINS=${OPT[kdump_post]}
CHECK_FILES=${OPT[kdump_pre]}
HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/"
if [[ -d /etc/kdump/post.d ]]; then
for file in /etc/kdump/post.d/*; do
if [[ -x $file ]]; then
Expand All @@ -478,13 +475,18 @@ check_files_modified()
fi
done
fi
HOOKS="$HOOKS $POST_FILES $PRE_FILES"
if [[ -d /etc/kdump/emergency.d ]]; then
for file in /etc/kdump/emergency.d/*; do
if [[ -x $file ]]; then
EMERGENCY_FILES="$EMERGENCY_FILES $file"
fi
done
fi
HOOKS="$POST_FILES $PRE_FILES $EMERGENCY_FILES"
CORE_COLLECTOR=$(echo "${OPT[core_collector]}" | awk '{print $1}')
CORE_COLLECTOR=$(type -P "$CORE_COLLECTOR")
# POST_FILES and PRE_FILES are already checked against executable, need not to check again.
EXTRA_BINS="$EXTRA_BINS $CHECK_FILES"
CHECK_FILES=${OPT[extra_bins]}
EXTRA_BINS="$EXTRA_BINS $CHECK_FILES"
EXTRA_BINS="${OPT[kdump_post]} ${OPT[kdump_pre]} ${OPT[kdump_emergency]} ${OPT[extra_bins]}"
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The variables OPT[kdump_post], OPT[kdump_pre], OPT[kdump_emergency], and OPT[extra_bins] are concatenated without any separators. This could lead to issues if the values contain spaces or special characters.

Suggested change
EXTRA_BINS="${OPT[kdump_post]} ${OPT[kdump_pre]} ${OPT[kdump_emergency]} ${OPT[extra_bins]}"
EXTRA_BINS="${OPT[kdump_post]} ${OPT[kdump_pre]} ${OPT[kdump_emergency]} ${OPT[extra_bins]}"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original code did not take into account cases where the values contain spaces or special characters.
Could you share your thoughts on how we should handle this?

files="$KDUMP_CONFIG_FILE $KDUMP_KERNEL $EXTRA_BINS $CORE_COLLECTOR"
[[ -e /etc/fstab ]] && files="$files /etc/fstab"

Expand Down
16 changes: 15 additions & 1 deletion kexec-kdump-howto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,28 @@ level in the above KDUMP_COMMANDLINE_APPEND.

Logging levels: no logging(0), error(1), warn(2), info(3), debug(4)

Kdump Emergency Executable
--------------------------

It is possible to specify a custom script or binary you wish to run in
emergency mode prior to the dump process. From the error handler launched
in emergency mode within the kdump capture kernel, you can trigger different
actions from within your specified executables.
If /etc/kdump/emergency.d directory exist, all files in the directory are
collectively sorted and executed in lexical order, before binary or script
specified using kdump_emergency option is executed.

In these scripts, the reference to the storage or network device should adhere
to the section 'Supported dump target types and requirements'

Kdump Post-Capture Executable
-----------------------------

It is possible to specify a custom script or binary you wish to run following
an attempt to capture a vmcore. The executable is passed an exit code from
the capture process, which can be used to trigger different actions from
within your post-capture executable.
If /etc/kdump/post.d directory exist, All files in the directory are
If /etc/kdump/post.d directory exist, all files in the directory are
collectively sorted and executed in lexical order, before binary or script
specified kdump_post parameter is executed.

Expand Down