fix the error of parsing the container environ variable for osbuild

Resolves: bz2024976
Upstream: Fedora
Conflict: None

commit 6a3ce83a60
Author: Coiby Xu <coxu@redhat.com>
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 <coxu@redhat.com>
    Reviewed-by: Pingfan Liu <piliu@redhat.com>
    Reviewed-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Coiby Xu <coxu@redhat.com>
This commit is contained in:
Coiby Xu 2022-01-26 14:39:13 +08:00
parent 149a6dc9b2
commit e943713401
1 changed files with 15 additions and 3 deletions

View File

@ -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