f226d6
From cecc1fbae879c189739691ecff3df67d20b0899a Mon Sep 17 00:00:00 2001
f226d6
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
f226d6
Date: Tue, 16 Nov 2021 11:15:52 +0100
f226d6
Subject: [PATCH] fix(shutdown): be robust against forced shutdown
f226d6
f226d6
When a forced shutdown is issued through sending a burst of Ctrl-Alt-Del
f226d6
keys, systemd sends SIGTERM to all processes. This ends up killing
f226d6
dracut-initramfs-restore as well, preventing the script from detecting
f226d6
that the unpack of the initramfs is incomplete, which later causes a
f226d6
crash to happen when "shutdown" tries to execute from the unpacked
f226d6
initramfs.
f226d6
f226d6
This fix makes sure dracut-initramfs-restore remains alive to detect
f226d6
the unpack failed (because cpio was killed by systemd too).
f226d6
f226d6
Refs:
f226d6
 * https://bugzilla.redhat.com/show_bug.cgi?id=2023665
f226d6
(cherry picked from commit b9ba3c8bb8f0f1328cd1ffaa8dbf64585b28c474)
f226d6
f226d6
Resolves: #2024502
f226d6
---
f226d6
 dracut-initramfs-restore.sh | 5 +++++
f226d6
 1 file changed, 5 insertions(+)
f226d6
f226d6
diff --git a/dracut-initramfs-restore.sh b/dracut-initramfs-restore.sh
f226d6
index abe6b1e2..d97030a3 100644
f226d6
--- a/dracut-initramfs-restore.sh
f226d6
+++ b/dracut-initramfs-restore.sh
f226d6
@@ -6,6 +6,11 @@ set -e
f226d6
 [ -e /run/initramfs/bin/sh ] && exit 0
f226d6
 [ -e /run/initramfs/.need_shutdown ] || exit 0
f226d6
 
f226d6
+# SIGTERM signal is received upon forced shutdown: ignore the signal
f226d6
+# We want to remain alive to be able to trap unpacking errors to avoid
f226d6
+# switching root to an incompletely unpacked initramfs
f226d6
+trap 'echo "Received SIGTERM signal, ignoring!" >&2' TERM
f226d6
+
f226d6
 KERNEL_VERSION="$(uname -r)"
f226d6
 
f226d6
 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
f226d6