richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
9fc0f6
From fee295c75582ada1c7cfe8a2b69f32d610d92020 Mon Sep 17 00:00:00 2001
9fc0f6
From: Lukas Nykryn <lnykryn@redhat.com>
9fc0f6
Date: Fri, 12 Sep 2014 13:27:36 +0200
9fc0f6
Subject: [PATCH] systemctl: unbreak switchroot
9fc0f6
9fc0f6
rhel-only patch
9fc0f6
cad8ec5980d63253586d9f884649c45eed0667a1 backport broke it
9fc0f6
9fc0f6
Related: #1138546
9fc0f6
---
9fc0f6
 src/systemctl/systemctl.c | 22 +++++++++++-----------
9fc0f6
 1 file changed, 11 insertions(+), 11 deletions(-)
9fc0f6
9fc0f6
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
9fc0f6
index 90a80bd..544025c 100644
9fc0f6
--- a/src/systemctl/systemctl.c
9fc0f6
+++ b/src/systemctl/systemctl.c
9fc0f6
@@ -4147,8 +4147,8 @@ static int show_enviroment(DBusConnection *bus, char **args) {
9fc0f6
 }
9fc0f6
 
9fc0f6
 static int switch_root(DBusConnection *bus, char **args) {
9fc0f6
-        _cleanup_free_ char *cmdline_init = NULL;
9fc0f6
-        const char *root, *init;
9fc0f6
+        _cleanup_free_ char *init = NULL;
9fc0f6
+        const char *root;
9fc0f6
         unsigned l;
9fc0f6
         int r;
9fc0f6
 
9fc0f6
@@ -4161,23 +4161,20 @@ static int switch_root(DBusConnection *bus, char **args) {
9fc0f6
         root = args[1];
9fc0f6
 
9fc0f6
         if (l >= 3)
9fc0f6
-                init = args[2];
9fc0f6
+                init = strdup(args[2]);
9fc0f6
         else {
9fc0f6
                 r = parse_env_file("/proc/cmdline", WHITESPACE,
9fc0f6
-                                   "init", &cmdline_init,
9fc0f6
+                                   "init", &init,
9fc0f6
                                    NULL);
9fc0f6
                 if (r < 0)
9fc0f6
                         log_debug("Failed to parse /proc/cmdline: %s", strerror(-r));
9fc0f6
 
9fc0f6
-                init = cmdline_init;
9fc0f6
+                if (!init)
9fc0f6
+                        init = strdup("");
9fc0f6
         }
9fc0f6
-        if (!init)
9fc0f6
-                return log_oom();
9fc0f6
 
9fc0f6
-        if (isempty(init))
9fc0f6
-                init = NULL;
9fc0f6
 
9fc0f6
-        if (init) {
9fc0f6
+        if (!isempty(init)) {
9fc0f6
                 const char *root_systemd_path = NULL, *root_init_path = NULL;
9fc0f6
 
9fc0f6
                 root_systemd_path = strappenda(root, "/" SYSTEMD_BINARY_PATH);
9fc0f6
@@ -4186,9 +4183,12 @@ static int switch_root(DBusConnection *bus, char **args) {
9fc0f6
                 /* If the passed init is actually the same as the
9fc0f6
                  * systemd binary, then let's suppress it. */
9fc0f6
                 if (files_same(root_init_path, root_systemd_path) > 0)
9fc0f6
-                        init = NULL;
9fc0f6
+                        init = strdup("");
9fc0f6
         }
9fc0f6
 
9fc0f6
+        if (!init)
9fc0f6
+                return log_oom();
9fc0f6
+
9fc0f6
         log_debug("Switching root - root: %s; init: %s", root, strna(init));
9fc0f6
 
9fc0f6
         return bus_method_call_with_reply(
9fc0f6
-- 
9fc0f6
1.8.3.1
9fc0f6