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