2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 #include <sys/prctl.h>
24 #include "alloc-util.h"
25 #include "architecture.h"
27 #include "bus-common-errors.h"
28 #include "clock-util.h"
29 #include "dbus-execute.h"
31 #include "dbus-manager.h"
32 #include "dbus-unit.h"
37 #include "formats-util.h"
40 #include "path-util.h"
41 #include "selinux-access.h"
42 #include "stat-util.h"
43 #include "string-util.h"
45 #include "syslog-util.h"
46 #include "user-util.h"
50 static int property_get_version(
53 const char *interface
,
55 sd_bus_message
*reply
,
57 sd_bus_error
*error
) {
62 return sd_bus_message_append(reply
, "s", PACKAGE_VERSION
);
65 static int property_get_features(
68 const char *interface
,
70 sd_bus_message
*reply
,
72 sd_bus_error
*error
) {
77 return sd_bus_message_append(reply
, "s", SYSTEMD_FEATURES
);
80 static int property_get_virtualization(
83 const char *interface
,
85 sd_bus_message
*reply
,
87 sd_bus_error
*error
) {
94 v
= detect_virtualization();
96 /* Make sure to return the empty string when we detect no virtualization, as that is the API.
98 * https://github.com/systemd/systemd/issues/1423
101 return sd_bus_message_append(
103 v
== VIRTUALIZATION_NONE
? "" : virtualization_to_string(v
));
106 static int property_get_architecture(
109 const char *interface
,
110 const char *property
,
111 sd_bus_message
*reply
,
113 sd_bus_error
*error
) {
118 return sd_bus_message_append(reply
, "s", architecture_to_string(uname_architecture()));
121 static int property_get_tainted(
124 const char *interface
,
125 const char *property
,
126 sd_bus_message
*reply
,
128 sd_bus_error
*error
) {
130 char buf
[sizeof("split-usr:cgroups-missing:local-hwclock:")] = "", *e
= buf
;
131 Manager
*m
= userdata
;
138 e
= stpcpy(e
, "split-usr:");
140 if (access("/proc/cgroups", F_OK
) < 0)
141 e
= stpcpy(e
, "cgroups-missing:");
143 if (clock_is_localtime(NULL
) > 0)
144 e
= stpcpy(e
, "local-hwclock:");
146 /* remove the last ':' */
150 return sd_bus_message_append(reply
, "s", buf
);
153 static int property_get_log_target(
156 const char *interface
,
157 const char *property
,
158 sd_bus_message
*reply
,
160 sd_bus_error
*error
) {
165 return sd_bus_message_append(reply
, "s", log_target_to_string(log_get_target()));
168 static int property_set_log_target(
171 const char *interface
,
172 const char *property
,
173 sd_bus_message
*value
,
175 sd_bus_error
*error
) {
183 r
= sd_bus_message_read(value
, "s", &t
);
187 return log_set_target_from_string(t
);
190 static int property_get_log_level(
193 const char *interface
,
194 const char *property
,
195 sd_bus_message
*reply
,
197 sd_bus_error
*error
) {
199 _cleanup_free_
char *t
= NULL
;
205 r
= log_level_to_string_alloc(log_get_max_level(), &t
);
209 return sd_bus_message_append(reply
, "s", t
);
212 static int property_set_log_level(
215 const char *interface
,
216 const char *property
,
217 sd_bus_message
*value
,
219 sd_bus_error
*error
) {
227 r
= sd_bus_message_read(value
, "s", &t
);
231 r
= log_set_max_level_from_string(t
);
233 log_info("Setting log level to %s.", t
);
237 static int property_get_n_names(
240 const char *interface
,
241 const char *property
,
242 sd_bus_message
*reply
,
244 sd_bus_error
*error
) {
246 Manager
*m
= userdata
;
252 return sd_bus_message_append(reply
, "u", (uint32_t) hashmap_size(m
->units
));
255 static int property_get_n_failed_units(
258 const char *interface
,
259 const char *property
,
260 sd_bus_message
*reply
,
262 sd_bus_error
*error
) {
264 Manager
*m
= userdata
;
270 return sd_bus_message_append(reply
, "u", (uint32_t) set_size(m
->failed_units
));
273 static int property_get_n_jobs(
276 const char *interface
,
277 const char *property
,
278 sd_bus_message
*reply
,
280 sd_bus_error
*error
) {
282 Manager
*m
= userdata
;
288 return sd_bus_message_append(reply
, "u", (uint32_t) hashmap_size(m
->jobs
));
291 static int property_get_progress(
294 const char *interface
,
295 const char *property
,
296 sd_bus_message
*reply
,
298 sd_bus_error
*error
) {
300 Manager
*m
= userdata
;
307 if (dual_timestamp_is_set(&m
->finish_timestamp
))
310 d
= 1.0 - ((double) hashmap_size(m
->jobs
) / (double) m
->n_installed_jobs
);
312 return sd_bus_message_append(reply
, "d", d
);
315 static int property_get_system_state(
318 const char *interface
,
319 const char *property
,
320 sd_bus_message
*reply
,
322 sd_bus_error
*error
) {
324 Manager
*m
= userdata
;
330 return sd_bus_message_append(reply
, "s", manager_state_to_string(manager_state(m
)));
333 static int property_set_runtime_watchdog(
336 const char *interface
,
337 const char *property
,
338 sd_bus_message
*value
,
340 sd_bus_error
*error
) {
342 usec_t
*t
= userdata
;
348 assert_cc(sizeof(usec_t
) == sizeof(uint64_t));
350 r
= sd_bus_message_read(value
, "t", t
);
354 return watchdog_set_timeout(t
);
357 static int property_get_timer_slack_nsec(
360 const char *interface
,
361 const char *property
,
362 sd_bus_message
*reply
,
364 sd_bus_error
*error
) {
369 return sd_bus_message_append(reply
, "t", (uint64_t) prctl(PR_GET_TIMERSLACK
));
372 static int method_get_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
373 _cleanup_free_
char *path
= NULL
;
374 Manager
*m
= userdata
;
382 /* Anyone can call this method */
384 r
= sd_bus_message_read(message
, "s", &name
);
389 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
392 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
396 r
= sd_bus_creds_get_pid(creds
, &pid
);
400 u
= manager_get_unit_by_pid(m
, pid
);
402 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
404 u
= manager_get_unit(m
, name
);
406 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s not loaded.", name
);
409 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
413 path
= unit_dbus_path(u
);
417 return sd_bus_reply_method_return(message
, "o", path
);
420 static int method_get_unit_by_pid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
421 _cleanup_free_
char *path
= NULL
;
422 Manager
*m
= userdata
;
430 assert_cc(sizeof(pid_t
) == sizeof(uint32_t));
432 /* Anyone can call this method */
434 r
= sd_bus_message_read(message
, "u", &pid
);
438 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PID " PID_FMT
, pid
);
441 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
443 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
447 r
= sd_bus_creds_get_pid(creds
, &pid
);
452 u
= manager_get_unit_by_pid(m
, pid
);
454 return sd_bus_error_setf(error
, BUS_ERROR_NO_UNIT_FOR_PID
, "PID "PID_FMT
" does not belong to any loaded unit.", pid
);
456 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
460 path
= unit_dbus_path(u
);
464 return sd_bus_reply_method_return(message
, "o", path
);
467 static int method_get_unit_by_invocation_id(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
468 _cleanup_free_
char *path
= NULL
;
469 Manager
*m
= userdata
;
479 /* Anyone can call this method */
481 r
= sd_bus_message_read_array(message
, 'y', &a
, &sz
);
489 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid invocation ID");
491 if (sd_id128_is_null(id
)) {
492 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
495 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
499 r
= sd_bus_creds_get_pid(creds
, &pid
);
503 u
= manager_get_unit_by_pid(m
, pid
);
505 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client " PID_FMT
" not member of any unit.", pid
);
507 u
= hashmap_get(m
->units_by_invocation_id
, &id
);
509 return sd_bus_error_setf(error
, BUS_ERROR_NO_UNIT_FOR_INVOCATION_ID
, "No unit with the specified invocation ID " SD_ID128_FORMAT_STR
" known.", SD_ID128_FORMAT_VAL(id
));
512 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
516 /* So here's a special trick: the bus path we return actually references the unit by its invocation ID instead
517 * of the unit name. This means it stays valid only as long as the invocation ID stays the same. */
518 path
= unit_dbus_path_invocation_id(u
);
522 return sd_bus_reply_method_return(message
, "o", path
);
525 static int method_load_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
526 _cleanup_free_
char *path
= NULL
;
527 Manager
*m
= userdata
;
535 /* Anyone can call this method */
537 r
= sd_bus_message_read(message
, "s", &name
);
542 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
545 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
549 r
= sd_bus_creds_get_pid(creds
, &pid
);
553 u
= manager_get_unit_by_pid(m
, pid
);
555 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
557 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
562 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
566 path
= unit_dbus_path(u
);
570 return sd_bus_reply_method_return(message
, "o", path
);
573 static int method_start_unit_generic(sd_bus_message
*message
, Manager
*m
, JobType job_type
, bool reload_if_possible
, sd_bus_error
*error
) {
581 r
= sd_bus_message_read(message
, "s", &name
);
585 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
589 return bus_unit_method_start_generic(message
, u
, job_type
, reload_if_possible
, error
);
592 static int method_start_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
593 return method_start_unit_generic(message
, userdata
, JOB_START
, false, error
);
596 static int method_stop_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
597 return method_start_unit_generic(message
, userdata
, JOB_STOP
, false, error
);
600 static int method_reload_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
601 return method_start_unit_generic(message
, userdata
, JOB_RELOAD
, false, error
);
604 static int method_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
605 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, false, error
);
608 static int method_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
609 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, false, error
);
612 static int method_reload_or_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
613 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, true, error
);
616 static int method_reload_or_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
617 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, true, error
);
620 static int method_start_unit_replace(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
621 Manager
*m
= userdata
;
622 const char *old_name
;
629 r
= sd_bus_message_read(message
, "s", &old_name
);
633 u
= manager_get_unit(m
, old_name
);
634 if (!u
|| !u
->job
|| u
->job
->type
!= JOB_START
)
635 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "No job queued for unit %s", old_name
);
637 return method_start_unit_generic(message
, m
, JOB_START
, false, error
);
640 static int method_kill_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
641 Manager
*m
= userdata
;
649 r
= sd_bus_message_read(message
, "s", &name
);
653 u
= manager_get_unit(m
, name
);
655 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not loaded.", name
);
657 return bus_unit_method_kill(message
, u
, error
);
660 static int method_reset_failed_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
661 Manager
*m
= userdata
;
669 r
= sd_bus_message_read(message
, "s", &name
);
673 u
= manager_get_unit(m
, name
);
675 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not loaded.", name
);
677 return bus_unit_method_reset_failed(message
, u
, error
);
680 static int method_set_unit_properties(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
681 Manager
*m
= userdata
;
689 r
= sd_bus_message_read(message
, "s", &name
);
693 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
697 r
= bus_unit_check_load_state(u
, error
);
701 return bus_unit_method_set_properties(message
, u
, error
);
704 static int method_ref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
705 Manager
*m
= userdata
;
713 r
= sd_bus_message_read(message
, "s", &name
);
717 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
721 r
= bus_unit_check_load_state(u
, error
);
725 return bus_unit_method_ref(message
, u
, error
);
728 static int method_unref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
729 Manager
*m
= userdata
;
737 r
= sd_bus_message_read(message
, "s", &name
);
741 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
745 r
= bus_unit_check_load_state(u
, error
);
749 return bus_unit_method_unref(message
, u
, error
);
752 static int reply_unit_info(sd_bus_message
*reply
, Unit
*u
) {
753 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
756 following
= unit_following(u
);
758 unit_path
= unit_dbus_path(u
);
763 job_path
= job_dbus_path(u
->job
);
768 return sd_bus_message_append(
769 reply
, "(ssssssouso)",
772 unit_load_state_to_string(u
->load_state
),
773 unit_active_state_to_string(unit_active_state(u
)),
774 unit_sub_state_to_string(u
),
775 following
? following
->id
: "",
777 u
->job
? u
->job
->id
: 0,
778 u
->job
? job_type_to_string(u
->job
->type
) : "",
779 job_path
? job_path
: "/");
782 static int method_list_units_by_names(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
783 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
784 Manager
*m
= userdata
;
787 _cleanup_strv_free_
char **units
= NULL
;
792 r
= sd_bus_message_read_strv(message
, &units
);
796 r
= sd_bus_message_new_method_return(message
, &reply
);
800 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
804 STRV_FOREACH(unit
, units
) {
807 if (!unit_name_is_valid(*unit
, UNIT_NAME_ANY
))
810 r
= manager_load_unit(m
, *unit
, NULL
, error
, &u
);
814 r
= reply_unit_info(reply
, u
);
819 r
= sd_bus_message_close_container(reply
);
823 return sd_bus_send(NULL
, reply
, NULL
);
826 static int method_get_unit_processes(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
827 Manager
*m
= userdata
;
835 r
= sd_bus_message_read(message
, "s", &name
);
839 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
843 r
= bus_unit_check_load_state(u
, error
);
847 return bus_unit_method_get_processes(message
, u
, error
);
850 static int transient_unit_from_message(
852 sd_bus_message
*message
,
855 sd_bus_error
*error
) {
865 t
= unit_name_to_type(name
);
867 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid unit name or type.");
869 if (!unit_vtable
[t
]->can_transient
)
870 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unit type %s does not support transient units.", unit_type_to_string(t
));
872 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
876 if (!unit_is_pristine(u
))
877 return sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
, "Unit %s already exists.", name
);
879 /* OK, the unit failed to load and is unreferenced, now let's
880 * fill in the transient data instead */
881 r
= unit_make_transient(u
);
885 /* Set our properties */
886 r
= bus_unit_set_properties(u
, message
, UNIT_RUNTIME
, false, error
);
890 /* If the client asked for it, automatically add a reference to this unit. */
891 if (u
->bus_track_add
) {
892 r
= bus_unit_track_add_sender(u
, message
);
894 return log_error_errno(r
, "Failed to watch sender: %m");
897 /* Now load the missing bits of the unit we just created */
898 unit_add_to_load_queue(u
);
899 manager_dispatch_load_queue(m
);
906 static int transient_aux_units_from_message(
908 sd_bus_message
*message
,
909 sd_bus_error
*error
) {
916 r
= sd_bus_message_enter_container(message
, 'a', "(sa(sv))");
920 while ((r
= sd_bus_message_enter_container(message
, 'r', "sa(sv)")) > 0) {
921 const char *name
= NULL
;
924 r
= sd_bus_message_read(message
, "s", &name
);
928 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
932 r
= sd_bus_message_exit_container(message
);
939 r
= sd_bus_message_exit_container(message
);
946 static int method_start_transient_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
947 const char *name
, *smode
;
948 Manager
*m
= userdata
;
956 r
= mac_selinux_access_check(message
, "start", error
);
960 r
= sd_bus_message_read(message
, "ss", &name
, &smode
);
964 mode
= job_mode_from_string(smode
);
966 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Job mode %s is invalid.", smode
);
968 r
= bus_verify_manage_units_async(m
, message
, error
);
972 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
974 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
978 r
= transient_aux_units_from_message(m
, message
, error
);
982 /* Finally, start it */
983 return bus_unit_queue_job(message
, u
, JOB_START
, mode
, false, error
);
986 static int method_get_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
987 _cleanup_free_
char *path
= NULL
;
988 Manager
*m
= userdata
;
996 /* Anyone can call this method */
998 r
= sd_bus_message_read(message
, "u", &id
);
1002 j
= manager_get_job(m
, id
);
1004 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
1006 r
= mac_selinux_unit_access_check(j
->unit
, message
, "status", error
);
1010 path
= job_dbus_path(j
);
1014 return sd_bus_reply_method_return(message
, "o", path
);
1017 static int method_cancel_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1018 Manager
*m
= userdata
;
1026 r
= sd_bus_message_read(message
, "u", &id
);
1030 j
= manager_get_job(m
, id
);
1032 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
1034 return bus_job_method_cancel(message
, j
, error
);
1037 static int method_clear_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1038 Manager
*m
= userdata
;
1044 r
= mac_selinux_access_check(message
, "reload", error
);
1048 r
= bus_verify_manage_units_async(m
, message
, error
);
1052 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1054 manager_clear_jobs(m
);
1056 return sd_bus_reply_method_return(message
, NULL
);
1059 static int method_reset_failed(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1060 Manager
*m
= userdata
;
1066 r
= mac_selinux_access_check(message
, "reload", error
);
1070 r
= bus_verify_manage_units_async(m
, message
, error
);
1074 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1076 manager_reset_failed(m
);
1078 return sd_bus_reply_method_return(message
, NULL
);
1081 static int list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1082 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1083 Manager
*m
= userdata
;
1092 /* Anyone can call this method */
1094 r
= mac_selinux_access_check(message
, "status", error
);
1098 r
= sd_bus_message_new_method_return(message
, &reply
);
1102 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
1106 HASHMAP_FOREACH_KEY(u
, k
, m
->units
, i
) {
1110 if (!strv_isempty(states
) &&
1111 !strv_contains(states
, unit_load_state_to_string(u
->load_state
)) &&
1112 !strv_contains(states
, unit_active_state_to_string(unit_active_state(u
))) &&
1113 !strv_contains(states
, unit_sub_state_to_string(u
)))
1116 if (!strv_isempty(patterns
) &&
1117 !strv_fnmatch_or_empty(patterns
, u
->id
, FNM_NOESCAPE
))
1120 r
= reply_unit_info(reply
, u
);
1125 r
= sd_bus_message_close_container(reply
);
1129 return sd_bus_send(NULL
, reply
, NULL
);
1132 static int method_list_units(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1133 return list_units_filtered(message
, userdata
, error
, NULL
, NULL
);
1136 static int method_list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1137 _cleanup_strv_free_
char **states
= NULL
;
1140 r
= sd_bus_message_read_strv(message
, &states
);
1144 return list_units_filtered(message
, userdata
, error
, states
, NULL
);
1147 static int method_list_units_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1148 _cleanup_strv_free_
char **states
= NULL
;
1149 _cleanup_strv_free_
char **patterns
= NULL
;
1152 r
= sd_bus_message_read_strv(message
, &states
);
1156 r
= sd_bus_message_read_strv(message
, &patterns
);
1160 return list_units_filtered(message
, userdata
, error
, states
, patterns
);
1163 static int method_list_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1164 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1165 Manager
*m
= userdata
;
1173 /* Anyone can call this method */
1175 r
= mac_selinux_access_check(message
, "status", error
);
1179 r
= sd_bus_message_new_method_return(message
, &reply
);
1183 r
= sd_bus_message_open_container(reply
, 'a', "(usssoo)");
1187 HASHMAP_FOREACH(j
, m
->jobs
, i
) {
1188 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
1190 job_path
= job_dbus_path(j
);
1194 unit_path
= unit_dbus_path(j
->unit
);
1198 r
= sd_bus_message_append(
1202 job_type_to_string(j
->type
),
1203 job_state_to_string(j
->state
),
1210 r
= sd_bus_message_close_container(reply
);
1214 return sd_bus_send(NULL
, reply
, NULL
);
1217 static int method_subscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1218 Manager
*m
= userdata
;
1224 /* Anyone can call this method */
1226 r
= mac_selinux_access_check(message
, "status", error
);
1230 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1232 /* Note that direct bus connection subscribe by
1233 * default, we only track peers on the API bus here */
1235 if (!m
->subscribed
) {
1236 r
= sd_bus_track_new(sd_bus_message_get_bus(message
), &m
->subscribed
, NULL
, NULL
);
1241 r
= sd_bus_track_add_sender(m
->subscribed
, message
);
1245 return sd_bus_error_setf(error
, BUS_ERROR_ALREADY_SUBSCRIBED
, "Client is already subscribed.");
1248 return sd_bus_reply_method_return(message
, NULL
);
1251 static int method_unsubscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1252 Manager
*m
= userdata
;
1258 /* Anyone can call this method */
1260 r
= mac_selinux_access_check(message
, "status", error
);
1264 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1265 r
= sd_bus_track_remove_sender(m
->subscribed
, message
);
1269 return sd_bus_error_setf(error
, BUS_ERROR_NOT_SUBSCRIBED
, "Client is not subscribed.");
1272 return sd_bus_reply_method_return(message
, NULL
);
1275 static int method_dump(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1276 _cleanup_free_
char *dump
= NULL
;
1277 _cleanup_fclose_
FILE *f
= NULL
;
1278 Manager
*m
= userdata
;
1285 /* Anyone can call this method */
1287 r
= mac_selinux_access_check(message
, "status", error
);
1291 f
= open_memstream(&dump
, &size
);
1295 manager_dump_units(m
, f
, NULL
);
1296 manager_dump_jobs(m
, f
, NULL
);
1298 r
= fflush_and_check(f
);
1302 return sd_bus_reply_method_return(message
, "s", dump
);
1305 static int method_refuse_snapshot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1306 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Support for snapshots has been removed.");
1309 static int method_reload(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1310 Manager
*m
= userdata
;
1316 r
= mac_selinux_access_check(message
, "reload", error
);
1320 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1324 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1326 /* Instead of sending the reply back right away, we just
1327 * remember that we need to and then send it after the reload
1328 * is finished. That way the caller knows when the reload
1331 assert(!m
->queued_message
);
1332 r
= sd_bus_message_new_method_return(message
, &m
->queued_message
);
1336 m
->exit_code
= MANAGER_RELOAD
;
1341 static int method_reexecute(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1342 Manager
*m
= userdata
;
1348 r
= mac_selinux_access_check(message
, "reload", error
);
1352 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1356 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1358 /* We don't send a reply back here, the client should
1359 * just wait for us disconnecting. */
1361 m
->exit_code
= MANAGER_REEXECUTE
;
1365 static int method_exit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1366 Manager
*m
= userdata
;
1372 r
= mac_selinux_access_check(message
, "halt", error
);
1376 /* Exit() (in contrast to SetExitCode()) is actually allowed even if
1377 * we are running on the host. It will fall back on reboot() in
1378 * systemd-shutdown if it cannot do the exit() because it isn't a
1381 m
->exit_code
= MANAGER_EXIT
;
1383 return sd_bus_reply_method_return(message
, NULL
);
1386 static int method_reboot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1387 Manager
*m
= userdata
;
1393 r
= mac_selinux_access_check(message
, "reboot", error
);
1397 if (!MANAGER_IS_SYSTEM(m
))
1398 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Reboot is only supported for system managers.");
1400 m
->exit_code
= MANAGER_REBOOT
;
1402 return sd_bus_reply_method_return(message
, NULL
);
1405 static int method_poweroff(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1406 Manager
*m
= userdata
;
1412 r
= mac_selinux_access_check(message
, "halt", error
);
1416 if (!MANAGER_IS_SYSTEM(m
))
1417 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Powering off is only supported for system managers.");
1419 m
->exit_code
= MANAGER_POWEROFF
;
1421 return sd_bus_reply_method_return(message
, NULL
);
1424 static int method_halt(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1425 Manager
*m
= userdata
;
1431 r
= mac_selinux_access_check(message
, "halt", error
);
1435 if (!MANAGER_IS_SYSTEM(m
))
1436 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Halt is only supported for system managers.");
1438 m
->exit_code
= MANAGER_HALT
;
1440 return sd_bus_reply_method_return(message
, NULL
);
1443 static int method_kexec(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1444 Manager
*m
= userdata
;
1450 r
= mac_selinux_access_check(message
, "reboot", error
);
1454 if (!MANAGER_IS_SYSTEM(m
))
1455 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "KExec is only supported for system managers.");
1457 m
->exit_code
= MANAGER_KEXEC
;
1459 return sd_bus_reply_method_return(message
, NULL
);
1462 static int method_switch_root(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1463 char *ri
= NULL
, *rt
= NULL
;
1464 const char *root
, *init
;
1465 Manager
*m
= userdata
;
1471 r
= mac_selinux_access_check(message
, "reboot", error
);
1475 if (!MANAGER_IS_SYSTEM(m
))
1476 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Root switching is only supported by system manager.");
1478 r
= sd_bus_message_read(message
, "ss", &root
, &init
);
1482 if (path_equal(root
, "/") || !path_is_absolute(root
))
1483 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid switch root path %s", root
);
1486 if (isempty(init
)) {
1487 if (!path_is_os_tree(root
))
1488 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
);
1490 _cleanup_free_
char *p
= NULL
;
1492 if (!path_is_absolute(init
))
1493 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid init path %s", init
);
1495 p
= strappend(root
, init
);
1499 if (access(p
, X_OK
) < 0)
1500 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Specified init binary %s does not exist.", p
);
1507 if (!isempty(init
)) {
1515 free(m
->switch_root
);
1516 m
->switch_root
= rt
;
1518 free(m
->switch_root_init
);
1519 m
->switch_root_init
= ri
;
1521 m
->exit_code
= MANAGER_SWITCH_ROOT
;
1523 return sd_bus_reply_method_return(message
, NULL
);
1526 static int method_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1527 _cleanup_strv_free_
char **plus
= NULL
;
1528 Manager
*m
= userdata
;
1534 r
= mac_selinux_access_check(message
, "reload", error
);
1538 r
= sd_bus_message_read_strv(message
, &plus
);
1541 if (!strv_env_is_valid(plus
))
1542 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1544 r
= bus_verify_set_environment_async(m
, message
, error
);
1548 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1550 r
= manager_environment_add(m
, NULL
, plus
);
1554 return sd_bus_reply_method_return(message
, NULL
);
1557 static int method_unset_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1558 _cleanup_strv_free_
char **minus
= NULL
;
1559 Manager
*m
= userdata
;
1565 r
= mac_selinux_access_check(message
, "reload", error
);
1569 r
= sd_bus_message_read_strv(message
, &minus
);
1573 if (!strv_env_name_or_assignment_is_valid(minus
))
1574 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1576 r
= bus_verify_set_environment_async(m
, message
, error
);
1580 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1582 r
= manager_environment_add(m
, minus
, NULL
);
1586 return sd_bus_reply_method_return(message
, NULL
);
1589 static int method_unset_and_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1590 _cleanup_strv_free_
char **minus
= NULL
, **plus
= NULL
;
1591 Manager
*m
= userdata
;
1597 r
= mac_selinux_access_check(message
, "reload", error
);
1601 r
= sd_bus_message_read_strv(message
, &minus
);
1605 r
= sd_bus_message_read_strv(message
, &plus
);
1609 if (!strv_env_name_or_assignment_is_valid(minus
))
1610 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1611 if (!strv_env_is_valid(plus
))
1612 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1614 r
= bus_verify_set_environment_async(m
, message
, error
);
1618 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1620 r
= manager_environment_add(m
, minus
, plus
);
1624 return sd_bus_reply_method_return(message
, NULL
);
1627 static int method_set_exit_code(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1628 Manager
*m
= userdata
;
1635 r
= mac_selinux_access_check(message
, "exit", error
);
1639 r
= sd_bus_message_read_basic(message
, 'y', &code
);
1643 if (MANAGER_IS_SYSTEM(m
) && detect_container() <= 0)
1644 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "ExitCode can only be set for user service managers or in containers.");
1646 m
->return_value
= code
;
1648 return sd_bus_reply_method_return(message
, NULL
);
1651 static int method_lookup_dynamic_user_by_name(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1652 Manager
*m
= userdata
;
1660 r
= sd_bus_message_read_basic(message
, 's', &name
);
1664 if (!MANAGER_IS_SYSTEM(m
))
1665 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1666 if (!valid_user_group_name(name
))
1667 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User name invalid: %s", name
);
1669 r
= dynamic_user_lookup_name(m
, name
, &uid
);
1671 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user %s does not exist.", name
);
1675 return sd_bus_reply_method_return(message
, "u", (uint32_t) uid
);
1678 static int method_lookup_dynamic_user_by_uid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1679 _cleanup_free_
char *name
= NULL
;
1680 Manager
*m
= userdata
;
1687 assert_cc(sizeof(uid
) == sizeof(uint32_t));
1688 r
= sd_bus_message_read_basic(message
, 'u', &uid
);
1692 if (!MANAGER_IS_SYSTEM(m
))
1693 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1694 if (!uid_is_valid(uid
))
1695 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User ID invalid: " UID_FMT
, uid
);
1697 r
= dynamic_user_lookup_uid(m
, uid
, &name
);
1699 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user ID " UID_FMT
" does not exist.", uid
);
1703 return sd_bus_reply_method_return(message
, "s", name
);
1706 static int list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1707 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1708 Manager
*m
= userdata
;
1717 /* Anyone can call this method */
1719 r
= mac_selinux_access_check(message
, "status", error
);
1723 r
= sd_bus_message_new_method_return(message
, &reply
);
1727 h
= hashmap_new(&string_hash_ops
);
1731 r
= unit_file_get_list(m
->unit_file_scope
, NULL
, h
, states
, patterns
);
1735 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1739 HASHMAP_FOREACH(item
, h
, i
) {
1741 r
= sd_bus_message_append(reply
, "(ss)", item
->path
, unit_file_state_to_string(item
->state
));
1746 unit_file_list_free(h
);
1748 r
= sd_bus_message_close_container(reply
);
1752 return sd_bus_send(NULL
, reply
, NULL
);
1755 unit_file_list_free(h
);
1759 static int method_list_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1760 return list_unit_files_by_patterns(message
, userdata
, error
, NULL
, NULL
);
1763 static int method_list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1764 _cleanup_strv_free_
char **states
= NULL
;
1765 _cleanup_strv_free_
char **patterns
= NULL
;
1768 r
= sd_bus_message_read_strv(message
, &states
);
1772 r
= sd_bus_message_read_strv(message
, &patterns
);
1776 return list_unit_files_by_patterns(message
, userdata
, error
, states
, patterns
);
1779 static int method_get_unit_file_state(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1780 Manager
*m
= userdata
;
1782 UnitFileState state
;
1788 /* Anyone can call this method */
1790 r
= mac_selinux_access_check(message
, "status", error
);
1794 r
= sd_bus_message_read(message
, "s", &name
);
1798 r
= unit_file_get_state(m
->unit_file_scope
, NULL
, name
, &state
);
1802 return sd_bus_reply_method_return(message
, "s", unit_file_state_to_string(state
));
1805 static int method_get_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1806 _cleanup_free_
char *default_target
= NULL
;
1807 Manager
*m
= userdata
;
1813 /* Anyone can call this method */
1815 r
= mac_selinux_access_check(message
, "status", error
);
1819 r
= unit_file_get_default(m
->unit_file_scope
, NULL
, &default_target
);
1823 return sd_bus_reply_method_return(message
, "s", default_target
);
1826 static int send_unit_files_changed(sd_bus
*bus
, void *userdata
) {
1827 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
1832 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
1836 return sd_bus_send(bus
, message
, NULL
);
1839 static int reply_unit_file_changes_and_free(
1841 sd_bus_message
*message
,
1842 int carries_install_info
,
1843 UnitFileChange
*changes
,
1844 unsigned n_changes
) {
1846 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1850 if (unit_file_changes_have_modification(changes
, n_changes
)) {
1851 r
= bus_foreach_bus(m
, NULL
, send_unit_files_changed
, NULL
);
1853 log_debug_errno(r
, "Failed to send UnitFilesChanged signal: %m");
1856 r
= sd_bus_message_new_method_return(message
, &reply
);
1860 if (carries_install_info
>= 0) {
1861 r
= sd_bus_message_append(reply
, "b", carries_install_info
);
1866 r
= sd_bus_message_open_container(reply
, 'a', "(sss)");
1870 for (i
= 0; i
< n_changes
; i
++)
1871 if (changes
[i
].type
>= 0) {
1872 const char *change
= unit_file_change_type_to_string(changes
[i
].type
);
1873 assert(change
!= NULL
);
1875 r
= sd_bus_message_append(
1884 r
= sd_bus_message_close_container(reply
);
1888 unit_file_changes_free(changes
, n_changes
);
1889 return sd_bus_send(NULL
, reply
, NULL
);
1892 unit_file_changes_free(changes
, n_changes
);
1896 /* Create an error reply, using the error information from changes[]
1897 * if possible, and fall back to generating an error from error code c.
1898 * The error message only describes the first error.
1900 * Coordinate with unit_file_dump_changes() in install.c.
1902 static int install_error(
1903 sd_bus_error
*error
,
1905 UnitFileChange
*changes
,
1906 unsigned n_changes
) {
1911 for (i
= 0; i
< n_changes
; i
++)
1912 switch(changes
[i
].type
) {
1916 if (changes
[i
].source
)
1917 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1918 "File %s already exists and is a symlink to %s.",
1919 changes
[i
].path
, changes
[i
].source
);
1921 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1922 "File %s already exists.",
1926 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_MASKED
,
1927 "Unit file %s is masked.", changes
[i
].path
);
1929 case -EADDRNOTAVAIL
:
1930 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_GENERATED
,
1931 "Unit %s is transient or generated.", changes
[i
].path
);
1934 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_LINKED
,
1935 "Refusing to operate on linked unit file %s", changes
[i
].path
);
1938 r
= sd_bus_error_set_errnof(error
, changes
[i
].type
, "File %s: %m", changes
[i
].path
);
1944 unit_file_changes_free(changes
, n_changes
);
1948 static int method_enable_unit_files_generic(
1949 sd_bus_message
*message
,
1951 int (*call
)(UnitFileScope scope
, bool runtime
, const char *root_dir
, char *files
[], bool force
, UnitFileChange
**changes
, unsigned *n_changes
),
1952 bool carries_install_info
,
1953 sd_bus_error
*error
) {
1955 _cleanup_strv_free_
char **l
= NULL
;
1956 UnitFileChange
*changes
= NULL
;
1957 unsigned n_changes
= 0;
1958 int runtime
, force
, r
;
1963 r
= sd_bus_message_read_strv(message
, &l
);
1967 r
= sd_bus_message_read(message
, "bb", &runtime
, &force
);
1971 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
1975 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1977 r
= call(m
->unit_file_scope
, runtime
, NULL
, l
, force
, &changes
, &n_changes
);
1979 return install_error(error
, r
, changes
, n_changes
);
1981 return reply_unit_file_changes_and_free(m
, message
, carries_install_info
? r
: -1, changes
, n_changes
);
1984 static int method_enable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1985 return method_enable_unit_files_generic(message
, userdata
, unit_file_enable
, true, error
);
1988 static int method_reenable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1989 return method_enable_unit_files_generic(message
, userdata
, unit_file_reenable
, true, error
);
1992 static int method_link_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1993 return method_enable_unit_files_generic(message
, userdata
, unit_file_link
, false, error
);
1996 static int unit_file_preset_without_mode(UnitFileScope scope
, bool runtime
, const char *root_dir
, char **files
, bool force
, UnitFileChange
**changes
, unsigned *n_changes
) {
1997 return unit_file_preset(scope
, runtime
, root_dir
, files
, UNIT_FILE_PRESET_FULL
, force
, changes
, n_changes
);
2000 static int method_preset_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2001 return method_enable_unit_files_generic(message
, userdata
, unit_file_preset_without_mode
, true, error
);
2004 static int method_mask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2005 return method_enable_unit_files_generic(message
, userdata
, unit_file_mask
, false, error
);
2008 static int method_preset_unit_files_with_mode(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2010 _cleanup_strv_free_
char **l
= NULL
;
2011 UnitFileChange
*changes
= NULL
;
2012 unsigned n_changes
= 0;
2013 Manager
*m
= userdata
;
2014 UnitFilePresetMode mm
;
2015 int runtime
, force
, r
;
2021 r
= sd_bus_message_read_strv(message
, &l
);
2025 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2030 mm
= UNIT_FILE_PRESET_FULL
;
2032 mm
= unit_file_preset_mode_from_string(mode
);
2037 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2041 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2043 r
= unit_file_preset(m
->unit_file_scope
, runtime
, NULL
, l
, mm
, force
, &changes
, &n_changes
);
2045 return install_error(error
, r
, changes
, n_changes
);
2047 return reply_unit_file_changes_and_free(m
, message
, r
, changes
, n_changes
);
2050 static int method_disable_unit_files_generic(
2051 sd_bus_message
*message
,
2053 int (*call
)(UnitFileScope scope
, bool runtime
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, unsigned *n_changes
),
2054 sd_bus_error
*error
) {
2056 _cleanup_strv_free_
char **l
= NULL
;
2057 UnitFileChange
*changes
= NULL
;
2058 unsigned n_changes
= 0;
2064 r
= sd_bus_message_read_strv(message
, &l
);
2068 r
= sd_bus_message_read(message
, "b", &runtime
);
2072 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2076 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2078 r
= call(m
->unit_file_scope
, runtime
, NULL
, l
, &changes
, &n_changes
);
2080 return install_error(error
, r
, changes
, n_changes
);
2082 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
);
2085 static int method_disable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2086 return method_disable_unit_files_generic(message
, userdata
, unit_file_disable
, error
);
2089 static int method_unmask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2090 return method_disable_unit_files_generic(message
, userdata
, unit_file_unmask
, error
);
2093 static int method_revert_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2094 _cleanup_strv_free_
char **l
= NULL
;
2095 UnitFileChange
*changes
= NULL
;
2096 unsigned n_changes
= 0;
2097 Manager
*m
= userdata
;
2103 r
= sd_bus_message_read_strv(message
, &l
);
2107 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2111 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2113 r
= unit_file_revert(m
->unit_file_scope
, NULL
, l
, &changes
, &n_changes
);
2115 return install_error(error
, r
, changes
, n_changes
);
2117 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
);
2120 static int method_set_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2121 UnitFileChange
*changes
= NULL
;
2122 unsigned n_changes
= 0;
2123 Manager
*m
= userdata
;
2130 r
= mac_selinux_access_check(message
, "enable", error
);
2134 r
= sd_bus_message_read(message
, "sb", &name
, &force
);
2138 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2142 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2144 r
= unit_file_set_default(m
->unit_file_scope
, NULL
, name
, force
, &changes
, &n_changes
);
2146 return install_error(error
, r
, changes
, n_changes
);
2148 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
);
2151 static int method_preset_all_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2152 UnitFileChange
*changes
= NULL
;
2153 unsigned n_changes
= 0;
2154 Manager
*m
= userdata
;
2155 UnitFilePresetMode mm
;
2157 int force
, runtime
, r
;
2162 r
= mac_selinux_access_check(message
, "enable", error
);
2166 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2171 mm
= UNIT_FILE_PRESET_FULL
;
2173 mm
= unit_file_preset_mode_from_string(mode
);
2178 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2182 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2184 r
= unit_file_preset_all(m
->unit_file_scope
, runtime
, NULL
, mm
, force
, &changes
, &n_changes
);
2186 return install_error(error
, r
, changes
, n_changes
);
2188 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
);
2191 static int method_add_dependency_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2192 _cleanup_strv_free_
char **l
= NULL
;
2193 Manager
*m
= userdata
;
2194 UnitFileChange
*changes
= NULL
;
2195 unsigned n_changes
= 0;
2196 int runtime
, force
, r
;
2197 char *target
, *type
;
2203 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2207 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2209 r
= sd_bus_message_read_strv(message
, &l
);
2213 r
= sd_bus_message_read(message
, "ssbb", &target
, &type
, &runtime
, &force
);
2217 dep
= unit_dependency_from_string(type
);
2221 r
= unit_file_add_dependency(m
->unit_file_scope
, runtime
, NULL
, l
, target
, dep
, force
, &changes
, &n_changes
);
2223 return install_error(error
, r
, changes
, n_changes
);
2225 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
);
2228 const sd_bus_vtable bus_manager_vtable
[] = {
2229 SD_BUS_VTABLE_START(0),
2231 SD_BUS_PROPERTY("Version", "s", property_get_version
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2232 SD_BUS_PROPERTY("Features", "s", property_get_features
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2233 SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2234 SD_BUS_PROPERTY("Architecture", "s", property_get_architecture
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2235 SD_BUS_PROPERTY("Tainted", "s", property_get_tainted
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2236 BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager
, firmware_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2237 BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager
, loader_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2238 BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager
, kernel_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2239 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager
, initrd_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2240 BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager
, userspace_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2241 BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager
, finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2242 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager
, security_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2243 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager
, security_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2244 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager
, generators_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2245 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager
, generators_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2246 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager
, units_load_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2247 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager
, units_load_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2248 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level
, property_set_log_level
, 0, 0),
2249 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target
, property_set_log_target
, 0, 0),
2250 SD_BUS_PROPERTY("NNames", "u", property_get_n_names
, 0, 0),
2251 SD_BUS_PROPERTY("NFailedUnits", "u", property_get_n_failed_units
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
2252 SD_BUS_PROPERTY("NJobs", "u", property_get_n_jobs
, 0, 0),
2253 SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_installed_jobs
), 0),
2254 SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_failed_jobs
), 0),
2255 SD_BUS_PROPERTY("Progress", "d", property_get_progress
, 0, 0),
2256 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(Manager
, environment
), 0),
2257 SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool
, offsetof(Manager
, confirm_spawn
), SD_BUS_VTABLE_PROPERTY_CONST
),
2258 SD_BUS_PROPERTY("ShowStatus", "b", bus_property_get_bool
, offsetof(Manager
, show_status
), SD_BUS_VTABLE_PROPERTY_CONST
),
2259 SD_BUS_PROPERTY("UnitPath", "as", NULL
, offsetof(Manager
, lookup_paths
.search_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
2260 SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2261 SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2262 SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec
, property_set_runtime_watchdog
, offsetof(Manager
, runtime_watchdog
), 0),
2263 SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec
, bus_property_set_usec
, offsetof(Manager
, shutdown_watchdog
), 0),
2264 SD_BUS_PROPERTY("ControlGroup", "s", NULL
, offsetof(Manager
, cgroup_root
), 0),
2265 SD_BUS_PROPERTY("SystemState", "s", property_get_system_state
, 0, 0),
2266 SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned
, offsetof(Manager
, return_value
), 0),
2267 SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timer_accuracy_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2268 SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_start_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2269 SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_stop_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2270 SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_restart_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2271 SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
),
2272 SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
), /* obsolete alias name */
2273 SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned
, offsetof(Manager
, default_start_limit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
2274 SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_cpu_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2275 SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_blockio_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2276 SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_memory_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2277 SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_tasks_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2278 SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2279 SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2280 SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2281 SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2282 SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2283 SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2284 SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2285 SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2286 SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2287 SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2288 SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2289 SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2290 SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2291 SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2292 SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2293 SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2294 SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2295 SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2296 SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2297 SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2298 SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2299 SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2300 SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2301 SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2302 SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2303 SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2304 SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2305 SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2306 SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2307 SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2308 SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2309 SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2310 SD_BUS_PROPERTY("DefaultTasksMax", "t", NULL
, offsetof(Manager
, default_tasks_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
2311 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2313 SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2314 SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2315 SD_BUS_METHOD("GetUnitByInvocationID", "ay", "o", method_get_unit_by_invocation_id
, SD_BUS_VTABLE_UNPRIVILEGED
),
2316 SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2317 SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2318 SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace
, SD_BUS_VTABLE_UNPRIVILEGED
),
2319 SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2320 SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2321 SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2322 SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2323 SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2324 SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2325 SD_BUS_METHOD("KillUnit", "ssi", NULL
, method_kill_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2326 SD_BUS_METHOD("ResetFailedUnit", "s", NULL
, method_reset_failed_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2327 SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL
, method_set_unit_properties
, SD_BUS_VTABLE_UNPRIVILEGED
),
2328 SD_BUS_METHOD("RefUnit", "s", NULL
, method_ref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2329 SD_BUS_METHOD("UnrefUnit", "s", NULL
, method_unref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2330 SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2331 SD_BUS_METHOD("GetUnitProcesses", "s", "a(sus)", method_get_unit_processes
, SD_BUS_VTABLE_UNPRIVILEGED
),
2332 SD_BUS_METHOD("GetJob", "u", "o", method_get_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2333 SD_BUS_METHOD("CancelJob", "u", NULL
, method_cancel_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2334 SD_BUS_METHOD("ClearJobs", NULL
, NULL
, method_clear_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2335 SD_BUS_METHOD("ResetFailed", NULL
, NULL
, method_reset_failed
, SD_BUS_VTABLE_UNPRIVILEGED
),
2336 SD_BUS_METHOD("ListUnits", NULL
, "a(ssssssouso)", method_list_units
, SD_BUS_VTABLE_UNPRIVILEGED
),
2337 SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered
, SD_BUS_VTABLE_UNPRIVILEGED
),
2338 SD_BUS_METHOD("ListUnitsByPatterns", "asas", "a(ssssssouso)", method_list_units_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2339 SD_BUS_METHOD("ListUnitsByNames", "as", "a(ssssssouso)", method_list_units_by_names
, SD_BUS_VTABLE_UNPRIVILEGED
),
2340 SD_BUS_METHOD("ListJobs", NULL
, "a(usssoo)", method_list_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2341 SD_BUS_METHOD("Subscribe", NULL
, NULL
, method_subscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2342 SD_BUS_METHOD("Unsubscribe", NULL
, NULL
, method_unsubscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2343 SD_BUS_METHOD("Dump", NULL
, "s", method_dump
, SD_BUS_VTABLE_UNPRIVILEGED
),
2344 SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
),
2345 SD_BUS_METHOD("RemoveSnapshot", "s", NULL
, method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
),
2346 SD_BUS_METHOD("Reload", NULL
, NULL
, method_reload
, SD_BUS_VTABLE_UNPRIVILEGED
),
2347 SD_BUS_METHOD("Reexecute", NULL
, NULL
, method_reexecute
, SD_BUS_VTABLE_UNPRIVILEGED
),
2348 SD_BUS_METHOD("Exit", NULL
, NULL
, method_exit
, 0),
2349 SD_BUS_METHOD("Reboot", NULL
, NULL
, method_reboot
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2350 SD_BUS_METHOD("PowerOff", NULL
, NULL
, method_poweroff
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2351 SD_BUS_METHOD("Halt", NULL
, NULL
, method_halt
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2352 SD_BUS_METHOD("KExec", NULL
, NULL
, method_kexec
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2353 SD_BUS_METHOD("SwitchRoot", "ss", NULL
, method_switch_root
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2354 SD_BUS_METHOD("SetEnvironment", "as", NULL
, method_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2355 SD_BUS_METHOD("UnsetEnvironment", "as", NULL
, method_unset_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2356 SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL
, method_unset_and_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2357 SD_BUS_METHOD("ListUnitFiles", NULL
, "a(ss)", method_list_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2358 SD_BUS_METHOD("ListUnitFilesByPatterns", "asas", "a(ss)", method_list_unit_files_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2359 SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state
, SD_BUS_VTABLE_UNPRIVILEGED
),
2360 SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2361 SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2362 SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2363 SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2364 SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2365 SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode
, SD_BUS_VTABLE_UNPRIVILEGED
),
2366 SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2367 SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2368 SD_BUS_METHOD("RevertUnitFiles", "as", "a(sss)", method_revert_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2369 SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2370 SD_BUS_METHOD("GetDefaultTarget", NULL
, "s", method_get_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2371 SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2372 SD_BUS_METHOD("AddDependencyUnitFiles", "asssbb", "a(sss)", method_add_dependency_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2373 SD_BUS_METHOD("SetExitCode", "y", NULL
, method_set_exit_code
, SD_BUS_VTABLE_UNPRIVILEGED
),
2374 SD_BUS_METHOD("LookupDynamicUserByName", "s", "u", method_lookup_dynamic_user_by_name
, SD_BUS_VTABLE_UNPRIVILEGED
),
2375 SD_BUS_METHOD("LookupDynamicUserByUID", "u", "s", method_lookup_dynamic_user_by_uid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2377 SD_BUS_SIGNAL("UnitNew", "so", 0),
2378 SD_BUS_SIGNAL("UnitRemoved", "so", 0),
2379 SD_BUS_SIGNAL("JobNew", "uos", 0),
2380 SD_BUS_SIGNAL("JobRemoved", "uoss", 0),
2381 SD_BUS_SIGNAL("StartupFinished", "tttttt", 0),
2382 SD_BUS_SIGNAL("UnitFilesChanged", NULL
, 0),
2383 SD_BUS_SIGNAL("Reloading", "b", 0),
2388 static int send_finished(sd_bus
*bus
, void *userdata
) {
2389 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2390 usec_t
*times
= userdata
;
2396 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
2400 r
= sd_bus_message_append(message
, "tttttt", times
[0], times
[1], times
[2], times
[3], times
[4], times
[5]);
2404 return sd_bus_send(bus
, message
, NULL
);
2407 void bus_manager_send_finished(
2409 usec_t firmware_usec
,
2413 usec_t userspace_usec
,
2414 usec_t total_usec
) {
2420 r
= bus_foreach_bus(
2433 log_debug_errno(r
, "Failed to send finished signal: %m");
2436 static int send_reloading(sd_bus
*bus
, void *userdata
) {
2437 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2442 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
2446 r
= sd_bus_message_append(message
, "b", PTR_TO_INT(userdata
));
2450 return sd_bus_send(bus
, message
, NULL
);
2453 void bus_manager_send_reloading(Manager
*m
, bool active
) {
2458 r
= bus_foreach_bus(m
, NULL
, send_reloading
, INT_TO_PTR(active
));
2460 log_debug_errno(r
, "Failed to send reloading signal: %m");
2463 static int send_changed_signal(sd_bus
*bus
, void *userdata
) {
2466 return sd_bus_emit_properties_changed_strv(bus
,
2467 "/org/freedesktop/systemd1",
2468 "org.freedesktop.systemd1.Manager",
2472 void bus_manager_send_change_signal(Manager
*m
) {
2477 r
= bus_foreach_bus(m
, NULL
, send_changed_signal
, NULL
);
2479 log_debug_errno(r
, "Failed to send manager change signal: %m");