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