teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
Blob Blame History Raw
From fee295c75582ada1c7cfe8a2b69f32d610d92020 Mon Sep 17 00:00:00 2001
From: Lukas Nykryn <lnykryn@redhat.com>
Date: Fri, 12 Sep 2014 13:27:36 +0200
Subject: [PATCH] systemctl: unbreak switchroot

rhel-only patch
cad8ec5980d63253586d9f884649c45eed0667a1 backport broke it

Related: #1138546
---
 src/systemctl/systemctl.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 90a80bd..544025c 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4147,8 +4147,8 @@ static int show_enviroment(DBusConnection *bus, char **args) {
 }
 
 static int switch_root(DBusConnection *bus, char **args) {
-        _cleanup_free_ char *cmdline_init = NULL;
-        const char *root, *init;
+        _cleanup_free_ char *init = NULL;
+        const char *root;
         unsigned l;
         int r;
 
@@ -4161,23 +4161,20 @@ static int switch_root(DBusConnection *bus, char **args) {
         root = args[1];
 
         if (l >= 3)
-                init = args[2];
+                init = strdup(args[2]);
         else {
                 r = parse_env_file("/proc/cmdline", WHITESPACE,
-                                   "init", &cmdline_init,
+                                   "init", &init,
                                    NULL);
                 if (r < 0)
                         log_debug("Failed to parse /proc/cmdline: %s", strerror(-r));
 
-                init = cmdline_init;
+                if (!init)
+                        init = strdup("");
         }
-        if (!init)
-                return log_oom();
 
-        if (isempty(init))
-                init = NULL;
 
-        if (init) {
+        if (!isempty(init)) {
                 const char *root_systemd_path = NULL, *root_init_path = NULL;
 
                 root_systemd_path = strappenda(root, "/" SYSTEMD_BINARY_PATH);
@@ -4186,9 +4183,12 @@ static int switch_root(DBusConnection *bus, char **args) {
                 /* If the passed init is actually the same as the
                  * systemd binary, then let's suppress it. */
                 if (files_same(root_init_path, root_systemd_path) > 0)
-                        init = NULL;
+                        init = strdup("");
         }
 
+        if (!init)
+                return log_oom();
+
         log_debug("Switching root - root: %s; init: %s", root, strna(init));
 
         return bus_method_call_with_reply(
-- 
1.8.3.1