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=\"carries_install_info\" type=\"b\" directrion=\"out\"/>\n" \
149 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
151 " <method name=\"DisableUnitFiles\">\n" \
152 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
153 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
154 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
156 " <method name=\"ReenableUnitFiles\">\n" \
157 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
158 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
159 " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
160 " <arg name=\"carries_install_info\" type=\"b\" directrion=\"out\"/>\n" \
161 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
163 " <method name=\"LinkUnitFiles\">\n" \
164 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
165 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
166 " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
167 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
169 " <method name=\"PresetUnitFiles\">\n" \
170 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
171 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
172 " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
173 " <arg name=\"carries_install_info\" type=\"b\" directrion=\"out\"/>\n" \
174 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
176 " <method name=\"MaskUnitFiles\">\n" \
177 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
178 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
179 " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
180 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
182 " <method name=\"UnmaskUnitFiles\">\n" \
183 " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
184 " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
185 " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
188 #define BUS_MANAGER_INTERFACE_SIGNALS \
189 " <signal name=\"UnitNew\">\n" \
190 " <arg name=\"id\" type=\"s\"/>\n" \
191 " <arg name=\"unit\" type=\"o\"/>\n" \
193 " <signal name=\"UnitRemoved\">\n" \
194 " <arg name=\"id\" type=\"s\"/>\n" \
195 " <arg name=\"unit\" type=\"o\"/>\n" \
197 " <signal name=\"JobNew\">\n" \
198 " <arg name=\"id\" type=\"u\"/>\n" \
199 " <arg name=\"job\" type=\"o\"/>\n" \
201 " <signal name=\"JobRemoved\">\n" \
202 " <arg name=\"id\" type=\"u\"/>\n" \
203 " <arg name=\"job\" type=\"o\"/>\n" \
204 " <arg name=\"result\" type=\"s\"/>\n" \
206 " <signal name=\"StartupFinished\">\n" \
207 " <arg name=\"kernel\" type=\"t\"/>\n" \
208 " <arg name=\"initrd\" type=\"t\"/>\n" \
209 " <arg name=\"userspace\" type=\"t\"/>\n" \
210 " <arg name=\"total\" type=\"t\"/>\n" \
212 " <signal name=\"UnitFilesChanged\"/>\n"
214 #define BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL \
215 " <property name=\"Version\" type=\"s\" access=\"read\"/>\n" \
216 " <property name=\"Distribution\" type=\"s\" access=\"read\"/>\n" \
217 " <property name=\"Features\" type=\"s\" access=\"read\"/>\n" \
218 " <property name=\"Tainted\" type=\"s\" access=\"read\"/>\n" \
219 " <property name=\"RunningAs\" type=\"s\" access=\"read\"/>\n" \
220 " <property name=\"InitRDTimestamp\" type=\"t\" access=\"read\"/>\n" \
221 " <property name=\"InitRDTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
222 " <property name=\"StartupTimestamp\" type=\"t\" access=\"read\"/>\n" \
223 " <property name=\"StartupTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
224 " <property name=\"FinishTimestamp\" type=\"t\" access=\"read\"/>\n" \
225 " <property name=\"FinishTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
226 " <property name=\"LogLevel\" type=\"s\" access=\"readwrite\"/>\n" \
227 " <property name=\"LogTarget\" type=\"s\" access=\"readwrite\"/>\n" \
228 " <property name=\"NNames\" type=\"u\" access=\"read\"/>\n" \
229 " <property name=\"NJobs\" type=\"u\" access=\"read\"/>\n" \
230 " <property name=\"NInstalledJobs\" type=\"u\" access=\"read\"/>\n" \
231 " <property name=\"NFailedJobs\" type=\"u\" access=\"read\"/>\n" \
232 " <property name=\"Progress\" type=\"d\" access=\"read\"/>\n" \
233 " <property name=\"Environment\" type=\"as\" access=\"read\"/>\n" \
234 " <property name=\"ConfirmSpawn\" type=\"b\" access=\"read\"/>\n" \
235 " <property name=\"ShowStatus\" type=\"b\" access=\"read\"/>\n" \
236 " <property name=\"UnitPath\" type=\"as\" access=\"read\"/>\n" \
237 " <property name=\"NotifySocket\" type=\"s\" access=\"read\"/>\n" \
238 " <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
239 " <property name=\"MountAuto\" type=\"b\" access=\"read\"/>\n" \
240 " <property name=\"SwapAuto\" type=\"b\" access=\"read\"/>\n" \
241 " <property name=\"DefaultControllers\" type=\"as\" access=\"read\"/>\n" \
242 " <property name=\"DefaultStandardOutput\" type=\"s\" access=\"read\"/>\n" \
243 " <property name=\"DefaultStandardError\" type=\"s\" access=\"read\"/>\n"
245 #ifdef HAVE_SYSV_COMPAT
246 #define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV \
247 " <property name=\"SysVConsole\" type=\"b\" access=\"read\"/>\n" \
248 " <property name=\"SysVInitPath\" type=\"as\" access=\"read\"/>\n" \
249 " <property name=\"SysVRcndPath\" type=\"as\" access=\"read\"/>\n"
251 #define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV
254 #define BUS_MANAGER_INTERFACE_END \
257 #define BUS_MANAGER_INTERFACE \
258 BUS_MANAGER_INTERFACE_BEGIN \
259 BUS_MANAGER_INTERFACE_METHODS \
260 BUS_MANAGER_INTERFACE_SIGNALS \
261 BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL \
262 BUS_MANAGER_INTERFACE_PROPERTIES_SYSV \
263 BUS_MANAGER_INTERFACE_END
265 #define INTROSPECTION_BEGIN \
266 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
268 BUS_MANAGER_INTERFACE \
269 BUS_PROPERTIES_INTERFACE \
271 BUS_INTROSPECTABLE_INTERFACE
273 #define INTROSPECTION_END \
276 #define INTERFACES_LIST \
277 BUS_GENERIC_INTERFACES_LIST \
278 "org.freedesktop.systemd1.Manager\0"
280 const char bus_manager_interface[] _introspect_("Manager") = BUS_MANAGER_INTERFACE;
282 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_running_as, manager_running_as, ManagerRunningAs);
283 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_exec_output, exec_output, ExecOutput);
285 static int bus_manager_append_tainted(DBusMessageIter *i, const char *property, void *data) {
288 char buf[LINE_MAX] = "", *e = buf, *p = NULL;
295 e = stpcpy(e, "usr-separate-fs ");
297 if (readlink_malloc("/etc/mtab", &p) < 0)
298 e = stpcpy(e, "etc-mtab-not-symlink ");
302 if (access("/proc/cgroups", F_OK) < 0)
303 e = stpcpy(e, "cgroups-missing ");
307 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
313 static int bus_manager_append_log_target(DBusMessageIter *i, const char *property, void *data) {
319 t = log_target_to_string(log_get_target());
321 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
327 static int bus_manager_set_log_target(DBusMessageIter *i, const char *property) {
333 dbus_message_iter_get_basic(i, &t);
335 return log_set_target_from_string(t);
338 static int bus_manager_append_log_level(DBusMessageIter *i, const char *property, void *data) {
344 t = log_level_to_string(log_get_max_level());
346 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
352 static int bus_manager_set_log_level(DBusMessageIter *i, const char *property) {
358 dbus_message_iter_get_basic(i, &t);
360 return log_set_max_level_from_string(t);
363 static int bus_manager_append_n_names(DBusMessageIter *i, const char *property, void *data) {
371 u = hashmap_size(m->units);
373 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
379 static int bus_manager_append_n_jobs(DBusMessageIter *i, const char *property, void *data) {
387 u = hashmap_size(m->jobs);
389 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
395 static int bus_manager_append_progress(DBusMessageIter *i, const char *property, void *data) {
403 if (dual_timestamp_is_set(&m->finish_timestamp))
406 d = 1.0 - ((double) hashmap_size(m->jobs) / (double) m->n_installed_jobs);
408 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_DOUBLE, &d))
414 static const char *message_get_sender_with_fallback(DBusMessage *m) {
419 if ((s = dbus_message_get_sender(m)))
422 /* When the message came in from a direct connection the
423 * message will have no sender. We fix that here. */
428 static DBusMessage *message_from_file_changes(
430 UnitFileChange *changes,
432 int carries_install_info) {
434 DBusMessageIter iter, sub, sub2;
440 reply = dbus_message_new_method_return(m);
444 dbus_message_iter_init_append(reply, &iter);
446 if (carries_install_info >= 0) {
449 b = carries_install_info;
450 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &b))
454 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(sss)", &sub))
457 for (i = 0; i < n_changes; i++) {
458 const char *type, *path, *source;
460 type = unit_file_change_type_to_string(changes[i].type);
461 path = strempty(changes[i].path);
462 source = strempty(changes[i].source);
464 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
465 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &type) ||
466 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &path) ||
467 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &source) ||
468 !dbus_message_iter_close_container(&sub, &sub2))
472 if (!dbus_message_iter_close_container(&iter, &sub))
478 dbus_message_unref(reply);
482 static int bus_manager_send_unit_files_changed(Manager *m) {
486 s = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
490 r = bus_broadcast(m, s);
491 dbus_message_unref(s);
496 static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
499 const BusProperty properties[] = {
500 { "org.freedesktop.systemd1.Manager", "Version", bus_property_append_string, "s", PACKAGE_STRING },
501 { "org.freedesktop.systemd1.Manager", "Distribution", bus_property_append_string, "s", DISTRIBUTION },
502 { "org.freedesktop.systemd1.Manager", "Features", bus_property_append_string, "s", SYSTEMD_FEATURES },
503 { "org.freedesktop.systemd1.Manager", "RunningAs", bus_manager_append_running_as, "s", &m->running_as },
504 { "org.freedesktop.systemd1.Manager", "Tainted", bus_manager_append_tainted, "s", m },
505 { "org.freedesktop.systemd1.Manager", "InitRDTimestamp", bus_property_append_uint64, "t", &m->initrd_timestamp.realtime },
506 { "org.freedesktop.systemd1.Manager", "InitRDTimestampMonotonic", bus_property_append_uint64, "t", &m->initrd_timestamp.monotonic },
507 { "org.freedesktop.systemd1.Manager", "StartupTimestamp", bus_property_append_uint64, "t", &m->startup_timestamp.realtime },
508 { "org.freedesktop.systemd1.Manager", "StartupTimestampMonotonic", bus_property_append_uint64, "t", &m->startup_timestamp.monotonic },
509 { "org.freedesktop.systemd1.Manager", "FinishTimestamp", bus_property_append_uint64, "t", &m->finish_timestamp.realtime },
510 { "org.freedesktop.systemd1.Manager", "FinishTimestampMonotonic", bus_property_append_uint64, "t",&m->finish_timestamp.monotonic },
511 { "org.freedesktop.systemd1.Manager", "LogLevel", bus_manager_append_log_level, "s", m, bus_manager_set_log_level },
512 { "org.freedesktop.systemd1.Manager", "LogTarget", bus_manager_append_log_target, "s", m, bus_manager_set_log_target },
513 { "org.freedesktop.systemd1.Manager", "NNames", bus_manager_append_n_names, "u", m },
514 { "org.freedesktop.systemd1.Manager", "NJobs", bus_manager_append_n_jobs, "u", m },
515 { "org.freedesktop.systemd1.Manager", "NInstalledJobs",bus_property_append_uint32, "u", &m->n_installed_jobs },
516 { "org.freedesktop.systemd1.Manager", "NFailedJobs", bus_property_append_uint32, "u", &m->n_failed_jobs },
517 { "org.freedesktop.systemd1.Manager", "Progress", bus_manager_append_progress, "d", m },
518 { "org.freedesktop.systemd1.Manager", "Environment", bus_property_append_strv, "as", m->environment },
519 { "org.freedesktop.systemd1.Manager", "ConfirmSpawn", bus_property_append_bool, "b", &m->confirm_spawn },
520 { "org.freedesktop.systemd1.Manager", "ShowStatus", bus_property_append_bool, "b", &m->show_status },
521 { "org.freedesktop.systemd1.Manager", "UnitPath", bus_property_append_strv, "as", m->lookup_paths.unit_path },
522 { "org.freedesktop.systemd1.Manager", "NotifySocket", bus_property_append_string, "s", m->notify_socket },
523 { "org.freedesktop.systemd1.Manager", "ControlGroupHierarchy", bus_property_append_string, "s", m->cgroup_hierarchy },
524 { "org.freedesktop.systemd1.Manager", "MountAuto", bus_property_append_bool, "b", &m->mount_auto },
525 { "org.freedesktop.systemd1.Manager", "SwapAuto", bus_property_append_bool, "b", &m->swap_auto },
526 { "org.freedesktop.systemd1.Manager", "DefaultControllers", bus_property_append_strv, "as", m->default_controllers },
527 { "org.freedesktop.systemd1.Manager", "DefaultStandardOutput", bus_manager_append_exec_output, "s", &m->default_std_output },
528 { "org.freedesktop.systemd1.Manager", "DefaultStandardError", bus_manager_append_exec_output, "s", &m->default_std_error },
529 #ifdef HAVE_SYSV_COMPAT
530 { "org.freedesktop.systemd1.Manager", "SysVConsole", bus_property_append_bool, "b", &m->sysv_console },
531 { "org.freedesktop.systemd1.Manager", "SysVInitPath", bus_property_append_strv, "as", m->lookup_paths.sysvinit_path },
532 { "org.freedesktop.systemd1.Manager", "SysVRcndPath", bus_property_append_strv, "as", m->lookup_paths.sysvrcnd_path },
534 { NULL, NULL, NULL, NULL, NULL }
539 DBusMessage *reply = NULL;
541 JobType job_type = _JOB_TYPE_INVALID;
542 bool reload_if_possible = false;
549 dbus_error_init(&error);
551 member = dbus_message_get_member(message);
553 if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnit")) {
557 if (!dbus_message_get_args(
560 DBUS_TYPE_STRING, &name,
562 return bus_send_error_reply(connection, message, &error, -EINVAL);
564 if (!(u = manager_get_unit(m, name))) {
565 dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
566 return bus_send_error_reply(connection, message, &error, -ENOENT);
569 if (!(reply = dbus_message_new_method_return(message)))
572 if (!(path = unit_dbus_path(u)))
575 if (!dbus_message_append_args(
577 DBUS_TYPE_OBJECT_PATH, &path,
580 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitByPID")) {
584 if (!dbus_message_get_args(
587 DBUS_TYPE_UINT32, &pid,
589 return bus_send_error_reply(connection, message, &error, -EINVAL);
591 if (!(u = cgroup_unit_by_pid(m, (pid_t) pid))) {
592 dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "No unit for PID %lu is loaded.", (unsigned long) pid);
593 return bus_send_error_reply(connection, message, &error, -ENOENT);
596 if (!(reply = dbus_message_new_method_return(message)))
599 if (!(path = unit_dbus_path(u)))
602 if (!dbus_message_append_args(
604 DBUS_TYPE_OBJECT_PATH, &path,
607 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "LoadUnit")) {
611 if (!dbus_message_get_args(
614 DBUS_TYPE_STRING, &name,
616 return bus_send_error_reply(connection, message, &error, -EINVAL);
618 if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
619 return bus_send_error_reply(connection, message, &error, r);
621 if (!(reply = dbus_message_new_method_return(message)))
624 if (!(path = unit_dbus_path(u)))
627 if (!dbus_message_append_args(
629 DBUS_TYPE_OBJECT_PATH, &path,
633 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnit"))
634 job_type = JOB_START;
635 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnitReplace"))
636 job_type = JOB_START;
637 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StopUnit"))
639 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadUnit"))
640 job_type = JOB_RELOAD;
641 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "RestartUnit"))
642 job_type = JOB_RESTART;
643 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "TryRestartUnit"))
644 job_type = JOB_TRY_RESTART;
645 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrRestartUnit")) {
646 reload_if_possible = true;
647 job_type = JOB_RESTART;
648 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrTryRestartUnit")) {
649 reload_if_possible = true;
650 job_type = JOB_TRY_RESTART;
651 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KillUnit")) {
652 const char *name, *swho, *smode;
658 if (!dbus_message_get_args(
661 DBUS_TYPE_STRING, &name,
662 DBUS_TYPE_STRING, &swho,
663 DBUS_TYPE_STRING, &smode,
664 DBUS_TYPE_INT32, &signo,
666 return bus_send_error_reply(connection, message, &error, -EINVAL);
671 who = kill_who_from_string(swho);
673 return bus_send_error_reply(connection, message, &error, -EINVAL);
677 mode = KILL_CONTROL_GROUP;
679 mode = kill_mode_from_string(smode);
681 return bus_send_error_reply(connection, message, &error, -EINVAL);
684 if (signo <= 0 || signo >= _NSIG)
685 return bus_send_error_reply(connection, message, &error, -EINVAL);
687 if (!(u = manager_get_unit(m, name))) {
688 dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
689 return bus_send_error_reply(connection, message, &error, -ENOENT);
692 if ((r = unit_kill(u, who, mode, signo, &error)) < 0)
693 return bus_send_error_reply(connection, message, &error, r);
695 if (!(reply = dbus_message_new_method_return(message)))
698 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetJob")) {
702 if (!dbus_message_get_args(
705 DBUS_TYPE_UINT32, &id,
707 return bus_send_error_reply(connection, message, &error, -EINVAL);
709 if (!(j = manager_get_job(m, id))) {
710 dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
711 return bus_send_error_reply(connection, message, &error, -ENOENT);
714 if (!(reply = dbus_message_new_method_return(message)))
717 if (!(path = job_dbus_path(j)))
720 if (!dbus_message_append_args(
722 DBUS_TYPE_OBJECT_PATH, &path,
726 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ClearJobs")) {
728 manager_clear_jobs(m);
730 if (!(reply = dbus_message_new_method_return(message)))
733 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailed")) {
735 manager_reset_failed(m);
737 if (!(reply = dbus_message_new_method_return(message)))
740 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailedUnit")) {
744 if (!dbus_message_get_args(
747 DBUS_TYPE_STRING, &name,
749 return bus_send_error_reply(connection, message, &error, -EINVAL);
751 if (!(u = manager_get_unit(m, name))) {
752 dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
753 return bus_send_error_reply(connection, message, &error, -ENOENT);
756 unit_reset_failed(u);
758 if (!(reply = dbus_message_new_method_return(message)))
761 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListUnits")) {
762 DBusMessageIter iter, sub;
767 if (!(reply = dbus_message_new_method_return(message)))
770 dbus_message_iter_init_append(reply, &iter);
772 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ssssssouso)", &sub))
775 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
776 char *u_path, *j_path;
777 const char *description, *load_state, *active_state, *sub_state, *sjob_type, *following;
778 DBusMessageIter sub2;
785 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
788 description = unit_description(u);
789 load_state = unit_load_state_to_string(u->meta.load_state);
790 active_state = unit_active_state_to_string(unit_active_state(u));
791 sub_state = unit_sub_state_to_string(u);
793 f = unit_following(u);
794 following = f ? f->meta.id : "";
796 if (!(u_path = unit_dbus_path(u)))
800 job_id = (uint32_t) u->meta.job->id;
802 if (!(j_path = job_dbus_path(u->meta.job))) {
807 sjob_type = job_type_to_string(u->meta.job->type);
814 if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &u->meta.id) ||
815 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &description) ||
816 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &load_state) ||
817 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &active_state) ||
818 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sub_state) ||
819 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &following) ||
820 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path) ||
821 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &job_id) ||
822 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sjob_type) ||
823 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path)) {
834 if (!dbus_message_iter_close_container(&sub, &sub2))
838 if (!dbus_message_iter_close_container(&iter, &sub))
841 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListJobs")) {
842 DBusMessageIter iter, sub;
846 if (!(reply = dbus_message_new_method_return(message)))
849 dbus_message_iter_init_append(reply, &iter);
851 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(usssoo)", &sub))
854 HASHMAP_FOREACH(j, m->jobs, i) {
855 char *u_path, *j_path;
856 const char *state, *type;
858 DBusMessageIter sub2;
860 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
863 id = (uint32_t) j->id;
864 state = job_state_to_string(j->state);
865 type = job_type_to_string(j->type);
867 if (!(j_path = job_dbus_path(j)))
870 if (!(u_path = unit_dbus_path(j->unit))) {
875 if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &id) ||
876 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &j->unit->meta.id) ||
877 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &type) ||
878 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &state) ||
879 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path) ||
880 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path)) {
889 if (!dbus_message_iter_close_container(&sub, &sub2))
893 if (!dbus_message_iter_close_container(&iter, &sub))
896 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Subscribe")) {
900 if (!(s = BUS_CONNECTION_SUBSCRIBED(m, connection))) {
901 if (!(s = set_new(string_hash_func, string_compare_func)))
904 if (!(dbus_connection_set_data(connection, m->subscribed_data_slot, s, NULL))) {
910 if (!(client = strdup(message_get_sender_with_fallback(message))))
913 if ((r = set_put(s, client)) < 0) {
915 return bus_send_error_reply(connection, message, NULL, r);
918 if (!(reply = dbus_message_new_method_return(message)))
921 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Unsubscribe")) {
924 if (!(client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) message_get_sender_with_fallback(message)))) {
925 dbus_set_error(&error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
926 return bus_send_error_reply(connection, message, &error, -ENOENT);
931 if (!(reply = dbus_message_new_method_return(message)))
934 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Dump")) {
939 if (!(reply = dbus_message_new_method_return(message)))
942 if (!(f = open_memstream(&dump, &size)))
945 manager_dump_units(m, f, NULL);
946 manager_dump_jobs(m, f, NULL);
956 if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &dump, DBUS_TYPE_INVALID)) {
962 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "CreateSnapshot")) {
967 if (!dbus_message_get_args(
970 DBUS_TYPE_STRING, &name,
971 DBUS_TYPE_BOOLEAN, &cleanup,
973 return bus_send_error_reply(connection, message, &error, -EINVAL);
975 if (name && name[0] == 0)
978 if ((r = snapshot_create(m, name, cleanup, &error, &s)) < 0)
979 return bus_send_error_reply(connection, message, &error, r);
981 if (!(reply = dbus_message_new_method_return(message)))
984 if (!(path = unit_dbus_path(UNIT(s))))
987 if (!dbus_message_append_args(
989 DBUS_TYPE_OBJECT_PATH, &path,
993 } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
994 char *introspection = NULL;
1002 if (!(reply = dbus_message_new_method_return(message)))
1005 /* We roll our own introspection code here, instead of
1006 * relying on bus_default_message_handler() because we
1007 * need to generate our introspection string
1010 if (!(f = open_memstream(&introspection, &size)))
1013 fputs(INTROSPECTION_BEGIN, f);
1015 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
1018 if (k != u->meta.id)
1021 if (!(p = bus_path_escape(k))) {
1023 free(introspection);
1027 fprintf(f, "<node name=\"unit/%s\"/>", p);
1031 HASHMAP_FOREACH(j, m->jobs, i)
1032 fprintf(f, "<node name=\"job/%lu\"/>", (unsigned long) j->id);
1034 fputs(INTROSPECTION_END, f);
1038 free(introspection);
1047 if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID)) {
1048 free(introspection);
1052 free(introspection);
1054 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reload")) {
1056 assert(!m->queued_message);
1058 /* Instead of sending the reply back right away, we
1059 * just remember that we need to and then send it
1060 * after the reload is finished. That way the caller
1061 * knows when the reload finished. */
1063 if (!(m->queued_message = dbus_message_new_method_return(message)))
1066 m->queued_message_connection = connection;
1067 m->exit_code = MANAGER_RELOAD;
1069 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reexecute")) {
1071 /* We don't send a reply back here, the client should
1072 * just wait for us disconnecting. */
1074 m->exit_code = MANAGER_REEXECUTE;
1076 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
1078 if (m->running_as == MANAGER_SYSTEM) {
1079 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
1080 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1083 if (!(reply = dbus_message_new_method_return(message)))
1086 m->exit_code = MANAGER_EXIT;
1088 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reboot")) {
1090 if (m->running_as != MANAGER_SYSTEM) {
1091 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
1092 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1095 if (!(reply = dbus_message_new_method_return(message)))
1098 m->exit_code = MANAGER_REBOOT;
1100 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "PowerOff")) {
1102 if (m->running_as != MANAGER_SYSTEM) {
1103 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
1104 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1107 if (!(reply = dbus_message_new_method_return(message)))
1110 m->exit_code = MANAGER_POWEROFF;
1112 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Halt")) {
1114 if (m->running_as != MANAGER_SYSTEM) {
1115 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Halting is only supported for system managers.");
1116 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1119 if (!(reply = dbus_message_new_method_return(message)))
1122 m->exit_code = MANAGER_HALT;
1124 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KExec")) {
1126 if (m->running_as != MANAGER_SYSTEM) {
1127 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "kexec is only supported for system managers.");
1128 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1131 if (!(reply = dbus_message_new_method_return(message)))
1134 m->exit_code = MANAGER_KEXEC;
1136 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetEnvironment")) {
1137 char **l = NULL, **e = NULL;
1139 if ((r = bus_parse_strv(message, &l)) < 0) {
1143 return bus_send_error_reply(connection, message, NULL, r);
1146 e = strv_env_merge(2, m->environment, l);
1152 if (!(reply = dbus_message_new_method_return(message))) {
1157 strv_free(m->environment);
1160 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetEnvironment")) {
1161 char **l = NULL, **e = NULL;
1163 if ((r = bus_parse_strv(message, &l)) < 0) {
1167 return bus_send_error_reply(connection, message, NULL, r);
1170 e = strv_env_delete(m->environment, 1, l);
1176 if (!(reply = dbus_message_new_method_return(message))) {
1181 strv_free(m->environment);
1184 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetAndSetEnvironment")) {
1185 char **l_set = NULL, **l_unset = NULL, **e = NULL, **f = NULL;
1186 DBusMessageIter iter;
1188 if (!dbus_message_iter_init(message, &iter))
1191 r = bus_parse_strv_iter(&iter, &l_unset);
1196 return bus_send_error_reply(connection, message, NULL, r);
1199 if (!dbus_message_iter_next(&iter)) {
1201 return bus_send_error_reply(connection, message, NULL, -EINVAL);
1204 r = bus_parse_strv_iter(&iter, &l_set);
1210 return bus_send_error_reply(connection, message, NULL, r);
1213 e = strv_env_delete(m->environment, 1, l_unset);
1221 f = strv_env_merge(2, e, l_set);
1228 if (!(reply = dbus_message_new_method_return(message))) {
1233 strv_free(m->environment);
1235 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListUnitFiles")) {
1236 DBusMessageIter iter, sub, sub2;
1241 reply = dbus_message_new_method_return(message);
1245 h = hashmap_new(string_hash_func, string_compare_func);
1249 r = unit_file_get_list(m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);
1251 unit_file_list_free(h);
1252 dbus_message_unref(reply);
1253 return bus_send_error_reply(connection, message, NULL, r);
1256 dbus_message_iter_init_append(reply, &iter);
1258 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ss)", &sub)) {
1259 unit_file_list_free(h);
1263 HASHMAP_FOREACH(item, h, i) {
1266 state = unit_file_state_to_string(item->state);
1269 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
1270 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &item->path) ||
1271 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &state) ||
1272 !dbus_message_iter_close_container(&sub, &sub2)) {
1273 unit_file_list_free(h);
1278 unit_file_list_free(h);
1280 if (!dbus_message_iter_close_container(&iter, &sub))
1283 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitFileState")) {
1285 UnitFileState state;
1288 if (!dbus_message_get_args(
1291 DBUS_TYPE_STRING, &name,
1293 return bus_send_error_reply(connection, message, &error, -EINVAL);
1295 state = unit_file_get_state(m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, name);
1297 return bus_send_error_reply(connection, message, NULL, state);
1299 s = unit_file_state_to_string(state);
1302 reply = dbus_message_new_method_return(message);
1306 if (!dbus_message_append_args(
1308 DBUS_TYPE_STRING, &s,
1311 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "EnableUnitFiles") ||
1312 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReenableUnitFiles") ||
1313 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "LinkUnitFiles") ||
1314 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "PresetUnitFiles") ||
1315 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "MaskUnitFiles")) {
1318 DBusMessageIter iter;
1319 UnitFileScope scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1320 UnitFileChange *changes = NULL;
1321 unsigned n_changes = 0;
1322 dbus_bool_t runtime, force;
1323 bool carries_install_info = -1;
1325 if (!dbus_message_iter_init(message, &iter))
1328 r = bus_parse_strv_iter(&iter, &l);
1333 return bus_send_error_reply(connection, message, NULL, r);
1336 if (!dbus_message_iter_next(&iter) ||
1337 bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &runtime, true) < 0 ||
1338 bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &force, false) < 0) {
1340 return bus_send_error_reply(connection, message, NULL, -EIO);
1343 if (streq(member, "EnableUnitFiles")) {
1344 r = unit_file_enable(scope, runtime, NULL, l, force, &changes, &n_changes);
1345 carries_install_info = r;
1346 } else if (streq(member, "ReenableUnitFiles")) {
1347 r = unit_file_reenable(scope, runtime, NULL, l, force, &changes, &n_changes);
1348 carries_install_info = r;
1349 } else if (streq(member, "LinkUnitFiles"))
1350 r = unit_file_link(scope, runtime, NULL, l, force, &changes, &n_changes);
1351 else if (streq(member, "PresetUnitFiles")) {
1352 r = unit_file_preset(scope, runtime, NULL, l, force, &changes, &n_changes);
1353 carries_install_info = r;
1354 } else if (streq(member, "MaskUnitFiles"))
1355 r = unit_file_mask(scope, runtime, NULL, l, force, &changes, &n_changes);
1357 assert_not_reached("Uh? Wrong method");
1360 bus_manager_send_unit_files_changed(m);
1363 unit_file_changes_free(changes, n_changes);
1364 return bus_send_error_reply(connection, message, NULL, r);
1367 reply = message_from_file_changes(message, changes, n_changes, carries_install_info);
1368 unit_file_changes_free(changes, n_changes);
1373 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "DisableUnitFiles") ||
1374 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnmaskUnitFiles")) {
1377 DBusMessageIter iter;
1378 UnitFileScope scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1379 UnitFileChange *changes = NULL;
1380 unsigned n_changes = 0;
1381 dbus_bool_t runtime;
1383 if (!dbus_message_iter_init(message, &iter))
1386 r = bus_parse_strv_iter(&iter, &l);
1391 return bus_send_error_reply(connection, message, NULL, r);
1394 if (!dbus_message_iter_next(&iter) ||
1395 bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &runtime, false) < 0) {
1397 return bus_send_error_reply(connection, message, NULL, -EIO);
1400 if (streq(member, "DisableUnitFiles"))
1401 r = unit_file_disable(scope, runtime, NULL, l, &changes, &n_changes);
1402 else if (streq(member, "UnmaskUnitFiles"))
1403 r = unit_file_unmask(scope, runtime, NULL, l, &changes, &n_changes);
1405 assert_not_reached("Uh? Wrong method");
1408 bus_manager_send_unit_files_changed(m);
1411 unit_file_changes_free(changes, n_changes);
1412 return bus_send_error_reply(connection, message, NULL, r);
1415 reply = message_from_file_changes(message, changes, n_changes, -1);
1416 unit_file_changes_free(changes, n_changes);
1422 return bus_default_message_handler(connection, message, NULL, INTERFACES_LIST, properties);
1424 if (job_type != _JOB_TYPE_INVALID) {
1425 const char *name, *smode, *old_name = NULL;
1431 if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnitReplace"))
1432 b = dbus_message_get_args(
1435 DBUS_TYPE_STRING, &old_name,
1436 DBUS_TYPE_STRING, &name,
1437 DBUS_TYPE_STRING, &smode,
1440 b = dbus_message_get_args(
1443 DBUS_TYPE_STRING, &name,
1444 DBUS_TYPE_STRING, &smode,
1448 return bus_send_error_reply(connection, message, &error, -EINVAL);
1451 if (!(u = manager_get_unit(m, old_name)) ||
1453 u->meta.job->type != JOB_START) {
1454 dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
1455 return bus_send_error_reply(connection, message, &error, -ENOENT);
1459 if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
1460 dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
1461 return bus_send_error_reply(connection, message, &error, -EINVAL);
1464 if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
1465 return bus_send_error_reply(connection, message, &error, r);
1467 if (reload_if_possible && unit_can_reload(u)) {
1468 if (job_type == JOB_RESTART)
1469 job_type = JOB_RELOAD_OR_START;
1470 else if (job_type == JOB_TRY_RESTART)
1471 job_type = JOB_RELOAD;
1474 if ((job_type == JOB_START && u->meta.refuse_manual_start) ||
1475 (job_type == JOB_STOP && u->meta.refuse_manual_stop) ||
1476 ((job_type == JOB_RESTART || job_type == JOB_TRY_RESTART) &&
1477 (u->meta.refuse_manual_start || u->meta.refuse_manual_stop))) {
1478 dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, may be requested by dependency only.");
1479 return bus_send_error_reply(connection, message, &error, -EPERM);
1482 if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
1483 return bus_send_error_reply(connection, message, &error, r);
1485 if (!(j->bus_client = strdup(message_get_sender_with_fallback(message))))
1488 j->bus = connection;
1490 if (!(reply = dbus_message_new_method_return(message)))
1493 if (!(path = job_dbus_path(j)))
1496 if (!dbus_message_append_args(
1498 DBUS_TYPE_OBJECT_PATH, &path,
1504 if (!dbus_connection_send(connection, reply, NULL))
1507 dbus_message_unref(reply);
1512 return DBUS_HANDLER_RESULT_HANDLED;
1518 dbus_message_unref(reply);
1520 dbus_error_free(&error);
1522 return DBUS_HANDLER_RESULT_NEED_MEMORY;
1525 const DBusObjectPathVTable bus_manager_vtable = {
1526 .message_function = bus_manager_message_handler