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"
37 #include "dbus-manager.h"
38 #include "dbus-unit.h"
39 #include "dbus-snapshot.h"
40 #include "dbus-execute.h"
41 #include "bus-errors.h"
43 static int property_get_version(
46 const char *interface,
48 sd_bus_message *reply,
50 sd_bus_error *error) {
55 return sd_bus_message_append(reply, "s", PACKAGE_VERSION);
58 static int property_get_features(
61 const char *interface,
63 sd_bus_message *reply,
65 sd_bus_error *error) {
70 return sd_bus_message_append(reply, "s", SYSTEMD_FEATURES);
73 static int property_get_virtualization(
76 const char *interface,
78 sd_bus_message *reply,
80 sd_bus_error *error) {
82 const char *id = NULL;
87 detect_virtualization(&id);
89 return sd_bus_message_append(reply, "s", id);
92 static int property_get_architecture(
95 const char *interface,
97 sd_bus_message *reply,
99 sd_bus_error *error) {
104 return sd_bus_message_append(reply, "s", architecture_to_string(uname_architecture()));
107 static int property_get_tainted(
110 const char *interface,
111 const char *property,
112 sd_bus_message *reply,
114 sd_bus_error *error) {
116 char buf[sizeof("split-usr:mtab-not-symlink:cgroups-missing:local-hwclock:")] = "", *e = buf;
117 _cleanup_free_ char *p = NULL;
118 Manager *m = userdata;
125 e = stpcpy(e, "split-usr:");
127 if (readlink_malloc("/etc/mtab", &p) < 0)
128 e = stpcpy(e, "mtab-not-symlink:");
130 if (access("/proc/cgroups", F_OK) < 0)
131 e = stpcpy(e, "cgroups-missing:");
133 if (clock_is_localtime() > 0)
134 e = stpcpy(e, "local-hwclock:");
136 /* remove the last ':' */
140 return sd_bus_message_append(reply, "s", buf);
143 static int property_get_log_target(
146 const char *interface,
147 const char *property,
148 sd_bus_message *reply,
150 sd_bus_error *error) {
155 return sd_bus_message_append(reply, "s", log_target_to_string(log_get_target()));
158 static int property_set_log_target(
161 const char *interface,
162 const char *property,
163 sd_bus_message *value,
165 sd_bus_error *error) {
173 r = sd_bus_message_read(value, "s", &t);
177 return log_set_target_from_string(t);
180 static int property_get_log_level(
183 const char *interface,
184 const char *property,
185 sd_bus_message *reply,
187 sd_bus_error *error) {
189 _cleanup_free_ char *t = NULL;
195 r = log_level_to_string_alloc(log_get_max_level(), &t);
199 return sd_bus_message_append(reply, "s", t);
202 static int property_set_log_level(
205 const char *interface,
206 const char *property,
207 sd_bus_message *value,
209 sd_bus_error *error) {
217 r = sd_bus_message_read(value, "s", &t);
221 return log_set_max_level_from_string(t);
224 static int property_get_n_names(
227 const char *interface,
228 const char *property,
229 sd_bus_message *reply,
231 sd_bus_error *error) {
233 Manager *m = userdata;
239 return sd_bus_message_append(reply, "u", (uint32_t) hashmap_size(m->units));
242 static int property_get_n_failed_units(
245 const char *interface,
246 const char *property,
247 sd_bus_message *reply,
249 sd_bus_error *error) {
251 Manager *m = userdata;
257 return sd_bus_message_append(reply, "u", (uint32_t) set_size(m->failed_units));
260 static int property_get_n_jobs(
263 const char *interface,
264 const char *property,
265 sd_bus_message *reply,
267 sd_bus_error *error) {
269 Manager *m = userdata;
275 return sd_bus_message_append(reply, "u", (uint32_t) hashmap_size(m->jobs));
278 static int property_get_progress(
281 const char *interface,
282 const char *property,
283 sd_bus_message *reply,
285 sd_bus_error *error) {
287 Manager *m = userdata;
294 if (dual_timestamp_is_set(&m->finish_timestamp))
297 d = 1.0 - ((double) hashmap_size(m->jobs) / (double) m->n_installed_jobs);
299 return sd_bus_message_append(reply, "d", d);
302 static int property_get_system_state(
305 const char *interface,
306 const char *property,
307 sd_bus_message *reply,
309 sd_bus_error *error) {
311 Manager *m = userdata;
317 return sd_bus_message_append(reply, "s", manager_state_to_string(manager_state(m)));
320 static int property_set_runtime_watchdog(
323 const char *interface,
324 const char *property,
325 sd_bus_message *value,
327 sd_bus_error *error) {
329 usec_t *t = userdata;
335 assert_cc(sizeof(usec_t) == sizeof(uint64_t));
337 r = sd_bus_message_read(value, "t", t);
341 return watchdog_set_timeout(t);
344 static int method_get_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
345 _cleanup_free_ char *path = NULL;
346 Manager *m = userdata;
355 r = sd_bus_message_read(message, "s", &name);
359 u = manager_get_unit(m, name);
361 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", name);
363 r = selinux_unit_access_check(u, message, "status", error);
367 path = unit_dbus_path(u);
371 return sd_bus_reply_method_return(message, "o", path);
374 static int method_get_unit_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
375 _cleanup_free_ char *path = NULL;
376 Manager *m = userdata;
385 assert_cc(sizeof(pid_t) == sizeof(uint32_t));
387 r = sd_bus_message_read(message, "u", &pid);
392 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
394 r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
398 r = sd_bus_creds_get_pid(creds, &pid);
403 u = manager_get_unit_by_pid(m, pid);
405 return sd_bus_error_setf(error, BUS_ERROR_NO_UNIT_FOR_PID, "PID %u does not belong to any loaded unit.", pid);
407 r = selinux_unit_access_check(u, message, "status", error);
411 path = unit_dbus_path(u);
415 return sd_bus_reply_method_return(message, "o", path);
418 static int method_load_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
419 _cleanup_free_ char *path = NULL;
420 Manager *m = userdata;
429 r = sd_bus_message_read(message, "s", &name);
433 r = manager_load_unit(m, name, NULL, error, &u);
437 r = selinux_unit_access_check(u, message, "status", error);
441 path = unit_dbus_path(u);
445 return sd_bus_reply_method_return(message, "o", path);
448 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) {
457 r = sd_bus_message_read(message, "s", &name);
461 r = manager_load_unit(m, name, NULL, error, &u);
465 return bus_unit_method_start_generic(bus, message, u, job_type, reload_if_possible, error);
468 static int method_start_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
469 return method_start_unit_generic(bus, message, userdata, JOB_START, false, error);
472 static int method_stop_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
473 return method_start_unit_generic(bus, message, userdata, JOB_STOP, false, error);
476 static int method_reload_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
477 return method_start_unit_generic(bus, message, userdata, JOB_RELOAD, false, error);
480 static int method_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
481 return method_start_unit_generic(bus, message, userdata, JOB_RESTART, false, error);
484 static int method_try_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
485 return method_start_unit_generic(bus, message, userdata, JOB_TRY_RESTART, false, error);
488 static int method_reload_or_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
489 return method_start_unit_generic(bus, message, userdata, JOB_RESTART, true, error);
492 static int method_reload_or_try_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
493 return method_start_unit_generic(bus, message, userdata, JOB_TRY_RESTART, true, error);
496 static int method_start_unit_replace(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
497 Manager *m = userdata;
498 const char *old_name;
506 r = sd_bus_message_read(message, "s", &old_name);
510 u = manager_get_unit(m, old_name);
511 if (!u || !u->job || u->job->type != JOB_START)
512 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
514 return method_start_unit_generic(bus, message, m, JOB_START, false, error);
517 static int method_kill_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
518 Manager *m = userdata;
527 r = sd_bus_message_read(message, "s", &name);
531 u = manager_get_unit(m, name);
533 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
535 return bus_unit_method_kill(bus, message, u, error);
538 static int method_reset_failed_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
539 Manager *m = userdata;
548 r = sd_bus_message_read(message, "s", &name);
552 u = manager_get_unit(m, name);
554 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
556 return bus_unit_method_reset_failed(bus, message, u, error);
559 static int method_set_unit_properties(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
560 Manager *m = userdata;
569 r = sd_bus_message_read(message, "s", &name);
573 u = manager_get_unit(m, name);
575 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
577 return bus_unit_method_set_properties(bus, message, u, error);
580 static int method_start_transient_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
581 const char *name, *smode;
582 Manager *m = userdata;
592 r = sd_bus_message_read(message, "ss", &name, &smode);
596 t = unit_name_to_type(name);
598 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit type.");
600 if (!unit_vtable[t]->can_transient)
601 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit type %s does not support transient units.", unit_type_to_string(t));
603 mode = job_mode_from_string(smode);
605 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s is invalid.", smode);
607 r = selinux_access_check(message, "start", error);
611 r = manager_load_unit(m, name, NULL, error, &u);
615 if (u->load_state != UNIT_NOT_FOUND || set_size(u->dependencies[UNIT_REFERENCED_BY]) > 0)
616 return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name);
618 /* OK, the unit failed to load and is unreferenced, now let's
619 * fill in the transient data instead */
620 r = unit_make_transient(u);
624 /* Set our properties */
625 r = bus_unit_set_properties(u, message, UNIT_RUNTIME, false, error);
629 /* And load this stub fully */
634 manager_dispatch_load_queue(m);
636 /* Finally, start it */
637 return bus_unit_queue_job(bus, message, u, JOB_START, mode, false, error);
640 static int method_get_job(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
641 _cleanup_free_ char *path = NULL;
642 Manager *m = userdata;
651 r = sd_bus_message_read(message, "u", &id);
655 j = manager_get_job(m, id);
657 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
659 r = selinux_unit_access_check(j->unit, message, "status", error);
663 path = job_dbus_path(j);
667 return sd_bus_reply_method_return(message, "o", path);
670 static int method_cancel_job(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
671 Manager *m = userdata;
680 r = sd_bus_message_read(message, "u", &id);
684 j = manager_get_job(m, id);
686 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
688 r = selinux_unit_access_check(j->unit, message, "stop", error);
692 job_finish_and_invalidate(j, JOB_CANCELED, true);
694 return sd_bus_reply_method_return(message, NULL);
697 static int method_clear_jobs(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
698 Manager *m = userdata;
705 r = selinux_access_check(message, "reboot", error);
709 manager_clear_jobs(m);
711 return sd_bus_reply_method_return(message, NULL);
714 static int method_reset_failed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
715 Manager *m = userdata;
722 r = selinux_access_check(message, "reload", error);
726 manager_reset_failed(m);
728 return sd_bus_reply_method_return(message, NULL);
731 static int list_units_filtered(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error, char **states) {
732 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
733 Manager *m = userdata;
743 r = selinux_access_check(message, "status", error);
747 r = sd_bus_message_new_method_return(message, &reply);
751 r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)");
755 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
756 _cleanup_free_ char *unit_path = NULL, *job_path = NULL;
762 following = unit_following(u);
764 if (!strv_isempty(states) &&
765 !strv_contains(states, unit_load_state_to_string(u->load_state)) &&
766 !strv_contains(states, unit_active_state_to_string(unit_active_state(u))) &&
767 !strv_contains(states, unit_sub_state_to_string(u)))
770 unit_path = unit_dbus_path(u);
775 job_path = job_dbus_path(u->job);
780 r = sd_bus_message_append(
781 reply, "(ssssssouso)",
784 unit_load_state_to_string(u->load_state),
785 unit_active_state_to_string(unit_active_state(u)),
786 unit_sub_state_to_string(u),
787 following ? following->id : "",
789 u->job ? u->job->id : 0,
790 u->job ? job_type_to_string(u->job->type) : "",
791 job_path ? job_path : "/");
796 r = sd_bus_message_close_container(reply);
800 return sd_bus_send(bus, reply, NULL);
803 static int method_list_units(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
804 return list_units_filtered(bus, message, userdata, error, NULL);
807 static int method_list_units_filtered(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
808 _cleanup_strv_free_ char **states = NULL;
811 r = sd_bus_message_read_strv(message, &states);
815 return list_units_filtered(bus, message, userdata, error, states);
818 static int method_list_jobs(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
819 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
820 Manager *m = userdata;
829 r = selinux_access_check(message, "status", error);
833 r = sd_bus_message_new_method_return(message, &reply);
837 r = sd_bus_message_open_container(reply, 'a', "(usssoo)");
841 HASHMAP_FOREACH(j, m->jobs, i) {
842 _cleanup_free_ char *unit_path = NULL, *job_path = NULL;
844 job_path = job_dbus_path(j);
848 unit_path = unit_dbus_path(j->unit);
852 r = sd_bus_message_append(
856 job_type_to_string(j->type),
857 job_state_to_string(j->state),
864 r = sd_bus_message_close_container(reply);
868 return sd_bus_send(bus, reply, NULL);
871 static int method_subscribe(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
872 Manager *m = userdata;
879 r = selinux_access_check(message, "status", error);
883 if (bus == m->api_bus) {
885 /* Note that direct bus connection subscribe by
886 * default, we only track peers on the API bus here */
888 if (!m->subscribed) {
889 r = sd_bus_track_new(bus, &m->subscribed, NULL, NULL);
894 r = sd_bus_track_add_sender(m->subscribed, message);
898 return sd_bus_error_setf(error, BUS_ERROR_ALREADY_SUBSCRIBED, "Client is already subscribed.");
901 return sd_bus_reply_method_return(message, NULL);
904 static int method_unsubscribe(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
905 Manager *m = userdata;
912 r = selinux_access_check(message, "status", error);
916 if (bus == m->api_bus) {
917 r = sd_bus_track_remove_sender(m->subscribed, message);
921 return sd_bus_error_setf(error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
924 return sd_bus_reply_method_return(message, NULL);
927 static int method_dump(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
928 _cleanup_free_ char *dump = NULL;
929 _cleanup_fclose_ FILE *f = NULL;
930 Manager *m = userdata;
938 r = selinux_access_check(message, "status", error);
942 f = open_memstream(&dump, &size);
946 manager_dump_units(m, f, NULL);
947 manager_dump_jobs(m, f, NULL);
954 return sd_bus_reply_method_return(message, "s", dump);
957 static int method_create_snapshot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
958 _cleanup_free_ char *path = NULL;
959 Manager *m = userdata;
969 r = selinux_access_check(message, "start", error);
973 r = sd_bus_message_read(message, "sb", &name, &cleanup);
980 r = snapshot_create(m, name, cleanup, error, &s);
984 path = unit_dbus_path(UNIT(s));
988 return sd_bus_reply_method_return(message, "o", path);
991 static int method_remove_snapshot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
992 Manager *m = userdata;
1001 r = selinux_access_check(message, "stop", error);
1005 r = sd_bus_message_read(message, "s", &name);
1009 u = manager_get_unit(m, name);
1011 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s does not exist.", name);
1013 if (u->type != UNIT_SNAPSHOT)
1014 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not a snapshot", name);
1016 return bus_snapshot_method_remove(bus, message, u, error);
1019 static int method_reload(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1020 Manager *m = userdata;
1027 r = selinux_access_check(message, "reload", error);
1031 /* Instead of sending the reply back right away, we just
1032 * remember that we need to and then send it after the reload
1033 * is finished. That way the caller knows when the reload
1036 assert(!m->queued_message);
1037 r = sd_bus_message_new_method_return(message, &m->queued_message);
1041 m->queued_message_bus = sd_bus_ref(bus);
1042 m->exit_code = MANAGER_RELOAD;
1047 static int method_reexecute(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1048 Manager *m = userdata;
1055 r = selinux_access_check(message, "reload", error);
1059 /* We don't send a reply back here, the client should
1060 * just wait for us disconnecting. */
1062 m->exit_code = MANAGER_REEXECUTE;
1066 static int method_exit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1067 Manager *m = userdata;
1074 r = selinux_access_check(message, "halt", error);
1078 if (m->running_as == SYSTEMD_SYSTEM)
1079 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
1081 m->exit_code = MANAGER_EXIT;
1083 return sd_bus_reply_method_return(message, NULL);
1086 static int method_reboot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1087 Manager *m = userdata;
1094 r = selinux_access_check(message, "reboot", error);
1098 if (m->running_as != SYSTEMD_SYSTEM)
1099 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
1101 m->exit_code = MANAGER_REBOOT;
1103 return sd_bus_reply_method_return(message, NULL);
1107 static int method_poweroff(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1108 Manager *m = userdata;
1115 r = selinux_access_check(message, "halt", error);
1119 if (m->running_as != SYSTEMD_SYSTEM)
1120 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
1122 m->exit_code = MANAGER_POWEROFF;
1124 return sd_bus_reply_method_return(message, NULL);
1127 static int method_halt(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1128 Manager *m = userdata;
1135 r = selinux_access_check(message, "halt", error);
1139 if (m->running_as != SYSTEMD_SYSTEM)
1140 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Halt is only supported for system managers.");
1142 m->exit_code = MANAGER_HALT;
1144 return sd_bus_reply_method_return(message, NULL);
1147 static int method_kexec(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1148 Manager *m = userdata;
1155 r = selinux_access_check(message, "reboot", error);
1159 if (m->running_as != SYSTEMD_SYSTEM)
1160 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers.");
1162 m->exit_code = MANAGER_KEXEC;
1164 return sd_bus_reply_method_return(message, NULL);
1167 static int method_switch_root(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1168 char *ri = NULL, *rt = NULL;
1169 const char *root, *init;
1170 Manager *m = userdata;
1177 r = selinux_access_check(message, "reboot", error);
1181 if (m->running_as != SYSTEMD_SYSTEM)
1182 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers.");
1184 r = sd_bus_message_read(message, "ss", &root, &init);
1188 if (path_equal(root, "/") || !path_is_absolute(root))
1189 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid switch root path %s", root);
1192 if (isempty(init)) {
1193 if (! path_is_os_tree(root))
1194 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);
1196 _cleanup_free_ char *p = NULL;
1198 if (!path_is_absolute(init))
1199 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid init path %s", init);
1201 p = strappend(root, init);
1205 if (access(p, X_OK) < 0)
1206 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified init binary %s does not exist.", p);
1213 if (!isempty(init)) {
1221 free(m->switch_root);
1222 m->switch_root = rt;
1224 free(m->switch_root_init);
1225 m->switch_root_init = ri;
1227 m->exit_code = MANAGER_SWITCH_ROOT;
1229 return sd_bus_reply_method_return(message, NULL);
1232 static int method_set_environment(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1233 _cleanup_strv_free_ char **plus = NULL;
1234 Manager *m = userdata;
1241 r = selinux_access_check(message, "reload", error);
1245 r = sd_bus_message_read_strv(message, &plus);
1248 if (!strv_env_is_valid(plus))
1249 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments");
1251 r = manager_environment_add(m, NULL, plus);
1255 return sd_bus_reply_method_return(message, NULL);
1258 static int method_unset_environment(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1259 _cleanup_strv_free_ char **minus = NULL;
1260 Manager *m = userdata;
1267 r = selinux_access_check(message, "reload", error);
1271 r = sd_bus_message_read_strv(message, &minus);
1275 if (!strv_env_name_or_assignment_is_valid(minus))
1276 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments");
1278 r = manager_environment_add(m, minus, NULL);
1282 return sd_bus_reply_method_return(message, NULL);
1285 static int method_unset_and_set_environment(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1286 _cleanup_strv_free_ char **minus = NULL, **plus = NULL;
1287 Manager *m = userdata;
1294 r = selinux_access_check(message, "reload", error);
1298 r = sd_bus_message_read_strv(message, &plus);
1302 r = sd_bus_message_read_strv(message, &minus);
1306 if (!strv_env_is_valid(plus))
1307 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments");
1308 if (!strv_env_name_or_assignment_is_valid(minus))
1309 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments");
1311 r = manager_environment_add(m, minus, plus);
1315 return sd_bus_reply_method_return(message, NULL);
1318 static int method_list_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1319 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
1320 Manager *m = userdata;
1330 r = selinux_access_check(message, "status", error);
1334 r = sd_bus_message_new_method_return(message, &reply);
1338 h = hashmap_new(string_hash_func, string_compare_func);
1342 r = unit_file_get_list(m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);
1346 r = sd_bus_message_open_container(reply, 'a', "(ss)");
1350 HASHMAP_FOREACH(item, h, i) {
1352 r = sd_bus_message_append(reply, "(ss)", item->path, unit_file_state_to_string(item->state));
1357 unit_file_list_free(h);
1359 r = sd_bus_message_close_container(reply);
1363 return sd_bus_send(bus, reply, NULL);
1366 unit_file_list_free(h);
1370 static int method_get_unit_file_state(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1371 Manager *m = userdata;
1373 UnitFileState state;
1374 UnitFileScope scope;
1381 r = selinux_access_check(message, "status", error);
1385 r = sd_bus_message_read(message, "s", &name);
1389 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1391 state = unit_file_get_state(scope, NULL, name);
1395 return sd_bus_reply_method_return(message, "s", unit_file_state_to_string(state));
1398 static int method_get_default_target(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1399 _cleanup_free_ char *default_target = NULL;
1400 Manager *m = userdata;
1401 UnitFileScope scope;
1408 r = selinux_access_check(message, "status", error);
1412 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1414 r = unit_file_get_default(scope, NULL, &default_target);
1418 return sd_bus_reply_method_return(message, "s", default_target);
1421 static int send_unit_files_changed(sd_bus *bus, void *userdata) {
1422 _cleanup_bus_message_unref_ sd_bus_message *message = NULL;
1427 r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
1431 return sd_bus_send(bus, message, NULL);
1434 static int reply_unit_file_changes_and_free(
1437 sd_bus_message *message,
1438 int carries_install_info,
1439 UnitFileChange *changes,
1440 unsigned n_changes) {
1442 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
1446 if (n_changes > 0) {
1447 r = bus_foreach_bus(m, NULL, send_unit_files_changed, NULL);
1449 log_debug("Failed to send UnitFilesChanged signal: %s", strerror(-r));
1452 r = sd_bus_message_new_method_return(message, &reply);
1456 if (carries_install_info >= 0) {
1457 r = sd_bus_message_append(reply, "b", carries_install_info);
1462 r = sd_bus_message_open_container(reply, 'a', "(sss)");
1466 for (i = 0; i < n_changes; i++) {
1467 r = sd_bus_message_append(
1469 unit_file_change_type_to_string(changes[i].type),
1476 r = sd_bus_message_close_container(reply);
1480 return sd_bus_send(bus, reply, NULL);
1483 unit_file_changes_free(changes, n_changes);
1487 static int method_enable_unit_files_generic(
1489 sd_bus_message *message,
1492 int (*call)(UnitFileScope scope, bool runtime, const char *root_dir, char *files[], bool force, UnitFileChange **changes, unsigned *n_changes),
1493 bool carries_install_info,
1494 sd_bus_error *error) {
1496 _cleanup_strv_free_ char **l = NULL;
1500 UnitFileChange *changes = NULL;
1501 unsigned n_changes = 0;
1502 UnitFileScope scope;
1503 int runtime, force, r;
1509 r = sd_bus_message_read_strv(message, &l);
1513 r = sd_bus_message_read(message, "bb", &runtime, &force);
1518 STRV_FOREACH(i, l) {
1521 u = manager_get_unit(m, *i);
1523 r = selinux_unit_access_check(u, message, verb, error);
1530 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1532 r = call(scope, runtime, NULL, l, force, &changes, &n_changes);
1536 return reply_unit_file_changes_and_free(m, bus, message, carries_install_info ? r : -1, changes, n_changes);
1539 static int method_enable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1540 return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_enable, true, error);
1543 static int method_reenable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1544 return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_reenable, true, error);
1547 static int method_link_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1548 return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_link, false, error);
1551 static int unit_file_preset_without_mode(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes) {
1552 return unit_file_preset(scope, runtime, root_dir, files, UNIT_FILE_PRESET_FULL, force, changes, n_changes);
1555 static int method_preset_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1556 return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_preset_without_mode, true, error);
1559 static int method_mask_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1560 return method_enable_unit_files_generic(bus, message, userdata, "disable", unit_file_mask, false, error);
1563 static int method_preset_unit_files_with_mode(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1565 _cleanup_strv_free_ char **l = NULL;
1569 UnitFileChange *changes = NULL;
1570 unsigned n_changes = 0;
1571 Manager *m = userdata;
1572 UnitFilePresetMode mm;
1573 UnitFileScope scope;
1574 int runtime, force, r;
1581 r = sd_bus_message_read_strv(message, &l);
1585 r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force);
1590 mm = UNIT_FILE_PRESET_FULL;
1592 mm = unit_file_preset_mode_from_string(mode);
1598 STRV_FOREACH(i, l) {
1601 u = manager_get_unit(m, *i);
1603 r = selinux_unit_access_check(u, message, "enable", error);
1610 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1612 r = unit_file_preset(scope, runtime, NULL, l, mm, force, &changes, &n_changes);
1616 return reply_unit_file_changes_and_free(m, bus, message, r, changes, n_changes);
1619 static int method_disable_unit_files_generic(
1621 sd_bus_message *message,
1624 int (*call)(UnitFileScope scope, bool runtime, const char *root_dir, char *files[], UnitFileChange **changes, unsigned *n_changes),
1625 sd_bus_error *error) {
1627 _cleanup_strv_free_ char **l = NULL;
1628 UnitFileChange *changes = NULL;
1629 unsigned n_changes = 0;
1630 UnitFileScope scope;
1637 r = selinux_access_check(message, verb, error);
1641 r = sd_bus_message_read_strv(message, &l);
1645 r = sd_bus_message_read(message, "b", &runtime);
1649 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1651 r = call(scope, runtime, NULL, l, &changes, &n_changes);
1655 return reply_unit_file_changes_and_free(m, bus, message, -1, changes, n_changes);
1658 static int method_disable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1659 return method_disable_unit_files_generic(bus, message, userdata, "disable", unit_file_disable, error);
1662 static int method_unmask_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1663 return method_disable_unit_files_generic(bus, message, userdata, "enable", unit_file_unmask, error);
1666 static int method_set_default_target(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1667 UnitFileChange *changes = NULL;
1668 unsigned n_changes = 0;
1669 Manager *m = userdata;
1670 UnitFileScope scope;
1678 r = selinux_access_check(message, "enable", error);
1682 r = sd_bus_message_read(message, "sb", &name, &force);
1686 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1688 r = unit_file_set_default(scope, NULL, name, force, &changes, &n_changes);
1692 return reply_unit_file_changes_and_free(m, bus, message, -1, changes, n_changes);
1695 static int method_preset_all_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1696 UnitFileChange *changes = NULL;
1697 unsigned n_changes = 0;
1698 Manager *m = userdata;
1699 UnitFilePresetMode mm;
1700 UnitFileScope scope;
1702 int force, runtime, r;
1708 r = selinux_access_check(message, "enable", error);
1712 r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force);
1717 mm = UNIT_FILE_PRESET_FULL;
1719 mm = unit_file_preset_mode_from_string(mode);
1724 scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
1726 r = unit_file_preset_all(scope, runtime, NULL, mm, force, &changes, &n_changes);
1730 return reply_unit_file_changes_and_free(m, bus, message, -1, changes, n_changes);
1733 const sd_bus_vtable bus_manager_vtable[] = {
1734 SD_BUS_VTABLE_START(0),
1736 SD_BUS_PROPERTY("Version", "s", property_get_version, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1737 SD_BUS_PROPERTY("Features", "s", property_get_features, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1738 SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1739 SD_BUS_PROPERTY("Architecture", "s", property_get_architecture, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1740 SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1741 BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager, firmware_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1742 BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager, loader_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1743 BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager, kernel_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1744 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager, initrd_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1745 BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager, userspace_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1746 BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager, finish_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1747 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager, security_start_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1748 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager, security_finish_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1749 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager, generators_start_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1750 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager, generators_finish_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1751 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager, units_load_start_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1752 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager, units_load_finish_timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
1753 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level, property_set_log_level, 0, 0),
1754 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target, property_set_log_target, 0, 0),
1755 SD_BUS_PROPERTY("NNames", "u", property_get_n_names, 0, 0),
1756 SD_BUS_PROPERTY("NFailedUnits", "u", property_get_n_failed_units, 0, 0),
1757 SD_BUS_PROPERTY("NJobs", "u", property_get_n_jobs, 0, 0),
1758 SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_installed_jobs), 0),
1759 SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_failed_jobs), 0),
1760 SD_BUS_PROPERTY("Progress", "d", property_get_progress, 0, 0),
1761 SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(Manager, environment), 0),
1762 SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool, offsetof(Manager, confirm_spawn), SD_BUS_VTABLE_PROPERTY_CONST),
1763 SD_BUS_PROPERTY("ShowStatus", "b", bus_property_get_bool, offsetof(Manager, show_status), SD_BUS_VTABLE_PROPERTY_CONST),
1764 SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.unit_path), SD_BUS_VTABLE_PROPERTY_CONST),
1765 SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST),
1766 SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST),
1767 SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec, property_set_runtime_watchdog, offsetof(Manager, runtime_watchdog), SD_BUS_VTABLE_PROPERTY_CONST),
1768 SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec, bus_property_set_usec, offsetof(Manager, shutdown_watchdog), SD_BUS_VTABLE_PROPERTY_CONST),
1769 SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Manager, cgroup_root), 0),
1770 SD_BUS_PROPERTY("SystemState", "s", property_get_system_state, 0, 0),
1772 SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1773 SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid, SD_BUS_VTABLE_UNPRIVILEGED),
1774 SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit, SD_BUS_VTABLE_UNPRIVILEGED),
1775 SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit, 0),
1776 SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace, 0),
1777 SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit, 0),
1778 SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit, 0),
1779 SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit, 0),
1780 SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit, 0),
1781 SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit, 0),
1782 SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit, 0),
1783 SD_BUS_METHOD("KillUnit", "ssi", NULL, method_kill_unit, SD_BUS_VTABLE_CAPABILITY(CAP_KILL)),
1784 SD_BUS_METHOD("ResetFailedUnit", "s", NULL, method_reset_failed_unit, 0),
1785 SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL, method_set_unit_properties, 0),
1786 SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit, 0),
1787 SD_BUS_METHOD("GetJob", "u", "o", method_get_job, SD_BUS_VTABLE_UNPRIVILEGED),
1788 SD_BUS_METHOD("CancelJob", "u", NULL, method_cancel_job, 0),
1789 SD_BUS_METHOD("ClearJobs", NULL, NULL, method_clear_jobs, 0),
1790 SD_BUS_METHOD("ResetFailed", NULL, NULL, method_reset_failed, 0),
1791 SD_BUS_METHOD("ListUnits", NULL, "a(ssssssouso)", method_list_units, SD_BUS_VTABLE_UNPRIVILEGED),
1792 SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered, SD_BUS_VTABLE_UNPRIVILEGED),
1793 SD_BUS_METHOD("ListJobs", NULL, "a(usssoo)", method_list_jobs, SD_BUS_VTABLE_UNPRIVILEGED),
1794 SD_BUS_METHOD("Subscribe", NULL, NULL, method_subscribe, SD_BUS_VTABLE_UNPRIVILEGED),
1795 SD_BUS_METHOD("Unsubscribe", NULL, NULL, method_unsubscribe, SD_BUS_VTABLE_UNPRIVILEGED),
1796 SD_BUS_METHOD("Dump", NULL, "s", method_dump, SD_BUS_VTABLE_UNPRIVILEGED),
1797 SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_create_snapshot, 0),
1798 SD_BUS_METHOD("RemoveSnapshot", "s", NULL, method_remove_snapshot, 0),
1799 SD_BUS_METHOD("Reload", NULL, NULL, method_reload, 0),
1800 SD_BUS_METHOD("Reexecute", NULL, NULL, method_reexecute, 0),
1801 SD_BUS_METHOD("Exit", NULL, NULL, method_exit, 0),
1802 SD_BUS_METHOD("Reboot", NULL, NULL, method_reboot, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1803 SD_BUS_METHOD("PowerOff", NULL, NULL, method_poweroff, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1804 SD_BUS_METHOD("Halt", NULL, NULL, method_halt, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1805 SD_BUS_METHOD("KExec", NULL, NULL, method_kexec, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1806 SD_BUS_METHOD("SwitchRoot", "ss", NULL, method_switch_root, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)),
1807 SD_BUS_METHOD("SetEnvironment", "as", NULL, method_set_environment, 0),
1808 SD_BUS_METHOD("UnsetEnvironment", "as", NULL, method_unset_environment, 0),
1809 SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL, method_unset_and_set_environment, 0),
1810 SD_BUS_METHOD("ListUnitFiles", NULL, "a(ss)", method_list_unit_files, SD_BUS_VTABLE_UNPRIVILEGED),
1811 SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state, SD_BUS_VTABLE_UNPRIVILEGED),
1812 SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files, 0),
1813 SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files, 0),
1814 SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files, 0),
1815 SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files, 0),
1816 SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files, 0),
1817 SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode, 0),
1818 SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files, 0),
1819 SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files, 0),
1820 SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target, 0),
1821 SD_BUS_METHOD("GetDefaultTarget", NULL, "s", method_get_default_target, SD_BUS_VTABLE_UNPRIVILEGED),
1822 SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files, 0),
1824 SD_BUS_SIGNAL("UnitNew", "so", 0),
1825 SD_BUS_SIGNAL("UnitRemoved", "so", 0),
1826 SD_BUS_SIGNAL("JobNew", "uos", 0),
1827 SD_BUS_SIGNAL("JobRemoved", "uoss", 0),
1828 SD_BUS_SIGNAL("StartupFinished", "tttttt", 0),
1829 SD_BUS_SIGNAL("UnitFilesChanged", NULL, 0),
1830 SD_BUS_SIGNAL("Reloading", "b", 0),
1835 static int send_finished(sd_bus *bus, void *userdata) {
1836 _cleanup_bus_message_unref_ sd_bus_message *message = NULL;
1837 usec_t *times = userdata;
1843 r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
1847 r = sd_bus_message_append(message, "tttttt", times[0], times[1], times[2], times[3], times[4], times[5]);
1851 return sd_bus_send(bus, message, NULL);
1854 void bus_manager_send_finished(
1856 usec_t firmware_usec,
1860 usec_t userspace_usec,
1861 usec_t total_usec) {
1867 r = bus_foreach_bus(
1880 log_debug("Failed to send finished signal: %s", strerror(-r));
1883 static int send_reloading(sd_bus *bus, void *userdata) {
1884 _cleanup_bus_message_unref_ sd_bus_message *message = NULL;
1889 r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
1893 r = sd_bus_message_append(message, "b", PTR_TO_INT(userdata));
1897 return sd_bus_send(bus, message, NULL);
1900 void bus_manager_send_reloading(Manager *m, bool active) {
1905 r = bus_foreach_bus(m, NULL, send_reloading, INT_TO_PTR(active));
1907 log_debug("Failed to send reloading signal: %s", strerror(-r));