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