naccyde / rpms / systemd

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