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\" direction=\"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\" direction=\"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\" direction=\"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 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;
438 reply = dbus_message_new_method_return(m);
442 dbus_message_iter_init_append(reply, &iter);
444 if (carries_install_info >= 0) {
447 b = !!carries_install_info;
448 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &b))
452 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(sss)", &sub))
455 for (i = 0; i < n_changes; i++) {
456 const char *type, *path, *source;
458 type = unit_file_change_type_to_string(changes[i].type);
459 path = strempty(changes[i].path);
460 source = strempty(changes[i].source);
462 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
463 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &type) ||
464 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &path) ||
465 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &source) ||
466 !dbus_message_iter_close_container(&sub, &sub2))
470 if (!dbus_message_iter_close_container(&iter, &sub))
476 dbus_message_unref(reply);
480 static int bus_manager_send_unit_files_changed(Manager *m) {
484 s = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
488 r = bus_broadcast(m, s);
489 dbus_message_unref(s);
494 static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
497 const BusProperty properties[] = {
498 { "org.freedesktop.systemd1.Manager", "Version", bus_property_append_string, "s", PACKAGE_STRING },
499 { "org.freedesktop.systemd1.Manager", "Distribution", bus_property_append_string, "s", DISTRIBUTION },
500 { "org.freedesktop.systemd1.Manager", "Features", bus_property_append_string, "s", SYSTEMD_FEATURES },
501 { "org.freedesktop.systemd1.Manager", "RunningAs", bus_manager_append_running_as, "s", &m->running_as },
502 { "org.freedesktop.systemd1.Manager", "Tainted", bus_manager_append_tainted, "s", m },
503 { "org.freedesktop.systemd1.Manager", "InitRDTimestamp", bus_property_append_uint64, "t", &m->initrd_timestamp.realtime },
504 { "org.freedesktop.systemd1.Manager", "InitRDTimestampMonotonic", bus_property_append_uint64, "t", &m->initrd_timestamp.monotonic },
505 { "org.freedesktop.systemd1.Manager", "StartupTimestamp", bus_property_append_uint64, "t", &m->startup_timestamp.realtime },
506 { "org.freedesktop.systemd1.Manager", "StartupTimestampMonotonic", bus_property_append_uint64, "t", &m->startup_timestamp.monotonic },
507 { "org.freedesktop.systemd1.Manager", "FinishTimestamp", bus_property_append_uint64, "t", &m->finish_timestamp.realtime },
508 { "org.freedesktop.systemd1.Manager", "FinishTimestampMonotonic", bus_property_append_uint64, "t",&m->finish_timestamp.monotonic },
509 { "org.freedesktop.systemd1.Manager", "LogLevel", bus_manager_append_log_level, "s", m, bus_manager_set_log_level },
510 { "org.freedesktop.systemd1.Manager", "LogTarget", bus_manager_append_log_target, "s", m, bus_manager_set_log_target },
511 { "org.freedesktop.systemd1.Manager", "NNames", bus_manager_append_n_names, "u", m },
512 { "org.freedesktop.systemd1.Manager", "NJobs", bus_manager_append_n_jobs, "u", m },
513 { "org.freedesktop.systemd1.Manager", "NInstalledJobs",bus_property_append_uint32, "u", &m->n_installed_jobs },
514 { "org.freedesktop.systemd1.Manager", "NFailedJobs", bus_property_append_uint32, "u", &m->n_failed_jobs },
515 { "org.freedesktop.systemd1.Manager", "Progress", bus_manager_append_progress, "d", m },
516 { "org.freedesktop.systemd1.Manager", "Environment", bus_property_append_strv, "as", m->environment },
517 { "org.freedesktop.systemd1.Manager", "ConfirmSpawn", bus_property_append_bool, "b", &m->confirm_spawn },
518 { "org.freedesktop.systemd1.Manager", "ShowStatus", bus_property_append_bool, "b", &m->show_status },
519 { "org.freedesktop.systemd1.Manager", "UnitPath", bus_property_append_strv, "as", m->lookup_paths.unit_path },
520 { "org.freedesktop.systemd1.Manager", "NotifySocket", bus_property_append_string, "s", m->notify_socket },
521 { "org.freedesktop.systemd1.Manager", "ControlGroupHierarchy", bus_property_append_string, "s", m->cgroup_hierarchy },
522 { "org.freedesktop.systemd1.Manager", "MountAuto", bus_property_append_bool, "b", &m->mount_auto },
523 { "org.freedesktop.systemd1.Manager", "SwapAuto", bus_property_append_bool, "b", &m->swap_auto },
524 { "org.freedesktop.systemd1.Manager", "DefaultControllers", bus_property_append_strv, "as", m->default_controllers },
525 { "org.freedesktop.systemd1.Manager", "DefaultStandardOutput", bus_manager_append_exec_output, "s", &m->default_std_output },
526 { "org.freedesktop.systemd1.Manager", "DefaultStandardError", bus_manager_append_exec_output, "s", &m->default_std_error },
527 #ifdef HAVE_SYSV_COMPAT
528 { "org.freedesktop.systemd1.Manager", "SysVConsole", bus_property_append_bool, "b", &m->sysv_console },
529 { "org.freedesktop.systemd1.Manager", "SysVInitPath", bus_property_append_strv, "as", m->lookup_paths.sysvinit_path },
530 { "org.freedesktop.systemd1.Manager", "SysVRcndPath", bus_property_append_strv, "as", m->lookup_paths.sysvrcnd_path },
532 { NULL, NULL, NULL, NULL, NULL }
537 DBusMessage *reply = NULL;
539 JobType job_type = _JOB_TYPE_INVALID;
540 bool reload_if_possible = false;
547 dbus_error_init(&error);
549 member = dbus_message_get_member(message);
551 if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnit")) {
555 if (!dbus_message_get_args(
558 DBUS_TYPE_STRING, &name,
560 return bus_send_error_reply(connection, message, &error, -EINVAL);
562 if (!(u = manager_get_unit(m, name))) {
563 dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
564 return bus_send_error_reply(connection, message, &error, -ENOENT);
567 if (!(reply = dbus_message_new_method_return(message)))
570 if (!(path = unit_dbus_path(u)))
573 if (!dbus_message_append_args(
575 DBUS_TYPE_OBJECT_PATH, &path,
578 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitByPID")) {
582 if (!dbus_message_get_args(
585 DBUS_TYPE_UINT32, &pid,
587 return bus_send_error_reply(connection, message, &error, -EINVAL);
589 if (!(u = cgroup_unit_by_pid(m, (pid_t) pid))) {
590 dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "No unit for PID %lu is loaded.", (unsigned long) pid);
591 return bus_send_error_reply(connection, message, &error, -ENOENT);
594 if (!(reply = dbus_message_new_method_return(message)))
597 if (!(path = unit_dbus_path(u)))
600 if (!dbus_message_append_args(
602 DBUS_TYPE_OBJECT_PATH, &path,
605 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "LoadUnit")) {
609 if (!dbus_message_get_args(
612 DBUS_TYPE_STRING, &name,
614 return bus_send_error_reply(connection, message, &error, -EINVAL);
616 if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
617 return bus_send_error_reply(connection, message, &error, r);
619 if (!(reply = dbus_message_new_method_return(message)))
622 if (!(path = unit_dbus_path(u)))
625 if (!dbus_message_append_args(
627 DBUS_TYPE_OBJECT_PATH, &path,
631 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnit"))
632 job_type = JOB_START;
633 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnitReplace"))
634 job_type = JOB_START;
635 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StopUnit"))
637 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadUnit"))
638 job_type = JOB_RELOAD;
639 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "RestartUnit"))
640 job_type = JOB_RESTART;
641 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "TryRestartUnit"))
642 job_type = JOB_TRY_RESTART;
643 else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrRestartUnit")) {
644 reload_if_possible = true;
645 job_type = JOB_RESTART;
646 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrTryRestartUnit")) {
647 reload_if_possible = true;
648 job_type = JOB_TRY_RESTART;
649 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KillUnit")) {
650 const char *name, *swho, *smode;
656 if (!dbus_message_get_args(
659 DBUS_TYPE_STRING, &name,
660 DBUS_TYPE_STRING, &swho,
661 DBUS_TYPE_STRING, &smode,
662 DBUS_TYPE_INT32, &signo,
664 return bus_send_error_reply(connection, message, &error, -EINVAL);
669 who = kill_who_from_string(swho);
671 return bus_send_error_reply(connection, message, &error, -EINVAL);
675 mode = KILL_CONTROL_GROUP;
677 mode = kill_mode_from_string(smode);
679 return bus_send_error_reply(connection, message, &error, -EINVAL);
682 if (signo <= 0 || signo >= _NSIG)
683 return bus_send_error_reply(connection, message, &error, -EINVAL);
685 if (!(u = manager_get_unit(m, name))) {
686 dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
687 return bus_send_error_reply(connection, message, &error, -ENOENT);
690 if ((r = unit_kill(u, who, mode, signo, &error)) < 0)
691 return bus_send_error_reply(connection, message, &error, r);
693 if (!(reply = dbus_message_new_method_return(message)))
696 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetJob")) {
700 if (!dbus_message_get_args(
703 DBUS_TYPE_UINT32, &id,
705 return bus_send_error_reply(connection, message, &error, -EINVAL);
707 if (!(j = manager_get_job(m, id))) {
708 dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
709 return bus_send_error_reply(connection, message, &error, -ENOENT);
712 if (!(reply = dbus_message_new_method_return(message)))
715 if (!(path = job_dbus_path(j)))
718 if (!dbus_message_append_args(
720 DBUS_TYPE_OBJECT_PATH, &path,
724 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ClearJobs")) {
726 manager_clear_jobs(m);
728 if (!(reply = dbus_message_new_method_return(message)))
731 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailed")) {
733 manager_reset_failed(m);
735 if (!(reply = dbus_message_new_method_return(message)))
738 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailedUnit")) {
742 if (!dbus_message_get_args(
745 DBUS_TYPE_STRING, &name,
747 return bus_send_error_reply(connection, message, &error, -EINVAL);
749 if (!(u = manager_get_unit(m, name))) {
750 dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
751 return bus_send_error_reply(connection, message, &error, -ENOENT);
754 unit_reset_failed(u);
756 if (!(reply = dbus_message_new_method_return(message)))
759 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListUnits")) {
760 DBusMessageIter iter, sub;
765 if (!(reply = dbus_message_new_method_return(message)))
768 dbus_message_iter_init_append(reply, &iter);
770 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ssssssouso)", &sub))
773 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
774 char *u_path, *j_path;
775 const char *description, *load_state, *active_state, *sub_state, *sjob_type, *following;
776 DBusMessageIter sub2;
783 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
786 description = unit_description(u);
787 load_state = unit_load_state_to_string(u->meta.load_state);
788 active_state = unit_active_state_to_string(unit_active_state(u));
789 sub_state = unit_sub_state_to_string(u);
791 f = unit_following(u);
792 following = f ? f->meta.id : "";
794 if (!(u_path = unit_dbus_path(u)))
798 job_id = (uint32_t) u->meta.job->id;
800 if (!(j_path = job_dbus_path(u->meta.job))) {
805 sjob_type = job_type_to_string(u->meta.job->type);
812 if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &u->meta.id) ||
813 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &description) ||
814 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &load_state) ||
815 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &active_state) ||
816 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sub_state) ||
817 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &following) ||
818 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path) ||
819 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &job_id) ||
820 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sjob_type) ||
821 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path)) {
832 if (!dbus_message_iter_close_container(&sub, &sub2))
836 if (!dbus_message_iter_close_container(&iter, &sub))
839 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListJobs")) {
840 DBusMessageIter iter, sub;
844 if (!(reply = dbus_message_new_method_return(message)))
847 dbus_message_iter_init_append(reply, &iter);
849 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(usssoo)", &sub))
852 HASHMAP_FOREACH(j, m->jobs, i) {
853 char *u_path, *j_path;
854 const char *state, *type;
856 DBusMessageIter sub2;
858 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
861 id = (uint32_t) j->id;
862 state = job_state_to_string(j->state);
863 type = job_type_to_string(j->type);
865 if (!(j_path = job_dbus_path(j)))
868 if (!(u_path = unit_dbus_path(j->unit))) {
873 if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &id) ||
874 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &j->unit->meta.id) ||
875 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &type) ||
876 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &state) ||
877 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path) ||
878 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path)) {
887 if (!dbus_message_iter_close_container(&sub, &sub2))
891 if (!dbus_message_iter_close_container(&iter, &sub))
894 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Subscribe")) {
898 if (!(s = BUS_CONNECTION_SUBSCRIBED(m, connection))) {
899 if (!(s = set_new(string_hash_func, string_compare_func)))
902 if (!(dbus_connection_set_data(connection, m->subscribed_data_slot, s, NULL))) {
908 if (!(client = strdup(message_get_sender_with_fallback(message))))
911 if ((r = set_put(s, client)) < 0) {
913 return bus_send_error_reply(connection, message, NULL, r);
916 if (!(reply = dbus_message_new_method_return(message)))
919 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Unsubscribe")) {
922 if (!(client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) message_get_sender_with_fallback(message)))) {
923 dbus_set_error(&error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
924 return bus_send_error_reply(connection, message, &error, -ENOENT);
929 if (!(reply = dbus_message_new_method_return(message)))
932 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Dump")) {
937 if (!(reply = dbus_message_new_method_return(message)))
940 if (!(f = open_memstream(&dump, &size)))
943 manager_dump_units(m, f, NULL);
944 manager_dump_jobs(m, f, NULL);
954 if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &dump, DBUS_TYPE_INVALID)) {
960 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "CreateSnapshot")) {
965 if (!dbus_message_get_args(
968 DBUS_TYPE_STRING, &name,
969 DBUS_TYPE_BOOLEAN, &cleanup,
971 return bus_send_error_reply(connection, message, &error, -EINVAL);
973 if (name && name[0] == 0)
976 if ((r = snapshot_create(m, name, cleanup, &error, &s)) < 0)
977 return bus_send_error_reply(connection, message, &error, r);
979 if (!(reply = dbus_message_new_method_return(message)))
982 if (!(path = unit_dbus_path(UNIT(s))))
985 if (!dbus_message_append_args(
987 DBUS_TYPE_OBJECT_PATH, &path,
991 } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
992 char *introspection = NULL;
1000 if (!(reply = dbus_message_new_method_return(message)))
1003 /* We roll our own introspection code here, instead of
1004 * relying on bus_default_message_handler() because we
1005 * need to generate our introspection string
1008 if (!(f = open_memstream(&introspection, &size)))
1011 fputs(INTROSPECTION_BEGIN, f);
1013 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
1016 if (k != u->meta.id)
1019 if (!(p = bus_path_escape(k))) {
1021 free(introspection);
1025 fprintf(f, "<node name=\"unit/%s\"/>", p);
1029 HASHMAP_FOREACH(j, m->jobs, i)
1030 fprintf(f, "<node name=\"job/%lu\"/>", (unsigned long) j->id);
1032 fputs(INTROSPECTION_END, f);
1036 free(introspection);
1045 if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID)) {
1046 free(introspection);
1050 free(introspection);
1052 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reload")) {
1054 assert(!m->queued_message);
1056 /* Instead of sending the reply back right away, we
1057 * just remember that we need to and then send it
1058 * after the reload is finished. That way the caller
1059 * knows when the reload finished. */
1061 if (!(m->queued_message = dbus_message_new_method_return(message)))
1064 m->queued_message_connection = connection;
1065 m->exit_code = MANAGER_RELOAD;
1067 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reexecute")) {
1069 /* We don't send a reply back here, the client should
1070 * just wait for us disconnecting. */
1072 m->exit_code = MANAGER_REEXECUTE;
1074 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
1076 if (m->running_as == MANAGER_SYSTEM) {
1077 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
1078 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1081 if (!(reply = dbus_message_new_method_return(message)))
1084 m->exit_code = MANAGER_EXIT;
1086 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reboot")) {
1088 if (m->running_as != MANAGER_SYSTEM) {
1089 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
1090 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1093 if (!(reply = dbus_message_new_method_return(message)))
1096 m->exit_code = MANAGER_REBOOT;
1098 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "PowerOff")) {
1100 if (m->running_as != MANAGER_SYSTEM) {
1101 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
1102 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1105 if (!(reply = dbus_message_new_method_return(message)))
1108 m->exit_code = MANAGER_POWEROFF;
1110 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Halt")) {
1112 if (m->running_as != MANAGER_SYSTEM) {
1113 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Halting is only supported for system managers.");
1114 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1117 if (!(reply = dbus_message_new_method_return(message)))
1120 m->exit_code = MANAGER_HALT;
1122 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KExec")) {
1124 if (m->running_as != MANAGER_SYSTEM) {
1125 dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "kexec is only supported for system managers.");
1126 return bus_send_error_reply(connection, message, &error, -ENOTSUP);
1129 if (!(reply = dbus_message_new_method_return(message)))
1132 m->exit_code = MANAGER_KEXEC;
1134 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetEnvironment")) {
1135 char **l = NULL, **e = NULL;
1137 if ((r = bus_parse_strv(message, &l)) < 0) {
1141 return bus_send_error_reply(connection, message, NULL, r);
1144 e = strv_env_merge(2, m->environment, l);
1150 if (!(reply = dbus_message_new_method_return(message))) {
1155 strv_free(m->environment);
1158 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetEnvironment")) {
1159 char **l = NULL, **e = NULL;
1161 if ((r = bus_parse_strv(message, &l)) < 0) {
1165 return bus_send_error_reply(connection, message, NULL, r);
1168 e = strv_env_delete(m->environment, 1, l);
1174 if (!(reply = dbus_message_new_method_return(message))) {
1179 strv_free(m->environment);
1182 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetAndSetEnvironment")) {
1183 char **l_set = NULL, **l_unset = NULL, **e = NULL, **f = NULL;
1184 DBusMessageIter iter;
1186 if (!dbus_message_iter_init(message, &iter))
1189 r = bus_parse_strv_iter(&iter, &l_unset);
1194 return bus_send_error_reply(connection, message, NULL, r);
1197 if (!dbus_message_iter_next(&iter)) {
1199 return bus_send_error_reply(connection, message, NULL, -EINVAL);
1202 r = bus_parse_strv_iter(&iter, &l_set);
1208 return bus_send_error_reply(connection, message, NULL, r);
1211 e = strv_env_delete(m->environment, 1, l_unset);
1219 f = strv_env_merge(2, e, l_set);
1226 if (!(reply = dbus_message_new_method_return(message))) {
1231 strv_free(m->environment);
1233 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListUnitFiles")) {
1234 DBusMessageIter iter, sub, sub2;
1239 reply = dbus_message_new_method_return(message);
1243 h = hashmap_new(string_hash_func, string_compare_func);
1247 r = unit_file_get_list(m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);
1249 unit_file_list_free(h);
1250 dbus_message_unref(reply);
1251 return bus_send_error_reply(connection, message, NULL, r);
1254 dbus_message_iter_init_append(reply, &iter);
1256 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ss)", &sub)) {
1257 unit_file_list_free(h);
1261 HASHMAP_FOREACH(item, h, i) {
1264 state = unit_file_state_to_string(item->state);
1267 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
1268 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &item->path) ||
1269 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &state) ||
1270 !dbus_message_iter_close_container(&sub, &sub2)) {
1271 unit_file_list_free(h);
1276 unit_file_list_free(h);
1278 if (!dbus_message_iter_close_container(&iter, &sub))
1281 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitFileState")) {
1283 UnitFileState state;
1286 if (!dbus_message_get_args(
1289 DBUS_TYPE_STRING, &name,
1291 return bus_send_error_reply(connection, message, &error, -EINVAL);
1293 state = unit_file_get_state(m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, name);
1295 return bus_send_error_reply(connection, message, NULL, state);
1297 s = unit_file_state_to_string(state);
1300 reply = dbus_message_new_method_return(message);
1304 if (!dbus_message_append_args(
1306 DBUS_TYPE_STRING, &s,
1309 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "EnableUnitFiles") ||
1310 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReenableUnitFiles") ||
1311 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "LinkUnitFiles") ||
1312 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "PresetUnitFiles") ||
1313 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "MaskUnitFiles")) {
1316 DBusMessageIter iter;
1317 UnitFileScope scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1318 UnitFileChange *changes = NULL;
1319 unsigned n_changes = 0;
1320 dbus_bool_t runtime, force;
1321 int carries_install_info = -1;
1323 if (!dbus_message_iter_init(message, &iter))
1326 r = bus_parse_strv_iter(&iter, &l);
1331 return bus_send_error_reply(connection, message, NULL, r);
1334 if (!dbus_message_iter_next(&iter) ||
1335 bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &runtime, true) < 0 ||
1336 bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &force, false) < 0) {
1338 return bus_send_error_reply(connection, message, NULL, -EIO);
1341 if (streq(member, "EnableUnitFiles")) {
1342 r = unit_file_enable(scope, runtime, NULL, l, force, &changes, &n_changes);
1343 carries_install_info = r;
1344 } else if (streq(member, "ReenableUnitFiles")) {
1345 r = unit_file_reenable(scope, runtime, NULL, l, force, &changes, &n_changes);
1346 carries_install_info = r;
1347 } else if (streq(member, "LinkUnitFiles"))
1348 r = unit_file_link(scope, runtime, NULL, l, force, &changes, &n_changes);
1349 else if (streq(member, "PresetUnitFiles")) {
1350 r = unit_file_preset(scope, runtime, NULL, l, force, &changes, &n_changes);
1351 carries_install_info = r;
1352 } else if (streq(member, "MaskUnitFiles"))
1353 r = unit_file_mask(scope, runtime, NULL, l, force, &changes, &n_changes);
1355 assert_not_reached("Uh? Wrong method");
1358 bus_manager_send_unit_files_changed(m);
1361 unit_file_changes_free(changes, n_changes);
1362 return bus_send_error_reply(connection, message, NULL, r);
1365 reply = message_from_file_changes(message, changes, n_changes, carries_install_info);
1366 unit_file_changes_free(changes, n_changes);
1371 } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "DisableUnitFiles") ||
1372 dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnmaskUnitFiles")) {
1375 DBusMessageIter iter;
1376 UnitFileScope scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1377 UnitFileChange *changes = NULL;
1378 unsigned n_changes = 0;
1379 dbus_bool_t runtime;
1381 if (!dbus_message_iter_init(message, &iter))
1384 r = bus_parse_strv_iter(&iter, &l);
1389 return bus_send_error_reply(connection, message, NULL, r);
1392 if (!dbus_message_iter_next(&iter) ||
1393 bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &runtime, false) < 0) {
1395 return bus_send_error_reply(connection, message, NULL, -EIO);
1398 if (streq(member, "DisableUnitFiles"))
1399 r = unit_file_disable(scope, runtime, NULL, l, &changes, &n_changes);
1400 else if (streq(member, "UnmaskUnitFiles"))
1401 r = unit_file_unmask(scope, runtime, NULL, l, &changes, &n_changes);
1403 assert_not_reached("Uh? Wrong method");
1406 bus_manager_send_unit_files_changed(m);
1409 unit_file_changes_free(changes, n_changes);
1410 return bus_send_error_reply(connection, message, NULL, r);
1413 reply = message_from_file_changes(message, changes, n_changes, -1);
1414 unit_file_changes_free(changes, n_changes);
1420 return bus_default_message_handler(connection, message, NULL, INTERFACES_LIST, properties);
1422 if (job_type != _JOB_TYPE_INVALID) {
1423 const char *name, *smode, *old_name = NULL;
1429 if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnitReplace"))
1430 b = dbus_message_get_args(
1433 DBUS_TYPE_STRING, &old_name,
1434 DBUS_TYPE_STRING, &name,
1435 DBUS_TYPE_STRING, &smode,
1438 b = dbus_message_get_args(
1441 DBUS_TYPE_STRING, &name,
1442 DBUS_TYPE_STRING, &smode,
1446 return bus_send_error_reply(connection, message, &error, -EINVAL);
1449 if (!(u = manager_get_unit(m, old_name)) ||
1451 u->meta.job->type != JOB_START) {
1452 dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
1453 return bus_send_error_reply(connection, message, &error, -ENOENT);
1457 if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
1458 dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
1459 return bus_send_error_reply(connection, message, &error, -EINVAL);
1462 if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
1463 return bus_send_error_reply(connection, message, &error, r);
1465 if (reload_if_possible && unit_can_reload(u)) {
1466 if (job_type == JOB_RESTART)
1467 job_type = JOB_RELOAD_OR_START;
1468 else if (job_type == JOB_TRY_RESTART)
1469 job_type = JOB_RELOAD;
1472 if ((job_type == JOB_START && u->meta.refuse_manual_start) ||
1473 (job_type == JOB_STOP && u->meta.refuse_manual_stop) ||
1474 ((job_type == JOB_RESTART || job_type == JOB_TRY_RESTART) &&
1475 (u->meta.refuse_manual_start || u->meta.refuse_manual_stop))) {
1476 dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, may be requested by dependency only.");
1477 return bus_send_error_reply(connection, message, &error, -EPERM);
1480 if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
1481 return bus_send_error_reply(connection, message, &error, r);
1483 if (!(j->bus_client = strdup(message_get_sender_with_fallback(message))))
1486 j->bus = connection;
1488 if (!(reply = dbus_message_new_method_return(message)))
1491 if (!(path = job_dbus_path(j)))
1494 if (!dbus_message_append_args(
1496 DBUS_TYPE_OBJECT_PATH, &path,
1502 if (!dbus_connection_send(connection, reply, NULL))
1505 dbus_message_unref(reply);
1510 return DBUS_HANDLER_RESULT_HANDLED;
1516 dbus_message_unref(reply);
1518 dbus_error_free(&error);
1520 return DBUS_HANDLER_RESULT_NEED_MEMORY;
1523 const DBusObjectPathVTable bus_manager_vtable = {
1524 .message_function = bus_manager_message_handler