X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fdbus-manager.c;h=33dcb56c09af48a36a63d498310afd962906ca14;hb=50913bc0c8ced894ceabc7e893c0fdf73af9a261;hp=6655f2940ca8b82ebae0871a35f9c38256455c04;hpb=e677bf7ef610acdc5068b9d5d4c79556a236e52f;p=elogind.git diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 6655f2940..33dcb56c0 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -31,6 +31,8 @@ #include "dbus-common.h" #include "install.h" #include "watchdog.h" +#include "hwclock.h" +#include "path-util.h" #define BUS_MANAGER_INTERFACE_BEGIN \ " \n" @@ -125,6 +127,10 @@ " \n" \ " \n" \ " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ " \n" \ " \n" \ " \n" \ @@ -198,10 +204,12 @@ " \n" \ " \n" \ " \n" \ + " \n" \ " \n" \ " \n" \ " \n" \ " \n" \ + " \n" \ " \n" \ " " \ " \n" \ @@ -302,13 +310,14 @@ static int bus_manager_append_tainted(DBusMessageIter *i, const char *property, free(p); if (access("/proc/cgroups", F_OK) < 0) - stpcpy(e, "cgroups-missing:"); + e = stpcpy(e, "cgroups-missing:"); if (hwclock_is_localtime() > 0) - stpcpy(e, "local-hwclock:"); + e = stpcpy(e, "local-hwclock:"); - if (endswith(buf, ":")) - buf[strlen(buf)-1] = 0; + /* remove the last ':' */ + if (e != buf) + e[-1] = 0; t = buf; @@ -1174,6 +1183,70 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, m->exit_code = MANAGER_KEXEC; + } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SwitchRoot")) { + const char *switch_root, *switch_root_init; + char *u, *v; + int k; + + if (!dbus_message_get_args( + message, + &error, + DBUS_TYPE_STRING, &switch_root, + DBUS_TYPE_STRING, &switch_root_init, + DBUS_TYPE_INVALID)) + return bus_send_error_reply(connection, message, &error, -EINVAL); + + if (path_equal(switch_root, "/") || !is_path(switch_root)) + return bus_send_error_reply(connection, message, NULL, -EINVAL); + + if (!isempty(switch_root_init) && !is_path(switch_root_init)) + return bus_send_error_reply(connection, message, NULL, -EINVAL); + + if (m->running_as != MANAGER_SYSTEM) { + dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Switching root is only supported for system managers."); + return bus_send_error_reply(connection, message, &error, -ENOTSUP); + } + + /* Safety check */ + if (isempty(switch_root_init)) + k = access(switch_root, F_OK); + else { + char *p; + + p = join(switch_root, "/", switch_root_init, NULL); + if (!p) + goto oom; + + k = access(p, X_OK); + free(p); + } + if (k < 0) + return bus_send_error_reply(connection, message, NULL, -errno); + + u = strdup(switch_root); + if (!u) + goto oom; + + if (!isempty(switch_root_init)) { + v = strdup(switch_root_init); + if (!v) { + free(u); + goto oom; + } + } else + v = NULL; + + free(m->switch_root); + free(m->switch_root_init); + m->switch_root = u; + m->switch_root_init = v; + + reply = dbus_message_new_method_return(message); + if (!reply) + goto oom; + + m->exit_code = MANAGER_SWITCH_ROOT; + } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetEnvironment")) { char **l = NULL, **e = NULL;