Enable complete xtrace in kdumpctl and mkdumprd#126
Enable complete xtrace in kdumpctl and mkdumprd#126coiby wants to merge 2 commits intorhkdump:mainfrom
Conversation
Summary of ChangesHello @coiby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the debugging capabilities of the kdump system by integrating Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request enables xtrace to be propagated from kdumpctl to mkdumprd by checking if xtrace is enabled in kdumpctl and exporting a debug variable. This allows mkdumprd to enable its own tracing and pass a debug flag to dracut. The implementation is correct and achieves the intended goal. I have one suggestion to improve the readability of how the xtrace option is checked.
kdumpctl
Outdated
| if [[ "$-" == *"x"* ]]; then | ||
| export debug=1 | ||
| fi |
There was a problem hiding this comment.
For better readability and explicitness, you could use shopt -q xtrace to check if the xtrace option is enabled. This is generally considered more readable than checking the special $- variable.
| if [[ "$-" == *"x"* ]]; then | |
| export debug=1 | |
| fi | |
| if shopt -q xtrace; then | |
| export debug=1 | |
| fi |
There was a problem hiding this comment.
shopt -q xtrace
bash: shopt: xtrace: invalid shell option name
Use `shopt -q -o xtrace" to resolve the above error,
-o Restricts the values of optname to be those defined for the -o option to the set builtin
kdumpctl
Outdated
|
|
||
| shopt -q -o xtrace && export debug=1 | ||
|
|
||
| KEXEC=/sbin/kexec | ||
|
|
||
| KDUMP_KERNELVER="" |
There was a problem hiding this comment.
Hi @coiby,
this won't fix #108 entirely. Especially it won't fix the problem with rd.debug in the initrd. For me this issue is a bug in the kdump-logger.sh not kdumpctl. So I'd also fix it in there. Simply moving the line to kdump-logger.sh or dlog_init should fix it for all users. What do you think?
Thanks
Philipp
There was a problem hiding this comment.
Thanks for pointing out this issue! I've moved this code to kdump-logger.sh with slight change since kdump-logger.sh is supposed to POSIX-compliant.
5cde42d to
2f7929f
Compare
prudo1
left a comment
There was a problem hiding this comment.
Hi @coiby,
at first I found adding the additional --debug option for mkdumprd and mkfadumprd a little bit over kill. So I played around but ultimately ended up with almost the same solution (you can find the patch below). There are two small QOL things I've added
- I've updated the prompt to contain the file and function name (just like it is done in dracut). Personally I find that very helpful to figure out where you are in a large trace.
- I've automatically added
rd.debuginprepare_cmdline(I got so fed up aftermake installreplaced the sysconfig file and I had to add it over and over again...). It's not perfect when you use it together withkdumpctl testas it updates the command line but still better than re-running a test over and over again because you forgot to re-add it aftermake install...
While testing my changes I noticed something weird. In the initrd most of the traces are only written to the console but don't end up in kexec-dmesg.log (although some are). I'm not sure what's the reason for this. While having them in kexec-dmesg.log would be great I don't think it is strictly necessary. In the end this feature is mostly for us.
Anyway, with the small nit fixed I the series looks good to me.
Thanks
Philipp
diff --git a/kdump-lib.sh b/kdump-lib.sh
index 816a6ff..5e88325 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 "
+ [[ -n $debug ]] && 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 dd617f6..0ea2577 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -1,4 +1,11 @@
#!/bin/bash
+
+shopt -q -o xtrace && debug=1
+[[ -n $debug ]] && {
+ export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]-}): '
+ set -x
+}
+
KEXEC=/sbin/kexec
KDUMP_KERNELVER=""
@@ -6,6 +13,11 @@ KDUMP_KERNEL=""
KEXEC_ARGS=""
MKDUMPRD="/sbin/mkdumprd -f"
MKFADUMPRD="/sbin/mkfadumprd"
+if [[ -n $debug ]]; then
+ MKDUMPRD="bash -x $MKDUMPRD"
+ MKFADUMPRD="bash -x $MKFADUMPRD"
+fi
+
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 f1116d1..8b91eef 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -6,7 +6,11 @@
# Written by Cong Wang <amwang@redhat.com>
#
-[[ -n $debug ]] && set -x
+shopt -q -o xtrace && debug=1
+[[ -n $debug ]] && {
+ export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]-}): '
+ set -x
+}
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 948f1cf..0d1436c 100755
--- a/mkfadumprd
+++ b/mkfadumprd
@@ -2,6 +2,20 @@
# Generate an initramfs image that isolates dump capture capability within
# the default initramfs using zz-fadumpinit dracut module.
+shopt -q -o xtrace && debug=1
+[[ -n $debug ]] && {
+ export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]-}): '
+ set -x
+}
+
+MKDUMPRD="/sbin/mkdumprd -f"
+if [[ -n $debug ]]; then
+ MKDUMPRD="bash -x $MKDUMPRD"
+ debug_dracut=--debug
+else
+ debug_dracut=--quiet
+fi
+
if [[ -f /etc/sysconfig/kdump ]]; then
# shellcheck source=/dev/null
. /etc/sysconfig/kdump
@@ -33,7 +47,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 +87,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
--
Resolves: rhkdump#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 <coxu@redhat.com>
|
Hi @prudo1, Thanks for carefully reviewing the patches and the suggested improvements! I especially like the prompt to contain the file and function name. It will make life much easier when debugging kdump intitramfs building failure! |
kdumpctl
Outdated
| MKDUMPRD="/sbin/mkdumprd" | ||
| MKFADUMPRD="/sbin/mkfadumprd" | ||
| if shopt -q -o xtrace; then | ||
| export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]-}): ' |
There was a problem hiding this comment.
Last small nit, with mkdumprd and mkfadumprd being separate executables you need to export the prompt there as well. Otherwise it will only show on the kdumpctl part.
There was a problem hiding this comment.
I thought with PS4 already exported in kdumpctl, mkdumprd should inherit it. I did an experiment and can confirm this is indeed true when non-root users run a script. After trial and error, I find (quoting NEWS - bash.git),
nn. Shells running as root no longer inherit PS4 from the environment, closing
a security hole involving PS4 expansion performing command substitution.
This security hole is CVE-2016-7543. But I think it's safe for our case.
There was a problem hiding this comment.
I've dropped "export" and also explicitly set PS4 in mk/fadumpfd in new version, thanks for pointing out this issue!
…s xtrace Resolves: rhkdump#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 <coxu@redhat.com>
This PR resolves #108 and #118 to enable complete xtrace in kdumpctl and mkdumprd.