1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 #include "dbus-manager.h"
29 #include "bus-errors.h"
31 #include "dbus-common.h"
34 #define BUS_MANAGER_INTERFACE_BEGIN \
35 " <interface name=\"org.freedesktop.systemd1.Manager\">\n"
37 #define BUS_MANAGER_INTERFACE_METHODS \
38 " <method name=\"GetUnit\">\n" \
39 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
40 " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
42 " <method name=\"GetUnitByPID\">\n" \
43 " <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n" \
44 " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
46 " <method name=\"LoadUnit\">\n" \
47 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
48 " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
50 " <method name=\"StartUnit\">\n" \
51 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
52 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
53 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
55 " <method name=\"StartUnitReplace\">\n" \
56 " <arg name=\"old_unit\" type=\"s\" direction=\"in\"/>\n" \
57 " <arg name=\"new_unit\" type=\"s\" direction=\"in\"/>\n" \
58 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
59 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
61 " <method name=\"StopUnit\">\n" \
62 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
63 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
64 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
66 " <method name=\"ReloadUnit\">\n" \
67 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
68 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
69 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
71 " <method name=\"RestartUnit\">\n" \
72 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
73 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
74 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
76 " <method name=\"TryRestartUnit\">\n" \
77 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
78 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
79 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
81 " <method name=\"ReloadOrRestartUnit\">\n" \
82 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
83 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
84 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
86 " <method name=\"ReloadOrTryRestartUnit\">\n" \
87 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
88 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
89 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
91 " <method name=\"KillUnit\">\n" \
92 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
93 " <arg name=\"who\" type=\"s\" direction=\"in\"/>\n" \
94 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
95 " <arg name=\"signal\" type=\"i\" direction=\"in\"/>\n" \
97 " <method name=\"ResetFailedUnit\">\n" \
98 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
100 " <method name=\"GetJob\">\n" \
101 " <arg name=\"id\" type=\"u\" direction=\"in\"/>\n" \
102 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
104 " <method name=\"ClearJobs\"/>\n" \
105 " <method name=\"ResetFailed\"/>\n" \
106 " <method name=\"ListUnits\">\n" \
107 " <arg name=\"units\" type=\"a(ssssssouso)\" direction=\"out\"/>\n" \
109 " <method name=\"ListJobs\">\n" \
110 " <arg name=\"jobs\" type=\"a(usssoo)\" direction=\"out\"/>\n" \
112 " <method name=\"Subscribe\"/>\n" \
113 " <method name=\"Unsubscribe\"/>\n" \
114 " <method name=\"Dump\"/>\n" \
115 " <method name=\"CreateSnapshot\">\n" \
116 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
117 " <arg name=\"cleanup\" type=\"b\" direction=\"in\"/>\n" \
118 " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
120 " <method name=\"Reload\"/>\n" \
121 " <method name=\"Reexecute\"/>\n" \
122 " <method name=\"Exit\"/>\n" \
123 " <method name=\"Reboot\"/>\n" \
124 " <method name=\"PowerOff\"/>\n" \
125 " <method name=\"Halt\"/>\n" \
126 " <method name=\"KExec\"/>\n" \
127 " <method name=\"SetEnvironment\">\n" \
128 " <arg name=\"names\" type=\"as\" direction=\"in\"/>\n" \
130 " <method name=\"UnsetEnvironment\">\n" \
131 " <arg name=\"names\" type=\"as\" direction=\"in\"/>\n" \
133 " <method name=\"UnsetAndSetEnvironment\">\n" \
134 " <arg name=\"unset\" type=\"as\" direction=\"in\"/>\n" \
135 " <arg name=\"set\" type=\"as\" direction=\"in\"/>\n" \
137 " <method name=\"ListUnitFiles\">\n" \
138 " <arg name=\"changes\" type=\"a(ss)\" direction=\"out\"/>\n" \
140 " <method name=\"GetUnitFileState\">\n" \
141 " <arg name=\"file\" type=\"s\" direction=\"in\"/>\n" \
142 " <arg name=\"state\" type=\"s\" direction=\"out\"/>\n" \
144 " <method name=\"EnableUnitFiles\">\n" \
145 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
146 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
147 " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
148 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
150 " <method name=\"DisableUnitFiles\">\n" \
151 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
152 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
153 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
155 " <method name=\"ReenableUnitFiles\">\n" \
156 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
157 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
158 " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
159 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
161 " <method name=\"LinkUnitFiles\">\n" \
162 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
163 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
164 " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
165 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
167 " <method name=\"PresetUnitFiles\">\n" \
168 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
169 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
170 " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
171 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
173 " <method name=\"MaskUnitFiles\">\n" \
174 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
175 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
176 " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
177 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
179 " <method name=\"UnmaskUnitFiles\">\n" \
180 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
181 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
182 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
185 #define BUS_MANAGER_INTERFACE_SIGNALS \
186 " <signal name=\"UnitNew\">\n" \
187 " <arg name=\"id\" type=\"s\"/>\n" \
188 " <arg name=\"unit\" type=\"o\"/>\n" \
190 " <signal name=\"UnitRemoved\">\n" \
191 " <arg name=\"id\" type=\"s\"/>\n" \
192 " <arg name=\"unit\" type=\"o\"/>\n" \
194 " <signal name=\"JobNew\">\n" \
195 " <arg name=\"id\" type=\"u\"/>\n" \
196 " <arg name=\"job\" type=\"o\"/>\n" \
198 " <signal name=\"JobRemoved\">\n" \
199 " <arg name=\"id\" type=\"u\"/>\n" \
200 " <arg name=\"job\" type=\"o\"/>\n" \
201 " <arg name=\"result\" type=\"s\"/>\n" \
203 " <signal name=\"StartupFinished\">\n" \
204 " <arg name=\"kernel\" type=\"t\"/>\n" \
205 " <arg name=\"initrd\" type=\"t\"/>\n" \
206 " <arg name=\"userspace\" type=\"t\"/>\n" \
207 " <arg name=\"total\" type=\"t\"/>\n" \
209 " <signal name=\"UnitFilesChanged\"/>\n"
211 #define BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL \
212 " <property name=\"Version\" type=\"s\" access=\"read\"/>\n" \
213 " <property name=\"Distribution\" type=\"s\" access=\"read\"/>\n" \
214 " <property name=\"Features\" type=\"s\" access=\"read\"/>\n" \
215 " <property name=\"Tainted\" type=\"s\" access=\"read\"/>\n" \
216 " <property name=\"RunningAs\" type=\"s\" access=\"read\"/>\n" \
217 " <property name=\"InitRDTimestamp\" type=\"t\" access=\"read\"/>\n" \
218 " <property name=\"InitRDTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
219 " <property name=\"StartupTimestamp\" type=\"t\" access=\"read\"/>\n" \
220 " <property name=\"StartupTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
221 " <property name=\"FinishTimestamp\" type=\"t\" access=\"read\"/>\n" \
222 " <property name=\"FinishTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
223 " <property name=\"LogLevel\" type=\"s\" access=\"readwrite\"/>\n" \
224 " <property name=\"LogTarget\" type=\"s\" access=\"readwrite\"/>\n" \
225 " <property name=\"NNames\" type=\"u\" access=\"read\"/>\n" \
226 " <property name=\"NJobs\" type=\"u\" access=\"read\"/>\n" \
227 " <property name=\"NInstalledJobs\" type=\"u\" access=\"read\"/>\n" \
228 " <property name=\"NFailedJobs\" type=\"u\" access=\"read\"/>\n" \
229 " <property name=\"Progress\" type=\"d\" access=\"read\"/>\n" \
230 " <property name=\"Environment\" type=\"as\" access=\"read\"/>\n" \
231 " <property name=\"ConfirmSpawn\" type=\"b\" access=\"read\"/>\n" \
232 " <property name=\"ShowStatus\" type=\"b\" access=\"read\"/>\n" \
233 " <property name=\"UnitPath\" type=\"as\" access=\"read\"/>\n" \
234 " <property name=\"NotifySocket\" type=\"s\" access=\"read\"/>\n" \
235 " <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
236 " <property name=\"MountAuto\" type=\"b\" access=\"read\"/>\n" \
237 " <property name=\"SwapAuto\" type=\"b\" access=\"read\"/>\n" \
238 " <property name=\"DefaultControllers\" type=\"as\" access=\"read\"/>\n" \
239 " <property name=\"DefaultStandardOutput\" type=\"s\" access=\"read\"/>\n" \
240 " <property name=\"DefaultStandardError\" type=\"s\" access=\"read\"/>\n"
242 #ifdef HAVE_SYSV_COMPAT
243 #define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV \
244 " <property name=\"SysVConsole\" type=\"b\" access=\"read\"/>\n" \
245 " <property name=\"SysVInitPath\" type=\"as\" access=\"read\"/>\n" \
246 " <property name=\"SysVRcndPath\" type=\"as\" access=\"read\"/>\n"
248 #define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV
251 #define BUS_MANAGER_INTERFACE_END \
254 #define BUS_MANAGER_INTERFACE \
255 BUS_MANAGER_INTERFACE_BEGIN \
256 BUS_MANAGER_INTERFACE_METHODS \
257 BUS_MANAGER_INTERFACE_SIGNALS \
258 BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL \
259 BUS_MANAGER_INTERFACE_PROPERTIES_SYSV \
260 BUS_MANAGER_INTERFACE_END
262 #define INTROSPECTION_BEGIN \
263 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
265 BUS_MANAGER_INTERFACE \
266 BUS_PROPERTIES_INTERFACE \
268 BUS_INTROSPECTABLE_INTERFACE
270 #define INTROSPECTION_END \
273 #define INTERFACES_LIST \
274 BUS_GENERIC_INTERFACES_LIST \
275 "org.freedesktop.systemd1.Manager\0"
277 const char bus_manager_interface[] _introspect_("Manager") = BUS_MANAGER_INTERFACE;
279 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_running_as, manager_running_as, ManagerRunningAs);
280 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_exec_output, exec_output, ExecOutput);
282 static int bus_manager_append_tainted(DBusMessageIter *i, const char *property, void *data) {
285 char buf[LINE_MAX] = "", *e = buf, *p = NULL;
292 e = stpcpy(e, "usr-separate-fs ");
294 if (readlink_malloc("/etc/mtab", &p) < 0)
295 e = stpcpy(e, "etc-mtab-not-symlink ");
299 if (access("/proc/cgroups", F_OK) < 0)
300 e = stpcpy(e, "cgroups-missing ");
304 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
310 static int bus_manager_append_log_target(DBusMessageIter *i, const char *property, void *data) {
316 t = log_target_to_string(log_get_target());
318 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
324 static int bus_manager_set_log_target(DBusMessageIter *i, const char *property) {
330 dbus_message_iter_get_basic(i, &t);
332 return log_set_target_from_string(t);
335 static int bus_manager_append_log_level(DBusMessageIter *i, const char *property, void *data) {
341 t = log_level_to_string(log_get_max_level());
343 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
349 static int bus_manager_set_log_level(DBusMessageIter *i, const char *property) {
355 dbus_message_iter_get_basic(i, &t);
357 return log_set_max_level_from_string(t);
360 static int bus_manager_append_n_names(DBusMessageIter *i, const char *property, void *data) {
368 u = hashmap_size(m->units);
370 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
376 static int bus_manager_append_n_jobs(DBusMessageIter *i, const char *property, void *data) {
384 u = hashmap_size(m->jobs);
386 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
392 static int bus_manager_append_progress(DBusMessageIter *i, const char *property, void *data) {
400 if (dual_timestamp_is_set(&m->finish_timestamp))
403 d = 1.0 - ((double) hashmap_size(m->jobs) / (double) m->n_installed_jobs);
405 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_DOUBLE, &d))
411 static const char *message_get_sender_with_fallback(DBusMessage *m) {
416 if ((s = dbus_message_get_sender(m)))
419 /* When the message came in from a direct connection the
420 * message will have no sender. We fix that here. */
425 static DBusMessage *message_from_file_changes(DBusMessage *m, UnitFileChange *changes, unsigned n_changes) {
426 DBusMessageIter iter, sub, sub2;
432 reply = dbus_message_new_method_return(m);
436 dbus_message_iter_init_append(reply, &iter);
438 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(sss)", &sub))
441 for (i = 0; i < n_changes; i++) {
442 const char *type, *path, *source;
444 type = unit_file_change_type_to_string(changes[i].type);
445 path = strempty(changes[i].path);
446 source = strempty(changes[i].source);
448 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
449 !dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &type) ||
450 !dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &path) ||
451 !dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &source) ||
452 !dbus_message_iter_close_container(&sub, &sub2))
456 if (!dbus_message_iter_close_container(&iter, &sub))
462 dbus_message_unref(reply);
466 static int bus_manager_send_unit_files_changed(Manager *m) {
470 s = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
474 r = bus_broadcast(m, s);
475 dbus_message_unref(s);
480 static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
483 const BusProperty properties[] = {
484 { "org.freedesktop.systemd1.Manager", "Version", bus_property_append_string, "s", PACKAGE_STRING },
485 { "org.freedesktop.systemd1.Manager", "Distribution", bus_property_append_string, "s", DISTRIBUTION },
486 { "org.freedesktop.systemd1.Manager", "Features", bus_property_append_string, "s", SYSTEMD_FEATURES },
487 { "org.freedesktop.systemd1.Manager", "RunningAs", bus_manager_append_running_as, "s", &m->running_as },
488 { "org.freedesktop.systemd1.Manager", "Tainted", bus_manager_append_tainted, "s", m },
489 { "org.freedesktop.systemd1.Manager", "InitRDTimestamp", bus_property_append_uint64, "t", &m->initrd_timestamp.realtime },
490 { "org.freedesktop.systemd1.Manager", "InitRDTimestampMonotonic", bus_property_append_uint64, "t", &m->initrd_timestamp.monotonic },
491 { "org.freedesktop.systemd1.Manager", "StartupTimestamp", bus_property_append_uint64, "t", &m->startup_timestamp.realtime },
492 { "org.freedesktop.systemd1.Manager", "StartupTimestampMonotonic", bus_property_append_uint64, "t", &m->startup_timestamp.monotonic },
493 { "org.freedesktop.systemd1.Manager", "FinishTimestamp", bus_property_append_uint64, "t", &m->finish_timestamp.realtime },
494 { "org.freedesktop.systemd1.Manager", "FinishTimestampMonotonic", bus_property_append_uint64, "t",&m->finish_timestamp.monotonic },
495 { "org.freedesktop.systemd1.Manager", "LogLevel", bus_manager_append_log_level, "s", m, bus_manager_set_log_level },
496 { "org.freedesktop.systemd1.Manager", "LogTarget", bus_manager_append_log_target, "s", m, bus_manager_set_log_target },
497 { "org.freedesktop.systemd1.Manager", "NNames", bus_manager_append_n_names, "u", m },
498 { "org.freedesktop.systemd1.Manager", "NJobs", bus_manager_append_n_jobs, "u", m },
499 { "org.freedesktop.systemd1.Manager", "NInstalledJobs",bus_property_append_uint32, "u", &m->n_installed_jobs },
500 { "org.freedesktop.systemd1.Manager", "NFailedJobs", bus_property_append_uint32, "u", &m->n_failed_jobs },
501 { "org.freedesktop.systemd1.Manager", "Progress", bus_manager_append_progress, "d", m },
502 { "org.freedesktop.systemd1.Manager", "Environment", bus_property_append_strv, "as", m->environment },
503 { "org.freedesktop.systemd1.Manager", "ConfirmSpawn", bus_property_append_bool, "b", &m->confirm_spawn },
504 { "org.freedesktop.systemd1.Manager", "ShowStatus", bus_property_append_bool, "b", &m->show_status },
505 { "org.freedesktop.systemd1.Manager", "UnitPath", bus_property_append_strv, "as", m->lookup_paths.unit_path },
506 { "org.freedesktop.systemd1.Manager", "NotifySocket", bus_property_append_string, "s", m->notify_socket },
507 { "org.freedesktop.systemd1.Manager", "ControlGroupHierarchy", bus_property_append_string, "s", m->cgroup_hierarchy },
508 { "org.freedesktop.systemd1.Manager", "MountAuto", bus_property_append_bool, "b", &m->mount_auto },
509 { "org.freedesktop.systemd1.Manager", "SwapAuto", bus_property_append_bool, "b", &m->swap_auto },
510 { "org.freedesktop.systemd1.Manager", "DefaultControllers", bus_property_append_strv, "as", m->default_controllers },
511 { "org.freedesktop.systemd1.Manager", "DefaultStandardOutput", bus_manager_append_exec_output, "s", &m->default_std_output },
512 { "org.freedesktop.systemd1.Manager", "DefaultStandardError", bus_manager_append_exec_output, "s", &m->default_std_error },
513 #ifdef HAVE_SYSV_COMPAT
514 { "org.freedesktop.systemd1.Manager", "SysVConsole", bus_property_append_bool, "b", &m->sysv_console },
515 { "org.freedesktop.systemd1.Manager", "SysVInitPath", bus_property_append_strv, "as", m->lookup_paths.sysvinit_path },
516 { "org.freedesktop.systemd1.Manager", "SysVRcndPath", bus_property_append_strv, "as", m->lookup_paths.sysvrcnd_path },
518 { NULL, NULL, NULL, NULL, NULL }
523 DBusMessage *reply = NULL;
525 JobType job_type = _JOB_TYPE_INVALID;
526 bool reload_if_possible = false;
533 dbus_error_init(&error);
535 member = dbus_message_get_member(message);
537 if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnit")) {
541 if (!dbus_message_get_args(
544 DBUS_TYPE_STRING, &name,
546 return bus_send_error_reply(connection, message, &error, -EINVAL);
548 if (!(u = manager_get_unit(m, name))) {
549 dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
550 return bus_send_error_reply(connection, message, &error, -ENOENT);
553 if (!(reply = dbus_message_new_method_return(message)))
556 if (!(path = unit_dbus_path(u)))
559 if (!dbus_message_append_args(
561 DBUS_TYPE_OBJECT_PATH, &path,
564 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitByPID")) {
568 if (!dbus_message_get_args(
571 DBUS_TYPE_UINT32, &pid,
573 return bus_send_error_reply(connection, message, &error, -EINVAL);
575 if (!(u = cgroup_unit_by_pid(m, (pid_t) pid))) {
576 dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "No unit for PID %lu is loaded.", (unsigned long) pid);
577 return bus_send_error_reply(connection, message, &error, -ENOENT);
580 if (!(reply = dbus_message_new_method_return(message)))
583 if (!(path = unit_dbus_path(u)))
586 if (!dbus_message_append_args(
588 DBUS_TYPE_OBJECT_PATH, &path,
591 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "LoadUnit")) {
595 if (!dbus_message_get_args(
598 DBUS_TYPE_STRING, &name,
600 return bus_send_error_reply(connection, message, &error, -EINVAL);
602 if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
603 return bus_send_error_reply(connection, message, &error, r);
605 if (!(reply = dbus_message_new_method_return(message)))
608 if (!(path = unit_dbus_path(u)))
611 if (!dbus_message_append_args(
613 DBUS_TYPE_OBJECT_PATH, &path,
617 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnit"))
618 job_type = JOB_START;
619 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnitReplace"))
620 job_type = JOB_START;
621 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StopUnit"))
623 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadUnit"))
624 job_type = JOB_RELOAD;
625 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "RestartUnit"))
626 job_type = JOB_RESTART;
627 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "TryRestartUnit"))
628 job_type = JOB_TRY_RESTART;
629 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrRestartUnit")) {
630 reload_if_possible = true;
631 job_type = JOB_RESTART;
632 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrTryRestartUnit")) {
633 reload_if_possible = true;
634 job_type = JOB_TRY_RESTART;
635 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KillUnit")) {
636 const char *name, *swho, *smode;
642 if (!dbus_message_get_args(
645 DBUS_TYPE_STRING, &name,
646 DBUS_TYPE_STRING, &swho,
647 DBUS_TYPE_STRING, &smode,
648 DBUS_TYPE_INT32, &signo,
650 return bus_send_error_reply(connection, message, &error, -EINVAL);
655 who = kill_who_from_string(swho);
657 return bus_send_error_reply(connection, message, &error, -EINVAL);
661 mode = KILL_CONTROL_GROUP;
663 mode = kill_mode_from_string(smode);
665 return bus_send_error_reply(connection, message, &error, -EINVAL);
668 if (signo <= 0 || signo >= _NSIG)
669 return bus_send_error_reply(connection, message, &error, -EINVAL);
671 if (!(u = manager_get_unit(m, name))) {
672 dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
673 return bus_send_error_reply(connection, message, &error, -ENOENT);
676 if ((r = unit_kill(u, who, mode, signo, &error)) < 0)
677 return bus_send_error_reply(connection, message, &error, r);
679 if (!(reply = dbus_message_new_method_return(message)))
682 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetJob")) {
686 if (!dbus_message_get_args(
689 DBUS_TYPE_UINT32, &id,
691 return bus_send_error_reply(connection, message, &error, -EINVAL);
693 if (!(j = manager_get_job(m, id))) {
694 dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
695 return bus_send_error_reply(connection, message, &error, -ENOENT);
698 if (!(reply = dbus_message_new_method_return(message)))
701 if (!(path = job_dbus_path(j)))
704 if (!dbus_message_append_args(
706 DBUS_TYPE_OBJECT_PATH, &path,
710 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ClearJobs")) {
712 manager_clear_jobs(m);
714 if (!(reply = dbus_message_new_method_return(message)))
717 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailed")) {
719 manager_reset_failed(m);
721 if (!(reply = dbus_message_new_method_return(message)))
724 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailedUnit")) {
728 if (!dbus_message_get_args(
731 DBUS_TYPE_STRING, &name,
733 return bus_send_error_reply(connection, message, &error, -EINVAL);
735 if (!(u = manager_get_unit(m, name))) {
736 dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
737 return bus_send_error_reply(connection, message, &error, -ENOENT);
740 unit_reset_failed(u);
742 if (!(reply = dbus_message_new_method_return(message)))
745 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListUnits")) {
746 DBusMessageIter iter, sub;
751 if (!(reply = dbus_message_new_method_return(message)))
754 dbus_message_iter_init_append(reply, &iter);
756 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ssssssouso)", &sub))
759 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
760 char *u_path, *j_path;
761 const char *description, *load_state, *active_state, *sub_state, *sjob_type, *following;
762 DBusMessageIter sub2;
769 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
772 description = unit_description(u);
773 load_state = unit_load_state_to_string(u->meta.load_state);
774 active_state = unit_active_state_to_string(unit_active_state(u));
775 sub_state = unit_sub_state_to_string(u);
777 f = unit_following(u);
778 following = f ? f->meta.id : "";
780 if (!(u_path = unit_dbus_path(u)))
784 job_id = (uint32_t) u->meta.job->id;
786 if (!(j_path = job_dbus_path(u->meta.job))) {
791 sjob_type = job_type_to_string(u->meta.job->type);
798 if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &u->meta.id) ||
799 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &description) ||
800 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &load_state) ||
801 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &active_state) ||
802 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sub_state) ||
803 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &following) ||
804 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path) ||
805 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &job_id) ||
806 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sjob_type) ||
807 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path)) {
818 if (!dbus_message_iter_close_container(&sub, &sub2))
822 if (!dbus_message_iter_close_container(&iter, &sub))
825 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListJobs")) {
826 DBusMessageIter iter, sub;
830 if (!(reply = dbus_message_new_method_return(message)))
833 dbus_message_iter_init_append(reply, &iter);
835 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(usssoo)", &sub))
838 HASHMAP_FOREACH(j, m->jobs, i) {
839 char *u_path, *j_path;
840 const char *state, *type;
842 DBusMessageIter sub2;
844 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
847 id = (uint32_t) j->id;
848 state = job_state_to_string(j->state);
849 type = job_type_to_string(j->type);
851 if (!(j_path = job_dbus_path(j)))
854 if (!(u_path = unit_dbus_path(j->unit))) {
859 if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &id) ||
860 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &j->unit->meta.id) ||
861 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &type) ||
862 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &state) ||
863 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path) ||
864 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path)) {
873 if (!dbus_message_iter_close_container(&sub, &sub2))
877 if (!dbus_message_iter_close_container(&iter, &sub))
880 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Subscribe")) {
884 if (!(s = BUS_CONNECTION_SUBSCRIBED(m, connection))) {
885 if (!(s = set_new(string_hash_func, string_compare_func)))
888 if (!(dbus_connection_set_data(connection, m->subscribed_data_slot, s, NULL))) {
894 if (!(client = strdup(message_get_sender_with_fallback(message))))
897 if ((r = set_put(s, client)) < 0) {
899 return bus_send_error_reply(connection, message, NULL, r);
902 if (!(reply = dbus_message_new_method_return(message)))
905 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Unsubscribe")) {
908 if (!(client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) message_get_sender_with_fallback(message)))) {
909 dbus_set_error(&error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
910 return bus_send_error_reply(connection, message, &error, -ENOENT);
915 if (!(reply = dbus_message_new_method_return(message)))
918 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Dump")) {
923 if (!(reply = dbus_message_new_method_return(message)))
926 if (!(f = open_memstream(&dump, &size)))
929 manager_dump_units(m, f, NULL);
930 manager_dump_jobs(m, f, NULL);
940 if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &dump, DBUS_TYPE_INVALID)) {
946 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "CreateSnapshot")) {
951 if (!dbus_message_get_args(
954 DBUS_TYPE_STRING, &name,
955 DBUS_TYPE_BOOLEAN, &cleanup,
957 return bus_send_error_reply(connection, message, &error, -EINVAL);
959 if (name && name[0] == 0)
962 if ((r = snapshot_create(m, name, cleanup, &error, &s)) < 0)
963 return bus_send_error_reply(connection, message, &error, r);
965 if (!(reply = dbus_message_new_method_return(message)))
968 if (!(path = unit_dbus_path(UNIT(s))))
971 if (!dbus_message_append_args(
973 DBUS_TYPE_OBJECT_PATH, &path,
977 } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
978 char *introspection = NULL;
986 if (!(reply = dbus_message_new_method_return(message)))
989 /* We roll our own introspection code here, instead of
990 * relying on bus_default_message_handler() because we
991 * need to generate our introspection string
994 if (!(f = open_memstream(&introspection, &size)))
997 fputs(INTROSPECTION_BEGIN, f);
999 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
1002 if (k != u->meta.id)
1005 if (!(p = bus_path_escape(k))) {
1007 free(introspection);
1011 fprintf(f, "<node name=\"unit/%s\"/>", p);
1015 HASHMAP_FOREACH(j, m->jobs, i)
1016 fprintf(f, "<node name=\"job/%lu\"/>", (unsigned long) j->id);
1018 fputs(INTROSPECTION_END, f);
1022 free(introspection);
1031 if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID)) {
1032 free(introspection);
1036 free(introspection);
1038 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reload")) {
1040 assert(!m->queued_message);
1042 /* Instead of sending the reply back right away, we
1043 * just remember that we need to and then send it
1044 * after the reload is finished. That way the caller
1045 * knows when the reload finished. */
1047 if (!(m->queued_message = dbus_message_new_method_return(message)))
1050 m->queued_message_connection = connection;
1051 m->exit_code = MANAGER_RELOAD;
1053 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reexecute")) {
1055 /* We don't send a reply back here, the client should
1056 * just wait for us disconnecting. */
1058 m->exit_code = MANAGER_REEXECUTE;
1060 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
1062 if (m->running_as == MANAGER_SYSTEM) {
1063 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
1064 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1067 if (!(reply = dbus_message_new_method_return(message)))
1070 m->exit_code = MANAGER_EXIT;
1072 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reboot")) {
1074 if (m->running_as != MANAGER_SYSTEM) {
1075 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
1076 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1079 if (!(reply = dbus_message_new_method_return(message)))
1082 m->exit_code = MANAGER_REBOOT;
1084 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "PowerOff")) {
1086 if (m->running_as != MANAGER_SYSTEM) {
1087 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
1088 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1091 if (!(reply = dbus_message_new_method_return(message)))
1094 m->exit_code = MANAGER_POWEROFF;
1096 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Halt")) {
1098 if (m->running_as != MANAGER_SYSTEM) {
1099 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Halting is only supported for system managers.");
1100 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1103 if (!(reply = dbus_message_new_method_return(message)))
1106 m->exit_code = MANAGER_HALT;
1108 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KExec")) {
1110 if (m->running_as != MANAGER_SYSTEM) {
1111 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "kexec is only supported for system managers.");
1112 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1115 if (!(reply = dbus_message_new_method_return(message)))
1118 m->exit_code = MANAGER_KEXEC;
1120 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetEnvironment")) {
1121 char **l = NULL, **e = NULL;
1123 if ((r = bus_parse_strv(message, &l)) < 0) {
1127 return bus_send_error_reply(connection, message, NULL, r);
1130 e = strv_env_merge(2, m->environment, l);
1136 if (!(reply = dbus_message_new_method_return(message))) {
1141 strv_free(m->environment);
1144 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetEnvironment")) {
1145 char **l = NULL, **e = NULL;
1147 if ((r = bus_parse_strv(message, &l)) < 0) {
1151 return bus_send_error_reply(connection, message, NULL, r);
1154 e = strv_env_delete(m->environment, 1, l);
1160 if (!(reply = dbus_message_new_method_return(message))) {
1165 strv_free(m->environment);
1168 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetAndSetEnvironment")) {
1169 char **l_set = NULL, **l_unset = NULL, **e = NULL, **f = NULL;
1170 DBusMessageIter iter;
1172 if (!dbus_message_iter_init(message, &iter))
1175 r = bus_parse_strv_iter(&iter, &l_unset);
1180 return bus_send_error_reply(connection, message, NULL, r);
1183 if (!dbus_message_iter_next(&iter)) {
1185 return bus_send_error_reply(connection, message, NULL, -EINVAL);
1188 r = bus_parse_strv_iter(&iter, &l_set);
1194 return bus_send_error_reply(connection, message, NULL, r);
1197 e = strv_env_delete(m->environment, 1, l_unset);
1205 f = strv_env_merge(2, e, l_set);
1212 if (!(reply = dbus_message_new_method_return(message))) {
1217 strv_free(m->environment);
1219 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListUnitFiles")) {
1220 DBusMessageIter iter, sub, sub2;
1225 reply = dbus_message_new_method_return(message);
1229 h = hashmap_new(string_hash_func, string_compare_func);
1233 r = unit_file_get_list(m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);
1235 unit_file_list_free(h);
1236 dbus_message_unref(reply);
1237 return bus_send_error_reply(connection, message, NULL, r);
1240 dbus_message_iter_init_append(reply, &iter);
1242 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ss)", &sub)) {
1243 unit_file_list_free(h);
1247 HASHMAP_FOREACH(item, h, i) {
1250 state = unit_file_state_to_string(item->state);
1253 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
1254 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &item->path) ||
1255 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &state) ||
1256 !dbus_message_iter_close_container(&sub, &sub2)) {
1257 unit_file_list_free(h);
1262 unit_file_list_free(h);
1264 if (!dbus_message_iter_close_container(&iter, &sub))
1267 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitFileState")) {
1269 UnitFileState state;
1272 if (!dbus_message_get_args(
1275 DBUS_TYPE_STRING, &name,
1277 return bus_send_error_reply(connection, message, &error, -EINVAL);
1279 state = unit_file_get_state(m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, name);
1281 return bus_send_error_reply(connection, message, NULL, state);
1283 s = unit_file_state_to_string(state);
1286 reply = dbus_message_new_method_return(message);
1290 if (!dbus_message_append_args(
1292 DBUS_TYPE_STRING, &s,
1295 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "EnableUnitFiles") ||
1296 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReenableUnitFiles") ||
1297 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "LinkUnitFiles") ||
1298 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "PresetUnitFiles") ||
1299 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "MaskUnitFiles")) {
1302 DBusMessageIter iter;
1303 UnitFileScope scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1304 UnitFileChange *changes = NULL;
1305 unsigned n_changes = 0;
1306 dbus_bool_t runtime, force;
1308 if (!dbus_message_iter_init(message, &iter))
1311 r = bus_parse_strv_iter(&iter, &l);
1316 return bus_send_error_reply(connection, message, NULL, r);
1319 if (!dbus_message_iter_next(&iter) ||
1320 bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &runtime, true) < 0 ||
1321 bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &force, false) < 0) {
1323 return bus_send_error_reply(connection, message, NULL, -EIO);
1326 if (streq(member, "EnableUnitFiles"))
1327 r = unit_file_enable(scope, runtime, NULL, l, force, &changes, &n_changes);
1328 else if (streq(member, "ReenableUnitFiles"))
1329 r = unit_file_reenable(scope, runtime, NULL, l, force, &changes, &n_changes);
1330 else if (streq(member, "LinkUnitFiles"))
1331 r = unit_file_link(scope, runtime, NULL, l, force, &changes, &n_changes);
1332 else if (streq(member, "PresetUnitFiles"))
1333 r = unit_file_preset(scope, runtime, NULL, l, force, &changes, &n_changes);
1334 else if (streq(member, "MaskUnitFiles"))
1335 r = unit_file_mask(scope, runtime, NULL, l, force, &changes, &n_changes);
1337 assert_not_reached("Uh? Wrong method");
1340 bus_manager_send_unit_files_changed(m);
1343 unit_file_changes_free(changes, n_changes);
1344 return bus_send_error_reply(connection, message, NULL, r);
1347 reply = message_from_file_changes(message, changes, n_changes);
1348 unit_file_changes_free(changes, n_changes);
1353 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "DisableUnitFiles") ||
1354 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnmaskUnitFiles")) {
1357 DBusMessageIter iter;
1358 UnitFileScope scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1359 UnitFileChange *changes = NULL;
1360 unsigned n_changes = 0;
1361 dbus_bool_t runtime;
1363 if (!dbus_message_iter_init(message, &iter))
1366 r = bus_parse_strv_iter(&iter, &l);
1371 return bus_send_error_reply(connection, message, NULL, r);
1374 if (!dbus_message_iter_next(&iter) ||
1375 bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &runtime, false) < 0) {
1377 return bus_send_error_reply(connection, message, NULL, -EIO);
1380 if (streq(member, "DisableUnitFiles"))
1381 r = unit_file_disable(scope, runtime, NULL, l, &changes, &n_changes);
1382 else if (streq(member, "UnmaskUnitFiles"))
1383 r = unit_file_unmask(scope, runtime, NULL, l, &changes, &n_changes);
1385 assert_not_reached("Uh? Wrong method");
1388 bus_manager_send_unit_files_changed(m);
1391 unit_file_changes_free(changes, n_changes);
1392 return bus_send_error_reply(connection, message, NULL, r);
1395 reply = message_from_file_changes(message, changes, n_changes);
1396 unit_file_changes_free(changes, n_changes);
1402 return bus_default_message_handler(connection, message, NULL, INTERFACES_LIST, properties);
1404 if (job_type != _JOB_TYPE_INVALID) {
1405 const char *name, *smode, *old_name = NULL;
1411 if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnitReplace"))
1412 b = dbus_message_get_args(
1415 DBUS_TYPE_STRING, &old_name,
1416 DBUS_TYPE_STRING, &name,
1417 DBUS_TYPE_STRING, &smode,
1420 b = dbus_message_get_args(
1423 DBUS_TYPE_STRING, &name,
1424 DBUS_TYPE_STRING, &smode,
1428 return bus_send_error_reply(connection, message, &error, -EINVAL);
1431 if (!(u = manager_get_unit(m, old_name)) ||
1433 u->meta.job->type != JOB_START) {
1434 dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
1435 return bus_send_error_reply(connection, message, &error, -ENOENT);
1439 if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
1440 dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
1441 return bus_send_error_reply(connection, message, &error, -EINVAL);
1444 if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
1445 return bus_send_error_reply(connection, message, &error, r);
1447 if (reload_if_possible && unit_can_reload(u)) {
1448 if (job_type == JOB_RESTART)
1449 job_type = JOB_RELOAD_OR_START;
1450 else if (job_type == JOB_TRY_RESTART)
1451 job_type = JOB_RELOAD;
1454 if ((job_type == JOB_START && u->meta.refuse_manual_start) ||
1455 (job_type == JOB_STOP && u->meta.refuse_manual_stop) ||
1456 ((job_type == JOB_RESTART || job_type == JOB_TRY_RESTART) &&
1457 (u->meta.refuse_manual_start || u->meta.refuse_manual_stop))) {
1458 dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, may be requested by dependency only.");
1459 return bus_send_error_reply(connection, message, &error, -EPERM);
1462 if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
1463 return bus_send_error_reply(connection, message, &error, r);
1465 if (!(j->bus_client = strdup(message_get_sender_with_fallback(message))))
1468 j->bus = connection;
1470 if (!(reply = dbus_message_new_method_return(message)))
1473 if (!(path = job_dbus_path(j)))
1476 if (!dbus_message_append_args(
1478 DBUS_TYPE_OBJECT_PATH, &path,
1484 if (!dbus_connection_send(connection, reply, NULL))
1487 dbus_message_unref(reply);
1492 return DBUS_HANDLER_RESULT_HANDLED;
1498 dbus_message_unref(reply);
1500 dbus_error_free(&error);
1502 return DBUS_HANDLER_RESULT_NEED_MEMORY;
1505 const DBusObjectPathVTable bus_manager_vtable = {
1506 .message_function = bus_manager_message_handler