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 <coxu@redhat.com>
Reviewed-by: Pingfan Liu <piliu@redhat.com>
Reviewed-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
parent
ca5a33855f
commit
6a3ce83a60
16
kdumpctl
16
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
|
||||
if _is_osbuild; then
|
||||
if ! grep -qs crashkernel= /etc/kernel/cmdline; then
|
||||
reset_crashkernel "--kernel=$_installed_kernel"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user