1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
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/>.
26 #include "dbus-manager.h"
28 #include "bus-errors.h"
30 #define BUS_MANAGER_INTERFACE \
31 " <interface name=\"org.freedesktop.systemd1.Manager\">\n" \
32 " <method name=\"GetUnit\">\n" \
33 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
34 " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
36 " <method name=\"LoadUnit\">\n" \
37 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
38 " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
40 " <method name=\"StartUnit\">\n" \
41 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
42 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
43 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
45 " <method name=\"StopUnit\">\n" \
46 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
47 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
48 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
50 " <method name=\"ReloadUnit\">\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=\"RestartUnit\">\n" \
56 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
57 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
58 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
60 " <method name=\"TryRestartUnit\">\n" \
61 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
62 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
63 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
65 " <method name=\"ReloadOrRestartUnit\">\n" \
66 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
67 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
68 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
70 " <method name=\"ReloadOrTryRestartUnit\">\n" \
71 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
72 " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
73 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
75 " <method name=\"GetJob\">\n" \
76 " <arg name=\"id\" type=\"u\" direction=\"in\"/>\n" \
77 " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
79 " <method name=\"ClearJobs\"/>\n" \
80 " <method name=\"ListUnits\">\n" \
81 " <arg name=\"units\" type=\"a(sssssouso)\" direction=\"out\"/>\n" \
83 " <method name=\"ListJobs\">\n" \
84 " <arg name=\"jobs\" type=\"a(usssoo)\" direction=\"out\"/>\n" \
86 " <method name=\"Subscribe\"/>\n" \
87 " <method name=\"Unsubscribe\"/>\n" \
88 " <method name=\"Dump\"/>\n" \
89 " <method name=\"CreateSnapshot\">\n" \
90 " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
91 " <arg nane=\"cleanup\" type=\"b\" direction=\"in\"/>\n" \
92 " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
94 " <method name=\"Reload\"/>\n" \
95 " <method name=\"Reexecute\"/>\n" \
96 " <method name=\"Exit\"/>\n" \
97 " <method name=\"SetEnvironment\">\n" \
98 " <arg name=\"names\" type=\"as\" direction=\"in\"/>\n" \
100 " <method name=\"UnsetEnvironment\">\n" \
101 " <arg name=\"names\" type=\"as\" direction=\"in\"/>\n" \
103 " <signal name=\"UnitNew\">\n" \
104 " <arg name=\"id\" type=\"s\"/>\n" \
105 " <arg name=\"unit\" type=\"o\"/>\n" \
107 " <signal name=\"UnitRemoved\">\n" \
108 " <arg name=\"id\" type=\"s\"/>\n" \
109 " <arg name=\"unit\" type=\"o\"/>\n" \
111 " <signal name=\"JobNew\">\n" \
112 " <arg name=\"id\" type=\"u\"/>\n" \
113 " <arg name=\"job\" type=\"o\"/>\n" \
115 " <signal name=\"JobRemoved\">\n" \
116 " <arg name=\"id\" type=\"u\"/>\n" \
117 " <arg name=\"job\" type=\"o\"/>\n" \
118 " <arg name=\"success\" type=\"b\"/>\n" \
120 " <property name=\"Version\" type=\"s\" access=\"read\"/>\n" \
121 " <property name=\"RunningAs\" type=\"s\" access=\"read\"/>\n" \
122 " <property name=\"StartupTimestamp\" type=\"t\" access=\"read\"/>\n" \
123 " <property name=\"LogLevel\" type=\"s\" access=\"read\"/>\n" \
124 " <property name=\"LogTarget\" type=\"s\" access=\"read\"/>\n" \
125 " <property name=\"NNames\" type=\"u\" access=\"read\"/>\n" \
126 " <property name=\"NJobs\" type=\"u\" access=\"read\"/>\n" \
127 " <property name=\"Environment\" type=\"as\" access=\"read\"/>\n" \
128 " <property name=\"ConfirmSpawn\" type=\"b\" access=\"read\"/>\n" \
129 " <property name=\"ShowStatus\" type=\"b\" access=\"read\"/>\n" \
130 " <property name=\"UnitPath\" type=\"as\" access=\"read\"/>\n" \
131 " <property name=\"SysVInitPath\" type=\"as\" access=\"read\"/>\n" \
132 " <property name=\"SysVRcndPath\" type=\"as\" access=\"read\"/>\n" \
133 " <property name=\"NotifySocket\" type=\"s\" access=\"read\"/>\n" \
134 " <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
137 #define INTROSPECTION_BEGIN \
138 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
140 BUS_MANAGER_INTERFACE \
141 BUS_PROPERTIES_INTERFACE \
142 BUS_INTROSPECTABLE_INTERFACE
144 #define INTROSPECTION_END \
147 const char bus_manager_interface
[] = BUS_MANAGER_INTERFACE
;
149 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_running_as
, manager_running_as
, ManagerRunningAs
);
151 static int bus_manager_append_log_target(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
158 t
= log_target_to_string(log_get_target());
160 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_STRING
, &t
))
166 static int bus_manager_append_log_level(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
173 t
= log_level_to_string(log_get_max_level());
175 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_STRING
, &t
))
181 static int bus_manager_append_n_names(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
188 u
= hashmap_size(m
->units
);
190 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_UINT32
, &u
))
196 static int bus_manager_append_n_jobs(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
203 u
= hashmap_size(m
->jobs
);
205 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_UINT32
, &u
))
211 static const char *message_get_sender_with_fallback(DBusMessage
*m
) {
216 if ((s
= dbus_message_get_sender(m
)))
219 /* When the message came in from a direct connection the
220 * message will have no sender. We fix that here. */
225 static DBusHandlerResult
bus_manager_message_handler(DBusConnection
*connection
, DBusMessage
*message
, void *data
) {
228 const BusProperty properties
[] = {
229 { "org.freedesktop.systemd1.Manager", "Version", bus_property_append_string
, "s", PACKAGE_STRING
},
230 { "org.freedesktop.systemd1.Manager", "RunningAs", bus_manager_append_running_as
, "s", &m
->running_as
},
231 { "org.freedesktop.systemd1.Manager", "StartupTimestamp", bus_property_append_uint64
, "t", &m
->startup_timestamp
.realtime
},
232 { "org.freedesktop.systemd1.Manager", "LogLevel", bus_manager_append_log_level
, "s", NULL
},
233 { "org.freedesktop.systemd1.Manager", "LogTarget", bus_manager_append_log_target
, "s", NULL
},
234 { "org.freedesktop.systemd1.Manager", "NNames", bus_manager_append_n_names
, "u", NULL
},
235 { "org.freedesktop.systemd1.Manager", "NJobs", bus_manager_append_n_jobs
, "u", NULL
},
236 { "org.freedesktop.systemd1.Manager", "Environment", bus_property_append_strv
, "as", m
->environment
},
237 { "org.freedesktop.systemd1.Manager", "ConfirmSpawn", bus_property_append_bool
, "b", &m
->confirm_spawn
},
238 { "org.freedesktop.systemd1.Manager", "ShowStatus", bus_property_append_bool
, "b", &m
->show_status
},
239 { "org.freedesktop.systemd1.Manager", "UnitPath", bus_property_append_strv
, "as", m
->lookup_paths
.unit_path
},
240 { "org.freedesktop.systemd1.Manager", "SysVInitPath", bus_property_append_strv
, "as", m
->lookup_paths
.sysvinit_path
},
241 { "org.freedesktop.systemd1.Manager", "SysVRcndPath", bus_property_append_strv
, "as", m
->lookup_paths
.sysvrcnd_path
},
242 { "org.freedesktop.systemd1.Manager", "NotifySocket", bus_property_append_string
, "s", m
->notify_socket
},
243 { "org.freedesktop.systemd1.Manager", "ControlGroupHierarchy", bus_property_append_string
, "s", m
->cgroup_hierarchy
},
244 { NULL
, NULL
, NULL
, NULL
, NULL
}
249 DBusMessage
*reply
= NULL
;
251 JobType job_type
= _JOB_TYPE_INVALID
;
252 bool reload_if_possible
= false;
258 dbus_error_init(&error
);
260 if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "GetUnit")) {
264 if (!dbus_message_get_args(
267 DBUS_TYPE_STRING
, &name
,
269 return bus_send_error_reply(m
, connection
, message
, &error
, -EINVAL
);
271 if (!(u
= manager_get_unit(m
, name
))) {
272 dbus_set_error(&error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not loaded.", name
);
273 return bus_send_error_reply(m
, connection
, message
, &error
, -ENOENT
);
276 if (!(reply
= dbus_message_new_method_return(message
)))
279 if (!(path
= unit_dbus_path(u
)))
282 if (!dbus_message_append_args(
284 DBUS_TYPE_OBJECT_PATH
, &path
,
288 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "LoadUnit")) {
292 if (!dbus_message_get_args(
295 DBUS_TYPE_STRING
, &name
,
297 return bus_send_error_reply(m
, connection
, message
, &error
, -EINVAL
);
299 if ((r
= manager_load_unit(m
, name
, NULL
, &error
, &u
)) < 0)
300 return bus_send_error_reply(m
, connection
, message
, &error
, r
);
302 if (!(reply
= dbus_message_new_method_return(message
)))
305 if (!(path
= unit_dbus_path(u
)))
308 if (!dbus_message_append_args(
310 DBUS_TYPE_OBJECT_PATH
, &path
,
314 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "StartUnit"))
315 job_type
= JOB_START
;
316 else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "StopUnit"))
318 else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "ReloadUnit"))
319 job_type
= JOB_RELOAD
;
320 else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "RestartUnit"))
321 job_type
= JOB_RESTART
;
322 else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "TryRestartUnit"))
323 job_type
= JOB_TRY_RESTART
;
324 else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "ReloadOrRestartUnit")) {
325 reload_if_possible
= true;
326 job_type
= JOB_RESTART
;
327 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "ReloadOrTryRestartUnit")) {
328 reload_if_possible
= true;
329 job_type
= JOB_TRY_RESTART
;
330 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "GetJob")) {
334 if (!dbus_message_get_args(
337 DBUS_TYPE_UINT32
, &id
,
339 return bus_send_error_reply(m
, connection
, message
, &error
, -EINVAL
);
341 if (!(j
= manager_get_job(m
, id
))) {
342 dbus_set_error(&error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
343 return bus_send_error_reply(m
, connection
, message
, &error
, -ENOENT
);
346 if (!(reply
= dbus_message_new_method_return(message
)))
349 if (!(path
= job_dbus_path(j
)))
352 if (!dbus_message_append_args(
354 DBUS_TYPE_OBJECT_PATH
, &path
,
358 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "ClearJobs")) {
360 manager_clear_jobs(m
);
362 if (!(reply
= dbus_message_new_method_return(message
)))
365 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "ListUnits")) {
366 DBusMessageIter iter
, sub
;
371 if (!(reply
= dbus_message_new_method_return(message
)))
374 dbus_message_iter_init_append(reply
, &iter
);
376 if (!dbus_message_iter_open_container(&iter
, DBUS_TYPE_ARRAY
, "(sssssouso)", &sub
))
379 HASHMAP_FOREACH_KEY(u
, k
, m
->units
, i
) {
380 char *u_path
, *j_path
;
381 const char *description
, *load_state
, *active_state
, *sub_state
, *sjob_type
;
382 DBusMessageIter sub2
;
388 if (!dbus_message_iter_open_container(&sub
, DBUS_TYPE_STRUCT
, NULL
, &sub2
))
391 description
= unit_description(u
);
392 load_state
= unit_load_state_to_string(u
->meta
.load_state
);
393 active_state
= unit_active_state_to_string(unit_active_state(u
));
394 sub_state
= unit_sub_state_to_string(u
);
396 if (!(u_path
= unit_dbus_path(u
)))
400 job_id
= (uint32_t) u
->meta
.job
->id
;
402 if (!(j_path
= job_dbus_path(u
->meta
.job
))) {
407 sjob_type
= job_type_to_string(u
->meta
.job
->type
);
414 if (!dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_STRING
, &u
->meta
.id
) ||
415 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_STRING
, &description
) ||
416 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_STRING
, &load_state
) ||
417 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_STRING
, &active_state
) ||
418 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_STRING
, &sub_state
) ||
419 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_OBJECT_PATH
, &u_path
) ||
420 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_UINT32
, &job_id
) ||
421 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_STRING
, &sjob_type
) ||
422 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_OBJECT_PATH
, &j_path
)) {
433 if (!dbus_message_iter_close_container(&sub
, &sub2
))
437 if (!dbus_message_iter_close_container(&iter
, &sub
))
440 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "ListJobs")) {
441 DBusMessageIter iter
, sub
;
445 if (!(reply
= dbus_message_new_method_return(message
)))
448 dbus_message_iter_init_append(reply
, &iter
);
450 if (!dbus_message_iter_open_container(&iter
, DBUS_TYPE_ARRAY
, "(usssoo)", &sub
))
453 HASHMAP_FOREACH(j
, m
->jobs
, i
) {
454 char *u_path
, *j_path
;
455 const char *state
, *type
;
457 DBusMessageIter sub2
;
459 if (!dbus_message_iter_open_container(&sub
, DBUS_TYPE_STRUCT
, NULL
, &sub2
))
462 id
= (uint32_t) j
->id
;
463 state
= job_state_to_string(j
->state
);
464 type
= job_type_to_string(j
->type
);
466 if (!(j_path
= job_dbus_path(j
)))
469 if (!(u_path
= unit_dbus_path(j
->unit
))) {
474 if (!dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_UINT32
, &id
) ||
475 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_STRING
, &j
->unit
->meta
.id
) ||
476 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_STRING
, &type
) ||
477 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_STRING
, &state
) ||
478 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_OBJECT_PATH
, &j_path
) ||
479 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_OBJECT_PATH
, &u_path
)) {
488 if (!dbus_message_iter_close_container(&sub
, &sub2
))
492 if (!dbus_message_iter_close_container(&iter
, &sub
))
495 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "Subscribe")) {
499 if (!(s
= BUS_CONNECTION_SUBSCRIBED(m
, connection
))) {
500 if (!(s
= set_new(string_hash_func
, string_compare_func
)))
503 if (!(dbus_connection_set_data(connection
, m
->subscribed_data_slot
, s
, NULL
))) {
509 if (!(client
= strdup(message_get_sender_with_fallback(message
))))
512 if ((r
= set_put(s
, client
)) < 0) {
514 return bus_send_error_reply(m
, connection
, message
, NULL
, r
);
517 if (!(reply
= dbus_message_new_method_return(message
)))
520 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "Unsubscribe")) {
523 if (!(client
= set_remove(BUS_CONNECTION_SUBSCRIBED(m
, connection
), (char*) message_get_sender_with_fallback(message
)))) {
524 dbus_set_error(&error
, BUS_ERROR_NOT_SUBSCRIBED
, "Client is not subscribed.");
525 return bus_send_error_reply(m
, connection
, message
, &error
, -ENOENT
);
530 if (!(reply
= dbus_message_new_method_return(message
)))
533 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "Dump")) {
538 if (!(reply
= dbus_message_new_method_return(message
)))
541 if (!(f
= open_memstream(&dump
, &size
)))
544 manager_dump_units(m
, f
, NULL
);
545 manager_dump_jobs(m
, f
, NULL
);
555 if (!dbus_message_append_args(reply
, DBUS_TYPE_STRING
, &dump
, DBUS_TYPE_INVALID
)) {
561 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "CreateSnapshot")) {
566 if (!dbus_message_get_args(
569 DBUS_TYPE_STRING
, &name
,
570 DBUS_TYPE_BOOLEAN
, &cleanup
,
572 return bus_send_error_reply(m
, connection
, message
, &error
, -EINVAL
);
574 if (name
&& name
[0] == 0)
577 if ((r
= snapshot_create(m
, name
, cleanup
, &error
, &s
)) < 0)
578 return bus_send_error_reply(m
, connection
, message
, &error
, r
);
580 if (!(reply
= dbus_message_new_method_return(message
)))
583 if (!(path
= unit_dbus_path(UNIT(s
))))
586 if (!dbus_message_append_args(
588 DBUS_TYPE_OBJECT_PATH
, &path
,
592 } else if (dbus_message_is_method_call(message
, "org.freedesktop.DBus.Introspectable", "Introspect")) {
593 char *introspection
= NULL
;
601 if (!(reply
= dbus_message_new_method_return(message
)))
604 /* We roll our own introspection code here, instead of
605 * relying on bus_default_message_handler() because we
606 * need to generate our introspection string
609 if (!(f
= open_memstream(&introspection
, &size
)))
612 fputs(INTROSPECTION_BEGIN
, f
);
614 HASHMAP_FOREACH_KEY(u
, k
, m
->units
, i
) {
620 if (!(p
= bus_path_escape(k
))) {
626 fprintf(f
, "<node name=\"unit/%s\"/>", p
);
630 HASHMAP_FOREACH(j
, m
->jobs
, i
)
631 fprintf(f
, "<node name=\"job/%lu\"/>", (unsigned long) j
->id
);
633 fputs(INTROSPECTION_END
, f
);
646 if (!dbus_message_append_args(reply
, DBUS_TYPE_STRING
, &introspection
, DBUS_TYPE_INVALID
)) {
653 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "Reload")) {
655 assert(!m
->queued_message
);
657 /* Instead of sending the reply back right away, we
658 * just remember that we need to and then send it
659 * after the reload is finished. That way the caller
660 * knows when the reload finished. */
662 if (!(m
->queued_message
= dbus_message_new_method_return(message
)))
665 m
->queued_message_connection
= connection
;
666 m
->exit_code
= MANAGER_RELOAD
;
668 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "Reexecute")) {
670 if (!(reply
= dbus_message_new_method_return(message
)))
673 m
->exit_code
= MANAGER_REEXECUTE
;
675 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "Exit")) {
677 if (m
->running_as
== MANAGER_SYSTEM
) {
678 dbus_set_error(&error
, BUS_ERROR_NOT_SUPPORTED
, "Exit is only supported for session managers.");
679 return bus_send_error_reply(m
, connection
, message
, &error
, -ENOTSUP
);
682 if (!(reply
= dbus_message_new_method_return(message
)))
685 m
->exit_code
= MANAGER_EXIT
;
687 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "SetEnvironment")) {
688 char **l
= NULL
, **e
= NULL
;
690 if ((r
= bus_parse_strv(message
, &l
)) < 0) {
694 return bus_send_error_reply(m
, connection
, message
, NULL
, r
);
697 e
= strv_env_merge(2, m
->environment
, l
);
703 if (!(reply
= dbus_message_new_method_return(message
))) {
708 strv_free(m
->environment
);
711 } else if (dbus_message_is_method_call(message
, "org.freedesktop.systemd1.Manager", "UnsetEnvironment")) {
712 char **l
= NULL
, **e
= NULL
;
714 if ((r
= bus_parse_strv(message
, &l
)) < 0) {
718 return bus_send_error_reply(m
, connection
, message
, NULL
, r
);
721 e
= strv_env_delete(m
->environment
, 1, l
);
727 if (!(reply
= dbus_message_new_method_return(message
)))
730 strv_free(m
->environment
);
734 return bus_default_message_handler(m
, connection
, message
, NULL
, properties
);
737 if (job_type
!= _JOB_TYPE_INVALID
) {
738 const char *name
, *smode
;
743 if (!dbus_message_get_args(
746 DBUS_TYPE_STRING
, &name
,
747 DBUS_TYPE_STRING
, &smode
,
749 return bus_send_error_reply(m
, connection
, message
, &error
, -EINVAL
);
751 if ((mode
= job_mode_from_string(smode
)) == _JOB_MODE_INVALID
) {
752 dbus_set_error(&error
, BUS_ERROR_INVALID_JOB_MODE
, "Job mode %s is invalid.", smode
);
753 return bus_send_error_reply(m
, connection
, message
, &error
, -EINVAL
);
756 if ((r
= manager_load_unit(m
, name
, NULL
, &error
, &u
)) < 0)
757 return bus_send_error_reply(m
, connection
, message
, &error
, r
);
759 if (reload_if_possible
&& unit_can_reload(u
)) {
760 if (job_type
== JOB_RESTART
)
761 job_type
= JOB_RELOAD_OR_START
;
762 else if (job_type
== JOB_TRY_RESTART
)
763 job_type
= JOB_RELOAD
;
766 if (job_type
== JOB_START
&& u
->meta
.only_by_dependency
) {
767 dbus_set_error(&error
, BUS_ERROR_ONLY_BY_DEPENDENCY
, "Unit may be activated by dependency only.");
768 return bus_send_error_reply(m
, connection
, message
, &error
, -EPERM
);
771 if ((r
= manager_add_job(m
, job_type
, u
, mode
, true, &error
, &j
)) < 0)
772 return bus_send_error_reply(m
, connection
, message
, &error
, r
);
774 if (!(j
->bus_client
= strdup(message_get_sender_with_fallback(message
))))
779 if (!(reply
= dbus_message_new_method_return(message
)))
782 if (!(path
= job_dbus_path(j
)))
785 if (!dbus_message_append_args(
787 DBUS_TYPE_OBJECT_PATH
, &path
,
795 if (!dbus_connection_send(connection
, reply
, NULL
))
798 dbus_message_unref(reply
);
801 return DBUS_HANDLER_RESULT_HANDLED
;
807 dbus_message_unref(reply
);
809 dbus_error_free(&error
);
811 return DBUS_HANDLER_RESULT_NEED_MEMORY
;
814 const DBusObjectPathVTable bus_manager_vtable
= {
815 .message_function
= bus_manager_message_handler