X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Fdbus-manager.c;h=c341d36a6bb926cdccfcbd9aa319c07a032fe264;hp=b5b51133f4e238dd2adc984220020125749783a6;hb=96342de68d0d6de71a062d984dafd2a0905ed9fe;hpb=06dab8e18aebf822392c7ca66c5bf3c1200fdec8 diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index b5b51133f..c341d36a6 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" @@ -92,7 +94,6 @@ " \n" \ " \n" \ " \n" \ - " \n" \ " \n" \ " \n" \ " \n" \ @@ -112,7 +113,9 @@ " \n" \ " \n" \ " \n" \ - " \n" \ + " \n" \ + " \n" \ + " \n" \ " \n" \ " \n" \ " \n" \ @@ -125,6 +128,10 @@ " \n" \ " \n" \ " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ " \n" \ " \n" \ " \n" \ @@ -136,7 +143,7 @@ " \n" \ " \n" \ " \n" \ - " \n" \ + " \n" \ " \n" \ " \n" \ " \n" \ @@ -219,7 +226,6 @@ " \n" \ " \n" \ " \n" \ - " \n" \ " \n" \ " \n" \ " \n" \ @@ -237,23 +243,12 @@ " \n" \ " \n" \ " \n" \ - " \n" \ " \n" \ " \n" \ " \n" \ " \n" \ " \n" \ - " \n" \ - " \n" - -#ifdef HAVE_SYSV_COMPAT -#define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV \ - " \n" \ - " \n" \ - " \n" -#else -#define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV -#endif + " \n" #define BUS_MANAGER_INTERFACE_END \ " \n" @@ -263,7 +258,6 @@ BUS_MANAGER_INTERFACE_METHODS \ BUS_MANAGER_INTERFACE_SIGNALS \ BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL \ - BUS_MANAGER_INTERFACE_PROPERTIES_SYSV \ BUS_MANAGER_INTERFACE_END #define INTROSPECTION_BEGIN \ @@ -283,7 +277,6 @@ const char bus_manager_interface[] _introspect_("Manager") = BUS_MANAGER_INTERFACE; -static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_running_as, manager_running_as, ManagerRunningAs); static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_exec_output, exec_output, ExecOutput); static int bus_manager_append_tainted(DBusMessageIter *i, const char *property, void *data) { @@ -304,13 +297,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; @@ -501,20 +495,6 @@ static int bus_manager_send_unit_files_changed(Manager *m) { return r; } -static int bus_manager_append_have_watchdog(DBusMessageIter *i, const char *property, void *data) { - dbus_bool_t b; - - assert(i); - assert(property); - - b = access("/dev/watchdog", F_OK) >= 0; - - if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b)) - return -ENOMEM; - - return 0; -} - static int bus_manager_set_runtime_watchdog_usec(DBusMessageIter *i, const char *property, void *data) { uint64_t *t = data; @@ -539,7 +519,6 @@ static const BusProperty bus_systemd_properties[] = { }; static const BusProperty bus_manager_properties[] = { - { "RunningAs", bus_manager_append_running_as, "s", offsetof(Manager, running_as) }, { "Tainted", bus_manager_append_tainted, "s", 0 }, { "InitRDTimestamp", bus_property_append_uint64, "t", offsetof(Manager, initrd_timestamp.realtime) }, { "InitRDTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, initrd_timestamp.monotonic) }, @@ -558,19 +537,12 @@ static const BusProperty bus_manager_properties[] = { { "ConfirmSpawn", bus_property_append_bool, "b", offsetof(Manager, confirm_spawn) }, { "ShowStatus", bus_property_append_bool, "b", offsetof(Manager, show_status) }, { "UnitPath", bus_property_append_strv, "as", offsetof(Manager, lookup_paths.unit_path), true }, - { "NotifySocket", bus_property_append_string, "s", offsetof(Manager, notify_socket), true }, { "ControlGroupHierarchy", bus_property_append_string, "s", offsetof(Manager, cgroup_hierarchy), true }, { "DefaultControllers", bus_property_append_strv, "as", offsetof(Manager, default_controllers), true }, { "DefaultStandardOutput", bus_manager_append_exec_output, "s", offsetof(Manager, default_std_output) }, { "DefaultStandardError", bus_manager_append_exec_output, "s", offsetof(Manager, default_std_error) }, { "RuntimeWatchdogUSec", bus_property_append_usec, "t", offsetof(Manager, runtime_watchdog), false, bus_manager_set_runtime_watchdog_usec }, { "ShutdownWatchdogUSec", bus_property_append_usec, "t", offsetof(Manager, shutdown_watchdog), false, bus_property_set_usec }, - { "HaveWatchdog", bus_manager_append_have_watchdog, "b", 0 }, -#ifdef HAVE_SYSV_COMPAT - { "SysVConsole", bus_property_append_bool, "b", offsetof(Manager, sysv_console) }, - { "SysVInitPath", bus_property_append_strv, "as", offsetof(Manager, lookup_paths.sysvinit_path), true }, - { "SysVRcndPath", bus_property_append_strv, "as", offsetof(Manager, lookup_paths.sysvrcnd_path), true }, -#endif { NULL, } }; @@ -692,10 +664,9 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, reload_if_possible = true; job_type = JOB_TRY_RESTART; } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KillUnit")) { - const char *name, *swho, *smode; + const char *name, *swho; int32_t signo; Unit *u; - KillMode mode; KillWho who; if (!dbus_message_get_args( @@ -703,7 +674,6 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &swho, - DBUS_TYPE_STRING, &smode, DBUS_TYPE_INT32, &signo, DBUS_TYPE_INVALID)) return bus_send_error_reply(connection, message, &error, -EINVAL); @@ -716,23 +686,17 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, return bus_send_error_reply(connection, message, &error, -EINVAL); } - if (isempty(smode)) - mode = KILL_CONTROL_GROUP; - else { - mode = kill_mode_from_string(smode); - if (mode < 0) - return bus_send_error_reply(connection, message, &error, -EINVAL); - } - if (signo <= 0 || signo >= _NSIG) return bus_send_error_reply(connection, message, &error, -EINVAL); - if (!(u = manager_get_unit(m, name))) { + u = manager_get_unit(m, name); + if (!u) { dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name); return bus_send_error_reply(connection, message, &error, -ENOENT); } - if ((r = unit_kill(u, who, mode, signo, &error)) < 0) + r = unit_kill(u, who, signo, &error); + if (r < 0) return bus_send_error_reply(connection, message, &error, r); if (!(reply = dbus_message_new_method_return(message))) @@ -1176,6 +1140,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, "/") || !path_is_absolute(switch_root)) + return bus_send_error_reply(connection, message, NULL, -EINVAL); + + if (!isempty(switch_root_init) && !path_is_absolute(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 = strjoin(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; @@ -1521,6 +1549,11 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, job_type = JOB_RELOAD; } + if (job_type == JOB_STOP && u->load_state == UNIT_ERROR && unit_active_state(u) == UNIT_INACTIVE) { + dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", name); + return bus_send_error_reply(connection, message, &error, -EPERM); + } + if ((job_type == JOB_START && u->refuse_manual_start) || (job_type == JOB_STOP && u->refuse_manual_stop) || ((job_type == JOB_RESTART || job_type == JOB_TRY_RESTART) &&