ryantimwilson / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
661545
From 5e68640c5b25b3b682ca8ce92a4a573e8dfba6ae Mon Sep 17 00:00:00 2001
661545
From: Franck Bui <fbui@suse.com>
661545
Date: Thu, 24 Nov 2016 18:52:04 +0100
661545
Subject: [PATCH] core: make sure initrd-switch-root command survives PID1's
661545
 killing spree (#4730)
661545
661545
This is a different way to implement the fix proposed by commit
661545
a4021390fef27f4136497328f suggested by Lennart Poettering.
661545
661545
In this patch we instruct PID1 to not kill "systemctl switch-root" command
661545
started by initrd-switch-root service using the "argv[0][0]='@'" trick.
661545
661545
See: https://www.freedesktop.org/wiki/Software/systemd/RootStorageDaemons/ for
661545
more details.
661545
661545
We had to backup argv[0] because argv is modified by dispatch_verb().
661545
661545
(cherry picked from commit acc28e2e3037d689d6481e4664925cf31d4d087b)
661545
661545
Related: #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 f31137787a..f84b92ccbe 100644
661545
--- a/src/systemctl/systemctl.c
661545
+++ b/src/systemctl/systemctl.c
661545
@@ -128,6 +128,7 @@ static const char *arg_kill_who = NULL;
661545
 static int arg_signal = SIGTERM;
661545
 static const char *arg_root = NULL;
661545
 static usec_t arg_when = 0;
661545
+static char *argv_cmdline = NULL;
661545
 static enum action {
661545
         _ACTION_INVALID,
661545
         ACTION_SYSTEMCTL,
661545
@@ -5060,6 +5061,13 @@ static int switch_root(sd_bus *bus, char **args) {
661545
                         init = NULL;
661545
         }
661545
 
661545
+        /* Instruct PID1 to exclude us from its killing spree applied during
661545
+         * the transition from the initrd to the main system otherwise we would
661545
+         * exit with a failure status even though the switch to the new root
661545
+         * has succeed. */
661545
+        if (in_initrd())
661545
+                argv_cmdline[0] = '@';
661545
+
661545
         log_debug("Switching root - root: %s; init: %s", root, strna(init));
661545
 
661545
         r = sd_bus_call_method(
661545
@@ -7626,6 +7634,8 @@ int main(int argc, char*argv[]) {
661545
         _cleanup_bus_close_unref_ sd_bus *bus = NULL;
661545
         int r;
661545
 
661545
+        argv_cmdline = argv[0];
661545
+
661545
         setlocale(LC_ALL, "");
661545
         log_parse_environment();
661545
         log_open();