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 /* Anyone can call this method */
358 r = sd_bus_message_read(message, "s", &name);
362 u = manager_get_unit(m, name);
364 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", name);
366 r = selinux_unit_access_check(u, message, "status", error);
370 path = unit_dbus_path(u);
374 return sd_bus_reply_method_return(message, "o", path);
377 static int method_get_unit_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
378 _cleanup_free_ char *path = NULL;
379 Manager *m = userdata;
388 assert_cc(sizeof(pid_t) == sizeof(uint32_t));
390 /* Anyone can call this method */
392 r = sd_bus_message_read(message, "u", &pid);
397 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
399 r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
403 r = sd_bus_creds_get_pid(creds, &pid);
408 u = manager_get_unit_by_pid(m, pid);
410 return sd_bus_error_setf(error, BUS_ERROR_NO_UNIT_FOR_PID, "PID %u does not belong to any loaded unit.", pid);
412 r = selinux_unit_access_check(u, message, "status", error);
416 path = unit_dbus_path(u);
420 return sd_bus_reply_method_return(message, "o", path);
423 static int method_load_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
424 _cleanup_free_ char *path = NULL;
425 Manager *m = userdata;
434 /* Anyone can call this method */
436 r = sd_bus_message_read(message, "s", &name);
440 r = manager_load_unit(m, name, NULL, error, &u);
444 r = selinux_unit_access_check(u, message, "status", error);
448 path = unit_dbus_path(u);
452 return sd_bus_reply_method_return(message, "o", path);
455 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) {
464 r = bus_verify_manage_unit_async(m, message, error);
468 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
470 r = sd_bus_message_read(message, "s", &name);
474 r = manager_load_unit(m, name, NULL, error, &u);
478 return bus_unit_method_start_generic(bus, message, u, job_type, reload_if_possible, error);
481 static int method_start_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
482 return method_start_unit_generic(bus, message, userdata, JOB_START, false, error);
485 static int method_stop_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
486 return method_start_unit_generic(bus, message, userdata, JOB_STOP, false, error);
489 static int method_reload_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
490 return method_start_unit_generic(bus, message, userdata, JOB_RELOAD, false, error);
493 static int method_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_RESTART, false, error);
497 static int method_try_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
498 return method_start_unit_generic(bus, message, userdata, JOB_TRY_RESTART, false, error);
501 static int method_reload_or_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
502 return method_start_unit_generic(bus, message, userdata, JOB_RESTART, true, error);
505 static int method_reload_or_try_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
506 return method_start_unit_generic(bus, message, userdata, JOB_TRY_RESTART, true, error);
509 static int method_start_unit_replace(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
510 Manager *m = userdata;
511 const char *old_name;
519 r = bus_verify_manage_unit_async(m, message, error);
523 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
525 r = sd_bus_message_read(message, "s", &old_name);
529 u = manager_get_unit(m, old_name);
530 if (!u || !u->job || u->job->type != JOB_START)
531 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
533 return method_start_unit_generic(bus, message, m, JOB_START, false, error);
536 static int method_kill_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
537 Manager *m = userdata;
546 /* Like bus_verify_manage_unit_async(), but uses CAP_SYS_KILL */
547 r = bus_verify_manage_unit_async_for_kill(m, message, error);
551 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
553 r = sd_bus_message_read(message, "s", &name);
557 u = manager_get_unit(m, name);
559 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
561 return bus_unit_method_kill(bus, message, u, error);
564 static int method_reset_failed_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
565 Manager *m = userdata;
574 r = bus_verify_manage_unit_async(m, message, error);
578 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
580 r = sd_bus_message_read(message, "s", &name);
584 u = manager_get_unit(m, name);
586 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
588 return bus_unit_method_reset_failed(bus, message, u, error);
591 static int method_set_unit_properties(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
592 Manager *m = userdata;
601 r = bus_verify_manage_unit_async(m, message, error);
605 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
607 r = sd_bus_message_read(message, "s", &name);
611 u = manager_get_unit(m, name);
613 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
615 return bus_unit_method_set_properties(bus, message, u, error);
618 static int method_start_transient_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
619 const char *name, *smode;
620 Manager *m = userdata;
630 r = bus_verify_manage_unit_async(m, message, error);
634 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
636 r = sd_bus_message_read(message, "ss", &name, &smode);
640 t = unit_name_to_type(name);
642 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit type.");
644 if (!unit_vtable[t]->can_transient)
645 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit type %s does not support transient units.", unit_type_to_string(t));
647 mode = job_mode_from_string(smode);
649 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s is invalid.", smode);
651 r = selinux_access_check(message, "start", error);
655 r = manager_load_unit(m, name, NULL, error, &u);
659 if (u->load_state != UNIT_NOT_FOUND || set_size(u->dependencies[UNIT_REFERENCED_BY]) > 0)
660 return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name);
662 /* OK, the unit failed to load and is unreferenced, now let's
663 * fill in the transient data instead */
664 r = unit_make_transient(u);
668 /* Set our properties */
669 r = bus_unit_set_properties(u, message, UNIT_RUNTIME, false, error);
673 /* And load this stub fully */
678 manager_dispatch_load_queue(m);
680 /* Finally, start it */
681 return bus_unit_queue_job(bus, message, u, JOB_START, mode, false, error);
684 static int method_get_job(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
685 _cleanup_free_ char *path = NULL;
686 Manager *m = userdata;
695 /* Anyone can call this method */
697 r = sd_bus_message_read(message, "u", &id);
701 j = manager_get_job(m, id);
703 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
705 r = selinux_unit_access_check(j->unit, message, "status", error);
709 path = job_dbus_path(j);
713 return sd_bus_reply_method_return(message, "o", path);
716 static int method_cancel_job(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
717 Manager *m = userdata;
726 r = sd_bus_message_read(message, "u", &id);
730 j = manager_get_job(m, id);
732 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
734 return bus_job_method_cancel(bus, message, j, error);
737 static int method_clear_jobs(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
738 Manager *m = userdata;
745 r = selinux_access_check(message, "reboot", error);
749 manager_clear_jobs(m);
751 return sd_bus_reply_method_return(message, NULL);
754 static int method_reset_failed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
755 Manager *m = userdata;
762 r = selinux_access_check(message, "reload", error);
766 manager_reset_failed(m);
768 return sd_bus_reply_method_return(message, NULL);
771 static int list_units_filtered(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error, char **states) {
772 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
773 Manager *m = userdata;
783 /* Anyone can call this method */
785 r = selinux_access_check(message, "status", error);
789 r = sd_bus_message_new_method_return(message, &reply);
793 r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)");
797 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
798 _cleanup_free_ char *unit_path = NULL, *job_path = NULL;
804 following = unit_following(u);
806 if (!strv_isempty(states) &&
807 !strv_contains(states, unit_load_state_to_string(u->load_state)) &&
808 !strv_contains(states, unit_active_state_to_string(unit_active_state(u))) &&
809 !strv_contains(states, unit_sub_state_to_string(u)))
812 unit_path = unit_dbus_path(u);
817 job_path = job_dbus_path(u->job);
822 r = sd_bus_message_append(
823 reply, "(ssssssouso)",
826 unit_load_state_to_string(u->load_state),
827 unit_active_state_to_string(unit_active_state(u)),
828 unit_sub_state_to_string(u),
829 following ? following->id : "",
831 u->job ? u->job->id : 0,
832 u->job ? job_type_to_string(u->job->type) : "",
833 job_path ? job_path : "/");
838 r = sd_bus_message_close_container(reply);
842 return sd_bus_send(bus, reply, NULL);
845 static int method_list_units(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
846 return list_units_filtered(bus, message, userdata, error, NULL);
849 static int method_list_units_filtered(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
850 _cleanup_strv_free_ char **states = NULL;
853 r = sd_bus_message_read_strv(message, &states);
857 return list_units_filtered(bus, message, userdata, error, states);
860 static int method_list_jobs(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
861 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
862 Manager *m = userdata;
871 /* Anyone can call this method */
873 r = selinux_access_check(message, "status", error);
877 r = sd_bus_message_new_method_return(message, &reply);
881 r = sd_bus_message_open_container(reply, 'a', "(usssoo)");
885 HASHMAP_FOREACH(j, m->jobs, i) {
886 _cleanup_free_ char *unit_path = NULL, *job_path = NULL;
888 job_path = job_dbus_path(j);
892 unit_path = unit_dbus_path(j->unit);
896 r = sd_bus_message_append(
900 job_type_to_string(j->type),
901 job_state_to_string(j->state),
908 r = sd_bus_message_close_container(reply);
912 return sd_bus_send(bus, reply, NULL);
915 static int method_subscribe(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
916 Manager *m = userdata;
923 /* Anyone can call this method */
925 r = selinux_access_check(message, "status", error);
929 if (bus == m->api_bus) {
931 /* Note that direct bus connection subscribe by
932 * default, we only track peers on the API bus here */
934 if (!m->subscribed) {
935 r = sd_bus_track_new(bus, &m->subscribed, NULL, NULL);
940 r = sd_bus_track_add_sender(m->subscribed, message);
944 return sd_bus_error_setf(error, BUS_ERROR_ALREADY_SUBSCRIBED, "Client is already subscribed.");
947 return sd_bus_reply_method_return(message, NULL);
950 static int method_unsubscribe(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
951 Manager *m = userdata;
958 /* Anyone can call this method */
960 r = selinux_access_check(message, "status", error);
964 if (bus == m->api_bus) {
965 r = sd_bus_track_remove_sender(m->subscribed, message);
969 return sd_bus_error_setf(error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
972 return sd_bus_reply_method_return(message, NULL);
975 static int method_dump(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
976 _cleanup_free_ char *dump = NULL;
977 _cleanup_fclose_ FILE *f = NULL;
978 Manager *m = userdata;
986 /* Anyone can call this method */
988 r = selinux_access_check(message, "status", error);
992 f = open_memstream(&dump, &size);
996 manager_dump_units(m, f, NULL);
997 manager_dump_jobs(m, f, NULL);
1004 return sd_bus_reply_method_return(message, "s", dump);
1007 static int method_create_snapshot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1008 _cleanup_free_ char *path = NULL;
1009 Manager *m = userdata;
1019 r = selinux_access_check(message, "start", error);
1023 r = sd_bus_message_read(message, "sb", &name, &cleanup);
1030 r = snapshot_create(m, name, cleanup, error, &s);
1034 path = unit_dbus_path(UNIT(s));
1038 return sd_bus_reply_method_return(message, "o", path);
1041 static int method_remove_snapshot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1042 Manager *m = userdata;
1051 r = selinux_access_check(message, "stop", error);
1055 r = sd_bus_message_read(message, "s", &name);
1059 u = manager_get_unit(m, name);
1061 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s does not exist.", name);
1063 if (u->type != UNIT_SNAPSHOT)
1064 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not a snapshot", name);
1066 return bus_snapshot_method_remove(bus, message, u, error);
1069 static int method_reload(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1070 Manager *m = userdata;
1077 r = bus_verify_reload_daemon_async(m, message, error);
1081 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1083 r = selinux_access_check(message, "reload", error);
1087 /* Instead of sending the reply back right away, we just
1088 * remember that we need to and then send it after the reload
1089 * is finished. That way the caller knows when the reload
1092 assert(!m->queued_message);
1093 r = sd_bus_message_new_method_return(message, &m->queued_message);
1097 m->queued_message_bus = sd_bus_ref(bus);
1098 m->exit_code = MANAGER_RELOAD;
1103 static int method_reexecute(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1104 Manager *m = userdata;
1111 r = bus_verify_reload_daemon_async(m, message, error);
1115 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1117 r = selinux_access_check(message, "reload", error);
1121 /* We don't send a reply back here, the client should
1122 * just wait for us disconnecting. */
1124 m->exit_code = MANAGER_REEXECUTE;
1128 static int method_exit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1129 Manager *m = userdata;
1136 r = selinux_access_check(message, "halt", error);
1140 if (m->running_as == SYSTEMD_SYSTEM)
1141 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
1143 m->exit_code = MANAGER_EXIT;
1145 return sd_bus_reply_method_return(message, NULL);
1148 static int method_reboot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1149 Manager *m = userdata;
1156 r = selinux_access_check(message, "reboot", error);
1160 if (m->running_as != SYSTEMD_SYSTEM)
1161 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
1163 m->exit_code = MANAGER_REBOOT;
1165 return sd_bus_reply_method_return(message, NULL);
1169 static int method_poweroff(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1170 Manager *m = userdata;
1177 r = selinux_access_check(message, "halt", error);
1181 if (m->running_as != SYSTEMD_SYSTEM)
1182 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
1184 m->exit_code = MANAGER_POWEROFF;
1186 return sd_bus_reply_method_return(message, NULL);
1189 static int method_halt(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1190 Manager *m = userdata;
1197 r = selinux_access_check(message, "halt", error);
1201 if (m->running_as != SYSTEMD_SYSTEM)
1202 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Halt is only supported for system managers.");
1204 m->exit_code = MANAGER_HALT;
1206 return sd_bus_reply_method_return(message, NULL);
1209 static int method_kexec(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1210 Manager *m = userdata;
1217 r = selinux_access_check(message, "reboot", error);
1221 if (m->running_as != SYSTEMD_SYSTEM)
1222 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers.");
1224 m->exit_code = MANAGER_KEXEC;
1226 return sd_bus_reply_method_return(message, NULL);
1229 static int method_switch_root(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1230 char *ri = NULL, *rt = NULL;
1231 const char *root, *init;
1232 Manager *m = userdata;
1239 r = selinux_access_check(message, "reboot", error);
1243 if (m->running_as != SYSTEMD_SYSTEM)
1244 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Root switching is only supported by system manager.");
1246 r = sd_bus_message_read(message, "ss", &root, &init);
1250 if (path_equal(root, "/") || !path_is_absolute(root))
1251 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid switch root path %s", root);
1254 if (isempty(init)) {
1255 if (!path_is_os_tree(root))
1256 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);
1258 _cleanup_free_ char *p = NULL;
1260 if (!path_is_absolute(init))
1261 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid init path %s", init);
1263 p = strappend(root, init);
1267 if (access(p, X_OK) < 0)
1268 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified init binary %s does not exist.", p);
1275 if (!isempty(init)) {
1283 free(m->switch_root);
1284 m->switch_root = rt;
1286 free(m->switch_root_init);
1287 m->switch_root_init = ri;
1289 m->exit_code = MANAGER_SWITCH_ROOT;
1291 return sd_bus_reply_method_return(message, NULL);
1294 static int method_set_environment(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1295 _cleanup_strv_free_ char **plus = NULL;
1296 Manager *m = userdata;
1303 r = selinux_access_check(message, "reload", error);
1307 r = sd_bus_message_read_strv(message, &plus);
1310 if (!strv_env_is_valid(plus))
1311 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments");
1313 r = manager_environment_add(m, NULL, plus);
1317 return sd_bus_reply_method_return(message, NULL);
1320 static int method_unset_environment(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1321 _cleanup_strv_free_ char **minus = NULL;
1322 Manager *m = userdata;
1329 r = selinux_access_check(message, "reload", error);
1333 r = sd_bus_message_read_strv(message, &minus);
1337 if (!strv_env_name_or_assignment_is_valid(minus))
1338 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments");
1340 r = manager_environment_add(m, minus, NULL);
1344 return sd_bus_reply_method_return(message, NULL);
1347 static int method_unset_and_set_environment(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1348 _cleanup_strv_free_ char **minus = NULL, **plus = NULL;
1349 Manager *m = userdata;
1356 r = selinux_access_check(message, "reload", error);
1360 r = sd_bus_message_read_strv(message, &minus);
1364 r = sd_bus_message_read_strv(message, &plus);
1368 if (!strv_env_name_or_assignment_is_valid(minus))
1369 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments");
1370 if (!strv_env_is_valid(plus))
1371 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments");
1373 r = manager_environment_add(m, minus, plus);
1377 return sd_bus_reply_method_return(message, NULL);
1380 static int method_list_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1381 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
1382 Manager *m = userdata;
1392 /* Anyone can call this method */
1394 r = selinux_access_check(message, "status", error);
1398 r = sd_bus_message_new_method_return(message, &reply);
1402 h = hashmap_new(&string_hash_ops);
1406 r = unit_file_get_list(m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);
1410 r = sd_bus_message_open_container(reply, 'a', "(ss)");
1414 HASHMAP_FOREACH(item, h, i) {
1416 r = sd_bus_message_append(reply, "(ss)", item->path, unit_file_state_to_string(item->state));
1421 unit_file_list_free(h);
1423 r = sd_bus_message_close_container(reply);
1427 return sd_bus_send(bus, reply, NULL);
1430 unit_file_list_free(h);
1434 static int method_get_unit_file_state(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1435 Manager *m = userdata;
1437 UnitFileState state;
1438 UnitFileScope scope;
1445 /* Anyone can call this method */
1447 r = selinux_access_check(message, "status", error);
1451 r = sd_bus_message_read(message, "s", &name);
1455 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1457 state = unit_file_get_state(scope, NULL, name);
1461 return sd_bus_reply_method_return(message, "s", unit_file_state_to_string(state));
1464 static int method_get_default_target(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1465 _cleanup_free_ char *default_target = NULL;
1466 Manager *m = userdata;
1467 UnitFileScope scope;
1474 /* Anyone can call this method */
1476 r = selinux_access_check(message, "status", error);
1480 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1482 r = unit_file_get_default(scope, NULL, &default_target);
1486 return sd_bus_reply_method_return(message, "s", default_target);
1489 static int send_unit_files_changed(sd_bus *bus, void *userdata) {
1490 _cleanup_bus_message_unref_ sd_bus_message *message = NULL;
1495 r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
1499 return sd_bus_send(bus, message, NULL);
1502 static int reply_unit_file_changes_and_free(
1505 sd_bus_message *message,
1506 int carries_install_info,
1507 UnitFileChange *changes,
1508 unsigned n_changes) {
1510 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
1514 if (n_changes > 0) {
1515 r = bus_foreach_bus(m, NULL, send_unit_files_changed, NULL);
1517 log_debug("Failed to send UnitFilesChanged signal: %s", strerror(-r));
1520 r = sd_bus_message_new_method_return(message, &reply);
1524 if (carries_install_info >= 0) {
1525 r = sd_bus_message_append(reply, "b", carries_install_info);
1530 r = sd_bus_message_open_container(reply, 'a', "(sss)");
1534 for (i = 0; i < n_changes; i++) {
1535 r = sd_bus_message_append(
1537 unit_file_change_type_to_string(changes[i].type),
1544 r = sd_bus_message_close_container(reply);
1548 return sd_bus_send(bus, reply, NULL);
1551 unit_file_changes_free(changes, n_changes);
1555 static int method_enable_unit_files_generic(
1557 sd_bus_message *message,
1560 int (*call)(UnitFileScope scope, bool runtime, const char *root_dir, char *files[], bool force, UnitFileChange **changes, unsigned *n_changes),
1561 bool carries_install_info,
1562 sd_bus_error *error) {
1564 _cleanup_strv_free_ char **l = NULL;
1568 UnitFileChange *changes = NULL;
1569 unsigned n_changes = 0;
1570 UnitFileScope scope;
1571 int runtime, force, r;
1577 r = bus_verify_manage_unit_files_async(m, message, error);
1581 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1583 r = sd_bus_message_read_strv(message, &l);
1587 r = sd_bus_message_read(message, "bb", &runtime, &force);
1592 STRV_FOREACH(i, l) {
1595 u = manager_get_unit(m, *i);
1597 r = selinux_unit_access_check(u, message, verb, error);
1604 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1606 r = call(scope, runtime, NULL, l, force, &changes, &n_changes);
1610 return reply_unit_file_changes_and_free(m, bus, message, carries_install_info ? r : -1, changes, n_changes);
1613 static int method_enable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1614 return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_enable, true, error);
1617 static int method_reenable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1618 return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_reenable, true, error);
1621 static int method_link_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1622 return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_link, false, error);
1625 static int unit_file_preset_without_mode(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes) {
1626 return unit_file_preset(scope, runtime, root_dir, files, UNIT_FILE_PRESET_FULL, force, changes, n_changes);
1629 static int method_preset_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1630 return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_preset_without_mode, true, error);
1633 static int method_mask_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1634 return method_enable_unit_files_generic(bus, message, userdata, "disable", unit_file_mask, false, error);
1637 static int method_preset_unit_files_with_mode(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1639 _cleanup_strv_free_ char **l = NULL;
1643 UnitFileChange *changes = NULL;
1644 unsigned n_changes = 0;
1645 Manager *m = userdata;
1646 UnitFilePresetMode mm;
1647 UnitFileScope scope;
1648 int runtime, force, r;
1655 r = bus_verify_manage_unit_files_async(m, message, error);
1659 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1661 r = sd_bus_message_read_strv(message, &l);
1665 r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force);
1670 mm = UNIT_FILE_PRESET_FULL;
1672 mm = unit_file_preset_mode_from_string(mode);
1678 STRV_FOREACH(i, l) {
1681 u = manager_get_unit(m, *i);
1683 r = selinux_unit_access_check(u, message, "enable", error);
1690 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1692 r = unit_file_preset(scope, runtime, NULL, l, mm, force, &changes, &n_changes);
1696 return reply_unit_file_changes_and_free(m, bus, message, r, changes, n_changes);
1699 static int method_disable_unit_files_generic(
1701 sd_bus_message *message,
1704 int (*call)(UnitFileScope scope, bool runtime, const char *root_dir, char *files[], UnitFileChange **changes, unsigned *n_changes),
1705 sd_bus_error *error) {
1707 _cleanup_strv_free_ char **l = NULL;
1708 UnitFileChange *changes = NULL;
1709 unsigned n_changes = 0;
1710 UnitFileScope scope;
1717 r = bus_verify_manage_unit_files_async(m, message, error);
1721 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1723 r = selinux_access_check(message, verb, error);
1727 r = sd_bus_message_read_strv(message, &l);
1731 r = sd_bus_message_read(message, "b", &runtime);
1735 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1737 r = call(scope, runtime, NULL, l, &changes, &n_changes);
1741 return reply_unit_file_changes_and_free(m, bus, message, -1, changes, n_changes);
1744 static int method_disable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1745 return method_disable_unit_files_generic(bus, message, userdata, "disable", unit_file_disable, error);
1748 static int method_unmask_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1749 return method_disable_unit_files_generic(bus, message, userdata, "enable", unit_file_unmask, error);
1752 static int method_set_default_target(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1753 UnitFileChange *changes = NULL;
1754 unsigned n_changes = 0;
1755 Manager *m = userdata;
1756 UnitFileScope scope;
1764 r = bus_verify_manage_unit_files_async(m, message, error);
1768 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1770 r = selinux_access_check(message, "enable", error);
1774 r = sd_bus_message_read(message, "sb", &name, &force);
1778 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1780 r = unit_file_set_default(scope, NULL, name, force, &changes, &n_changes);
1784 return reply_unit_file_changes_and_free(m, bus, message, -1, changes, n_changes);
1787 static int method_preset_all_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1788 UnitFileChange *changes = NULL;
1789 unsigned n_changes = 0;
1790 Manager *m = userdata;
1791 UnitFilePresetMode mm;
1792 UnitFileScope scope;
1794 int force, runtime, r;
1800 r = bus_verify_manage_unit_files_async(m, message, error);
1804 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1806 r = selinux_access_check(message, "enable", error);
1810 r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force);
1815 mm = UNIT_FILE_PRESET_FULL;
1817 mm = unit_file_preset_mode_from_string(mode);
1822 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1824 r = unit_file_preset_all(scope, runtime, NULL, mm, force, &changes, &n_changes);
1828 return reply_unit_file_changes_and_free(m, bus, message, -1, changes, n_changes);
1831 const sd_bus_vtable bus_manager_vtable[] = {
1832 SD_BUS_VTABLE_START(0),
1834 SD_BUS_PROPERTY("Version", "s", property_get_version, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1835 SD_BUS_PROPERTY("Features", "s", property_get_features, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1836 SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1837 SD_BUS_PROPERTY("Architecture", "s", property_get_architecture, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1838 SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1839 BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager, firmware_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1840 BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager, loader_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1841 BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager, kernel_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1842 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager, initrd_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1843 BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager, userspace_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1844 BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager, finish_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1845 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager, security_start_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1846 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager, security_finish_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1847 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager, generators_start_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1848 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager, generators_finish_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1849 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager, units_load_start_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1850 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager, units_load_finish_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1851 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level, property_set_log_level, 0, 0),
1852 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target, property_set_log_target, 0, 0),
1853 SD_BUS_PROPERTY("NNames", "u", property_get_n_names, 0, 0),
1854 SD_BUS_PROPERTY("NFailedUnits", "u", property_get_n_failed_units, 0, 0),
1855 SD_BUS_PROPERTY("NJobs", "u", property_get_n_jobs, 0, 0),
1856 SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_installed_jobs), 0),
1857 SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_failed_jobs), 0),
1858 SD_BUS_PROPERTY("Progress", "d", property_get_progress, 0, 0),
1859 SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(Manager, environment), 0),
1860 SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool, offsetof(Manager, confirm_spawn), SD_BUS_VTABLE_PROPERTY_CONST),
1861 SD_BUS_PROPERTY("ShowStatus", "b", bus_property_get_bool, offsetof(Manager, show_status), SD_BUS_VTABLE_PROPERTY_CONST),
1862 SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.unit_path), SD_BUS_VTABLE_PROPERTY_CONST),
1863 SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST),
1864 SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST),
1865 SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec, property_set_runtime_watchdog, offsetof(Manager, runtime_watchdog), SD_BUS_VTABLE_PROPERTY_CONST),
1866 SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec, bus_property_set_usec, offsetof(Manager, shutdown_watchdog), SD_BUS_VTABLE_PROPERTY_CONST),
1867 SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Manager, cgroup_root), 0),
1868 SD_BUS_PROPERTY("SystemState", "s", property_get_system_state, 0, 0),
1870 SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1871 SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid, SD_BUS_VTABLE_UNPRIVILEGED),
1872 SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1873 SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1874 SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace, SD_BUS_VTABLE_UNPRIVILEGED),
1875 SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1876 SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1877 SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1878 SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1879 SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1880 SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1881 SD_BUS_METHOD("KillUnit", "ssi", NULL, method_kill_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1882 SD_BUS_METHOD("ResetFailedUnit", "s", NULL, method_reset_failed_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1883 SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL, method_set_unit_properties, SD_BUS_VTABLE_UNPRIVILEGED),
1884 SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1885 SD_BUS_METHOD("GetJob", "u", "o", method_get_job, SD_BUS_VTABLE_UNPRIVILEGED),
1886 SD_BUS_METHOD("CancelJob", "u", NULL, method_cancel_job, SD_BUS_VTABLE_UNPRIVILEGED),
1887 SD_BUS_METHOD("ClearJobs", NULL, NULL, method_clear_jobs, 0),
1888 SD_BUS_METHOD("ResetFailed", NULL, NULL, method_reset_failed, 0),
1889 SD_BUS_METHOD("ListUnits", NULL, "a(ssssssouso)", method_list_units, SD_BUS_VTABLE_UNPRIVILEGED),
1890 SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered, SD_BUS_VTABLE_UNPRIVILEGED),
1891 SD_BUS_METHOD("ListJobs", NULL, "a(usssoo)", method_list_jobs, SD_BUS_VTABLE_UNPRIVILEGED),
1892 SD_BUS_METHOD("Subscribe", NULL, NULL, method_subscribe, SD_BUS_VTABLE_UNPRIVILEGED),
1893 SD_BUS_METHOD("Unsubscribe", NULL, NULL, method_unsubscribe, SD_BUS_VTABLE_UNPRIVILEGED),
1894 SD_BUS_METHOD("Dump", NULL, "s", method_dump, SD_BUS_VTABLE_UNPRIVILEGED),
1895 SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_create_snapshot, 0),
1896 SD_BUS_METHOD("RemoveSnapshot", "s", NULL, method_remove_snapshot, 0),
1897 SD_BUS_METHOD("Reload", NULL, NULL, method_reload, SD_BUS_VTABLE_UNPRIVILEGED),
1898 SD_BUS_METHOD("Reexecute", NULL, NULL, method_reexecute, SD_BUS_VTABLE_UNPRIVILEGED),
1899 SD_BUS_METHOD("Exit", NULL, NULL, method_exit, 0),
1900 SD_BUS_METHOD("Reboot", NULL, NULL, method_reboot, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1901 SD_BUS_METHOD("PowerOff", NULL, NULL, method_poweroff, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1902 SD_BUS_METHOD("Halt", NULL, NULL, method_halt, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1903 SD_BUS_METHOD("KExec", NULL, NULL, method_kexec, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1904 SD_BUS_METHOD("SwitchRoot", "ss", NULL, method_switch_root, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1905 SD_BUS_METHOD("SetEnvironment", "as", NULL, method_set_environment, 0),
1906 SD_BUS_METHOD("UnsetEnvironment", "as", NULL, method_unset_environment, 0),
1907 SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL, method_unset_and_set_environment, 0),
1908 SD_BUS_METHOD("ListUnitFiles", NULL, "a(ss)", method_list_unit_files, SD_BUS_VTABLE_UNPRIVILEGED),
1909 SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state, SD_BUS_VTABLE_UNPRIVILEGED),
1910 SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files, SD_BUS_VTABLE_UNPRIVILEGED),
1911 SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files, SD_BUS_VTABLE_UNPRIVILEGED),
1912 SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files, SD_BUS_VTABLE_UNPRIVILEGED),
1913 SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files, SD_BUS_VTABLE_UNPRIVILEGED),
1914 SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files, SD_BUS_VTABLE_UNPRIVILEGED),
1915 SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode, SD_BUS_VTABLE_UNPRIVILEGED),
1916 SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files, SD_BUS_VTABLE_UNPRIVILEGED),
1917 SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files, SD_BUS_VTABLE_UNPRIVILEGED),
1918 SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target, SD_BUS_VTABLE_UNPRIVILEGED),
1919 SD_BUS_METHOD("GetDefaultTarget", NULL, "s", method_get_default_target, SD_BUS_VTABLE_UNPRIVILEGED),
1920 SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files, SD_BUS_VTABLE_UNPRIVILEGED),
1922 SD_BUS_SIGNAL("UnitNew", "so", 0),
1923 SD_BUS_SIGNAL("UnitRemoved", "so", 0),
1924 SD_BUS_SIGNAL("JobNew", "uos", 0),
1925 SD_BUS_SIGNAL("JobRemoved", "uoss", 0),
1926 SD_BUS_SIGNAL("StartupFinished", "tttttt", 0),
1927 SD_BUS_SIGNAL("UnitFilesChanged", NULL, 0),
1928 SD_BUS_SIGNAL("Reloading", "b", 0),
1933 static int send_finished(sd_bus *bus, void *userdata) {
1934 _cleanup_bus_message_unref_ sd_bus_message *message = NULL;
1935 usec_t *times = userdata;
1941 r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
1945 r = sd_bus_message_append(message, "tttttt", times[0], times[1], times[2], times[3], times[4], times[5]);
1949 return sd_bus_send(bus, message, NULL);
1952 void bus_manager_send_finished(
1954 usec_t firmware_usec,
1958 usec_t userspace_usec,
1959 usec_t total_usec) {
1965 r = bus_foreach_bus(
1978 log_debug("Failed to send finished signal: %s", strerror(-r));
1981 static int send_reloading(sd_bus *bus, void *userdata) {
1982 _cleanup_bus_message_unref_ sd_bus_message *message = NULL;
1987 r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
1991 r = sd_bus_message_append(message, "b", PTR_TO_INT(userdata));
1995 return sd_bus_send(bus, message, NULL);
1998 void bus_manager_send_reloading(Manager *m, bool active) {
2003 r = bus_foreach_bus(m, NULL, send_reloading, INT_TO_PTR(active));
2005 log_debug("Failed to send reloading signal: %s", strerror(-r));