From e9437134011842953f5c054acdf18bc2f9de87b0 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Jan 26 2022 06:39:13 +0000 Subject: fix the error of parsing the container environ variable for osbuild Resolves: bz2024976 Upstream: Fedora Conflict: None commit 6a3ce83a60c7107112d576223175410b180a41a0 Author: Coiby Xu Date: Wed Jan 19 11:16:29 2022 +0800 fix the error of parsing the container environ variable for osbuild 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 Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- diff --git a/kdumpctl b/kdumpctl index 1bdef71..a8384c8 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1602,9 +1602,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() @@ -1616,8 +1626,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