1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2010 Lennart Poettering
8 #include <sys/statvfs.h>
11 #include "alloc-util.h"
12 #include "architecture.h"
14 #include "bus-common-errors.h"
15 #include "dbus-execute.h"
17 #include "dbus-manager.h"
18 #include "dbus-unit.h"
23 #include "format-util.h"
28 #include "parse-util.h"
29 #include "path-util.h"
30 #include "selinux-access.h"
31 #include "stat-util.h"
32 #include "string-util.h"
34 #include "syslog-util.h"
35 #include "user-util.h"
39 /* Require 16MiB free in /run/systemd for reloading/reexecing. After all we need to serialize our state there, and if
40 * we can't we'll fail badly. */
41 #define RELOAD_DISK_SPACE_MIN (UINT64_C(16) * UINT64_C(1024) * UINT64_C(1024))
43 static UnitFileFlags
unit_file_bools_to_flags(bool runtime
, bool force
) {
44 return (runtime
? UNIT_FILE_RUNTIME
: 0) |
45 (force
? UNIT_FILE_FORCE
: 0);
48 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_version
, "s", PACKAGE_VERSION
);
49 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_features
, "s", SYSTEMD_FEATURES
);
50 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_architecture
, "s", architecture_to_string(uname_architecture()));
51 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_log_target
, "s", log_target_to_string(log_get_target()));
52 static BUS_DEFINE_PROPERTY_GET2(property_get_system_state
, "s", Manager
, manager_state
, manager_state_to_string
);
53 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_timer_slack_nsec
, "t", (uint64_t) prctl(PR_GET_TIMERSLACK
));
54 static BUS_DEFINE_PROPERTY_GET_REF(property_get_hashmap_size
, "u", Hashmap
*, hashmap_size
);
55 static BUS_DEFINE_PROPERTY_GET_REF(property_get_set_size
, "u", Set
*, set_size
);
57 static int property_get_virtualization(
60 const char *interface
,
62 sd_bus_message
*reply
,
64 sd_bus_error
*error
) {
71 v
= detect_virtualization();
73 /* Make sure to return the empty string when we detect no virtualization, as that is the API.
75 * https://github.com/systemd/systemd/issues/1423
78 return sd_bus_message_append(
80 v
== VIRTUALIZATION_NONE
? NULL
: virtualization_to_string(v
));
83 static int property_get_tainted(
86 const char *interface
,
88 sd_bus_message
*reply
,
90 sd_bus_error
*error
) {
92 _cleanup_free_
char *s
= NULL
;
93 Manager
*m
= userdata
;
99 s
= manager_taint_string(m
);
103 return sd_bus_message_append(reply
, "s", s
);
106 static int property_set_log_target(
109 const char *interface
,
110 const char *property
,
111 sd_bus_message
*value
,
113 sd_bus_error
*error
) {
115 Manager
*m
= userdata
;
122 r
= sd_bus_message_read(value
, "s", &t
);
127 manager_restore_original_log_target(m
);
131 target
= log_target_from_string(t
);
133 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid log target '%s'", t
);
135 manager_override_log_target(m
, target
);
141 static int property_get_log_level(
144 const char *interface
,
145 const char *property
,
146 sd_bus_message
*reply
,
148 sd_bus_error
*error
) {
150 _cleanup_free_
char *t
= NULL
;
156 r
= log_level_to_string_alloc(log_get_max_level(), &t
);
160 return sd_bus_message_append(reply
, "s", t
);
163 static int property_set_log_level(
166 const char *interface
,
167 const char *property
,
168 sd_bus_message
*value
,
170 sd_bus_error
*error
) {
172 Manager
*m
= userdata
;
179 r
= sd_bus_message_read(value
, "s", &t
);
184 manager_restore_original_log_level(m
);
188 level
= log_level_from_string(t
);
190 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid log level '%s'", t
);
192 manager_override_log_level(m
, level
);
198 static int property_get_progress(
201 const char *interface
,
202 const char *property
,
203 sd_bus_message
*reply
,
205 sd_bus_error
*error
) {
207 Manager
*m
= userdata
;
214 if (MANAGER_IS_FINISHED(m
))
217 d
= 1.0 - ((double) hashmap_size(m
->jobs
) / (double) m
->n_installed_jobs
);
219 return sd_bus_message_append(reply
, "d", d
);
222 static int property_get_show_status(
225 const char *interface
,
226 const char *property
,
227 sd_bus_message
*reply
,
229 sd_bus_error
*error
) {
231 Manager
*m
= userdata
;
238 b
= m
->show_status
> 0;
239 return sd_bus_message_append_basic(reply
, 'b', &b
);
242 static int property_set_runtime_watchdog(
245 const char *interface
,
246 const char *property
,
247 sd_bus_message
*value
,
249 sd_bus_error
*error
) {
251 usec_t
*t
= userdata
;
257 assert_cc(sizeof(usec_t
) == sizeof(uint64_t));
259 r
= sd_bus_message_read(value
, "t", t
);
263 return watchdog_set_timeout(t
);
266 static int bus_get_unit_by_name(Manager
*m
, sd_bus_message
*message
, const char *name
, Unit
**ret_unit
, sd_bus_error
*error
) {
274 /* More or less a wrapper around manager_get_unit() that generates nice errors and has one trick up its sleeve:
275 * if the name is specified empty we use the client's unit. */
278 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
281 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
285 r
= sd_bus_creds_get_pid(creds
, &pid
);
289 u
= manager_get_unit_by_pid(m
, pid
);
291 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
293 u
= manager_get_unit(m
, name
);
295 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s not loaded.", name
);
302 static int bus_load_unit_by_name(Manager
*m
, sd_bus_message
*message
, const char *name
, Unit
**ret_unit
, sd_bus_error
*error
) {
307 /* Pretty much the same as bus_get_unit_by_name(), but we also load the unit if necessary. */
310 return bus_get_unit_by_name(m
, message
, name
, ret_unit
, error
);
312 return manager_load_unit(m
, name
, NULL
, error
, ret_unit
);
315 static int method_get_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
316 _cleanup_free_
char *path
= NULL
;
317 Manager
*m
= userdata
;
325 /* Anyone can call this method */
327 r
= sd_bus_message_read(message
, "s", &name
);
331 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
335 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
339 path
= unit_dbus_path(u
);
343 return sd_bus_reply_method_return(message
, "o", path
);
346 static int method_get_unit_by_pid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
347 _cleanup_free_
char *path
= NULL
;
348 Manager
*m
= userdata
;
356 assert_cc(sizeof(pid_t
) == sizeof(uint32_t));
358 /* Anyone can call this method */
360 r
= sd_bus_message_read(message
, "u", &pid
);
364 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PID " PID_FMT
, pid
);
367 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
369 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
373 r
= sd_bus_creds_get_pid(creds
, &pid
);
378 u
= manager_get_unit_by_pid(m
, pid
);
380 return sd_bus_error_setf(error
, BUS_ERROR_NO_UNIT_FOR_PID
, "PID "PID_FMT
" does not belong to any loaded unit.", pid
);
382 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
386 path
= unit_dbus_path(u
);
390 return sd_bus_reply_method_return(message
, "o", path
);
393 static int method_get_unit_by_invocation_id(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
394 _cleanup_free_
char *path
= NULL
;
395 Manager
*m
= userdata
;
405 /* Anyone can call this method */
407 r
= sd_bus_message_read_array(message
, 'y', &a
, &sz
);
415 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid invocation ID");
417 if (sd_id128_is_null(id
)) {
418 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
421 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
425 r
= sd_bus_creds_get_pid(creds
, &pid
);
429 u
= manager_get_unit_by_pid(m
, pid
);
431 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client " PID_FMT
" not member of any unit.", pid
);
433 u
= hashmap_get(m
->units_by_invocation_id
, &id
);
435 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
));
438 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
442 /* So here's a special trick: the bus path we return actually references the unit by its invocation ID instead
443 * of the unit name. This means it stays valid only as long as the invocation ID stays the same. */
444 path
= unit_dbus_path_invocation_id(u
);
448 return sd_bus_reply_method_return(message
, "o", path
);
451 static int method_get_unit_by_control_group(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
452 _cleanup_free_
char *path
= NULL
;
453 Manager
*m
= userdata
;
458 r
= sd_bus_message_read(message
, "s", &cgroup
);
462 u
= manager_get_unit_by_cgroup(m
, cgroup
);
464 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Control group '%s' is not valid or not managed by this instance", cgroup
);
466 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
470 path
= unit_dbus_path(u
);
474 return sd_bus_reply_method_return(message
, "o", path
);
477 static int method_load_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
478 _cleanup_free_
char *path
= NULL
;
479 Manager
*m
= userdata
;
487 /* Anyone can call this method */
489 r
= sd_bus_message_read(message
, "s", &name
);
493 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
497 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
501 path
= unit_dbus_path(u
);
505 return sd_bus_reply_method_return(message
, "o", path
);
508 static int method_start_unit_generic(sd_bus_message
*message
, Manager
*m
, JobType job_type
, bool reload_if_possible
, sd_bus_error
*error
) {
516 r
= sd_bus_message_read(message
, "s", &name
);
520 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
524 return bus_unit_method_start_generic(message
, u
, job_type
, reload_if_possible
, error
);
527 static int method_start_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
528 return method_start_unit_generic(message
, userdata
, JOB_START
, false, error
);
531 static int method_stop_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
532 return method_start_unit_generic(message
, userdata
, JOB_STOP
, false, error
);
535 static int method_reload_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
536 return method_start_unit_generic(message
, userdata
, JOB_RELOAD
, false, error
);
539 static int method_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
540 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, false, error
);
543 static int method_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
544 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, false, error
);
547 static int method_reload_or_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
548 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, true, error
);
551 static int method_reload_or_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
552 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, true, error
);
555 static int method_start_unit_replace(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
556 Manager
*m
= userdata
;
557 const char *old_name
;
564 r
= sd_bus_message_read(message
, "s", &old_name
);
568 r
= bus_get_unit_by_name(m
, message
, old_name
, &u
, error
);
571 if (!u
->job
|| u
->job
->type
!= JOB_START
)
572 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "No job queued for unit %s", old_name
);
574 return method_start_unit_generic(message
, m
, JOB_START
, false, error
);
577 static int method_kill_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
578 Manager
*m
= userdata
;
586 r
= sd_bus_message_read(message
, "s", &name
);
590 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
594 return bus_unit_method_kill(message
, u
, error
);
597 static int method_reset_failed_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
598 Manager
*m
= userdata
;
606 r
= sd_bus_message_read(message
, "s", &name
);
610 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
614 return bus_unit_method_reset_failed(message
, u
, error
);
617 static int method_set_unit_properties(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
618 Manager
*m
= userdata
;
626 r
= sd_bus_message_read(message
, "s", &name
);
630 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
634 r
= bus_unit_validate_load_state(u
, error
);
638 return bus_unit_method_set_properties(message
, u
, error
);
641 static int method_ref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
642 Manager
*m
= userdata
;
650 r
= sd_bus_message_read(message
, "s", &name
);
654 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
658 r
= bus_unit_validate_load_state(u
, error
);
662 return bus_unit_method_ref(message
, u
, error
);
665 static int method_unref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
666 Manager
*m
= userdata
;
674 r
= sd_bus_message_read(message
, "s", &name
);
678 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
682 r
= bus_unit_validate_load_state(u
, error
);
686 return bus_unit_method_unref(message
, u
, error
);
689 static int reply_unit_info(sd_bus_message
*reply
, Unit
*u
) {
690 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
693 following
= unit_following(u
);
695 unit_path
= unit_dbus_path(u
);
700 job_path
= job_dbus_path(u
->job
);
705 return sd_bus_message_append(
706 reply
, "(ssssssouso)",
709 unit_load_state_to_string(u
->load_state
),
710 unit_active_state_to_string(unit_active_state(u
)),
711 unit_sub_state_to_string(u
),
712 following
? following
->id
: "",
714 u
->job
? u
->job
->id
: 0,
715 u
->job
? job_type_to_string(u
->job
->type
) : "",
716 job_path
? job_path
: "/");
719 static int method_list_units_by_names(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
720 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
721 Manager
*m
= userdata
;
724 _cleanup_strv_free_
char **units
= NULL
;
729 r
= sd_bus_message_read_strv(message
, &units
);
733 r
= sd_bus_message_new_method_return(message
, &reply
);
737 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
741 STRV_FOREACH(unit
, units
) {
744 if (!unit_name_is_valid(*unit
, UNIT_NAME_ANY
))
747 r
= bus_load_unit_by_name(m
, message
, *unit
, &u
, error
);
751 r
= reply_unit_info(reply
, u
);
756 r
= sd_bus_message_close_container(reply
);
760 return sd_bus_send(NULL
, reply
, NULL
);
763 static int method_get_unit_processes(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
764 Manager
*m
= userdata
;
772 r
= sd_bus_message_read(message
, "s", &name
);
776 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
780 return bus_unit_method_get_processes(message
, u
, error
);
783 static int method_attach_processes_to_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
784 Manager
*m
= userdata
;
792 r
= sd_bus_message_read(message
, "s", &name
);
796 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
800 return bus_unit_method_attach_processes(message
, u
, error
);
803 static int transient_unit_from_message(
805 sd_bus_message
*message
,
808 sd_bus_error
*error
) {
818 t
= unit_name_to_type(name
);
820 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid unit name or type.");
822 if (!unit_vtable
[t
]->can_transient
)
823 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unit type %s does not support transient units.", unit_type_to_string(t
));
825 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
829 if (!unit_is_pristine(u
))
830 return sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
, "Unit %s already exists.", name
);
832 /* OK, the unit failed to load and is unreferenced, now let's
833 * fill in the transient data instead */
834 r
= unit_make_transient(u
);
838 /* Set our properties */
839 r
= bus_unit_set_properties(u
, message
, UNIT_RUNTIME
, false, error
);
843 /* If the client asked for it, automatically add a reference to this unit. */
844 if (u
->bus_track_add
) {
845 r
= bus_unit_track_add_sender(u
, message
);
847 return log_error_errno(r
, "Failed to watch sender: %m");
850 /* Now load the missing bits of the unit we just created */
851 unit_add_to_load_queue(u
);
852 manager_dispatch_load_queue(m
);
859 static int transient_aux_units_from_message(
861 sd_bus_message
*message
,
862 sd_bus_error
*error
) {
869 r
= sd_bus_message_enter_container(message
, 'a', "(sa(sv))");
873 while ((r
= sd_bus_message_enter_container(message
, 'r', "sa(sv)")) > 0) {
874 const char *name
= NULL
;
877 r
= sd_bus_message_read(message
, "s", &name
);
881 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
885 r
= sd_bus_message_exit_container(message
);
892 r
= sd_bus_message_exit_container(message
);
899 static int method_start_transient_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
900 const char *name
, *smode
;
901 Manager
*m
= userdata
;
909 r
= mac_selinux_access_check(message
, "start", error
);
913 r
= sd_bus_message_read(message
, "ss", &name
, &smode
);
917 mode
= job_mode_from_string(smode
);
919 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Job mode %s is invalid.", smode
);
921 r
= bus_verify_manage_units_async(m
, message
, error
);
925 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
927 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
931 r
= transient_aux_units_from_message(m
, message
, error
);
935 /* Finally, start it */
936 return bus_unit_queue_job(message
, u
, JOB_START
, mode
, false, error
);
939 static int method_get_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
940 _cleanup_free_
char *path
= NULL
;
941 Manager
*m
= userdata
;
949 /* Anyone can call this method */
951 r
= sd_bus_message_read(message
, "u", &id
);
955 j
= manager_get_job(m
, id
);
957 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
959 r
= mac_selinux_unit_access_check(j
->unit
, message
, "status", error
);
963 path
= job_dbus_path(j
);
967 return sd_bus_reply_method_return(message
, "o", path
);
970 static int method_cancel_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
971 Manager
*m
= userdata
;
979 r
= sd_bus_message_read(message
, "u", &id
);
983 j
= manager_get_job(m
, id
);
985 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
987 return bus_job_method_cancel(message
, j
, error
);
990 static int method_clear_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
991 Manager
*m
= userdata
;
997 r
= mac_selinux_access_check(message
, "reload", error
);
1001 r
= bus_verify_manage_units_async(m
, message
, error
);
1005 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1007 manager_clear_jobs(m
);
1009 return sd_bus_reply_method_return(message
, NULL
);
1012 static int method_reset_failed(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1013 Manager
*m
= userdata
;
1019 r
= mac_selinux_access_check(message
, "reload", error
);
1023 r
= bus_verify_manage_units_async(m
, message
, error
);
1027 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1029 manager_reset_failed(m
);
1031 return sd_bus_reply_method_return(message
, NULL
);
1034 static int list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1035 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1036 Manager
*m
= userdata
;
1045 /* Anyone can call this method */
1047 r
= mac_selinux_access_check(message
, "status", error
);
1051 r
= sd_bus_message_new_method_return(message
, &reply
);
1055 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
1059 HASHMAP_FOREACH_KEY(u
, k
, m
->units
, i
) {
1063 if (!strv_isempty(states
) &&
1064 !strv_contains(states
, unit_load_state_to_string(u
->load_state
)) &&
1065 !strv_contains(states
, unit_active_state_to_string(unit_active_state(u
))) &&
1066 !strv_contains(states
, unit_sub_state_to_string(u
)))
1069 if (!strv_isempty(patterns
) &&
1070 !strv_fnmatch_or_empty(patterns
, u
->id
, FNM_NOESCAPE
))
1073 r
= reply_unit_info(reply
, u
);
1078 r
= sd_bus_message_close_container(reply
);
1082 return sd_bus_send(NULL
, reply
, NULL
);
1085 static int method_list_units(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1086 return list_units_filtered(message
, userdata
, error
, NULL
, NULL
);
1089 static int method_list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1090 _cleanup_strv_free_
char **states
= NULL
;
1093 r
= sd_bus_message_read_strv(message
, &states
);
1097 return list_units_filtered(message
, userdata
, error
, states
, NULL
);
1100 static int method_list_units_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1101 _cleanup_strv_free_
char **states
= NULL
;
1102 _cleanup_strv_free_
char **patterns
= NULL
;
1105 r
= sd_bus_message_read_strv(message
, &states
);
1109 r
= sd_bus_message_read_strv(message
, &patterns
);
1113 return list_units_filtered(message
, userdata
, error
, states
, patterns
);
1116 static int method_list_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1117 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1118 Manager
*m
= userdata
;
1126 /* Anyone can call this method */
1128 r
= mac_selinux_access_check(message
, "status", error
);
1132 r
= sd_bus_message_new_method_return(message
, &reply
);
1136 r
= sd_bus_message_open_container(reply
, 'a', "(usssoo)");
1140 HASHMAP_FOREACH(j
, m
->jobs
, i
) {
1141 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
1143 job_path
= job_dbus_path(j
);
1147 unit_path
= unit_dbus_path(j
->unit
);
1151 r
= sd_bus_message_append(
1155 job_type_to_string(j
->type
),
1156 job_state_to_string(j
->state
),
1163 r
= sd_bus_message_close_container(reply
);
1167 return sd_bus_send(NULL
, reply
, NULL
);
1170 static int method_subscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1171 Manager
*m
= userdata
;
1177 /* Anyone can call this method */
1179 r
= mac_selinux_access_check(message
, "status", error
);
1183 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1185 /* Note that direct bus connection subscribe by
1186 * default, we only track peers on the API bus here */
1188 if (!m
->subscribed
) {
1189 r
= sd_bus_track_new(sd_bus_message_get_bus(message
), &m
->subscribed
, NULL
, NULL
);
1194 r
= sd_bus_track_add_sender(m
->subscribed
, message
);
1198 return sd_bus_error_setf(error
, BUS_ERROR_ALREADY_SUBSCRIBED
, "Client is already subscribed.");
1201 return sd_bus_reply_method_return(message
, NULL
);
1204 static int method_unsubscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1205 Manager
*m
= userdata
;
1211 /* Anyone can call this method */
1213 r
= mac_selinux_access_check(message
, "status", error
);
1217 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1218 r
= sd_bus_track_remove_sender(m
->subscribed
, message
);
1222 return sd_bus_error_setf(error
, BUS_ERROR_NOT_SUBSCRIBED
, "Client is not subscribed.");
1225 return sd_bus_reply_method_return(message
, NULL
);
1228 static int dump_impl(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, int (*reply
)(sd_bus_message
*, char *)) {
1229 _cleanup_free_
char *dump
= NULL
;
1230 Manager
*m
= userdata
;
1236 /* Anyone can call this method */
1238 r
= mac_selinux_access_check(message
, "status", error
);
1242 r
= manager_get_dump_string(m
, &dump
);
1246 return reply(message
, dump
);
1249 static int reply_dump(sd_bus_message
*message
, char *dump
) {
1250 return sd_bus_reply_method_return(message
, "s", dump
);
1253 static int method_dump(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1254 return dump_impl(message
, userdata
, error
, reply_dump
);
1257 static int reply_dump_by_fd(sd_bus_message
*message
, char *dump
) {
1258 _cleanup_close_
int fd
= -1;
1260 fd
= acquire_data_fd(dump
, strlen(dump
), 0);
1264 return sd_bus_reply_method_return(message
, "h", fd
);
1267 static int method_dump_by_fd(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1268 return dump_impl(message
, userdata
, error
, reply_dump_by_fd
);
1271 static int method_refuse_snapshot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1272 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Support for snapshots has been removed.");
1275 static int verify_run_space(const char *message
, sd_bus_error
*error
) {
1276 struct statvfs svfs
;
1279 if (statvfs("/run/systemd", &svfs
) < 0)
1280 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1282 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1284 if (available
< RELOAD_DISK_SPACE_MIN
) {
1285 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1286 return sd_bus_error_setf(error
,
1287 BUS_ERROR_DISK_FULL
,
1288 "%s, not enough space available on /run/systemd. "
1289 "Currently, %s are free, but a safety buffer of %s is enforced.",
1291 format_bytes(fb_available
, sizeof(fb_available
), available
),
1292 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1298 int verify_run_space_and_log(const char *message
) {
1299 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1302 r
= verify_run_space(message
, &error
);
1304 log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1309 static int method_reload(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1310 Manager
*m
= userdata
;
1316 r
= verify_run_space("Refusing to reload", error
);
1320 r
= mac_selinux_access_check(message
, "reload", error
);
1324 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1328 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1330 /* Instead of sending the reply back right away, we just
1331 * remember that we need to and then send it after the reload
1332 * is finished. That way the caller knows when the reload
1335 assert(!m
->queued_message
);
1336 r
= sd_bus_message_new_method_return(message
, &m
->queued_message
);
1340 m
->exit_code
= MANAGER_RELOAD
;
1345 static int method_reexecute(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1346 Manager
*m
= userdata
;
1352 r
= verify_run_space("Refusing to reexecute", error
);
1356 r
= mac_selinux_access_check(message
, "reload", error
);
1360 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1364 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1366 /* We don't send a reply back here, the client should
1367 * just wait for us disconnecting. */
1369 m
->exit_code
= MANAGER_REEXECUTE
;
1373 static int method_exit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1374 Manager
*m
= userdata
;
1380 r
= mac_selinux_access_check(message
, "halt", error
);
1384 /* Exit() (in contrast to SetExitCode()) is actually allowed even if
1385 * we are running on the host. It will fall back on reboot() in
1386 * systemd-shutdown if it cannot do the exit() because it isn't a
1389 m
->exit_code
= MANAGER_EXIT
;
1391 return sd_bus_reply_method_return(message
, NULL
);
1394 static int method_reboot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1395 Manager
*m
= userdata
;
1401 r
= mac_selinux_access_check(message
, "reboot", error
);
1405 if (!MANAGER_IS_SYSTEM(m
))
1406 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Reboot is only supported for system managers.");
1408 m
->exit_code
= MANAGER_REBOOT
;
1410 return sd_bus_reply_method_return(message
, NULL
);
1413 static int method_poweroff(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1414 Manager
*m
= userdata
;
1420 r
= mac_selinux_access_check(message
, "halt", error
);
1424 if (!MANAGER_IS_SYSTEM(m
))
1425 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Powering off is only supported for system managers.");
1427 m
->exit_code
= MANAGER_POWEROFF
;
1429 return sd_bus_reply_method_return(message
, NULL
);
1432 static int method_halt(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1433 Manager
*m
= userdata
;
1439 r
= mac_selinux_access_check(message
, "halt", error
);
1443 if (!MANAGER_IS_SYSTEM(m
))
1444 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Halt is only supported for system managers.");
1446 m
->exit_code
= MANAGER_HALT
;
1448 return sd_bus_reply_method_return(message
, NULL
);
1451 static int method_kexec(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1452 Manager
*m
= userdata
;
1458 r
= mac_selinux_access_check(message
, "reboot", error
);
1462 if (!MANAGER_IS_SYSTEM(m
))
1463 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "KExec is only supported for system managers.");
1465 m
->exit_code
= MANAGER_KEXEC
;
1467 return sd_bus_reply_method_return(message
, NULL
);
1470 static int method_switch_root(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1471 char *ri
= NULL
, *rt
= NULL
;
1472 const char *root
, *init
;
1473 Manager
*m
= userdata
;
1474 struct statvfs svfs
;
1481 if (statvfs("/run/systemd", &svfs
) < 0)
1482 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1484 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1486 if (available
< RELOAD_DISK_SPACE_MIN
) {
1487 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1488 log_warning("Dangerously low amount of free space on /run/systemd, root switching operation might not complete successfuly. "
1489 "Currently, %s are free, but %s are suggested. Proceeding anyway.",
1490 format_bytes(fb_available
, sizeof(fb_available
), available
),
1491 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1494 r
= mac_selinux_access_check(message
, "reboot", error
);
1498 if (!MANAGER_IS_SYSTEM(m
))
1499 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Root switching is only supported by system manager.");
1501 r
= sd_bus_message_read(message
, "ss", &root
, &init
);
1506 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory may not be the empty string.");
1507 if (!path_is_absolute(root
))
1508 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root path '%s' is not absolute.", root
);
1509 if (path_equal(root
, "/"))
1510 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory cannot be the old root directory.");
1513 if (isempty(init
)) {
1514 r
= path_is_os_tree(root
);
1516 return sd_bus_error_set_errnof(error
, r
, "Failed to determine whether root path '%s' contains an OS tree: %m", root
);
1518 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
);
1520 _cleanup_free_
char *chased
= NULL
;
1522 if (!path_is_absolute(init
))
1523 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path to init binary '%s' not absolute.", init
);
1525 r
= chase_symlinks(init
, root
, CHASE_PREFIX_ROOT
|CHASE_TRAIL_SLASH
, &chased
);
1527 return sd_bus_error_set_errnof(error
, r
, "Could not resolve init executable %s: %m", init
);
1529 if (laccess(chased
, X_OK
) < 0) {
1530 if (errno
== EACCES
)
1531 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Init binary %s is not executable.", init
);
1533 return sd_bus_error_set_errnof(error
, r
, "Could not check whether init binary %s is executable: %m", init
);
1541 if (!isempty(init
)) {
1549 free(m
->switch_root
);
1550 m
->switch_root
= rt
;
1552 free(m
->switch_root_init
);
1553 m
->switch_root_init
= ri
;
1555 m
->exit_code
= MANAGER_SWITCH_ROOT
;
1557 return sd_bus_reply_method_return(message
, NULL
);
1560 static int method_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1561 _cleanup_strv_free_
char **plus
= NULL
;
1562 Manager
*m
= userdata
;
1568 r
= mac_selinux_access_check(message
, "reload", error
);
1572 r
= sd_bus_message_read_strv(message
, &plus
);
1575 if (!strv_env_is_valid(plus
))
1576 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1578 r
= bus_verify_set_environment_async(m
, message
, error
);
1582 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1584 r
= manager_environment_add(m
, NULL
, plus
);
1588 return sd_bus_reply_method_return(message
, NULL
);
1591 static int method_unset_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1592 _cleanup_strv_free_
char **minus
= NULL
;
1593 Manager
*m
= userdata
;
1599 r
= mac_selinux_access_check(message
, "reload", error
);
1603 r
= sd_bus_message_read_strv(message
, &minus
);
1607 if (!strv_env_name_or_assignment_is_valid(minus
))
1608 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1610 r
= bus_verify_set_environment_async(m
, message
, error
);
1614 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1616 r
= manager_environment_add(m
, minus
, NULL
);
1620 return sd_bus_reply_method_return(message
, NULL
);
1623 static int method_unset_and_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1624 _cleanup_strv_free_
char **minus
= NULL
, **plus
= NULL
;
1625 Manager
*m
= userdata
;
1631 r
= mac_selinux_access_check(message
, "reload", error
);
1635 r
= sd_bus_message_read_strv(message
, &minus
);
1639 r
= sd_bus_message_read_strv(message
, &plus
);
1643 if (!strv_env_name_or_assignment_is_valid(minus
))
1644 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1645 if (!strv_env_is_valid(plus
))
1646 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1648 r
= bus_verify_set_environment_async(m
, message
, error
);
1652 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1654 r
= manager_environment_add(m
, minus
, plus
);
1658 return sd_bus_reply_method_return(message
, NULL
);
1661 static int method_set_exit_code(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1662 Manager
*m
= userdata
;
1669 r
= mac_selinux_access_check(message
, "exit", error
);
1673 r
= sd_bus_message_read_basic(message
, 'y', &code
);
1677 if (MANAGER_IS_SYSTEM(m
) && detect_container() <= 0)
1678 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "ExitCode can only be set for user service managers or in containers.");
1680 m
->return_value
= code
;
1682 return sd_bus_reply_method_return(message
, NULL
);
1685 static int method_lookup_dynamic_user_by_name(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1686 Manager
*m
= userdata
;
1694 r
= sd_bus_message_read_basic(message
, 's', &name
);
1698 if (!MANAGER_IS_SYSTEM(m
))
1699 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1700 if (!valid_user_group_name(name
))
1701 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User name invalid: %s", name
);
1703 r
= dynamic_user_lookup_name(m
, name
, &uid
);
1705 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user %s does not exist.", name
);
1709 return sd_bus_reply_method_return(message
, "u", (uint32_t) uid
);
1712 static int method_lookup_dynamic_user_by_uid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1713 _cleanup_free_
char *name
= NULL
;
1714 Manager
*m
= userdata
;
1721 assert_cc(sizeof(uid
) == sizeof(uint32_t));
1722 r
= sd_bus_message_read_basic(message
, 'u', &uid
);
1726 if (!MANAGER_IS_SYSTEM(m
))
1727 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1728 if (!uid_is_valid(uid
))
1729 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User ID invalid: " UID_FMT
, uid
);
1731 r
= dynamic_user_lookup_uid(m
, uid
, &name
);
1733 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user ID " UID_FMT
" does not exist.", uid
);
1737 return sd_bus_reply_method_return(message
, "s", name
);
1740 static int method_get_dynamic_users(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1741 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1742 Manager
*m
= userdata
;
1750 assert_cc(sizeof(uid_t
) == sizeof(uint32_t));
1752 if (!MANAGER_IS_SYSTEM(m
))
1753 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1755 r
= sd_bus_message_new_method_return(message
, &reply
);
1759 r
= sd_bus_message_open_container(reply
, 'a', "(us)");
1763 HASHMAP_FOREACH(d
, m
->dynamic_users
, i
) {
1766 r
= dynamic_user_current(d
, &uid
);
1767 if (r
== -EAGAIN
) /* not realized yet? */
1770 return sd_bus_error_setf(error
, SD_BUS_ERROR_FAILED
, "Failed to lookup a dynamic user.");
1772 r
= sd_bus_message_append(reply
, "(us)", uid
, d
->name
);
1777 r
= sd_bus_message_close_container(reply
);
1781 return sd_bus_send(NULL
, reply
, NULL
);
1784 static int list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1785 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1786 Manager
*m
= userdata
;
1795 /* Anyone can call this method */
1797 r
= mac_selinux_access_check(message
, "status", error
);
1801 r
= sd_bus_message_new_method_return(message
, &reply
);
1805 h
= hashmap_new(&string_hash_ops
);
1809 r
= unit_file_get_list(m
->unit_file_scope
, NULL
, h
, states
, patterns
);
1813 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1817 HASHMAP_FOREACH(item
, h
, i
) {
1819 r
= sd_bus_message_append(reply
, "(ss)", item
->path
, unit_file_state_to_string(item
->state
));
1824 unit_file_list_free(h
);
1826 r
= sd_bus_message_close_container(reply
);
1830 return sd_bus_send(NULL
, reply
, NULL
);
1833 unit_file_list_free(h
);
1837 static int method_list_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1838 return list_unit_files_by_patterns(message
, userdata
, error
, NULL
, NULL
);
1841 static int method_list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1842 _cleanup_strv_free_
char **states
= NULL
;
1843 _cleanup_strv_free_
char **patterns
= NULL
;
1846 r
= sd_bus_message_read_strv(message
, &states
);
1850 r
= sd_bus_message_read_strv(message
, &patterns
);
1854 return list_unit_files_by_patterns(message
, userdata
, error
, states
, patterns
);
1857 static int method_get_unit_file_state(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1858 Manager
*m
= userdata
;
1860 UnitFileState state
;
1866 /* Anyone can call this method */
1868 r
= mac_selinux_access_check(message
, "status", error
);
1872 r
= sd_bus_message_read(message
, "s", &name
);
1876 r
= unit_file_get_state(m
->unit_file_scope
, NULL
, name
, &state
);
1880 return sd_bus_reply_method_return(message
, "s", unit_file_state_to_string(state
));
1883 static int method_get_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1884 _cleanup_free_
char *default_target
= NULL
;
1885 Manager
*m
= userdata
;
1891 /* Anyone can call this method */
1893 r
= mac_selinux_access_check(message
, "status", error
);
1897 r
= unit_file_get_default(m
->unit_file_scope
, NULL
, &default_target
);
1901 return sd_bus_reply_method_return(message
, "s", default_target
);
1904 static int send_unit_files_changed(sd_bus
*bus
, void *userdata
) {
1905 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
1910 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
1914 return sd_bus_send(bus
, message
, NULL
);
1917 /* Create an error reply, using the error information from changes[]
1918 * if possible, and fall back to generating an error from error code c.
1919 * The error message only describes the first error.
1921 * Coordinate with unit_file_dump_changes() in install.c.
1923 static int install_error(
1924 sd_bus_error
*error
,
1926 UnitFileChange
*changes
,
1932 for (i
= 0; i
< n_changes
; i
++)
1934 switch(changes
[i
].type
) {
1940 if (changes
[i
].source
)
1941 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1942 "File %s already exists and is a symlink to %s.",
1943 changes
[i
].path
, changes
[i
].source
);
1945 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1946 "File %s already exists.",
1951 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_MASKED
,
1952 "Unit file %s is masked.", changes
[i
].path
);
1955 case -EADDRNOTAVAIL
:
1956 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_GENERATED
,
1957 "Unit %s is transient or generated.", changes
[i
].path
);
1961 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_LINKED
,
1962 "Refusing to operate on linked unit file %s", changes
[i
].path
);
1966 r
= sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit file %s does not exist.", changes
[i
].path
);
1970 r
= sd_bus_error_set_errnof(error
, changes
[i
].type
, "File %s: %m", changes
[i
].path
);
1974 r
= c
< 0 ? c
: -EINVAL
;
1977 unit_file_changes_free(changes
, n_changes
);
1981 static int reply_unit_file_changes_and_free(
1983 sd_bus_message
*message
,
1984 int carries_install_info
,
1985 UnitFileChange
*changes
,
1987 sd_bus_error
*error
) {
1989 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1990 bool bad
= false, good
= false;
1994 if (unit_file_changes_have_modification(changes
, n_changes
)) {
1995 r
= bus_foreach_bus(m
, NULL
, send_unit_files_changed
, NULL
);
1997 log_debug_errno(r
, "Failed to send UnitFilesChanged signal: %m");
2000 r
= sd_bus_message_new_method_return(message
, &reply
);
2004 if (carries_install_info
>= 0) {
2005 r
= sd_bus_message_append(reply
, "b", carries_install_info
);
2010 r
= sd_bus_message_open_container(reply
, 'a', "(sss)");
2014 for (i
= 0; i
< n_changes
; i
++) {
2016 if (changes
[i
].type
< 0) {
2021 r
= sd_bus_message_append(
2023 unit_file_change_type_to_string(changes
[i
].type
),
2032 /* If there was a failed change, and no successful change, then return the first failure as proper method call
2035 return install_error(error
, 0, changes
, n_changes
);
2037 r
= sd_bus_message_close_container(reply
);
2041 unit_file_changes_free(changes
, n_changes
);
2042 return sd_bus_send(NULL
, reply
, NULL
);
2045 unit_file_changes_free(changes
, n_changes
);
2049 static int method_enable_unit_files_generic(
2050 sd_bus_message
*message
,
2052 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, size_t *n_changes
),
2053 bool carries_install_info
,
2054 sd_bus_error
*error
) {
2056 _cleanup_strv_free_
char **l
= NULL
;
2057 UnitFileChange
*changes
= NULL
;
2058 size_t n_changes
= 0;
2059 UnitFileFlags flags
;
2060 int runtime
, force
, r
;
2065 r
= sd_bus_message_read_strv(message
, &l
);
2069 r
= sd_bus_message_read(message
, "bb", &runtime
, &force
);
2073 flags
= unit_file_bools_to_flags(runtime
, force
);
2075 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2079 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2081 r
= call(m
->unit_file_scope
, flags
, NULL
, l
, &changes
, &n_changes
);
2083 return install_error(error
, r
, changes
, n_changes
);
2085 return reply_unit_file_changes_and_free(m
, message
, carries_install_info
? r
: -1, changes
, n_changes
, error
);
2088 static int method_enable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2089 return method_enable_unit_files_generic(message
, userdata
, unit_file_enable
, true, error
);
2092 static int method_reenable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2093 return method_enable_unit_files_generic(message
, userdata
, unit_file_reenable
, true, error
);
2096 static int method_link_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2097 return method_enable_unit_files_generic(message
, userdata
, unit_file_link
, false, error
);
2100 static int unit_file_preset_without_mode(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char **files
, UnitFileChange
**changes
, size_t *n_changes
) {
2101 return unit_file_preset(scope
, flags
, root_dir
, files
, UNIT_FILE_PRESET_FULL
, changes
, n_changes
);
2104 static int method_preset_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2105 return method_enable_unit_files_generic(message
, userdata
, unit_file_preset_without_mode
, true, error
);
2108 static int method_mask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2109 return method_enable_unit_files_generic(message
, userdata
, unit_file_mask
, false, error
);
2112 static int method_preset_unit_files_with_mode(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2114 _cleanup_strv_free_
char **l
= NULL
;
2115 UnitFileChange
*changes
= NULL
;
2116 size_t n_changes
= 0;
2117 Manager
*m
= userdata
;
2118 UnitFilePresetMode mm
;
2119 int runtime
, force
, r
;
2120 UnitFileFlags flags
;
2126 r
= sd_bus_message_read_strv(message
, &l
);
2130 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2134 flags
= unit_file_bools_to_flags(runtime
, force
);
2137 mm
= UNIT_FILE_PRESET_FULL
;
2139 mm
= unit_file_preset_mode_from_string(mode
);
2144 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2148 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2150 r
= unit_file_preset(m
->unit_file_scope
, flags
, NULL
, l
, mm
, &changes
, &n_changes
);
2152 return install_error(error
, r
, changes
, n_changes
);
2154 return reply_unit_file_changes_and_free(m
, message
, r
, changes
, n_changes
, error
);
2157 static int method_disable_unit_files_generic(
2158 sd_bus_message
*message
,
2160 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, size_t *n_changes
),
2161 sd_bus_error
*error
) {
2163 _cleanup_strv_free_
char **l
= NULL
;
2164 UnitFileChange
*changes
= NULL
;
2165 size_t n_changes
= 0;
2171 r
= sd_bus_message_read_strv(message
, &l
);
2175 r
= sd_bus_message_read(message
, "b", &runtime
);
2179 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2183 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2185 r
= call(m
->unit_file_scope
, runtime
? UNIT_FILE_RUNTIME
: 0, NULL
, l
, &changes
, &n_changes
);
2187 return install_error(error
, r
, changes
, n_changes
);
2189 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2192 static int method_disable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2193 return method_disable_unit_files_generic(message
, userdata
, unit_file_disable
, error
);
2196 static int method_unmask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2197 return method_disable_unit_files_generic(message
, userdata
, unit_file_unmask
, error
);
2200 static int method_revert_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2201 _cleanup_strv_free_
char **l
= NULL
;
2202 UnitFileChange
*changes
= NULL
;
2203 size_t n_changes
= 0;
2204 Manager
*m
= userdata
;
2210 r
= sd_bus_message_read_strv(message
, &l
);
2214 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2218 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2220 r
= unit_file_revert(m
->unit_file_scope
, NULL
, l
, &changes
, &n_changes
);
2222 return install_error(error
, r
, changes
, n_changes
);
2224 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2227 static int method_set_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2228 UnitFileChange
*changes
= NULL
;
2229 size_t n_changes
= 0;
2230 Manager
*m
= userdata
;
2237 r
= mac_selinux_access_check(message
, "enable", error
);
2241 r
= sd_bus_message_read(message
, "sb", &name
, &force
);
2245 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2249 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2251 r
= unit_file_set_default(m
->unit_file_scope
, force
? UNIT_FILE_FORCE
: 0, NULL
, name
, &changes
, &n_changes
);
2253 return install_error(error
, r
, changes
, n_changes
);
2255 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2258 static int method_preset_all_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2259 UnitFileChange
*changes
= NULL
;
2260 size_t n_changes
= 0;
2261 Manager
*m
= userdata
;
2262 UnitFilePresetMode mm
;
2264 UnitFileFlags flags
;
2265 int force
, runtime
, r
;
2270 r
= mac_selinux_access_check(message
, "enable", error
);
2274 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2278 flags
= unit_file_bools_to_flags(runtime
, force
);
2281 mm
= UNIT_FILE_PRESET_FULL
;
2283 mm
= unit_file_preset_mode_from_string(mode
);
2288 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2292 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2294 r
= unit_file_preset_all(m
->unit_file_scope
, flags
, NULL
, mm
, &changes
, &n_changes
);
2296 return install_error(error
, r
, changes
, n_changes
);
2298 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2301 static int method_add_dependency_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2302 _cleanup_strv_free_
char **l
= NULL
;
2303 Manager
*m
= userdata
;
2304 UnitFileChange
*changes
= NULL
;
2305 size_t n_changes
= 0;
2306 int runtime
, force
, r
;
2307 char *target
, *type
;
2309 UnitFileFlags flags
;
2314 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2318 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2320 r
= sd_bus_message_read_strv(message
, &l
);
2324 r
= sd_bus_message_read(message
, "ssbb", &target
, &type
, &runtime
, &force
);
2328 flags
= unit_file_bools_to_flags(runtime
, force
);
2330 dep
= unit_dependency_from_string(type
);
2334 r
= unit_file_add_dependency(m
->unit_file_scope
, flags
, NULL
, l
, target
, dep
, &changes
, &n_changes
);
2336 return install_error(error
, r
, changes
, n_changes
);
2338 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2341 static int method_get_unit_file_links(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2342 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
2343 UnitFileChange
*changes
= NULL
;
2344 size_t n_changes
= 0, i
;
2345 UnitFileFlags flags
;
2350 r
= sd_bus_message_read(message
, "sb", &name
, &runtime
);
2354 r
= sd_bus_message_new_method_return(message
, &reply
);
2358 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_ARRAY
, "s");
2362 p
= STRV_MAKE(name
);
2363 flags
= UNIT_FILE_DRY_RUN
|
2364 (runtime
? UNIT_FILE_RUNTIME
: 0);
2366 r
= unit_file_disable(UNIT_FILE_SYSTEM
, flags
, NULL
, p
, &changes
, &n_changes
);
2368 return log_error_errno(r
, "Failed to get file links for %s: %m", name
);
2370 for (i
= 0; i
< n_changes
; i
++)
2371 if (changes
[i
].type
== UNIT_FILE_UNLINK
) {
2372 r
= sd_bus_message_append(reply
, "s", changes
[i
].path
);
2377 r
= sd_bus_message_close_container(reply
);
2381 return sd_bus_send(NULL
, reply
, NULL
);
2384 static int method_get_job_waiting(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2385 Manager
*m
= userdata
;
2393 r
= sd_bus_message_read(message
, "u", &id
);
2397 j
= manager_get_job(m
, id
);
2399 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
2401 return bus_job_method_get_waiting_jobs(message
, j
, error
);
2404 const sd_bus_vtable bus_manager_vtable
[] = {
2405 SD_BUS_VTABLE_START(0),
2407 SD_BUS_PROPERTY("Version", "s", property_get_version
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2408 SD_BUS_PROPERTY("Features", "s", property_get_features
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2409 SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2410 SD_BUS_PROPERTY("Architecture", "s", property_get_architecture
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2411 SD_BUS_PROPERTY("Tainted", "s", property_get_tainted
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2412 BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_FIRMWARE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2413 BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_LOADER
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2414 BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_KERNEL
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2415 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_INITRD
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2416 BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_USERSPACE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2417 BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2418 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_SECURITY_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2419 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_SECURITY_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2420 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_GENERATORS_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2421 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_GENERATORS_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2422 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_UNITS_LOAD_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2423 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_UNITS_LOAD_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2424 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level
, property_set_log_level
, 0, 0),
2425 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target
, property_set_log_target
, 0, 0),
2426 SD_BUS_PROPERTY("NNames", "u", property_get_hashmap_size
, offsetof(Manager
, units
), 0),
2427 SD_BUS_PROPERTY("NFailedUnits", "u", property_get_set_size
, offsetof(Manager
, failed_units
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
2428 SD_BUS_PROPERTY("NJobs", "u", property_get_hashmap_size
, offsetof(Manager
, jobs
), 0),
2429 SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_installed_jobs
), 0),
2430 SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_failed_jobs
), 0),
2431 SD_BUS_PROPERTY("Progress", "d", property_get_progress
, 0, 0),
2432 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(Manager
, environment
), 0),
2433 SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool
, offsetof(Manager
, confirm_spawn
), SD_BUS_VTABLE_PROPERTY_CONST
),
2434 SD_BUS_PROPERTY("ShowStatus", "b", property_get_show_status
, 0, 0),
2435 SD_BUS_PROPERTY("UnitPath", "as", NULL
, offsetof(Manager
, lookup_paths
.search_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
2436 SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2437 SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2438 SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec
, property_set_runtime_watchdog
, offsetof(Manager
, runtime_watchdog
), 0),
2439 SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec
, bus_property_set_usec
, offsetof(Manager
, shutdown_watchdog
), 0),
2440 SD_BUS_WRITABLE_PROPERTY("ServiceWatchdogs", "b", bus_property_get_bool
, bus_property_set_bool
, offsetof(Manager
, service_watchdogs
), 0),
2441 SD_BUS_PROPERTY("ControlGroup", "s", NULL
, offsetof(Manager
, cgroup_root
), 0),
2442 SD_BUS_PROPERTY("SystemState", "s", property_get_system_state
, 0, 0),
2443 SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned
, offsetof(Manager
, return_value
), 0),
2444 SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timer_accuracy_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2445 SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_start_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2446 SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_stop_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2447 SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_restart_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2448 SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
),
2449 /* The following two items are obsolete alias */
2450 SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
2451 SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
2452 SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned
, offsetof(Manager
, default_start_limit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
2453 SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_cpu_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2454 SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_blockio_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2455 SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_memory_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2456 SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_tasks_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2457 SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2458 SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2459 SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2460 SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2461 SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2462 SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2463 SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2464 SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2465 SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2466 SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2467 SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2468 SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2469 SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2470 SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2471 SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2472 SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2473 SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2474 SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2475 SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2476 SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2477 SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2478 SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2479 SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2480 SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2481 SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2482 SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2483 SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2484 SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2485 SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2486 SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2487 SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2488 SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2489 SD_BUS_PROPERTY("DefaultTasksMax", "t", NULL
, offsetof(Manager
, default_tasks_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
2490 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2492 SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2493 SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2494 SD_BUS_METHOD("GetUnitByInvocationID", "ay", "o", method_get_unit_by_invocation_id
, SD_BUS_VTABLE_UNPRIVILEGED
),
2495 SD_BUS_METHOD("GetUnitByControlGroup", "s", "o", method_get_unit_by_control_group
, SD_BUS_VTABLE_UNPRIVILEGED
),
2496 SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2497 SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2498 SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace
, SD_BUS_VTABLE_UNPRIVILEGED
),
2499 SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2500 SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2501 SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2502 SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2503 SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2504 SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2505 SD_BUS_METHOD("KillUnit", "ssi", NULL
, method_kill_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2506 SD_BUS_METHOD("ResetFailedUnit", "s", NULL
, method_reset_failed_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2507 SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL
, method_set_unit_properties
, SD_BUS_VTABLE_UNPRIVILEGED
),
2508 SD_BUS_METHOD("RefUnit", "s", NULL
, method_ref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2509 SD_BUS_METHOD("UnrefUnit", "s", NULL
, method_unref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2510 SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2511 SD_BUS_METHOD("GetUnitProcesses", "s", "a(sus)", method_get_unit_processes
, SD_BUS_VTABLE_UNPRIVILEGED
),
2512 SD_BUS_METHOD("AttachProcessesToUnit", "ssau", NULL
, method_attach_processes_to_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2513 SD_BUS_METHOD("GetJob", "u", "o", method_get_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2514 SD_BUS_METHOD("GetJobAfter", "u", "a(usssoo)", method_get_job_waiting
, SD_BUS_VTABLE_UNPRIVILEGED
),
2515 SD_BUS_METHOD("GetJobBefore", "u", "a(usssoo)", method_get_job_waiting
, SD_BUS_VTABLE_UNPRIVILEGED
),
2516 SD_BUS_METHOD("CancelJob", "u", NULL
, method_cancel_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2517 SD_BUS_METHOD("ClearJobs", NULL
, NULL
, method_clear_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2518 SD_BUS_METHOD("ResetFailed", NULL
, NULL
, method_reset_failed
, SD_BUS_VTABLE_UNPRIVILEGED
),
2519 SD_BUS_METHOD("ListUnits", NULL
, "a(ssssssouso)", method_list_units
, SD_BUS_VTABLE_UNPRIVILEGED
),
2520 SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered
, SD_BUS_VTABLE_UNPRIVILEGED
),
2521 SD_BUS_METHOD("ListUnitsByPatterns", "asas", "a(ssssssouso)", method_list_units_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2522 SD_BUS_METHOD("ListUnitsByNames", "as", "a(ssssssouso)", method_list_units_by_names
, SD_BUS_VTABLE_UNPRIVILEGED
),
2523 SD_BUS_METHOD("ListJobs", NULL
, "a(usssoo)", method_list_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2524 SD_BUS_METHOD("Subscribe", NULL
, NULL
, method_subscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2525 SD_BUS_METHOD("Unsubscribe", NULL
, NULL
, method_unsubscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2526 SD_BUS_METHOD("Dump", NULL
, "s", method_dump
, SD_BUS_VTABLE_UNPRIVILEGED
),
2527 SD_BUS_METHOD("DumpByFileDescriptor", NULL
, "h", method_dump_by_fd
, SD_BUS_VTABLE_UNPRIVILEGED
),
2528 SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
|SD_BUS_VTABLE_HIDDEN
),
2529 SD_BUS_METHOD("RemoveSnapshot", "s", NULL
, method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
|SD_BUS_VTABLE_HIDDEN
),
2530 SD_BUS_METHOD("Reload", NULL
, NULL
, method_reload
, SD_BUS_VTABLE_UNPRIVILEGED
),
2531 SD_BUS_METHOD("Reexecute", NULL
, NULL
, method_reexecute
, SD_BUS_VTABLE_UNPRIVILEGED
),
2532 SD_BUS_METHOD("Exit", NULL
, NULL
, method_exit
, 0),
2533 SD_BUS_METHOD("Reboot", NULL
, NULL
, method_reboot
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2534 SD_BUS_METHOD("PowerOff", NULL
, NULL
, method_poweroff
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2535 SD_BUS_METHOD("Halt", NULL
, NULL
, method_halt
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2536 SD_BUS_METHOD("KExec", NULL
, NULL
, method_kexec
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2537 SD_BUS_METHOD("SwitchRoot", "ss", NULL
, method_switch_root
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2538 SD_BUS_METHOD("SetEnvironment", "as", NULL
, method_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2539 SD_BUS_METHOD("UnsetEnvironment", "as", NULL
, method_unset_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2540 SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL
, method_unset_and_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2541 SD_BUS_METHOD("ListUnitFiles", NULL
, "a(ss)", method_list_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2542 SD_BUS_METHOD("ListUnitFilesByPatterns", "asas", "a(ss)", method_list_unit_files_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2543 SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state
, SD_BUS_VTABLE_UNPRIVILEGED
),
2544 SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2545 SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2546 SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2547 SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2548 SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2549 SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode
, SD_BUS_VTABLE_UNPRIVILEGED
),
2550 SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2551 SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2552 SD_BUS_METHOD("RevertUnitFiles", "as", "a(sss)", method_revert_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2553 SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2554 SD_BUS_METHOD("GetDefaultTarget", NULL
, "s", method_get_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2555 SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2556 SD_BUS_METHOD("AddDependencyUnitFiles", "asssbb", "a(sss)", method_add_dependency_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2557 SD_BUS_METHOD("GetUnitFileLinks", "sb", "as", method_get_unit_file_links
, SD_BUS_VTABLE_UNPRIVILEGED
),
2558 SD_BUS_METHOD("SetExitCode", "y", NULL
, method_set_exit_code
, SD_BUS_VTABLE_UNPRIVILEGED
),
2559 SD_BUS_METHOD("LookupDynamicUserByName", "s", "u", method_lookup_dynamic_user_by_name
, SD_BUS_VTABLE_UNPRIVILEGED
),
2560 SD_BUS_METHOD("LookupDynamicUserByUID", "u", "s", method_lookup_dynamic_user_by_uid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2561 SD_BUS_METHOD("GetDynamicUsers", NULL
, "a(us)", method_get_dynamic_users
, SD_BUS_VTABLE_UNPRIVILEGED
),
2563 SD_BUS_SIGNAL("UnitNew", "so", 0),
2564 SD_BUS_SIGNAL("UnitRemoved", "so", 0),
2565 SD_BUS_SIGNAL("JobNew", "uos", 0),
2566 SD_BUS_SIGNAL("JobRemoved", "uoss", 0),
2567 SD_BUS_SIGNAL("StartupFinished", "tttttt", 0),
2568 SD_BUS_SIGNAL("UnitFilesChanged", NULL
, 0),
2569 SD_BUS_SIGNAL("Reloading", "b", 0),
2574 static int send_finished(sd_bus
*bus
, void *userdata
) {
2575 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2576 usec_t
*times
= userdata
;
2582 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
2586 r
= sd_bus_message_append(message
, "tttttt", times
[0], times
[1], times
[2], times
[3], times
[4], times
[5]);
2590 return sd_bus_send(bus
, message
, NULL
);
2593 void bus_manager_send_finished(
2595 usec_t firmware_usec
,
2599 usec_t userspace_usec
,
2600 usec_t total_usec
) {
2606 r
= bus_foreach_bus(
2619 log_debug_errno(r
, "Failed to send finished signal: %m");
2622 static int send_reloading(sd_bus
*bus
, void *userdata
) {
2623 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2628 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
2632 r
= sd_bus_message_append(message
, "b", PTR_TO_INT(userdata
));
2636 return sd_bus_send(bus
, message
, NULL
);
2639 void bus_manager_send_reloading(Manager
*m
, bool active
) {
2644 r
= bus_foreach_bus(m
, NULL
, send_reloading
, INT_TO_PTR(active
));
2646 log_debug_errno(r
, "Failed to send reloading signal: %m");
2649 static int send_changed_signal(sd_bus
*bus
, void *userdata
) {
2652 return sd_bus_emit_properties_changed_strv(bus
,
2653 "/org/freedesktop/systemd1",
2654 "org.freedesktop.systemd1.Manager",
2658 void bus_manager_send_change_signal(Manager
*m
) {
2663 r
= bus_foreach_bus(m
, NULL
, send_changed_signal
, NULL
);
2665 log_debug_errno(r
, "Failed to send manager change signal: %m");