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