If the path to init is not specified as an argumnt to systemctl, but
init= is given on the kernel commandline, use that.

This means the initrd does not need glue code to parse the kernel
commandline before passing on init= to systemctl.

Cc: Harald Hoyer <har...@redhat.com>
Cc: Dave Reisner <dreis...@archlinux.org>
---
 src/systemctl/systemctl.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 7a19d06..fc1db1a 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -3323,7 +3323,9 @@ finish:
 
 static int switch_root(DBusConnection *bus, char **args) {
         unsigned l;
-        const char *root, *init;
+        int r;
+        const char *root;
+        char *init = NULL;
 
         l = strv_length(args);
         if (l < 2 || l > 3) {
@@ -3332,9 +3334,22 @@ static int switch_root(DBusConnection *bus, char **args) 
{
         }
 
         root = args[1];
-        init = l >= 3 ? args[2] : "";
 
-        return bus_method_call_with_reply (
+        if (l >= 3) {
+                init = strdup(args[2]);
+        } else {
+                parse_env_file("/proc/cmdline", WHITESPACE,
+                               "init", &init,
+                               NULL);
+
+                if (!init)
+                        init = strdup("");
+
+        }
+
+        log_debug("switching root - root: %s; init: %s", root, init);
+
+        r = bus_method_call_with_reply (
                         bus,
                         "org.freedesktop.systemd1",
                         "/org/freedesktop/systemd1",
@@ -3345,6 +3360,10 @@ static int switch_root(DBusConnection *bus, char **args) 
{
                         DBUS_TYPE_STRING, &root,
                         DBUS_TYPE_STRING, &init,
                         DBUS_TYPE_INVALID);
+
+        free(init);
+
+        return r;
 }
 
 static int set_environment(DBusConnection *bus, char **args) {
-- 
1.8.0.1

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to