5d6eedd
From 409612865dd716752da4785b5d8cb75a24cebab4 Mon Sep 17 00:00:00 2001
03e93e2
From: Franck Bui <fbui@suse.com>
03e93e2
Date: Wed, 23 Nov 2016 16:31:24 +0100
03e93e2
Subject: [PATCH] core: consider SIGTERM as a clean exit status for
03e93e2
 initrd-switch-root.service (#4713)
03e93e2
03e93e2
Since commit 1f0958f640b8717, systemd considers SIGTERM for short-running
03e93e2
services (aka Type=oneshot) as a failure.
03e93e2
03e93e2
This can be an issue with initrd-switch-root.service as the command run by this
03e93e2
service (in order to switch to the new rootfs) may still be running when
03e93e2
systemd does the switch.
03e93e2
03e93e2
However PID1 sends SIGTERM to all remaining processes right before
03e93e2
switching and initrd-switch-root.service can be one of those.
03e93e2
03e93e2
After systemd is reexecuted and its previous state is deserialized, systemd
03e93e2
notices that initrd-switch-root.service was killed with SIGTERM and considers
03e93e2
this as a failure which leads to the emergency shell.
03e93e2
03e93e2
To prevent this, this patch teaches systemd to consider a SIGTERM exit as a
03e93e2
clean one for this service.
03e93e2
03e93e2
It also removes "KillMode=none" since this is pretty useless as the service is
03e93e2
never stopped by systemd but it either exits normally or it's killed by a
03e93e2
SIGTERM as described previously.
03e93e2
(cherry picked from commit a4021390fef27f4136497328f2e35e79bc88855d)
03e93e2
---
03e93e2
 units/initrd-switch-root.service.in | 8 +++++++-
03e93e2
 1 file changed, 7 insertions(+), 1 deletion(-)
03e93e2
03e93e2
diff --git a/units/initrd-switch-root.service.in b/units/initrd-switch-root.service.in
03e93e2
index 82893dafb1..b89f2348c7 100644
03e93e2
--- a/units/initrd-switch-root.service.in
03e93e2
+++ b/units/initrd-switch-root.service.in
03e93e2
@@ -17,4 +17,10 @@ AllowIsolate=yes
03e93e2
 Type=oneshot
03e93e2
 # we have to use "--force" here, otherwise systemd would umount /run
03e93e2
 ExecStart=@rootbindir@/systemctl --no-block --force switch-root /sysroot
03e93e2
-KillMode=none
03e93e2
+
03e93e2
+# Just before switching to the new rootfs, systemd might send us a TERM signal
03e93e2
+# depending on how fast we are to execute the main command and exit. If we get
03e93e2
+# the SIGTERM signal that simply means that we succeed but haven't got enough
03e93e2
+# time to exit properly. Since systemd considers SIGTERM as a failure for
03e93e2
+# short-running process (aka Type=oneshot), instruct it to ignore this case.
03e93e2
+SuccessExitStatus=SIGTERM