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 Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
29 #include "selinux-access.h"
31 #include "clock-util.h"
32 #include "path-util.h"
34 #include "architecture.h"
38 #include "dbus-manager.h"
39 #include "dbus-unit.h"
40 #include "dbus-snapshot.h"
41 #include "dbus-execute.h"
42 #include "bus-errors.h"
44 static int property_get_version(
47 const char *interface,
49 sd_bus_message *reply,
51 sd_bus_error *error) {
56 return sd_bus_message_append(reply, "s", PACKAGE_VERSION);
59 static int property_get_features(
62 const char *interface,
64 sd_bus_message *reply,
66 sd_bus_error *error) {
71 return sd_bus_message_append(reply, "s", SYSTEMD_FEATURES);
74 static int property_get_virtualization(
77 const char *interface,
79 sd_bus_message *reply,
81 sd_bus_error *error) {
83 const char *id = NULL;
88 detect_virtualization(&id);
90 return sd_bus_message_append(reply, "s", id);
93 static int property_get_architecture(
96 const char *interface,
98 sd_bus_message *reply,
100 sd_bus_error *error) {
105 return sd_bus_message_append(reply, "s", architecture_to_string(uname_architecture()));
108 static int property_get_tainted(
111 const char *interface,
112 const char *property,
113 sd_bus_message *reply,
115 sd_bus_error *error) {
117 char buf[sizeof("split-usr:mtab-not-symlink:cgroups-missing:local-hwclock:")] = "", *e = buf;
118 _cleanup_free_ char *p = NULL;
119 Manager *m = userdata;
126 e = stpcpy(e, "split-usr:");
128 if (readlink_malloc("/etc/mtab", &p) < 0)
129 e = stpcpy(e, "mtab-not-symlink:");
131 if (access("/proc/cgroups", F_OK) < 0)
132 e = stpcpy(e, "cgroups-missing:");
134 if (clock_is_localtime() > 0)
135 e = stpcpy(e, "local-hwclock:");
137 /* remove the last ':' */
141 return sd_bus_message_append(reply, "s", buf);
144 static int property_get_log_target(
147 const char *interface,
148 const char *property,
149 sd_bus_message *reply,
151 sd_bus_error *error) {
156 return sd_bus_message_append(reply, "s", log_target_to_string(log_get_target()));
159 static int property_set_log_target(
162 const char *interface,
163 const char *property,
164 sd_bus_message *value,
166 sd_bus_error *error) {
174 r = sd_bus_message_read(value, "s", &t);
178 return log_set_target_from_string(t);
181 static int property_get_log_level(
184 const char *interface,
185 const char *property,
186 sd_bus_message *reply,
188 sd_bus_error *error) {
190 _cleanup_free_ char *t = NULL;
196 r = log_level_to_string_alloc(log_get_max_level(), &t);
200 return sd_bus_message_append(reply, "s", t);
203 static int property_set_log_level(
206 const char *interface,
207 const char *property,
208 sd_bus_message *value,
210 sd_bus_error *error) {
218 r = sd_bus_message_read(value, "s", &t);
222 return log_set_max_level_from_string(t);
225 static int property_get_n_names(
228 const char *interface,
229 const char *property,
230 sd_bus_message *reply,
232 sd_bus_error *error) {
234 Manager *m = userdata;
240 return sd_bus_message_append(reply, "u", (uint32_t) hashmap_size(m->units));
243 static int property_get_n_failed_units(
246 const char *interface,
247 const char *property,
248 sd_bus_message *reply,
250 sd_bus_error *error) {
252 Manager *m = userdata;
258 return sd_bus_message_append(reply, "u", (uint32_t) set_size(m->failed_units));
261 static int property_get_n_jobs(
264 const char *interface,
265 const char *property,
266 sd_bus_message *reply,
268 sd_bus_error *error) {
270 Manager *m = userdata;
276 return sd_bus_message_append(reply, "u", (uint32_t) hashmap_size(m->jobs));
279 static int property_get_progress(
282 const char *interface,
283 const char *property,
284 sd_bus_message *reply,
286 sd_bus_error *error) {
288 Manager *m = userdata;
295 if (dual_timestamp_is_set(&m->finish_timestamp))
298 d = 1.0 - ((double) hashmap_size(m->jobs) / (double) m->n_installed_jobs);
300 return sd_bus_message_append(reply, "d", d);
303 static int property_get_system_state(
306 const char *interface,
307 const char *property,
308 sd_bus_message *reply,
310 sd_bus_error *error) {
312 Manager *m = userdata;
318 return sd_bus_message_append(reply, "s", manager_state_to_string(manager_state(m)));
321 static int property_set_runtime_watchdog(
324 const char *interface,
325 const char *property,
326 sd_bus_message *value,
328 sd_bus_error *error) {
330 usec_t *t = userdata;
336 assert_cc(sizeof(usec_t) == sizeof(uint64_t));
338 r = sd_bus_message_read(value, "t", t);
342 return watchdog_set_timeout(t);
345 static int method_get_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
346 _cleanup_free_ char *path = NULL;
347 Manager *m = userdata;
356 r = sd_bus_message_read(message, "s", &name);
360 u = manager_get_unit(m, name);
362 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", name);
364 r = selinux_unit_access_check(u, message, "status", error);
368 path = unit_dbus_path(u);
372 return sd_bus_reply_method_return(message, "o", path);
375 static int method_get_unit_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
376 _cleanup_free_ char *path = NULL;
377 Manager *m = userdata;
386 assert_cc(sizeof(pid_t) == sizeof(uint32_t));
388 r = sd_bus_message_read(message, "u", &pid);
393 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
395 r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
399 r = sd_bus_creds_get_pid(creds, &pid);
404 u = manager_get_unit_by_pid(m, pid);
406 return sd_bus_error_setf(error, BUS_ERROR_NO_UNIT_FOR_PID, "PID %u does not belong to any loaded unit.", pid);
408 r = selinux_unit_access_check(u, message, "status", error);
412 path = unit_dbus_path(u);
416 return sd_bus_reply_method_return(message, "o", path);
419 static int method_load_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
420 _cleanup_free_ char *path = NULL;
421 Manager *m = userdata;
430 r = sd_bus_message_read(message, "s", &name);
434 r = manager_load_unit(m, name, NULL, error, &u);
438 r = selinux_unit_access_check(u, message, "status", error);
442 path = unit_dbus_path(u);
446 return sd_bus_reply_method_return(message, "o", path);
449 static int method_start_unit_generic(sd_bus *bus, sd_bus_message *message, Manager *m, JobType job_type, bool reload_if_possible, sd_bus_error *error) {
458 r = sd_bus_message_read(message, "s", &name);
462 r = manager_load_unit(m, name, NULL, error, &u);
466 return bus_unit_method_start_generic(bus, message, u, job_type, reload_if_possible, error);
469 static int method_start_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
470 return method_start_unit_generic(bus, message, userdata, JOB_START, false, error);
473 static int method_stop_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
474 return method_start_unit_generic(bus, message, userdata, JOB_STOP, false, error);
477 static int method_reload_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
478 return method_start_unit_generic(bus, message, userdata, JOB_RELOAD, false, error);
481 static int method_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
482 return method_start_unit_generic(bus, message, userdata, JOB_RESTART, false, error);
485 static int method_try_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
486 return method_start_unit_generic(bus, message, userdata, JOB_TRY_RESTART, false, error);
489 static int method_reload_or_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
490 return method_start_unit_generic(bus, message, userdata, JOB_RESTART, true, error);
493 static int method_reload_or_try_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
494 return method_start_unit_generic(bus, message, userdata, JOB_TRY_RESTART, true, error);
497 static int method_start_unit_replace(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
498 Manager *m = userdata;
499 const char *old_name;
507 r = sd_bus_message_read(message, "s", &old_name);
511 u = manager_get_unit(m, old_name);
512 if (!u || !u->job || u->job->type != JOB_START)
513 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
515 return method_start_unit_generic(bus, message, m, JOB_START, false, error);
518 static int method_kill_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
519 Manager *m = userdata;
528 r = sd_bus_message_read(message, "s", &name);
532 u = manager_get_unit(m, name);
534 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
536 return bus_unit_method_kill(bus, message, u, error);
539 static int method_reset_failed_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
540 Manager *m = userdata;
549 r = sd_bus_message_read(message, "s", &name);
553 u = manager_get_unit(m, name);
555 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
557 return bus_unit_method_reset_failed(bus, message, u, error);
560 static int method_set_unit_properties(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
561 Manager *m = userdata;
570 r = sd_bus_message_read(message, "s", &name);
574 u = manager_get_unit(m, name);
576 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
578 return bus_unit_method_set_properties(bus, message, u, error);
581 static int method_start_transient_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
582 const char *name, *smode;
583 Manager *m = userdata;
593 r = sd_bus_message_read(message, "ss", &name, &smode);
597 t = unit_name_to_type(name);
599 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit type.");
601 if (!unit_vtable[t]->can_transient)
602 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit type %s does not support transient units.", unit_type_to_string(t));
604 mode = job_mode_from_string(smode);
606 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s is invalid.", smode);
608 r = selinux_access_check(message, "start", error);
612 r = manager_load_unit(m, name, NULL, error, &u);
616 if (u->load_state != UNIT_NOT_FOUND || set_size(u->dependencies[UNIT_REFERENCED_BY]) > 0)
617 return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name);
619 /* OK, the unit failed to load and is unreferenced, now let's
620 * fill in the transient data instead */
621 r = unit_make_transient(u);
625 /* Set our properties */
626 r = bus_unit_set_properties(u, message, UNIT_RUNTIME, false, error);
630 /* And load this stub fully */
635 manager_dispatch_load_queue(m);
637 /* Finally, start it */
638 return bus_unit_queue_job(bus, message, u, JOB_START, mode, false, error);
641 static int method_get_job(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
642 _cleanup_free_ char *path = NULL;
643 Manager *m = userdata;
652 r = sd_bus_message_read(message, "u", &id);
656 j = manager_get_job(m, id);
658 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
660 r = selinux_unit_access_check(j->unit, message, "status", error);
664 path = job_dbus_path(j);
668 return sd_bus_reply_method_return(message, "o", path);
671 static int method_cancel_job(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
672 Manager *m = userdata;
681 r = sd_bus_message_read(message, "u", &id);
685 j = manager_get_job(m, id);
687 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
689 return bus_job_method_cancel(bus, message, j, error);
692 static int method_clear_jobs(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
693 Manager *m = userdata;
700 r = selinux_access_check(message, "reboot", error);
704 manager_clear_jobs(m);
706 return sd_bus_reply_method_return(message, NULL);
709 static int method_reset_failed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
710 Manager *m = userdata;
717 r = selinux_access_check(message, "reload", error);
721 manager_reset_failed(m);
723 return sd_bus_reply_method_return(message, NULL);
726 static int list_units_filtered(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error, char **states) {
727 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
728 Manager *m = userdata;
738 r = selinux_access_check(message, "status", error);
742 r = sd_bus_message_new_method_return(message, &reply);
746 r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)");
750 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
751 _cleanup_free_ char *unit_path = NULL, *job_path = NULL;
757 following = unit_following(u);
759 if (!strv_isempty(states) &&
760 !strv_contains(states, unit_load_state_to_string(u->load_state)) &&
761 !strv_contains(states, unit_active_state_to_string(unit_active_state(u))) &&
762 !strv_contains(states, unit_sub_state_to_string(u)))
765 unit_path = unit_dbus_path(u);
770 job_path = job_dbus_path(u->job);
775 r = sd_bus_message_append(
776 reply, "(ssssssouso)",
779 unit_load_state_to_string(u->load_state),
780 unit_active_state_to_string(unit_active_state(u)),
781 unit_sub_state_to_string(u),
782 following ? following->id : "",
784 u->job ? u->job->id : 0,
785 u->job ? job_type_to_string(u->job->type) : "",
786 job_path ? job_path : "/");
791 r = sd_bus_message_close_container(reply);
795 return sd_bus_send(bus, reply, NULL);
798 static int method_list_units(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
799 return list_units_filtered(bus, message, userdata, error, NULL);
802 static int method_list_units_filtered(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
803 _cleanup_strv_free_ char **states = NULL;
806 r = sd_bus_message_read_strv(message, &states);
810 return list_units_filtered(bus, message, userdata, error, states);
813 static int method_list_jobs(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
814 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
815 Manager *m = userdata;
824 r = selinux_access_check(message, "status", error);
828 r = sd_bus_message_new_method_return(message, &reply);
832 r = sd_bus_message_open_container(reply, 'a', "(usssoo)");
836 HASHMAP_FOREACH(j, m->jobs, i) {
837 _cleanup_free_ char *unit_path = NULL, *job_path = NULL;
839 job_path = job_dbus_path(j);
843 unit_path = unit_dbus_path(j->unit);
847 r = sd_bus_message_append(
851 job_type_to_string(j->type),
852 job_state_to_string(j->state),
859 r = sd_bus_message_close_container(reply);
863 return sd_bus_send(bus, reply, NULL);
866 static int method_subscribe(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
867 Manager *m = userdata;
874 r = selinux_access_check(message, "status", error);
878 if (bus == m->api_bus) {
880 /* Note that direct bus connection subscribe by
881 * default, we only track peers on the API bus here */
883 if (!m->subscribed) {
884 r = sd_bus_track_new(bus, &m->subscribed, NULL, NULL);
889 r = sd_bus_track_add_sender(m->subscribed, message);
893 return sd_bus_error_setf(error, BUS_ERROR_ALREADY_SUBSCRIBED, "Client is already subscribed.");
896 return sd_bus_reply_method_return(message, NULL);
899 static int method_unsubscribe(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
900 Manager *m = userdata;
907 r = selinux_access_check(message, "status", error);
911 if (bus == m->api_bus) {
912 r = sd_bus_track_remove_sender(m->subscribed, message);
916 return sd_bus_error_setf(error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
919 return sd_bus_reply_method_return(message, NULL);
922 static int method_dump(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
923 _cleanup_free_ char *dump = NULL;
924 _cleanup_fclose_ FILE *f = NULL;
925 Manager *m = userdata;
933 r = selinux_access_check(message, "status", error);
937 f = open_memstream(&dump, &size);
941 manager_dump_units(m, f, NULL);
942 manager_dump_jobs(m, f, NULL);
949 return sd_bus_reply_method_return(message, "s", dump);
952 static int method_create_snapshot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
953 _cleanup_free_ char *path = NULL;
954 Manager *m = userdata;
964 r = selinux_access_check(message, "start", error);
968 r = sd_bus_message_read(message, "sb", &name, &cleanup);
975 r = snapshot_create(m, name, cleanup, error, &s);
979 path = unit_dbus_path(UNIT(s));
983 return sd_bus_reply_method_return(message, "o", path);
986 static int method_remove_snapshot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
987 Manager *m = userdata;
996 r = selinux_access_check(message, "stop", error);
1000 r = sd_bus_message_read(message, "s", &name);
1004 u = manager_get_unit(m, name);
1006 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s does not exist.", name);
1008 if (u->type != UNIT_SNAPSHOT)
1009 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not a snapshot", name);
1011 return bus_snapshot_method_remove(bus, message, u, error);
1014 static int method_reload(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1015 Manager *m = userdata;
1022 r = selinux_access_check(message, "reload", error);
1026 /* Instead of sending the reply back right away, we just
1027 * remember that we need to and then send it after the reload
1028 * is finished. That way the caller knows when the reload
1031 assert(!m->queued_message);
1032 r = sd_bus_message_new_method_return(message, &m->queued_message);
1036 m->queued_message_bus = sd_bus_ref(bus);
1037 m->exit_code = MANAGER_RELOAD;
1042 static int method_reexecute(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1043 Manager *m = userdata;
1050 r = selinux_access_check(message, "reload", error);
1054 /* We don't send a reply back here, the client should
1055 * just wait for us disconnecting. */
1057 m->exit_code = MANAGER_REEXECUTE;
1061 static int method_exit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1062 Manager *m = userdata;
1069 r = selinux_access_check(message, "halt", error);
1073 if (m->running_as == SYSTEMD_SYSTEM)
1074 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
1076 m->exit_code = MANAGER_EXIT;
1078 return sd_bus_reply_method_return(message, NULL);
1081 static int method_reboot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1082 Manager *m = userdata;
1089 r = selinux_access_check(message, "reboot", error);
1093 if (m->running_as != SYSTEMD_SYSTEM)
1094 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
1096 m->exit_code = MANAGER_REBOOT;
1098 return sd_bus_reply_method_return(message, NULL);
1102 static int method_poweroff(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1103 Manager *m = userdata;
1110 r = selinux_access_check(message, "halt", error);
1114 if (m->running_as != SYSTEMD_SYSTEM)
1115 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
1117 m->exit_code = MANAGER_POWEROFF;
1119 return sd_bus_reply_method_return(message, NULL);
1122 static int method_halt(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1123 Manager *m = userdata;
1130 r = selinux_access_check(message, "halt", error);
1134 if (m->running_as != SYSTEMD_SYSTEM)
1135 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Halt is only supported for system managers.");
1137 m->exit_code = MANAGER_HALT;
1139 return sd_bus_reply_method_return(message, NULL);
1142 static int method_kexec(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1143 Manager *m = userdata;
1150 r = selinux_access_check(message, "reboot", error);
1154 if (m->running_as != SYSTEMD_SYSTEM)
1155 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers.");
1157 m->exit_code = MANAGER_KEXEC;
1159 return sd_bus_reply_method_return(message, NULL);
1162 static int method_switch_root(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1163 char *ri = NULL, *rt = NULL;
1164 const char *root, *init;
1165 Manager *m = userdata;
1172 r = selinux_access_check(message, "reboot", error);
1176 if (m->running_as != SYSTEMD_SYSTEM)
1177 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers.");
1179 r = sd_bus_message_read(message, "ss", &root, &init);
1183 if (path_equal(root, "/") || !path_is_absolute(root))
1184 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid switch root path %s", root);
1187 if (isempty(init)) {
1188 if (! path_is_os_tree(root))
1189 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified switch root path %s does not seem to be an OS tree. os-release file is missing.", root);
1191 _cleanup_free_ char *p = NULL;
1193 if (!path_is_absolute(init))
1194 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid init path %s", init);
1196 p = strappend(root, init);
1200 if (access(p, X_OK) < 0)
1201 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified init binary %s does not exist.", p);
1208 if (!isempty(init)) {
1216 free(m->switch_root);
1217 m->switch_root = rt;
1219 free(m->switch_root_init);
1220 m->switch_root_init = ri;
1222 m->exit_code = MANAGER_SWITCH_ROOT;
1224 return sd_bus_reply_method_return(message, NULL);
1227 static int method_set_environment(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1228 _cleanup_strv_free_ char **plus = NULL;
1229 Manager *m = userdata;
1236 r = selinux_access_check(message, "reload", error);
1240 r = sd_bus_message_read_strv(message, &plus);
1243 if (!strv_env_is_valid(plus))
1244 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments");
1246 r = manager_environment_add(m, NULL, plus);
1250 return sd_bus_reply_method_return(message, NULL);
1253 static int method_unset_environment(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1254 _cleanup_strv_free_ char **minus = NULL;
1255 Manager *m = userdata;
1262 r = selinux_access_check(message, "reload", error);
1266 r = sd_bus_message_read_strv(message, &minus);
1270 if (!strv_env_name_or_assignment_is_valid(minus))
1271 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments");
1273 r = manager_environment_add(m, minus, NULL);
1277 return sd_bus_reply_method_return(message, NULL);
1280 static int method_unset_and_set_environment(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1281 _cleanup_strv_free_ char **minus = NULL, **plus = NULL;
1282 Manager *m = userdata;
1289 r = selinux_access_check(message, "reload", error);
1293 r = sd_bus_message_read_strv(message, &plus);
1297 r = sd_bus_message_read_strv(message, &minus);
1301 if (!strv_env_is_valid(plus))
1302 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments");
1303 if (!strv_env_name_or_assignment_is_valid(minus))
1304 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments");
1306 r = manager_environment_add(m, minus, plus);
1310 return sd_bus_reply_method_return(message, NULL);
1313 static int method_list_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1314 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
1315 Manager *m = userdata;
1325 r = selinux_access_check(message, "status", error);
1329 r = sd_bus_message_new_method_return(message, &reply);
1333 h = hashmap_new(string_hash_func, string_compare_func);
1337 r = unit_file_get_list(m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);
1341 r = sd_bus_message_open_container(reply, 'a', "(ss)");
1345 HASHMAP_FOREACH(item, h, i) {
1347 r = sd_bus_message_append(reply, "(ss)", item->path, unit_file_state_to_string(item->state));
1352 unit_file_list_free(h);
1354 r = sd_bus_message_close_container(reply);
1358 return sd_bus_send(bus, reply, NULL);
1361 unit_file_list_free(h);
1365 static int method_get_unit_file_state(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1366 Manager *m = userdata;
1368 UnitFileState state;
1369 UnitFileScope scope;
1376 r = selinux_access_check(message, "status", error);
1380 r = sd_bus_message_read(message, "s", &name);
1384 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1386 state = unit_file_get_state(scope, NULL, name);
1390 return sd_bus_reply_method_return(message, "s", unit_file_state_to_string(state));
1393 static int method_get_default_target(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1394 _cleanup_free_ char *default_target = NULL;
1395 Manager *m = userdata;
1396 UnitFileScope scope;
1403 r = selinux_access_check(message, "status", error);
1407 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1409 r = unit_file_get_default(scope, NULL, &default_target);
1413 return sd_bus_reply_method_return(message, "s", default_target);
1416 static int send_unit_files_changed(sd_bus *bus, void *userdata) {
1417 _cleanup_bus_message_unref_ sd_bus_message *message = NULL;
1422 r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
1426 return sd_bus_send(bus, message, NULL);
1429 static int reply_unit_file_changes_and_free(
1432 sd_bus_message *message,
1433 int carries_install_info,
1434 UnitFileChange *changes,
1435 unsigned n_changes) {
1437 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
1441 if (n_changes > 0) {
1442 r = bus_foreach_bus(m, NULL, send_unit_files_changed, NULL);
1444 log_debug("Failed to send UnitFilesChanged signal: %s", strerror(-r));
1447 r = sd_bus_message_new_method_return(message, &reply);
1451 if (carries_install_info >= 0) {
1452 r = sd_bus_message_append(reply, "b", carries_install_info);
1457 r = sd_bus_message_open_container(reply, 'a', "(sss)");
1461 for (i = 0; i < n_changes; i++) {
1462 r = sd_bus_message_append(
1464 unit_file_change_type_to_string(changes[i].type),
1471 r = sd_bus_message_close_container(reply);
1475 return sd_bus_send(bus, reply, NULL);
1478 unit_file_changes_free(changes, n_changes);
1482 static int method_enable_unit_files_generic(
1484 sd_bus_message *message,
1487 int (*call)(UnitFileScope scope, bool runtime, const char *root_dir, char *files[], bool force, UnitFileChange **changes, unsigned *n_changes),
1488 bool carries_install_info,
1489 sd_bus_error *error) {
1491 _cleanup_strv_free_ char **l = NULL;
1495 UnitFileChange *changes = NULL;
1496 unsigned n_changes = 0;
1497 UnitFileScope scope;
1498 int runtime, force, r;
1504 r = sd_bus_message_read_strv(message, &l);
1508 r = sd_bus_message_read(message, "bb", &runtime, &force);
1513 STRV_FOREACH(i, l) {
1516 u = manager_get_unit(m, *i);
1518 r = selinux_unit_access_check(u, message, verb, error);
1525 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1527 r = call(scope, runtime, NULL, l, force, &changes, &n_changes);
1531 return reply_unit_file_changes_and_free(m, bus, message, carries_install_info ? r : -1, changes, n_changes);
1534 static int method_enable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1535 return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_enable, true, error);
1538 static int method_reenable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1539 return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_reenable, true, error);
1542 static int method_link_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1543 return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_link, false, error);
1546 static int unit_file_preset_without_mode(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes) {
1547 return unit_file_preset(scope, runtime, root_dir, files, UNIT_FILE_PRESET_FULL, force, changes, n_changes);
1550 static int method_preset_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1551 return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_preset_without_mode, true, error);
1554 static int method_mask_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1555 return method_enable_unit_files_generic(bus, message, userdata, "disable", unit_file_mask, false, error);
1558 static int method_preset_unit_files_with_mode(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1560 _cleanup_strv_free_ char **l = NULL;
1564 UnitFileChange *changes = NULL;
1565 unsigned n_changes = 0;
1566 Manager *m = userdata;
1567 UnitFilePresetMode mm;
1568 UnitFileScope scope;
1569 int runtime, force, r;
1576 r = sd_bus_message_read_strv(message, &l);
1580 r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force);
1585 mm = UNIT_FILE_PRESET_FULL;
1587 mm = unit_file_preset_mode_from_string(mode);
1593 STRV_FOREACH(i, l) {
1596 u = manager_get_unit(m, *i);
1598 r = selinux_unit_access_check(u, message, "enable", error);
1605 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1607 r = unit_file_preset(scope, runtime, NULL, l, mm, force, &changes, &n_changes);
1611 return reply_unit_file_changes_and_free(m, bus, message, r, changes, n_changes);
1614 static int method_disable_unit_files_generic(
1616 sd_bus_message *message,
1619 int (*call)(UnitFileScope scope, bool runtime, const char *root_dir, char *files[], UnitFileChange **changes, unsigned *n_changes),
1620 sd_bus_error *error) {
1622 _cleanup_strv_free_ char **l = NULL;
1623 UnitFileChange *changes = NULL;
1624 unsigned n_changes = 0;
1625 UnitFileScope scope;
1632 r = selinux_access_check(message, verb, error);
1636 r = sd_bus_message_read_strv(message, &l);
1640 r = sd_bus_message_read(message, "b", &runtime);
1644 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1646 r = call(scope, runtime, NULL, l, &changes, &n_changes);
1650 return reply_unit_file_changes_and_free(m, bus, message, -1, changes, n_changes);
1653 static int method_disable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1654 return method_disable_unit_files_generic(bus, message, userdata, "disable", unit_file_disable, error);
1657 static int method_unmask_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1658 return method_disable_unit_files_generic(bus, message, userdata, "enable", unit_file_unmask, error);
1661 static int method_set_default_target(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1662 UnitFileChange *changes = NULL;
1663 unsigned n_changes = 0;
1664 Manager *m = userdata;
1665 UnitFileScope scope;
1673 r = selinux_access_check(message, "enable", error);
1677 r = sd_bus_message_read(message, "sb", &name, &force);
1681 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1683 r = unit_file_set_default(scope, NULL, name, force, &changes, &n_changes);
1687 return reply_unit_file_changes_and_free(m, bus, message, -1, changes, n_changes);
1690 static int method_preset_all_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1691 UnitFileChange *changes = NULL;
1692 unsigned n_changes = 0;
1693 Manager *m = userdata;
1694 UnitFilePresetMode mm;
1695 UnitFileScope scope;
1697 int force, runtime, r;
1703 r = selinux_access_check(message, "enable", error);
1707 r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force);
1712 mm = UNIT_FILE_PRESET_FULL;
1714 mm = unit_file_preset_mode_from_string(mode);
1719 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1721 r = unit_file_preset_all(scope, runtime, NULL, mm, force, &changes, &n_changes);
1725 return reply_unit_file_changes_and_free(m, bus, message, -1, changes, n_changes);
1728 const sd_bus_vtable bus_manager_vtable[] = {
1729 SD_BUS_VTABLE_START(0),
1731 SD_BUS_PROPERTY("Version", "s", property_get_version, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1732 SD_BUS_PROPERTY("Features", "s", property_get_features, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1733 SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1734 SD_BUS_PROPERTY("Architecture", "s", property_get_architecture, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1735 SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1736 BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager, firmware_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1737 BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager, loader_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1738 BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager, kernel_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1739 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager, initrd_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1740 BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager, userspace_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1741 BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager, finish_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1742 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager, security_start_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1743 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager, security_finish_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1744 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager, generators_start_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1745 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager, generators_finish_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1746 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager, units_load_start_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1747 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager, units_load_finish_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1748 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level, property_set_log_level, 0, 0),
1749 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target, property_set_log_target, 0, 0),
1750 SD_BUS_PROPERTY("NNames", "u", property_get_n_names, 0, 0),
1751 SD_BUS_PROPERTY("NFailedUnits", "u", property_get_n_failed_units, 0, 0),
1752 SD_BUS_PROPERTY("NJobs", "u", property_get_n_jobs, 0, 0),
1753 SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_installed_jobs), 0),
1754 SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_failed_jobs), 0),
1755 SD_BUS_PROPERTY("Progress", "d", property_get_progress, 0, 0),
1756 SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(Manager, environment), 0),
1757 SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool, offsetof(Manager, confirm_spawn), SD_BUS_VTABLE_PROPERTY_CONST),
1758 SD_BUS_PROPERTY("ShowStatus", "b", bus_property_get_bool, offsetof(Manager, show_status), SD_BUS_VTABLE_PROPERTY_CONST),
1759 SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.unit_path), SD_BUS_VTABLE_PROPERTY_CONST),
1760 SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST),
1761 SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST),
1762 SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec, property_set_runtime_watchdog, offsetof(Manager, runtime_watchdog), SD_BUS_VTABLE_PROPERTY_CONST),
1763 SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec, bus_property_set_usec, offsetof(Manager, shutdown_watchdog), SD_BUS_VTABLE_PROPERTY_CONST),
1764 SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Manager, cgroup_root), 0),
1765 SD_BUS_PROPERTY("SystemState", "s", property_get_system_state, 0, 0),
1767 SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1768 SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid, SD_BUS_VTABLE_UNPRIVILEGED),
1769 SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1770 SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit, 0),
1771 SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace, 0),
1772 SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit, 0),
1773 SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit, 0),
1774 SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit, 0),
1775 SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit, 0),
1776 SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit, 0),
1777 SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit, 0),
1778 SD_BUS_METHOD("KillUnit", "ssi", NULL, method_kill_unit, SD_BUS_VTABLE_CAPABILITY(CAP_KILL)),
1779 SD_BUS_METHOD("ResetFailedUnit", "s", NULL, method_reset_failed_unit, 0),
1780 SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL, method_set_unit_properties, 0),
1781 SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit, 0),
1782 SD_BUS_METHOD("GetJob", "u", "o", method_get_job, SD_BUS_VTABLE_UNPRIVILEGED),
1783 SD_BUS_METHOD("CancelJob", "u", NULL, method_cancel_job, 0),
1784 SD_BUS_METHOD("ClearJobs", NULL, NULL, method_clear_jobs, 0),
1785 SD_BUS_METHOD("ResetFailed", NULL, NULL, method_reset_failed, 0),
1786 SD_BUS_METHOD("ListUnits", NULL, "a(ssssssouso)", method_list_units, SD_BUS_VTABLE_UNPRIVILEGED),
1787 SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered, SD_BUS_VTABLE_UNPRIVILEGED),
1788 SD_BUS_METHOD("ListJobs", NULL, "a(usssoo)", method_list_jobs, SD_BUS_VTABLE_UNPRIVILEGED),
1789 SD_BUS_METHOD("Subscribe", NULL, NULL, method_subscribe, SD_BUS_VTABLE_UNPRIVILEGED),
1790 SD_BUS_METHOD("Unsubscribe", NULL, NULL, method_unsubscribe, SD_BUS_VTABLE_UNPRIVILEGED),
1791 SD_BUS_METHOD("Dump", NULL, "s", method_dump, SD_BUS_VTABLE_UNPRIVILEGED),
1792 SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_create_snapshot, 0),
1793 SD_BUS_METHOD("RemoveSnapshot", "s", NULL, method_remove_snapshot, 0),
1794 SD_BUS_METHOD("Reload", NULL, NULL, method_reload, 0),
1795 SD_BUS_METHOD("Reexecute", NULL, NULL, method_reexecute, 0),
1796 SD_BUS_METHOD("Exit", NULL, NULL, method_exit, 0),
1797 SD_BUS_METHOD("Reboot", NULL, NULL, method_reboot, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1798 SD_BUS_METHOD("PowerOff", NULL, NULL, method_poweroff, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1799 SD_BUS_METHOD("Halt", NULL, NULL, method_halt, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1800 SD_BUS_METHOD("KExec", NULL, NULL, method_kexec, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1801 SD_BUS_METHOD("SwitchRoot", "ss", NULL, method_switch_root, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1802 SD_BUS_METHOD("SetEnvironment", "as", NULL, method_set_environment, 0),
1803 SD_BUS_METHOD("UnsetEnvironment", "as", NULL, method_unset_environment, 0),
1804 SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL, method_unset_and_set_environment, 0),
1805 SD_BUS_METHOD("ListUnitFiles", NULL, "a(ss)", method_list_unit_files, SD_BUS_VTABLE_UNPRIVILEGED),
1806 SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state, SD_BUS_VTABLE_UNPRIVILEGED),
1807 SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files, 0),
1808 SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files, 0),
1809 SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files, 0),
1810 SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files, 0),
1811 SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files, 0),
1812 SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode, 0),
1813 SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files, 0),
1814 SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files, 0),
1815 SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target, 0),
1816 SD_BUS_METHOD("GetDefaultTarget", NULL, "s", method_get_default_target, SD_BUS_VTABLE_UNPRIVILEGED),
1817 SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files, 0),
1819 SD_BUS_SIGNAL("UnitNew", "so", 0),
1820 SD_BUS_SIGNAL("UnitRemoved", "so", 0),
1821 SD_BUS_SIGNAL("JobNew", "uos", 0),
1822 SD_BUS_SIGNAL("JobRemoved", "uoss", 0),
1823 SD_BUS_SIGNAL("StartupFinished", "tttttt", 0),
1824 SD_BUS_SIGNAL("UnitFilesChanged", NULL, 0),
1825 SD_BUS_SIGNAL("Reloading", "b", 0),
1830 static int send_finished(sd_bus *bus, void *userdata) {
1831 _cleanup_bus_message_unref_ sd_bus_message *message = NULL;
1832 usec_t *times = userdata;
1838 r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
1842 r = sd_bus_message_append(message, "tttttt", times[0], times[1], times[2], times[3], times[4], times[5]);
1846 return sd_bus_send(bus, message, NULL);
1849 void bus_manager_send_finished(
1851 usec_t firmware_usec,
1855 usec_t userspace_usec,
1856 usec_t total_usec) {
1862 r = bus_foreach_bus(
1875 log_debug("Failed to send finished signal: %s", strerror(-r));
1878 static int send_reloading(sd_bus *bus, void *userdata) {
1879 _cleanup_bus_message_unref_ sd_bus_message *message = NULL;
1884 r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
1888 r = sd_bus_message_append(message, "b", PTR_TO_INT(userdata));
1892 return sd_bus_send(bus, message, NULL);
1895 void bus_manager_send_reloading(Manager *m, bool active) {
1900 r = bus_foreach_bus(m, NULL, send_reloading, INT_TO_PTR(active));
1902 log_debug("Failed to send reloading signal: %s", strerror(-r));