[systemd-devel] [PATCH 2/2] systemctl: for switch-root check, if we switch to a systemd init

harald at redhat.com harald at redhat.com
Wed Mar 5 05:37:47 PST 2014


From: Harald Hoyer <harald at redhat.com>

If "systemctl switch-root" is called with a specific "INIT" or
/proc/cmdline contains "init=", then systemd would not serialize
itsself.

Let systemctl check, if the new init is in the standard systemd
installation path and if so, clear the INIT parameter,
to let systemd serialize itsself.
---
 src/systemctl/systemctl.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index f395265..18dbcc0 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4283,6 +4283,7 @@ static int show_environment(sd_bus *bus, char **args) {
 static int switch_root(sd_bus *bus, char **args) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_free_ char *init = NULL;
+        _cleanup_free_ char *root_systemd_path = NULL;
         const char *root;
         unsigned l;
         int r;
@@ -4309,6 +4310,16 @@ static int switch_root(sd_bus *bus, char **args) {
         if (!init)
                 return log_oom();
 
+        root_systemd_path = strjoin(root, "/", SYSTEMD_BINARY_PATH, NULL);
+        if (!root_systemd_path)
+                return log_oom();
+
+        if (files_same(init, root_systemd_path) > 0) {
+                char *t = init;
+                init = strdup("");
+                free(t);
+        }
+
         log_debug("switching root - root: %s; init: %s", root, init);
 
         r = sd_bus_call_method(
-- 
1.8.5.3



More information about the systemd-devel mailing list