Hi Coiby,
On Fri, 21 Jan 2022 16:44:02 +0800
Coiby Xu <coxu(a)redhat.com> wrote:
The environment variable entries in /proc/[pid]/environ are separated
by
null bytes instead of by spaces. Update the sed regex to fix this issue.
Note that,
1. this patch also fixes a issue which is kdumpctl would try to reset
crashkernel even osbuild has provided custom crashkernel value.
2. kernel hook 92-crashkernel.install installed by kexec-tools is
guaranteed to be ran by kernel-install. kexec-tools doesn't recommend
kernel so there is no guarantee kernel is installed after kexec-tools.
But dnf invokes kernel-install in the posttrans scriptlet (of kernel-core)
which is always ran after all packages including kexec-tools and kernel
in a dnf transaction.
3. To be able to do unit tests, the logic of reading environment variable
has been extracted as a separate function.
Fixes: ddd428a ("set up kernel crashkernel for osbuild in kernel hook")
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
Looks good to me.
Thanks
Reviewed-by: Philipp Rudo <prudo(a)redhat.com>
---
kdumpctl | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/kdumpctl b/kdumpctl
index 8107487..3ccfa97 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -1576,9 +1576,19 @@ reset_crashkernel_after_update()
done
}
+# read the value of an environ variable from given environ file path
+#
+# The environment variable entries in /proc/[pid]/environ are separated
+# by null bytes instead of by spaces.
+read_proc_environ_var()
+{
+ local _environ_path=$1 _var=$2
+ sed -n -E "s/.*(^|\x00)${_var}=([^\x00]*).*/\2/p" <
"$_environ_path"
+}
+
_is_osbuild()
{
- [[ $(sed -n -E 's/.*(^|\s)container=(\S*).*/\2/p' < /proc/1/environ) ==
bwrap-osbuild ]]
+ [[ $(read_proc_environ_var container /proc/1/environ) == bwrap-osbuild ]]
}
reset_crashkernel_for_installed_kernel()
@@ -1590,8 +1600,10 @@ reset_crashkernel_for_installed_kernel()
exit 1
fi
- if _is_osbuild && ! grep -qs crashkernel= /etc/kernel/cmdline; then
- reset_crashkernel "--kernel=$_installed_kernel"
+ if _is_osbuild; then
+ if ! grep -qs crashkernel= /etc/kernel/cmdline; then
+ reset_crashkernel "--kernel=$_installed_kernel"
+ fi
return
fi