ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
ff2b41
From 928f72e2070685886c0266891a74ca266587755a Mon Sep 17 00:00:00 2001
ff2b41
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
ff2b41
Date: Mon, 30 Jan 2017 13:06:10 -0500
ff2b41
Subject: [PATCH] systemctl: ignore SIGTERM after switch root
ff2b41
ff2b41
https://bugzilla.redhat.com/show_bug.cgi?id=1414904#c14 and #c15.
ff2b41
(cherry picked from commit 8a7a9ceab204fb02fd5d93a765b36b31efeb9beb)
ff2b41
ff2b41
Resolves: #1754053
ff2b41
---
ff2b41
 src/systemctl/systemctl.c | 10 ++++++++++
ff2b41
 1 file changed, 10 insertions(+)
ff2b41
ff2b41
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
ff2b41
index 0928e2972a..398727cc7d 100644
ff2b41
--- a/src/systemctl/systemctl.c
ff2b41
+++ b/src/systemctl/systemctl.c
ff2b41
@@ -5066,6 +5066,14 @@ static int switch_root(sd_bus *bus, char **args) {
ff2b41
          * though the switch to the new root has succeed. */
ff2b41
         argv_cmdline[0] = '@';
ff2b41
 
ff2b41
+        /* If we are slow to exit after the root switch, the new systemd instance
ff2b41
+         * will send us a signal to terminate. Just ignore it and exit normally.
ff2b41
+         * This way the unit does not end up as failed.
ff2b41
+         */
ff2b41
+        r = ignore_signals(SIGTERM, -1);
ff2b41
+        if (r < 0)
ff2b41
+                log_warning_errno(r, "Failed to change disposition of SIGTERM to ignore: %m");
ff2b41
+
ff2b41
         log_debug("Switching root - root: %s; init: %s", root, strna(init));
ff2b41
 
ff2b41
         r = sd_bus_call_method(
ff2b41
@@ -5078,6 +5086,8 @@ static int switch_root(sd_bus *bus, char **args) {
ff2b41
                         NULL,
ff2b41
                         "ss", root, init);
ff2b41
         if (r < 0) {
ff2b41
+                (void) default_signals(SIGTERM, -1);
ff2b41
+
ff2b41
                 log_error("Failed to switch root: %s", bus_error_message(&error, r));
ff2b41
                 return r;
ff2b41
         }