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/>.
23 #include <sys/prctl.h>
26 #include "architecture.h"
28 #include "bus-common-errors.h"
29 #include "clock-util.h"
30 #include "dbus-execute.h"
32 #include "dbus-manager.h"
33 #include "dbus-snapshot.h"
34 #include "dbus-unit.h"
39 #include "formats-util.h"
42 #include "path-util.h"
43 #include "selinux-access.h"
44 #include "stat-util.h"
45 #include "string-util.h"
47 #include "syslog-util.h"
51 static int property_get_version(
54 const char *interface
,
56 sd_bus_message
*reply
,
58 sd_bus_error
*error
) {
63 return sd_bus_message_append(reply
, "s", PACKAGE_VERSION
);
66 static int property_get_features(
69 const char *interface
,
71 sd_bus_message
*reply
,
73 sd_bus_error
*error
) {
78 return sd_bus_message_append(reply
, "s", SYSTEMD_FEATURES
);
81 static int property_get_virtualization(
84 const char *interface
,
86 sd_bus_message
*reply
,
88 sd_bus_error
*error
) {
95 v
= detect_virtualization();
97 /* Make sure to return the empty string when we detect no virtualization, as that is the API.
99 * https://github.com/systemd/systemd/issues/1423
102 return sd_bus_message_append(
104 v
== VIRTUALIZATION_NONE
? "" : virtualization_to_string(v
));
107 static int property_get_architecture(
110 const char *interface
,
111 const char *property
,
112 sd_bus_message
*reply
,
114 sd_bus_error
*error
) {
119 return sd_bus_message_append(reply
, "s", architecture_to_string(uname_architecture()));
122 static int property_get_tainted(
125 const char *interface
,
126 const char *property
,
127 sd_bus_message
*reply
,
129 sd_bus_error
*error
) {
131 char buf
[sizeof("split-usr:cgroups-missing:local-hwclock:")] = "", *e
= buf
;
132 Manager
*m
= userdata
;
139 e
= stpcpy(e
, "split-usr:");
141 if (access("/proc/cgroups", F_OK
) < 0)
142 e
= stpcpy(e
, "cgroups-missing:");
144 if (clock_is_localtime() > 0)
145 e
= stpcpy(e
, "local-hwclock:");
147 /* remove the last ':' */
151 return sd_bus_message_append(reply
, "s", buf
);
154 static int property_get_log_target(
157 const char *interface
,
158 const char *property
,
159 sd_bus_message
*reply
,
161 sd_bus_error
*error
) {
166 return sd_bus_message_append(reply
, "s", log_target_to_string(log_get_target()));
169 static int property_set_log_target(
172 const char *interface
,
173 const char *property
,
174 sd_bus_message
*value
,
176 sd_bus_error
*error
) {
184 r
= sd_bus_message_read(value
, "s", &t
);
188 return log_set_target_from_string(t
);
191 static int property_get_log_level(
194 const char *interface
,
195 const char *property
,
196 sd_bus_message
*reply
,
198 sd_bus_error
*error
) {
200 _cleanup_free_
char *t
= NULL
;
206 r
= log_level_to_string_alloc(log_get_max_level(), &t
);
210 return sd_bus_message_append(reply
, "s", t
);
213 static int property_set_log_level(
216 const char *interface
,
217 const char *property
,
218 sd_bus_message
*value
,
220 sd_bus_error
*error
) {
228 r
= sd_bus_message_read(value
, "s", &t
);
232 return log_set_max_level_from_string(t
);
235 static int property_get_n_names(
238 const char *interface
,
239 const char *property
,
240 sd_bus_message
*reply
,
242 sd_bus_error
*error
) {
244 Manager
*m
= userdata
;
250 return sd_bus_message_append(reply
, "u", (uint32_t) hashmap_size(m
->units
));
253 static int property_get_n_failed_units(
256 const char *interface
,
257 const char *property
,
258 sd_bus_message
*reply
,
260 sd_bus_error
*error
) {
262 Manager
*m
= userdata
;
268 return sd_bus_message_append(reply
, "u", (uint32_t) set_size(m
->failed_units
));
271 static int property_get_n_jobs(
274 const char *interface
,
275 const char *property
,
276 sd_bus_message
*reply
,
278 sd_bus_error
*error
) {
280 Manager
*m
= userdata
;
286 return sd_bus_message_append(reply
, "u", (uint32_t) hashmap_size(m
->jobs
));
289 static int property_get_progress(
292 const char *interface
,
293 const char *property
,
294 sd_bus_message
*reply
,
296 sd_bus_error
*error
) {
298 Manager
*m
= userdata
;
305 if (dual_timestamp_is_set(&m
->finish_timestamp
))
308 d
= 1.0 - ((double) hashmap_size(m
->jobs
) / (double) m
->n_installed_jobs
);
310 return sd_bus_message_append(reply
, "d", d
);
313 static int property_get_system_state(
316 const char *interface
,
317 const char *property
,
318 sd_bus_message
*reply
,
320 sd_bus_error
*error
) {
322 Manager
*m
= userdata
;
328 return sd_bus_message_append(reply
, "s", manager_state_to_string(manager_state(m
)));
331 static int property_set_runtime_watchdog(
334 const char *interface
,
335 const char *property
,
336 sd_bus_message
*value
,
338 sd_bus_error
*error
) {
340 usec_t
*t
= userdata
;
346 assert_cc(sizeof(usec_t
) == sizeof(uint64_t));
348 r
= sd_bus_message_read(value
, "t", t
);
352 return watchdog_set_timeout(t
);
355 static int property_get_timer_slack_nsec(
358 const char *interface
,
359 const char *property
,
360 sd_bus_message
*reply
,
362 sd_bus_error
*error
) {
367 return sd_bus_message_append(reply
, "t", (uint64_t) prctl(PR_GET_TIMERSLACK
));
370 static int method_get_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
371 _cleanup_free_
char *path
= NULL
;
372 Manager
*m
= userdata
;
380 /* Anyone can call this method */
382 r
= sd_bus_message_read(message
, "s", &name
);
387 _cleanup_bus_creds_unref_ sd_bus_creds
*creds
= NULL
;
390 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
394 r
= sd_bus_creds_get_pid(creds
, &pid
);
398 u
= manager_get_unit_by_pid(m
, pid
);
400 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
402 u
= manager_get_unit(m
, name
);
404 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s not loaded.", name
);
407 r
= mac_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_get_unit_by_pid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
419 _cleanup_free_
char *path
= NULL
;
420 Manager
*m
= userdata
;
428 assert_cc(sizeof(pid_t
) == sizeof(uint32_t));
430 /* Anyone can call this method */
432 r
= sd_bus_message_read(message
, "u", &pid
);
436 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PID " PID_FMT
, pid
);
439 _cleanup_bus_creds_unref_ sd_bus_creds
*creds
= NULL
;
441 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
445 r
= sd_bus_creds_get_pid(creds
, &pid
);
450 u
= manager_get_unit_by_pid(m
, pid
);
452 return sd_bus_error_setf(error
, BUS_ERROR_NO_UNIT_FOR_PID
, "PID "PID_FMT
" does not belong to any loaded unit.", pid
);
454 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
458 path
= unit_dbus_path(u
);
462 return sd_bus_reply_method_return(message
, "o", path
);
465 static int method_load_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
466 _cleanup_free_
char *path
= NULL
;
467 Manager
*m
= userdata
;
475 /* Anyone can call this method */
477 r
= sd_bus_message_read(message
, "s", &name
);
482 _cleanup_bus_creds_unref_ sd_bus_creds
*creds
= NULL
;
485 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
489 r
= sd_bus_creds_get_pid(creds
, &pid
);
493 u
= manager_get_unit_by_pid(m
, pid
);
495 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
497 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
502 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
506 path
= unit_dbus_path(u
);
510 return sd_bus_reply_method_return(message
, "o", path
);
513 static int method_start_unit_generic(sd_bus_message
*message
, Manager
*m
, JobType job_type
, bool reload_if_possible
, sd_bus_error
*error
) {
521 r
= sd_bus_message_read(message
, "s", &name
);
525 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
529 return bus_unit_method_start_generic(message
, u
, job_type
, reload_if_possible
, error
);
532 static int method_start_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
533 return method_start_unit_generic(message
, userdata
, JOB_START
, false, error
);
536 static int method_stop_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
537 return method_start_unit_generic(message
, userdata
, JOB_STOP
, false, error
);
540 static int method_reload_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
541 return method_start_unit_generic(message
, userdata
, JOB_RELOAD
, false, error
);
544 static int method_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
545 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, false, error
);
548 static int method_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
549 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, false, error
);
552 static int method_reload_or_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
553 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, true, error
);
556 static int method_reload_or_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
557 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, true, error
);
560 static int method_start_unit_replace(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
561 Manager
*m
= userdata
;
562 const char *old_name
;
569 r
= sd_bus_message_read(message
, "s", &old_name
);
573 u
= manager_get_unit(m
, old_name
);
574 if (!u
|| !u
->job
|| u
->job
->type
!= JOB_START
)
575 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "No job queued for unit %s", old_name
);
577 return method_start_unit_generic(message
, m
, JOB_START
, false, error
);
580 static int method_kill_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
581 Manager
*m
= userdata
;
589 r
= sd_bus_message_read(message
, "s", &name
);
593 u
= manager_get_unit(m
, name
);
595 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not loaded.", name
);
597 return bus_unit_method_kill(message
, u
, error
);
600 static int method_reset_failed_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
601 Manager
*m
= userdata
;
609 r
= sd_bus_message_read(message
, "s", &name
);
613 u
= manager_get_unit(m
, name
);
615 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not loaded.", name
);
617 return bus_unit_method_reset_failed(message
, u
, error
);
620 static int method_set_unit_properties(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
621 Manager
*m
= userdata
;
629 r
= sd_bus_message_read(message
, "s", &name
);
633 u
= manager_get_unit(m
, name
);
635 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not loaded.", name
);
637 return bus_unit_method_set_properties(message
, u
, error
);
640 static int transient_unit_from_message(
642 sd_bus_message
*message
,
645 sd_bus_error
*error
) {
654 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
658 if (u
->load_state
!= UNIT_NOT_FOUND
||
659 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
);
678 static int transient_aux_units_from_message(
680 sd_bus_message
*message
,
681 sd_bus_error
*error
) {
690 r
= sd_bus_message_enter_container(message
, 'a', "(sa(sv))");
694 while ((r
= sd_bus_message_enter_container(message
, 'r', "sa(sv)")) > 0) {
695 r
= sd_bus_message_read(message
, "s", &name
);
699 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
700 if (r
< 0 && r
!= -EEXIST
)
709 r
= sd_bus_message_exit_container(message
);
716 r
= sd_bus_message_exit_container(message
);
723 static int method_start_transient_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
724 const char *name
, *smode
;
725 Manager
*m
= userdata
;
734 r
= mac_selinux_access_check(message
, "start", error
);
738 r
= sd_bus_message_read(message
, "ss", &name
, &smode
);
742 t
= unit_name_to_type(name
);
744 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid unit type.");
746 if (!unit_vtable
[t
]->can_transient
)
747 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unit type %s does not support transient units.", unit_type_to_string(t
));
749 mode
= job_mode_from_string(smode
);
751 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Job mode %s is invalid.", smode
);
753 r
= bus_verify_manage_units_async(m
, message
, error
);
757 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
759 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
763 r
= transient_aux_units_from_message(m
, message
, error
);
767 /* And load this stub fully */
772 manager_dispatch_load_queue(m
);
774 /* Finally, start it */
775 return bus_unit_queue_job(message
, u
, JOB_START
, mode
, false, error
);
778 static int method_get_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
779 _cleanup_free_
char *path
= NULL
;
780 Manager
*m
= userdata
;
788 /* Anyone can call this method */
790 r
= sd_bus_message_read(message
, "u", &id
);
794 j
= manager_get_job(m
, id
);
796 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
798 r
= mac_selinux_unit_access_check(j
->unit
, message
, "status", error
);
802 path
= job_dbus_path(j
);
806 return sd_bus_reply_method_return(message
, "o", path
);
809 static int method_cancel_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
810 Manager
*m
= userdata
;
818 r
= sd_bus_message_read(message
, "u", &id
);
822 j
= manager_get_job(m
, id
);
824 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
826 return bus_job_method_cancel(message
, j
, error
);
829 static int method_clear_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
830 Manager
*m
= userdata
;
836 r
= mac_selinux_access_check(message
, "reload", error
);
840 r
= bus_verify_manage_units_async(m
, message
, error
);
844 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
846 manager_clear_jobs(m
);
848 return sd_bus_reply_method_return(message
, NULL
);
851 static int method_reset_failed(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
852 Manager
*m
= userdata
;
858 r
= mac_selinux_access_check(message
, "reload", error
);
862 r
= bus_verify_manage_units_async(m
, message
, error
);
866 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
868 manager_reset_failed(m
);
870 return sd_bus_reply_method_return(message
, NULL
);
873 static int list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
) {
874 _cleanup_bus_message_unref_ sd_bus_message
*reply
= NULL
;
875 Manager
*m
= userdata
;
884 /* Anyone can call this method */
886 r
= mac_selinux_access_check(message
, "status", error
);
890 r
= sd_bus_message_new_method_return(message
, &reply
);
894 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
898 HASHMAP_FOREACH_KEY(u
, k
, m
->units
, i
) {
899 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
905 following
= unit_following(u
);
907 if (!strv_isempty(states
) &&
908 !strv_contains(states
, unit_load_state_to_string(u
->load_state
)) &&
909 !strv_contains(states
, unit_active_state_to_string(unit_active_state(u
))) &&
910 !strv_contains(states
, unit_sub_state_to_string(u
)))
913 unit_path
= unit_dbus_path(u
);
918 job_path
= job_dbus_path(u
->job
);
923 r
= sd_bus_message_append(
924 reply
, "(ssssssouso)",
927 unit_load_state_to_string(u
->load_state
),
928 unit_active_state_to_string(unit_active_state(u
)),
929 unit_sub_state_to_string(u
),
930 following
? following
->id
: "",
932 u
->job
? u
->job
->id
: 0,
933 u
->job
? job_type_to_string(u
->job
->type
) : "",
934 job_path
? job_path
: "/");
939 r
= sd_bus_message_close_container(reply
);
943 return sd_bus_send(NULL
, reply
, NULL
);
946 static int method_list_units(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
947 return list_units_filtered(message
, userdata
, error
, NULL
);
950 static int method_list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
951 _cleanup_strv_free_
char **states
= NULL
;
954 r
= sd_bus_message_read_strv(message
, &states
);
958 return list_units_filtered(message
, userdata
, error
, states
);
961 static int method_list_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
962 _cleanup_bus_message_unref_ sd_bus_message
*reply
= NULL
;
963 Manager
*m
= userdata
;
971 /* Anyone can call this method */
973 r
= mac_selinux_access_check(message
, "status", error
);
977 r
= sd_bus_message_new_method_return(message
, &reply
);
981 r
= sd_bus_message_open_container(reply
, 'a', "(usssoo)");
985 HASHMAP_FOREACH(j
, m
->jobs
, i
) {
986 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
988 job_path
= job_dbus_path(j
);
992 unit_path
= unit_dbus_path(j
->unit
);
996 r
= sd_bus_message_append(
1000 job_type_to_string(j
->type
),
1001 job_state_to_string(j
->state
),
1008 r
= sd_bus_message_close_container(reply
);
1012 return sd_bus_send(NULL
, reply
, NULL
);
1015 static int method_subscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1016 Manager
*m
= userdata
;
1022 /* Anyone can call this method */
1024 r
= mac_selinux_access_check(message
, "status", error
);
1028 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1030 /* Note that direct bus connection subscribe by
1031 * default, we only track peers on the API bus here */
1033 if (!m
->subscribed
) {
1034 r
= sd_bus_track_new(sd_bus_message_get_bus(message
), &m
->subscribed
, NULL
, NULL
);
1039 r
= sd_bus_track_add_sender(m
->subscribed
, message
);
1043 return sd_bus_error_setf(error
, BUS_ERROR_ALREADY_SUBSCRIBED
, "Client is already subscribed.");
1046 return sd_bus_reply_method_return(message
, NULL
);
1049 static int method_unsubscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1050 Manager
*m
= userdata
;
1056 /* Anyone can call this method */
1058 r
= mac_selinux_access_check(message
, "status", error
);
1062 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1063 r
= sd_bus_track_remove_sender(m
->subscribed
, message
);
1067 return sd_bus_error_setf(error
, BUS_ERROR_NOT_SUBSCRIBED
, "Client is not subscribed.");
1070 return sd_bus_reply_method_return(message
, NULL
);
1073 static int method_dump(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1074 _cleanup_free_
char *dump
= NULL
;
1075 _cleanup_fclose_
FILE *f
= NULL
;
1076 Manager
*m
= userdata
;
1083 /* Anyone can call this method */
1085 r
= mac_selinux_access_check(message
, "status", error
);
1089 f
= open_memstream(&dump
, &size
);
1093 manager_dump_units(m
, f
, NULL
);
1094 manager_dump_jobs(m
, f
, NULL
);
1096 r
= fflush_and_check(f
);
1100 return sd_bus_reply_method_return(message
, "s", dump
);
1103 static int method_create_snapshot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1104 _cleanup_free_
char *path
= NULL
;
1105 Manager
*m
= userdata
;
1114 r
= mac_selinux_access_check(message
, "start", error
);
1118 r
= sd_bus_message_read(message
, "sb", &name
, &cleanup
);
1125 r
= bus_verify_manage_units_async(m
, message
, error
);
1129 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1131 r
= snapshot_create(m
, name
, cleanup
, error
, &s
);
1135 path
= unit_dbus_path(UNIT(s
));
1139 return sd_bus_reply_method_return(message
, "o", path
);
1142 static int method_remove_snapshot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1143 Manager
*m
= userdata
;
1151 r
= sd_bus_message_read(message
, "s", &name
);
1155 u
= manager_get_unit(m
, name
);
1157 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s does not exist.", name
);
1159 if (u
->type
!= UNIT_SNAPSHOT
)
1160 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not a snapshot", name
);
1162 return bus_snapshot_method_remove(message
, u
, error
);
1165 static int method_reload(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1166 Manager
*m
= userdata
;
1172 r
= mac_selinux_access_check(message
, "reload", error
);
1176 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1180 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1182 /* Instead of sending the reply back right away, we just
1183 * remember that we need to and then send it after the reload
1184 * is finished. That way the caller knows when the reload
1187 assert(!m
->queued_message
);
1188 r
= sd_bus_message_new_method_return(message
, &m
->queued_message
);
1192 m
->exit_code
= MANAGER_RELOAD
;
1197 static int method_reexecute(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1198 Manager
*m
= userdata
;
1204 r
= mac_selinux_access_check(message
, "reload", error
);
1208 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1212 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1214 /* We don't send a reply back here, the client should
1215 * just wait for us disconnecting. */
1217 m
->exit_code
= MANAGER_REEXECUTE
;
1221 static int method_exit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1222 Manager
*m
= userdata
;
1228 r
= mac_selinux_access_check(message
, "halt", error
);
1232 /* Exit() (in contrast to SetExitCode()) is actually allowed even if
1233 * we are running on the host. It will fall back on reboot() in
1234 * systemd-shutdown if it cannot do the exit() because it isn't a
1237 m
->exit_code
= MANAGER_EXIT
;
1239 return sd_bus_reply_method_return(message
, NULL
);
1242 static int method_reboot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1243 Manager
*m
= userdata
;
1249 r
= mac_selinux_access_check(message
, "reboot", error
);
1253 if (m
->running_as
!= MANAGER_SYSTEM
)
1254 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Reboot is only supported for system managers.");
1256 m
->exit_code
= MANAGER_REBOOT
;
1258 return sd_bus_reply_method_return(message
, NULL
);
1261 static int method_poweroff(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1262 Manager
*m
= userdata
;
1268 r
= mac_selinux_access_check(message
, "halt", error
);
1272 if (m
->running_as
!= MANAGER_SYSTEM
)
1273 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Powering off is only supported for system managers.");
1275 m
->exit_code
= MANAGER_POWEROFF
;
1277 return sd_bus_reply_method_return(message
, NULL
);
1280 static int method_halt(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1281 Manager
*m
= userdata
;
1287 r
= mac_selinux_access_check(message
, "halt", error
);
1291 if (m
->running_as
!= MANAGER_SYSTEM
)
1292 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Halt is only supported for system managers.");
1294 m
->exit_code
= MANAGER_HALT
;
1296 return sd_bus_reply_method_return(message
, NULL
);
1299 static int method_kexec(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1300 Manager
*m
= userdata
;
1306 r
= mac_selinux_access_check(message
, "reboot", error
);
1310 if (m
->running_as
!= MANAGER_SYSTEM
)
1311 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "KExec is only supported for system managers.");
1313 m
->exit_code
= MANAGER_KEXEC
;
1315 return sd_bus_reply_method_return(message
, NULL
);
1318 static int method_switch_root(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1319 char *ri
= NULL
, *rt
= NULL
;
1320 const char *root
, *init
;
1321 Manager
*m
= userdata
;
1327 r
= mac_selinux_access_check(message
, "reboot", error
);
1331 if (m
->running_as
!= MANAGER_SYSTEM
)
1332 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Root switching is only supported by system manager.");
1334 r
= sd_bus_message_read(message
, "ss", &root
, &init
);
1338 if (path_equal(root
, "/") || !path_is_absolute(root
))
1339 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid switch root path %s", root
);
1342 if (isempty(init
)) {
1343 if (!path_is_os_tree(root
))
1344 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
);
1346 _cleanup_free_
char *p
= NULL
;
1348 if (!path_is_absolute(init
))
1349 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid init path %s", init
);
1351 p
= strappend(root
, init
);
1355 if (access(p
, X_OK
) < 0)
1356 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Specified init binary %s does not exist.", p
);
1363 if (!isempty(init
)) {
1371 free(m
->switch_root
);
1372 m
->switch_root
= rt
;
1374 free(m
->switch_root_init
);
1375 m
->switch_root_init
= ri
;
1377 m
->exit_code
= MANAGER_SWITCH_ROOT
;
1379 return sd_bus_reply_method_return(message
, NULL
);
1382 static int method_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1383 _cleanup_strv_free_
char **plus
= NULL
;
1384 Manager
*m
= userdata
;
1390 r
= mac_selinux_access_check(message
, "reload", error
);
1394 r
= sd_bus_message_read_strv(message
, &plus
);
1397 if (!strv_env_is_valid(plus
))
1398 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1400 r
= bus_verify_set_environment_async(m
, message
, error
);
1404 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1406 r
= manager_environment_add(m
, NULL
, plus
);
1410 return sd_bus_reply_method_return(message
, NULL
);
1413 static int method_unset_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1414 _cleanup_strv_free_
char **minus
= NULL
;
1415 Manager
*m
= userdata
;
1421 r
= mac_selinux_access_check(message
, "reload", error
);
1425 r
= sd_bus_message_read_strv(message
, &minus
);
1429 if (!strv_env_name_or_assignment_is_valid(minus
))
1430 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1432 r
= bus_verify_set_environment_async(m
, message
, error
);
1436 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1438 r
= manager_environment_add(m
, minus
, NULL
);
1442 return sd_bus_reply_method_return(message
, NULL
);
1445 static int method_unset_and_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1446 _cleanup_strv_free_
char **minus
= NULL
, **plus
= NULL
;
1447 Manager
*m
= userdata
;
1453 r
= mac_selinux_access_check(message
, "reload", error
);
1457 r
= sd_bus_message_read_strv(message
, &minus
);
1461 r
= sd_bus_message_read_strv(message
, &plus
);
1465 if (!strv_env_name_or_assignment_is_valid(minus
))
1466 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1467 if (!strv_env_is_valid(plus
))
1468 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1470 r
= bus_verify_set_environment_async(m
, message
, error
);
1474 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1476 r
= manager_environment_add(m
, minus
, plus
);
1480 return sd_bus_reply_method_return(message
, NULL
);
1483 static int method_set_exit_code(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1485 Manager
*m
= userdata
;
1491 r
= mac_selinux_access_check(message
, "exit", error
);
1495 r
= sd_bus_message_read_basic(message
, 'y', &code
);
1499 if (m
->running_as
== MANAGER_SYSTEM
&& detect_container() <= 0)
1500 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "ExitCode can only be set for user service managers or in containers.");
1502 m
->return_value
= code
;
1504 return sd_bus_reply_method_return(message
, NULL
);
1507 static int method_list_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1508 _cleanup_bus_message_unref_ sd_bus_message
*reply
= NULL
;
1509 Manager
*m
= userdata
;
1518 /* Anyone can call this method */
1520 r
= mac_selinux_access_check(message
, "status", error
);
1524 r
= sd_bus_message_new_method_return(message
, &reply
);
1528 h
= hashmap_new(&string_hash_ops
);
1532 r
= unit_file_get_list(m
->running_as
== MANAGER_SYSTEM
? UNIT_FILE_SYSTEM
: UNIT_FILE_USER
, NULL
, h
);
1536 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1540 HASHMAP_FOREACH(item
, h
, i
) {
1542 r
= sd_bus_message_append(reply
, "(ss)", item
->path
, unit_file_state_to_string(item
->state
));
1547 unit_file_list_free(h
);
1549 r
= sd_bus_message_close_container(reply
);
1553 return sd_bus_send(NULL
, reply
, NULL
);
1556 unit_file_list_free(h
);
1560 static int method_get_unit_file_state(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1561 Manager
*m
= userdata
;
1563 UnitFileState state
;
1564 UnitFileScope scope
;
1570 /* Anyone can call this method */
1572 r
= mac_selinux_access_check(message
, "status", error
);
1576 r
= sd_bus_message_read(message
, "s", &name
);
1580 scope
= m
->running_as
== MANAGER_SYSTEM
? UNIT_FILE_SYSTEM
: UNIT_FILE_USER
;
1582 state
= unit_file_get_state(scope
, NULL
, name
);
1586 return sd_bus_reply_method_return(message
, "s", unit_file_state_to_string(state
));
1589 static int method_get_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1590 _cleanup_free_
char *default_target
= NULL
;
1591 Manager
*m
= userdata
;
1592 UnitFileScope scope
;
1598 /* Anyone can call this method */
1600 r
= mac_selinux_access_check(message
, "status", error
);
1604 scope
= m
->running_as
== MANAGER_SYSTEM
? UNIT_FILE_SYSTEM
: UNIT_FILE_USER
;
1606 r
= unit_file_get_default(scope
, NULL
, &default_target
);
1610 return sd_bus_reply_method_return(message
, "s", default_target
);
1613 static int send_unit_files_changed(sd_bus
*bus
, void *userdata
) {
1614 _cleanup_bus_message_unref_ sd_bus_message
*message
= NULL
;
1619 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
1623 return sd_bus_send(bus
, message
, NULL
);
1626 static int reply_unit_file_changes_and_free(
1628 sd_bus_message
*message
,
1629 int carries_install_info
,
1630 UnitFileChange
*changes
,
1631 unsigned n_changes
) {
1633 _cleanup_bus_message_unref_ sd_bus_message
*reply
= NULL
;
1637 if (n_changes
> 0) {
1638 r
= bus_foreach_bus(m
, NULL
, send_unit_files_changed
, NULL
);
1640 log_debug_errno(r
, "Failed to send UnitFilesChanged signal: %m");
1643 r
= sd_bus_message_new_method_return(message
, &reply
);
1647 if (carries_install_info
>= 0) {
1648 r
= sd_bus_message_append(reply
, "b", carries_install_info
);
1653 r
= sd_bus_message_open_container(reply
, 'a', "(sss)");
1657 for (i
= 0; i
< n_changes
; i
++) {
1658 r
= sd_bus_message_append(
1660 unit_file_change_type_to_string(changes
[i
].type
),
1667 r
= sd_bus_message_close_container(reply
);
1671 return sd_bus_send(NULL
, reply
, NULL
);
1674 unit_file_changes_free(changes
, n_changes
);
1678 static int method_enable_unit_files_generic(
1679 sd_bus_message
*message
,
1682 int (*call
)(UnitFileScope scope
, bool runtime
, const char *root_dir
, char *files
[], bool force
, UnitFileChange
**changes
, unsigned *n_changes
),
1683 bool carries_install_info
,
1684 sd_bus_error
*error
) {
1686 _cleanup_strv_free_
char **l
= NULL
;
1687 UnitFileChange
*changes
= NULL
;
1688 unsigned n_changes
= 0;
1689 UnitFileScope scope
;
1690 int runtime
, force
, r
;
1695 r
= sd_bus_message_read_strv(message
, &l
);
1699 r
= sd_bus_message_read(message
, "bb", &runtime
, &force
);
1703 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
1707 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1709 scope
= m
->running_as
== MANAGER_SYSTEM
? UNIT_FILE_SYSTEM
: UNIT_FILE_USER
;
1711 r
= call(scope
, runtime
, NULL
, l
, force
, &changes
, &n_changes
);
1715 return reply_unit_file_changes_and_free(m
, message
, carries_install_info
? r
: -1, changes
, n_changes
);
1718 static int method_enable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1719 return method_enable_unit_files_generic(message
, userdata
, "enable", unit_file_enable
, true, error
);
1722 static int method_reenable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1723 return method_enable_unit_files_generic(message
, userdata
, "enable", unit_file_reenable
, true, error
);
1726 static int method_link_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1727 return method_enable_unit_files_generic(message
, userdata
, "enable", unit_file_link
, false, error
);
1730 static int unit_file_preset_without_mode(UnitFileScope scope
, bool runtime
, const char *root_dir
, char **files
, bool force
, UnitFileChange
**changes
, unsigned *n_changes
) {
1731 return unit_file_preset(scope
, runtime
, root_dir
, files
, UNIT_FILE_PRESET_FULL
, force
, changes
, n_changes
);
1734 static int method_preset_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1735 return method_enable_unit_files_generic(message
, userdata
, "enable", unit_file_preset_without_mode
, true, error
);
1738 static int method_mask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1739 return method_enable_unit_files_generic(message
, userdata
, "disable", unit_file_mask
, false, error
);
1742 static int method_preset_unit_files_with_mode(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1744 _cleanup_strv_free_
char **l
= NULL
;
1745 UnitFileChange
*changes
= NULL
;
1746 unsigned n_changes
= 0;
1747 Manager
*m
= userdata
;
1748 UnitFilePresetMode mm
;
1749 UnitFileScope scope
;
1750 int runtime
, force
, r
;
1756 r
= sd_bus_message_read_strv(message
, &l
);
1760 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
1765 mm
= UNIT_FILE_PRESET_FULL
;
1767 mm
= unit_file_preset_mode_from_string(mode
);
1772 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
1776 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1778 scope
= m
->running_as
== MANAGER_SYSTEM
? UNIT_FILE_SYSTEM
: UNIT_FILE_USER
;
1780 r
= unit_file_preset(scope
, runtime
, NULL
, l
, mm
, force
, &changes
, &n_changes
);
1784 return reply_unit_file_changes_and_free(m
, message
, r
, changes
, n_changes
);
1787 static int method_disable_unit_files_generic(
1788 sd_bus_message
*message
,
1791 int (*call
)(UnitFileScope scope
, bool runtime
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, unsigned *n_changes
),
1792 sd_bus_error
*error
) {
1794 _cleanup_strv_free_
char **l
= NULL
;
1795 UnitFileChange
*changes
= NULL
;
1796 unsigned n_changes
= 0;
1797 UnitFileScope scope
;
1803 r
= sd_bus_message_read_strv(message
, &l
);
1807 r
= sd_bus_message_read(message
, "b", &runtime
);
1811 scope
= m
->running_as
== MANAGER_SYSTEM
? UNIT_FILE_SYSTEM
: UNIT_FILE_USER
;
1813 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
1817 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1819 r
= call(scope
, runtime
, NULL
, l
, &changes
, &n_changes
);
1823 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
);
1826 static int method_disable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1827 return method_disable_unit_files_generic(message
, userdata
, "disable", unit_file_disable
, error
);
1830 static int method_unmask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1831 return method_disable_unit_files_generic(message
, userdata
, "enable", unit_file_unmask
, error
);
1834 static int method_set_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1835 UnitFileChange
*changes
= NULL
;
1836 unsigned n_changes
= 0;
1837 Manager
*m
= userdata
;
1838 UnitFileScope scope
;
1845 r
= mac_selinux_access_check(message
, "enable", error
);
1849 r
= sd_bus_message_read(message
, "sb", &name
, &force
);
1853 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
1857 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1859 scope
= m
->running_as
== MANAGER_SYSTEM
? UNIT_FILE_SYSTEM
: UNIT_FILE_USER
;
1861 r
= unit_file_set_default(scope
, NULL
, name
, force
, &changes
, &n_changes
);
1865 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
);
1868 static int method_preset_all_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1869 UnitFileChange
*changes
= NULL
;
1870 unsigned n_changes
= 0;
1871 Manager
*m
= userdata
;
1872 UnitFilePresetMode mm
;
1873 UnitFileScope scope
;
1875 int force
, runtime
, r
;
1880 r
= mac_selinux_access_check(message
, "enable", error
);
1884 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
1889 mm
= UNIT_FILE_PRESET_FULL
;
1891 mm
= unit_file_preset_mode_from_string(mode
);
1896 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
1900 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1902 scope
= m
->running_as
== MANAGER_SYSTEM
? UNIT_FILE_SYSTEM
: UNIT_FILE_USER
;
1904 r
= unit_file_preset_all(scope
, runtime
, NULL
, mm
, force
, &changes
, &n_changes
);
1908 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
);
1911 static int method_add_dependency_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1912 _cleanup_strv_free_
char **l
= NULL
;
1913 Manager
*m
= userdata
;
1914 UnitFileChange
*changes
= NULL
;
1915 unsigned n_changes
= 0;
1916 UnitFileScope scope
;
1917 int runtime
, force
, r
;
1925 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
1929 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1931 r
= sd_bus_message_read_strv(message
, &l
);
1935 r
= sd_bus_message_read(message
, "ssbb", &target
, &type
, &runtime
, &force
);
1939 dep
= unit_dependency_from_string(type
);
1943 scope
= m
->running_as
== MANAGER_SYSTEM
? UNIT_FILE_SYSTEM
: UNIT_FILE_USER
;
1945 r
= unit_file_add_dependency(scope
, runtime
, NULL
, l
, target
, dep
, force
, &changes
, &n_changes
);
1949 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
);
1952 const sd_bus_vtable bus_manager_vtable
[] = {
1953 SD_BUS_VTABLE_START(0),
1955 SD_BUS_PROPERTY("Version", "s", property_get_version
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1956 SD_BUS_PROPERTY("Features", "s", property_get_features
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1957 SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1958 SD_BUS_PROPERTY("Architecture", "s", property_get_architecture
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1959 SD_BUS_PROPERTY("Tainted", "s", property_get_tainted
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1960 BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager
, firmware_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1961 BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager
, loader_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1962 BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager
, kernel_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1963 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager
, initrd_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1964 BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager
, userspace_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1965 BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager
, finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1966 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager
, security_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1967 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager
, security_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1968 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager
, generators_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1969 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager
, generators_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1970 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager
, units_load_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1971 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager
, units_load_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1972 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level
, property_set_log_level
, 0, 0),
1973 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target
, property_set_log_target
, 0, 0),
1974 SD_BUS_PROPERTY("NNames", "u", property_get_n_names
, 0, 0),
1975 SD_BUS_PROPERTY("NFailedUnits", "u", property_get_n_failed_units
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
1976 SD_BUS_PROPERTY("NJobs", "u", property_get_n_jobs
, 0, 0),
1977 SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_installed_jobs
), 0),
1978 SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_failed_jobs
), 0),
1979 SD_BUS_PROPERTY("Progress", "d", property_get_progress
, 0, 0),
1980 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(Manager
, environment
), 0),
1981 SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool
, offsetof(Manager
, confirm_spawn
), SD_BUS_VTABLE_PROPERTY_CONST
),
1982 SD_BUS_PROPERTY("ShowStatus", "b", bus_property_get_bool
, offsetof(Manager
, show_status
), SD_BUS_VTABLE_PROPERTY_CONST
),
1983 SD_BUS_PROPERTY("UnitPath", "as", NULL
, offsetof(Manager
, lookup_paths
.unit_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1984 SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
1985 SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
1986 SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec
, property_set_runtime_watchdog
, offsetof(Manager
, runtime_watchdog
), 0),
1987 SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec
, bus_property_set_usec
, offsetof(Manager
, shutdown_watchdog
), 0),
1988 SD_BUS_PROPERTY("ControlGroup", "s", NULL
, offsetof(Manager
, cgroup_root
), 0),
1989 SD_BUS_PROPERTY("SystemState", "s", property_get_system_state
, 0, 0),
1990 SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned
, offsetof(Manager
, return_value
), 0),
1991 SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timer_accuracy_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
1992 SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_start_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
1993 SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_stop_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
1994 SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_restart_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
1995 SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
),
1996 SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned
, offsetof(Manager
, default_start_limit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
1997 SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_cpu_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
1998 SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_blockio_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
1999 SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_memory_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2000 SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_tasks_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2001 SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2002 SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2003 SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2004 SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2005 SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2006 SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2007 SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2008 SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2009 SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2010 SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2011 SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2012 SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2013 SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2014 SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2015 SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2016 SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2017 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2019 SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2020 SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2021 SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2022 SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2023 SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace
, SD_BUS_VTABLE_UNPRIVILEGED
),
2024 SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2025 SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2026 SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2027 SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2028 SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2029 SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2030 SD_BUS_METHOD("KillUnit", "ssi", NULL
, method_kill_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2031 SD_BUS_METHOD("ResetFailedUnit", "s", NULL
, method_reset_failed_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2032 SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL
, method_set_unit_properties
, SD_BUS_VTABLE_UNPRIVILEGED
),
2033 SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2034 SD_BUS_METHOD("GetJob", "u", "o", method_get_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2035 SD_BUS_METHOD("CancelJob", "u", NULL
, method_cancel_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2036 SD_BUS_METHOD("ClearJobs", NULL
, NULL
, method_clear_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2037 SD_BUS_METHOD("ResetFailed", NULL
, NULL
, method_reset_failed
, SD_BUS_VTABLE_UNPRIVILEGED
),
2038 SD_BUS_METHOD("ListUnits", NULL
, "a(ssssssouso)", method_list_units
, SD_BUS_VTABLE_UNPRIVILEGED
),
2039 SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered
, SD_BUS_VTABLE_UNPRIVILEGED
),
2040 SD_BUS_METHOD("ListJobs", NULL
, "a(usssoo)", method_list_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2041 SD_BUS_METHOD("Subscribe", NULL
, NULL
, method_subscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2042 SD_BUS_METHOD("Unsubscribe", NULL
, NULL
, method_unsubscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2043 SD_BUS_METHOD("Dump", NULL
, "s", method_dump
, SD_BUS_VTABLE_UNPRIVILEGED
),
2044 SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_create_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
),
2045 SD_BUS_METHOD("RemoveSnapshot", "s", NULL
, method_remove_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
),
2046 SD_BUS_METHOD("Reload", NULL
, NULL
, method_reload
, SD_BUS_VTABLE_UNPRIVILEGED
),
2047 SD_BUS_METHOD("Reexecute", NULL
, NULL
, method_reexecute
, SD_BUS_VTABLE_UNPRIVILEGED
),
2048 SD_BUS_METHOD("Exit", NULL
, NULL
, method_exit
, 0),
2049 SD_BUS_METHOD("Reboot", NULL
, NULL
, method_reboot
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2050 SD_BUS_METHOD("PowerOff", NULL
, NULL
, method_poweroff
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2051 SD_BUS_METHOD("Halt", NULL
, NULL
, method_halt
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2052 SD_BUS_METHOD("KExec", NULL
, NULL
, method_kexec
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2053 SD_BUS_METHOD("SwitchRoot", "ss", NULL
, method_switch_root
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2054 SD_BUS_METHOD("SetEnvironment", "as", NULL
, method_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2055 SD_BUS_METHOD("UnsetEnvironment", "as", NULL
, method_unset_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2056 SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL
, method_unset_and_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2057 SD_BUS_METHOD("ListUnitFiles", NULL
, "a(ss)", method_list_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2058 SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state
, SD_BUS_VTABLE_UNPRIVILEGED
),
2059 SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2060 SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2061 SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2062 SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2063 SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2064 SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode
, SD_BUS_VTABLE_UNPRIVILEGED
),
2065 SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2066 SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2067 SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2068 SD_BUS_METHOD("GetDefaultTarget", NULL
, "s", method_get_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2069 SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2070 SD_BUS_METHOD("AddDependencyUnitFiles", "asssbb", "a(sss)", method_add_dependency_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2071 SD_BUS_METHOD("SetExitCode", "y", NULL
, method_set_exit_code
, SD_BUS_VTABLE_UNPRIVILEGED
),
2073 SD_BUS_SIGNAL("UnitNew", "so", 0),
2074 SD_BUS_SIGNAL("UnitRemoved", "so", 0),
2075 SD_BUS_SIGNAL("JobNew", "uos", 0),
2076 SD_BUS_SIGNAL("JobRemoved", "uoss", 0),
2077 SD_BUS_SIGNAL("StartupFinished", "tttttt", 0),
2078 SD_BUS_SIGNAL("UnitFilesChanged", NULL
, 0),
2079 SD_BUS_SIGNAL("Reloading", "b", 0),
2084 static int send_finished(sd_bus
*bus
, void *userdata
) {
2085 _cleanup_bus_message_unref_ sd_bus_message
*message
= NULL
;
2086 usec_t
*times
= userdata
;
2092 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
2096 r
= sd_bus_message_append(message
, "tttttt", times
[0], times
[1], times
[2], times
[3], times
[4], times
[5]);
2100 return sd_bus_send(bus
, message
, NULL
);
2103 void bus_manager_send_finished(
2105 usec_t firmware_usec
,
2109 usec_t userspace_usec
,
2110 usec_t total_usec
) {
2116 r
= bus_foreach_bus(
2129 log_debug_errno(r
, "Failed to send finished signal: %m");
2132 static int send_reloading(sd_bus
*bus
, void *userdata
) {
2133 _cleanup_bus_message_unref_ sd_bus_message
*message
= NULL
;
2138 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
2142 r
= sd_bus_message_append(message
, "b", PTR_TO_INT(userdata
));
2146 return sd_bus_send(bus
, message
, NULL
);
2149 void bus_manager_send_reloading(Manager
*m
, bool active
) {
2154 r
= bus_foreach_bus(m
, NULL
, send_reloading
, INT_TO_PTR(active
));
2156 log_debug_errno(r
, "Failed to send reloading signal: %m");
2159 static int send_changed_signal(sd_bus
*bus
, void *userdata
) {
2162 return sd_bus_emit_properties_changed_strv(bus
,
2163 "/org/freedesktop/systemd1",
2164 "org.freedesktop.systemd1.Manager",
2168 void bus_manager_send_change_signal(Manager
*m
) {
2173 r
= bus_foreach_bus(m
, NULL
, send_changed_signal
, NULL
);
2175 log_debug_errno(r
, "Failed to send manager change signal: %m");