From: Renaud Métrich Date: Tue, 16 Nov 2021 10:15:52 +0000 (+0100) Subject: fix(shutdown): be robust against forced shutdown X-Git-Tag: 056~85 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9ba3c8bb8f0f1328cd1ffaa8dbf64585b28c474;p=thirdparty%2Fdracut.git fix(shutdown): be robust against forced shutdown When a forced shutdown is issued through sending a burst of Ctrl-Alt-Del keys, systemd sends SIGTERM to all processes. This ends up killing dracut-initramfs-restore as well, preventing the script from detecting that the unpack of the initramfs is incomplete, which later causes a crash to happen when "shutdown" tries to execute from the unpacked initramfs. This fix makes sure dracut-initramfs-restore remains alive to detect the unpack failed (because cpio was killed by systemd too). Refs: * https://bugzilla.redhat.com/show_bug.cgi?id=2023665 --- diff --git a/dracut-initramfs-restore.sh b/dracut-initramfs-restore.sh index abe6b1e20..d97030a34 100644 --- a/dracut-initramfs-restore.sh +++ b/dracut-initramfs-restore.sh @@ -6,6 +6,11 @@ set -e [ -e /run/initramfs/bin/sh ] && exit 0 [ -e /run/initramfs/.need_shutdown ] || exit 0 +# SIGTERM signal is received upon forced shutdown: ignore the signal +# We want to remain alive to be able to trap unpacking errors to avoid +# switching root to an incompletely unpacked initramfs +trap 'echo "Received SIGTERM signal, ignoring!" >&2' TERM + KERNEL_VERSION="$(uname -r)" [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut