1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include <sys/statvfs.h>
8 #include "alloc-util.h"
9 #include "architecture.h"
11 #include "bus-common-errors.h"
12 #include "bus-log-control-api.h"
14 #include "dbus-cgroup.h"
15 #include "dbus-execute.h"
17 #include "dbus-manager.h"
18 #include "dbus-scope.h"
19 #include "dbus-unit.h"
24 #include "format-util.h"
29 #include "parse-util.h"
30 #include "path-util.h"
31 #include "selinux-access.h"
32 #include "stat-util.h"
33 #include "string-util.h"
35 #include "syslog-util.h"
36 #include "user-util.h"
40 /* Require 16MiB free in /run/systemd for reloading/reexecing. After all we need to serialize our state there, and if
41 * we can't we'll fail badly. */
42 #define RELOAD_DISK_SPACE_MIN (UINT64_C(16) * UINT64_C(1024) * UINT64_C(1024))
44 static UnitFileFlags
unit_file_bools_to_flags(bool runtime
, bool force
) {
45 return (runtime
? UNIT_FILE_RUNTIME
: 0) |
46 (force
? UNIT_FILE_FORCE
: 0);
49 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_oom_policy
, oom_policy
, OOMPolicy
);
51 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_version
, "s", GIT_VERSION
);
52 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_features
, "s", SYSTEMD_FEATURES
);
53 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_architecture
, "s", architecture_to_string(uname_architecture()));
54 static BUS_DEFINE_PROPERTY_GET2(property_get_system_state
, "s", Manager
, manager_state
, manager_state_to_string
);
55 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_timer_slack_nsec
, "t", (uint64_t) prctl(PR_GET_TIMERSLACK
));
56 static BUS_DEFINE_PROPERTY_GET_REF(property_get_hashmap_size
, "u", Hashmap
*, hashmap_size
);
57 static BUS_DEFINE_PROPERTY_GET_REF(property_get_set_size
, "u", Set
*, set_size
);
58 static BUS_DEFINE_PROPERTY_GET(property_get_default_timeout_abort_usec
, "t", Manager
, manager_default_timeout_abort_usec
);
60 static int property_get_virtualization(
63 const char *interface
,
65 sd_bus_message
*reply
,
67 sd_bus_error
*error
) {
74 v
= detect_virtualization();
76 /* Make sure to return the empty string when we detect no virtualization, as that is the API.
78 * https://github.com/systemd/systemd/issues/1423
81 return sd_bus_message_append(
83 v
== VIRTUALIZATION_NONE
? NULL
: virtualization_to_string(v
));
86 static int property_get_tainted(
89 const char *interface
,
91 sd_bus_message
*reply
,
93 sd_bus_error
*error
) {
95 _cleanup_free_
char *s
= NULL
;
96 Manager
*m
= userdata
;
102 s
= manager_taint_string(m
);
106 return sd_bus_message_append(reply
, "s", s
);
109 static int property_set_log_target(
112 const char *interface
,
113 const char *property
,
114 sd_bus_message
*value
,
116 sd_bus_error
*error
) {
118 Manager
*m
= userdata
;
125 r
= sd_bus_message_read(value
, "s", &t
);
130 manager_restore_original_log_target(m
);
134 target
= log_target_from_string(t
);
136 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid log target '%s'", t
);
138 manager_override_log_target(m
, target
);
144 static int property_set_log_level(
147 const char *interface
,
148 const char *property
,
149 sd_bus_message
*value
,
151 sd_bus_error
*error
) {
153 Manager
*m
= userdata
;
160 r
= sd_bus_message_read(value
, "s", &t
);
165 manager_restore_original_log_level(m
);
169 level
= log_level_from_string(t
);
171 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid log level '%s'", t
);
173 manager_override_log_level(m
, level
);
179 static int property_get_progress(
182 const char *interface
,
183 const char *property
,
184 sd_bus_message
*reply
,
186 sd_bus_error
*error
) {
188 Manager
*m
= userdata
;
195 if (MANAGER_IS_FINISHED(m
))
198 d
= 1.0 - ((double) hashmap_size(m
->jobs
) / (double) m
->n_installed_jobs
);
200 return sd_bus_message_append(reply
, "d", d
);
203 static int property_get_environment(
206 const char *interface
,
207 const char *property
,
208 sd_bus_message
*reply
,
210 sd_bus_error
*error
) {
212 _cleanup_strv_free_
char **l
= NULL
;
213 Manager
*m
= userdata
;
220 r
= manager_get_effective_environment(m
, &l
);
224 return sd_bus_message_append_strv(reply
, l
);
227 static int property_get_show_status(
230 const char *interface
,
231 const char *property
,
232 sd_bus_message
*reply
,
234 sd_bus_error
*error
) {
236 Manager
*m
= userdata
;
243 b
= IN_SET(m
->show_status
, SHOW_STATUS_TEMPORARY
, SHOW_STATUS_YES
);
244 return sd_bus_message_append_basic(reply
, 'b', &b
);
247 static int property_get_runtime_watchdog(
250 const char *interface
,
251 const char *property
,
252 sd_bus_message
*reply
,
254 sd_bus_error
*error
) {
256 Manager
*m
= userdata
;
262 return sd_bus_message_append(reply
, "t", manager_get_watchdog(m
, WATCHDOG_RUNTIME
));
265 static int property_get_reboot_watchdog(
268 const char *interface
,
269 const char *property
,
270 sd_bus_message
*reply
,
272 sd_bus_error
*error
) {
274 Manager
*m
= userdata
;
280 return sd_bus_message_append(reply
, "t", manager_get_watchdog(m
, WATCHDOG_REBOOT
));
283 static int property_get_kexec_watchdog(
286 const char *interface
,
287 const char *property
,
288 sd_bus_message
*reply
,
290 sd_bus_error
*error
) {
292 Manager
*m
= userdata
;
298 return sd_bus_message_append(reply
, "t", manager_get_watchdog(m
, WATCHDOG_KEXEC
));
301 static int property_set_watchdog(Manager
*m
, WatchdogType type
, sd_bus_message
*value
) {
308 assert_cc(sizeof(usec_t
) == sizeof(uint64_t));
310 r
= sd_bus_message_read(value
, "t", &timeout
);
314 return manager_set_watchdog_overridden(m
, type
, timeout
);
317 static int property_set_runtime_watchdog(
320 const char *interface
,
321 const char *property
,
322 sd_bus_message
*value
,
324 sd_bus_error
*error
) {
326 return property_set_watchdog(userdata
, WATCHDOG_RUNTIME
, value
);
329 static int property_set_reboot_watchdog(
332 const char *interface
,
333 const char *property
,
334 sd_bus_message
*value
,
336 sd_bus_error
*error
) {
338 return property_set_watchdog(userdata
, WATCHDOG_REBOOT
, value
);
341 static int property_set_kexec_watchdog(
344 const char *interface
,
345 const char *property
,
346 sd_bus_message
*value
,
348 sd_bus_error
*error
) {
350 _unused_ Manager
*m
= userdata
;
356 return property_set_watchdog(userdata
, WATCHDOG_KEXEC
, value
);
359 static int bus_get_unit_by_name(Manager
*m
, sd_bus_message
*message
, const char *name
, Unit
**ret_unit
, sd_bus_error
*error
) {
367 /* More or less a wrapper around manager_get_unit() that generates nice errors and has one trick up its sleeve:
368 * if the name is specified empty we use the client's unit. */
371 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
374 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
378 r
= sd_bus_creds_get_pid(creds
, &pid
);
382 u
= manager_get_unit_by_pid(m
, pid
);
384 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
386 u
= manager_get_unit(m
, name
);
388 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s not loaded.", name
);
395 static int bus_load_unit_by_name(Manager
*m
, sd_bus_message
*message
, const char *name
, Unit
**ret_unit
, sd_bus_error
*error
) {
400 /* Pretty much the same as bus_get_unit_by_name(), but we also load the unit if necessary. */
403 return bus_get_unit_by_name(m
, message
, name
, ret_unit
, error
);
405 return manager_load_unit(m
, name
, NULL
, error
, ret_unit
);
408 static int reply_unit_path(Unit
*u
, sd_bus_message
*message
, sd_bus_error
*error
) {
409 _cleanup_free_
char *path
= NULL
;
415 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
419 path
= unit_dbus_path(u
);
423 return sd_bus_reply_method_return(message
, "o", path
);
426 static int method_get_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
427 Manager
*m
= userdata
;
435 /* Anyone can call this method */
437 r
= sd_bus_message_read(message
, "s", &name
);
441 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
445 return reply_unit_path(u
, message
, error
);
448 static int method_get_unit_by_pid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
449 Manager
*m
= userdata
;
457 assert_cc(sizeof(pid_t
) == sizeof(uint32_t));
459 /* Anyone can call this method */
461 r
= sd_bus_message_read(message
, "u", &pid
);
465 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PID " PID_FMT
, pid
);
468 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
470 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
474 r
= sd_bus_creds_get_pid(creds
, &pid
);
479 u
= manager_get_unit_by_pid(m
, pid
);
481 return sd_bus_error_setf(error
, BUS_ERROR_NO_UNIT_FOR_PID
, "PID "PID_FMT
" does not belong to any loaded unit.", pid
);
483 return reply_unit_path(u
, message
, error
);
486 static int method_get_unit_by_invocation_id(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
487 _cleanup_free_
char *path
= NULL
;
488 Manager
*m
= userdata
;
498 /* Anyone can call this method */
500 r
= sd_bus_message_read_array(message
, 'y', &a
, &sz
);
508 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid invocation ID");
510 if (sd_id128_is_null(id
)) {
511 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
514 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
518 r
= sd_bus_creds_get_pid(creds
, &pid
);
522 u
= manager_get_unit_by_pid(m
, pid
);
524 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client " PID_FMT
" not member of any unit.", pid
);
526 u
= hashmap_get(m
->units_by_invocation_id
, &id
);
528 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
));
531 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
535 /* So here's a special trick: the bus path we return actually references the unit by its invocation ID instead
536 * of the unit name. This means it stays valid only as long as the invocation ID stays the same. */
537 path
= unit_dbus_path_invocation_id(u
);
541 return sd_bus_reply_method_return(message
, "o", path
);
544 static int method_get_unit_by_control_group(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
545 Manager
*m
= userdata
;
550 r
= sd_bus_message_read(message
, "s", &cgroup
);
554 u
= manager_get_unit_by_cgroup(m
, cgroup
);
556 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Control group '%s' is not valid or not managed by this instance", cgroup
);
558 return reply_unit_path(u
, message
, error
);
561 static int method_load_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
562 Manager
*m
= userdata
;
570 /* Anyone can call this method */
572 r
= sd_bus_message_read(message
, "s", &name
);
576 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
580 return reply_unit_path(u
, message
, error
);
583 static int method_start_unit_generic(sd_bus_message
*message
, Manager
*m
, JobType job_type
, bool reload_if_possible
, sd_bus_error
*error
) {
591 r
= sd_bus_message_read(message
, "s", &name
);
595 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
599 return bus_unit_method_start_generic(message
, u
, job_type
, reload_if_possible
, error
);
602 static int method_start_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
603 return method_start_unit_generic(message
, userdata
, JOB_START
, false, error
);
606 static int method_stop_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
607 return method_start_unit_generic(message
, userdata
, JOB_STOP
, false, error
);
610 static int method_reload_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
611 return method_start_unit_generic(message
, userdata
, JOB_RELOAD
, false, error
);
614 static int method_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
615 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, false, error
);
618 static int method_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
619 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, false, error
);
622 static int method_reload_or_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
623 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, true, error
);
626 static int method_reload_or_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
627 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, true, error
);
630 typedef enum GenericUnitOperationFlags
{
631 GENERIC_UNIT_LOAD
= 1 << 0, /* Load if the unit is not loaded yet */
632 GENERIC_UNIT_VALIDATE_LOADED
= 1 << 1, /* Verify unit is properly loaded before forwarding call */
633 } GenericUnitOperationFlags
;
635 static int method_generic_unit_operation(
636 sd_bus_message
*message
,
639 sd_bus_message_handler_t handler
,
640 GenericUnitOperationFlags flags
) {
649 /* Read the first argument from the command and pass the operation to the specified per-unit
652 r
= sd_bus_message_read(message
, "s", &name
);
656 if (!isempty(name
) && FLAGS_SET(flags
, GENERIC_UNIT_LOAD
))
657 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
659 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
663 if (FLAGS_SET(flags
, GENERIC_UNIT_VALIDATE_LOADED
)) {
664 r
= bus_unit_validate_load_state(u
, error
);
669 return handler(message
, u
, error
);
672 static int method_enqueue_unit_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
673 /* We don't bother with GENERIC_UNIT_VALIDATE_LOADED here, as the job logic validates that anyway */
674 return method_generic_unit_operation(message
, userdata
, error
, bus_unit_method_enqueue_job
, GENERIC_UNIT_LOAD
);
677 static int method_start_unit_replace(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
678 Manager
*m
= userdata
;
679 const char *old_name
;
686 r
= sd_bus_message_read(message
, "s", &old_name
);
690 r
= bus_get_unit_by_name(m
, message
, old_name
, &u
, error
);
693 if (!u
->job
|| u
->job
->type
!= JOB_START
)
694 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "No job queued for unit %s", old_name
);
696 return method_start_unit_generic(message
, m
, JOB_START
, false, error
);
699 static int method_kill_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
700 /* We don't bother with GENERIC_UNIT_LOAD nor GENERIC_UNIT_VALIDATE_LOADED here, as it shouldn't
701 * matter whether a unit is loaded for killing any processes possibly in the unit's cgroup. */
702 return method_generic_unit_operation(message
, userdata
, error
, bus_unit_method_kill
, 0);
705 static int method_clean_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
706 /* Load the unit if necessary, in order to load it, and insist on the unit being loaded to be
708 return method_generic_unit_operation(message
, userdata
, error
, bus_unit_method_clean
, GENERIC_UNIT_LOAD
|GENERIC_UNIT_VALIDATE_LOADED
);
711 static int method_freeze_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
712 return method_generic_unit_operation(message
, userdata
, error
, bus_unit_method_freeze
, 0);
715 static int method_thaw_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
716 return method_generic_unit_operation(message
, userdata
, error
, bus_unit_method_thaw
, 0);
719 static int method_reset_failed_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
720 /* Don't load the unit (because unloaded units can't be in failed state), and don't insist on the
721 * unit to be loaded properly (since a failed unit might have its unit file disappeared) */
722 return method_generic_unit_operation(message
, userdata
, error
, bus_unit_method_reset_failed
, 0);
725 static int method_set_unit_properties(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
726 /* Only change properties on fully loaded units, and load them in order to set properties */
727 return method_generic_unit_operation(message
, userdata
, error
, bus_unit_method_set_properties
, GENERIC_UNIT_LOAD
|GENERIC_UNIT_VALIDATE_LOADED
);
730 static int method_ref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
731 /* Only allow reffing of fully loaded units, and make sure reffing a unit loads it. */
732 return method_generic_unit_operation(message
, userdata
, error
, bus_unit_method_ref
, GENERIC_UNIT_LOAD
|GENERIC_UNIT_VALIDATE_LOADED
);
735 static int method_unref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
736 /* Dropping a ref OTOH should not require the unit to still be loaded. And since a reffed unit is a
737 * loaded unit there's no need to load the unit for unreffing it. */
738 return method_generic_unit_operation(message
, userdata
, error
, bus_unit_method_unref
, 0);
741 static int reply_unit_info(sd_bus_message
*reply
, Unit
*u
) {
742 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
745 following
= unit_following(u
);
747 unit_path
= unit_dbus_path(u
);
752 job_path
= job_dbus_path(u
->job
);
757 return sd_bus_message_append(
758 reply
, "(ssssssouso)",
761 unit_load_state_to_string(u
->load_state
),
762 unit_active_state_to_string(unit_active_state(u
)),
763 unit_sub_state_to_string(u
),
764 following
? following
->id
: "",
766 u
->job
? u
->job
->id
: 0,
767 u
->job
? job_type_to_string(u
->job
->type
) : "",
768 empty_to_root(job_path
));
771 static int method_list_units_by_names(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
772 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
773 Manager
*m
= userdata
;
776 _cleanup_strv_free_
char **units
= NULL
;
781 r
= sd_bus_message_read_strv(message
, &units
);
785 r
= sd_bus_message_new_method_return(message
, &reply
);
789 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
793 STRV_FOREACH(unit
, units
) {
796 if (!unit_name_is_valid(*unit
, UNIT_NAME_ANY
))
799 r
= bus_load_unit_by_name(m
, message
, *unit
, &u
, error
);
803 r
= reply_unit_info(reply
, u
);
808 r
= sd_bus_message_close_container(reply
);
812 return sd_bus_send(NULL
, reply
, NULL
);
815 static int method_get_unit_processes(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
816 /* Don't load a unit (since it won't have any processes if it's not loaded), but don't insist on the
817 * unit being loaded (because even improperly loaded units might still have processes around */
818 return method_generic_unit_operation(message
, userdata
, error
, bus_unit_method_get_processes
, 0);
821 static int method_attach_processes_to_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
822 /* Don't allow attaching new processes to units that aren't loaded. Don't bother with loading a unit
823 * for this purpose though, as an unloaded unit is a stopped unit, and we don't allow attaching
824 * processes to stopped units anyway. */
825 return method_generic_unit_operation(message
, userdata
, error
, bus_unit_method_attach_processes
, GENERIC_UNIT_VALIDATE_LOADED
);
828 static int transient_unit_from_message(
830 sd_bus_message
*message
,
833 sd_bus_error
*error
) {
843 t
= unit_name_to_type(name
);
845 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid unit name or type.");
847 if (!unit_vtable
[t
]->can_transient
)
848 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unit type %s does not support transient units.", unit_type_to_string(t
));
850 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
854 if (!unit_is_pristine(u
))
855 return sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
, "Unit %s already exists.", name
);
857 /* OK, the unit failed to load and is unreferenced, now let's
858 * fill in the transient data instead */
859 r
= unit_make_transient(u
);
863 /* Set our properties */
864 r
= bus_unit_set_properties(u
, message
, UNIT_RUNTIME
, false, error
);
868 /* If the client asked for it, automatically add a reference to this unit. */
869 if (u
->bus_track_add
) {
870 r
= bus_unit_track_add_sender(u
, message
);
872 return log_error_errno(r
, "Failed to watch sender: %m");
875 /* Now load the missing bits of the unit we just created */
876 unit_add_to_load_queue(u
);
877 manager_dispatch_load_queue(m
);
884 static int transient_aux_units_from_message(
886 sd_bus_message
*message
,
887 sd_bus_error
*error
) {
894 r
= sd_bus_message_enter_container(message
, 'a', "(sa(sv))");
898 while ((r
= sd_bus_message_enter_container(message
, 'r', "sa(sv)")) > 0) {
899 const char *name
= NULL
;
902 r
= sd_bus_message_read(message
, "s", &name
);
906 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
910 r
= sd_bus_message_exit_container(message
);
917 r
= sd_bus_message_exit_container(message
);
924 static int method_start_transient_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
925 const char *name
, *smode
;
926 Manager
*m
= userdata
;
934 r
= mac_selinux_access_check(message
, "start", error
);
938 r
= sd_bus_message_read(message
, "ss", &name
, &smode
);
942 mode
= job_mode_from_string(smode
);
944 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Job mode %s is invalid.", smode
);
946 r
= bus_verify_manage_units_async(m
, message
, error
);
950 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
952 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
956 r
= transient_aux_units_from_message(m
, message
, error
);
960 /* Finally, start it */
961 return bus_unit_queue_job(message
, u
, JOB_START
, mode
, 0, error
);
964 static int method_get_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
965 _cleanup_free_
char *path
= NULL
;
966 Manager
*m
= userdata
;
974 /* Anyone can call this method */
976 r
= sd_bus_message_read(message
, "u", &id
);
980 j
= manager_get_job(m
, id
);
982 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
984 r
= mac_selinux_unit_access_check(j
->unit
, message
, "status", error
);
988 path
= job_dbus_path(j
);
992 return sd_bus_reply_method_return(message
, "o", path
);
995 static int method_cancel_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
996 Manager
*m
= userdata
;
1004 r
= sd_bus_message_read(message
, "u", &id
);
1008 j
= manager_get_job(m
, id
);
1010 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
1012 return bus_job_method_cancel(message
, j
, error
);
1015 static int method_clear_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1016 Manager
*m
= userdata
;
1022 r
= mac_selinux_access_check(message
, "reload", error
);
1026 r
= bus_verify_manage_units_async(m
, message
, error
);
1030 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1032 manager_clear_jobs(m
);
1034 return sd_bus_reply_method_return(message
, NULL
);
1037 static int method_reset_failed(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_reset_failed(m
);
1056 return sd_bus_reply_method_return(message
, NULL
);
1059 static int list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1060 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1061 Manager
*m
= userdata
;
1070 /* Anyone can call this method */
1072 r
= mac_selinux_access_check(message
, "status", error
);
1076 r
= sd_bus_message_new_method_return(message
, &reply
);
1080 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
1084 HASHMAP_FOREACH_KEY(u
, k
, m
->units
, i
) {
1088 if (!strv_isempty(states
) &&
1089 !strv_contains(states
, unit_load_state_to_string(u
->load_state
)) &&
1090 !strv_contains(states
, unit_active_state_to_string(unit_active_state(u
))) &&
1091 !strv_contains(states
, unit_sub_state_to_string(u
)))
1094 if (!strv_isempty(patterns
) &&
1095 !strv_fnmatch_or_empty(patterns
, u
->id
, FNM_NOESCAPE
))
1098 r
= reply_unit_info(reply
, u
);
1103 r
= sd_bus_message_close_container(reply
);
1107 return sd_bus_send(NULL
, reply
, NULL
);
1110 static int method_list_units(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1111 return list_units_filtered(message
, userdata
, error
, NULL
, NULL
);
1114 static int method_list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1115 _cleanup_strv_free_
char **states
= NULL
;
1118 r
= sd_bus_message_read_strv(message
, &states
);
1122 return list_units_filtered(message
, userdata
, error
, states
, NULL
);
1125 static int method_list_units_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1126 _cleanup_strv_free_
char **states
= NULL
;
1127 _cleanup_strv_free_
char **patterns
= NULL
;
1130 r
= sd_bus_message_read_strv(message
, &states
);
1134 r
= sd_bus_message_read_strv(message
, &patterns
);
1138 return list_units_filtered(message
, userdata
, error
, states
, patterns
);
1141 static int method_list_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1142 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1143 Manager
*m
= userdata
;
1151 /* Anyone can call this method */
1153 r
= mac_selinux_access_check(message
, "status", error
);
1157 r
= sd_bus_message_new_method_return(message
, &reply
);
1161 r
= sd_bus_message_open_container(reply
, 'a', "(usssoo)");
1165 HASHMAP_FOREACH(j
, m
->jobs
, i
) {
1166 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
1168 job_path
= job_dbus_path(j
);
1172 unit_path
= unit_dbus_path(j
->unit
);
1176 r
= sd_bus_message_append(
1180 job_type_to_string(j
->type
),
1181 job_state_to_string(j
->state
),
1188 r
= sd_bus_message_close_container(reply
);
1192 return sd_bus_send(NULL
, reply
, NULL
);
1195 static int method_subscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1196 Manager
*m
= userdata
;
1202 /* Anyone can call this method */
1204 r
= mac_selinux_access_check(message
, "status", error
);
1208 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1210 /* Note that direct bus connection subscribe by
1211 * default, we only track peers on the API bus here */
1213 if (!m
->subscribed
) {
1214 r
= sd_bus_track_new(sd_bus_message_get_bus(message
), &m
->subscribed
, NULL
, NULL
);
1219 r
= sd_bus_track_add_sender(m
->subscribed
, message
);
1223 return sd_bus_error_setf(error
, BUS_ERROR_ALREADY_SUBSCRIBED
, "Client is already subscribed.");
1226 return sd_bus_reply_method_return(message
, NULL
);
1229 static int method_unsubscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1230 Manager
*m
= userdata
;
1236 /* Anyone can call this method */
1238 r
= mac_selinux_access_check(message
, "status", error
);
1242 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1243 r
= sd_bus_track_remove_sender(m
->subscribed
, message
);
1247 return sd_bus_error_setf(error
, BUS_ERROR_NOT_SUBSCRIBED
, "Client is not subscribed.");
1250 return sd_bus_reply_method_return(message
, NULL
);
1253 static int dump_impl(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, int (*reply
)(sd_bus_message
*, char *)) {
1254 _cleanup_free_
char *dump
= NULL
;
1255 Manager
*m
= userdata
;
1261 /* Anyone can call this method */
1263 r
= mac_selinux_access_check(message
, "status", error
);
1267 r
= manager_get_dump_string(m
, &dump
);
1271 return reply(message
, dump
);
1274 static int reply_dump(sd_bus_message
*message
, char *dump
) {
1275 return sd_bus_reply_method_return(message
, "s", dump
);
1278 static int method_dump(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1279 return dump_impl(message
, userdata
, error
, reply_dump
);
1282 static int reply_dump_by_fd(sd_bus_message
*message
, char *dump
) {
1283 _cleanup_close_
int fd
= -1;
1285 fd
= acquire_data_fd(dump
, strlen(dump
), 0);
1289 return sd_bus_reply_method_return(message
, "h", fd
);
1292 static int method_dump_by_fd(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1293 return dump_impl(message
, userdata
, error
, reply_dump_by_fd
);
1296 static int method_refuse_snapshot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1297 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Support for snapshots has been removed.");
1300 static int verify_run_space(const char *message
, sd_bus_error
*error
) {
1301 struct statvfs svfs
;
1304 if (statvfs("/run/systemd", &svfs
) < 0)
1305 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1307 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1309 if (available
< RELOAD_DISK_SPACE_MIN
) {
1310 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1311 return sd_bus_error_setf(error
,
1312 BUS_ERROR_DISK_FULL
,
1313 "%s, not enough space available on /run/systemd. "
1314 "Currently, %s are free, but a safety buffer of %s is enforced.",
1316 format_bytes(fb_available
, sizeof(fb_available
), available
),
1317 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1323 int verify_run_space_and_log(const char *message
) {
1324 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1327 r
= verify_run_space(message
, &error
);
1329 return log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1334 static int method_reload(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1335 Manager
*m
= userdata
;
1341 r
= verify_run_space("Refusing to reload", error
);
1345 r
= mac_selinux_access_check(message
, "reload", error
);
1349 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1353 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1355 /* Instead of sending the reply back right away, we just
1356 * remember that we need to and then send it after the reload
1357 * is finished. That way the caller knows when the reload
1360 assert(!m
->pending_reload_message
);
1361 r
= sd_bus_message_new_method_return(message
, &m
->pending_reload_message
);
1365 m
->objective
= MANAGER_RELOAD
;
1370 static int method_reexecute(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1371 Manager
*m
= userdata
;
1377 r
= verify_run_space("Refusing to reexecute", error
);
1381 r
= mac_selinux_access_check(message
, "reload", error
);
1385 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1389 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1391 /* We don't send a reply back here, the client should
1392 * just wait for us disconnecting. */
1394 m
->objective
= MANAGER_REEXECUTE
;
1398 static int method_exit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1399 Manager
*m
= userdata
;
1405 r
= mac_selinux_access_check(message
, "halt", error
);
1409 /* Exit() (in contrast to SetExitCode()) is actually allowed even if
1410 * we are running on the host. It will fall back on reboot() in
1411 * systemd-shutdown if it cannot do the exit() because it isn't a
1414 m
->objective
= MANAGER_EXIT
;
1416 return sd_bus_reply_method_return(message
, NULL
);
1419 static int method_reboot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1420 Manager
*m
= userdata
;
1426 r
= mac_selinux_access_check(message
, "reboot", error
);
1430 if (!MANAGER_IS_SYSTEM(m
))
1431 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Reboot is only supported for system managers.");
1433 m
->objective
= MANAGER_REBOOT
;
1435 return sd_bus_reply_method_return(message
, NULL
);
1438 static int method_poweroff(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1439 Manager
*m
= userdata
;
1445 r
= mac_selinux_access_check(message
, "halt", error
);
1449 if (!MANAGER_IS_SYSTEM(m
))
1450 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Powering off is only supported for system managers.");
1452 m
->objective
= MANAGER_POWEROFF
;
1454 return sd_bus_reply_method_return(message
, NULL
);
1457 static int method_halt(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1458 Manager
*m
= userdata
;
1464 r
= mac_selinux_access_check(message
, "halt", error
);
1468 if (!MANAGER_IS_SYSTEM(m
))
1469 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Halt is only supported for system managers.");
1471 m
->objective
= MANAGER_HALT
;
1473 return sd_bus_reply_method_return(message
, NULL
);
1476 static int method_kexec(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1477 Manager
*m
= userdata
;
1483 r
= mac_selinux_access_check(message
, "reboot", error
);
1487 if (!MANAGER_IS_SYSTEM(m
))
1488 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "KExec is only supported for system managers.");
1490 m
->objective
= MANAGER_KEXEC
;
1492 return sd_bus_reply_method_return(message
, NULL
);
1495 static int method_switch_root(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1496 _cleanup_free_
char *ri
= NULL
, *rt
= NULL
;
1497 const char *root
, *init
;
1498 Manager
*m
= userdata
;
1499 struct statvfs svfs
;
1506 if (statvfs("/run/systemd", &svfs
) < 0)
1507 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1509 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1511 if (available
< RELOAD_DISK_SPACE_MIN
) {
1512 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1513 log_warning("Dangerously low amount of free space on /run/systemd, root switching operation might not complete successfully. "
1514 "Currently, %s are free, but %s are suggested. Proceeding anyway.",
1515 format_bytes(fb_available
, sizeof(fb_available
), available
),
1516 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1519 r
= mac_selinux_access_check(message
, "reboot", error
);
1523 if (!MANAGER_IS_SYSTEM(m
))
1524 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Root switching is only supported by system manager.");
1526 r
= sd_bus_message_read(message
, "ss", &root
, &init
);
1531 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory may not be the empty string.");
1532 if (!path_is_absolute(root
))
1533 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root path '%s' is not absolute.", root
);
1534 if (path_equal(root
, "/"))
1535 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory cannot be the old root directory.");
1538 if (isempty(init
)) {
1539 r
= path_is_os_tree(root
);
1541 return sd_bus_error_set_errnof(error
, r
, "Failed to determine whether root path '%s' contains an OS tree: %m", root
);
1543 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
);
1545 _cleanup_free_
char *chased
= NULL
;
1547 if (!path_is_absolute(init
))
1548 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path to init binary '%s' not absolute.", init
);
1550 r
= chase_symlinks(init
, root
, CHASE_PREFIX_ROOT
|CHASE_TRAIL_SLASH
, &chased
, NULL
);
1552 return sd_bus_error_set_errnof(error
, r
, "Could not resolve init executable %s: %m", init
);
1554 if (laccess(chased
, X_OK
) < 0) {
1555 if (errno
== EACCES
)
1556 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Init binary %s is not executable.", init
);
1558 return sd_bus_error_set_errnof(error
, r
, "Could not check whether init binary %s is executable: %m", init
);
1566 if (!isempty(init
)) {
1572 free_and_replace(m
->switch_root
, rt
);
1573 free_and_replace(m
->switch_root_init
, ri
);
1575 m
->objective
= MANAGER_SWITCH_ROOT
;
1577 return sd_bus_reply_method_return(message
, NULL
);
1580 static int method_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1581 _cleanup_strv_free_
char **plus
= NULL
;
1582 Manager
*m
= userdata
;
1588 r
= mac_selinux_access_check(message
, "reload", error
);
1592 r
= sd_bus_message_read_strv(message
, &plus
);
1595 if (!strv_env_is_valid(plus
))
1596 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1598 r
= bus_verify_set_environment_async(m
, message
, error
);
1602 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1604 r
= manager_client_environment_modify(m
, NULL
, plus
);
1608 return sd_bus_reply_method_return(message
, NULL
);
1611 static int method_unset_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1612 _cleanup_strv_free_
char **minus
= NULL
;
1613 Manager
*m
= userdata
;
1619 r
= mac_selinux_access_check(message
, "reload", error
);
1623 r
= sd_bus_message_read_strv(message
, &minus
);
1627 if (!strv_env_name_or_assignment_is_valid(minus
))
1628 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1630 r
= bus_verify_set_environment_async(m
, message
, error
);
1634 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1636 r
= manager_client_environment_modify(m
, minus
, NULL
);
1640 return sd_bus_reply_method_return(message
, NULL
);
1643 static int method_unset_and_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1644 _cleanup_strv_free_
char **minus
= NULL
, **plus
= NULL
;
1645 Manager
*m
= userdata
;
1651 r
= mac_selinux_access_check(message
, "reload", error
);
1655 r
= sd_bus_message_read_strv(message
, &minus
);
1659 r
= sd_bus_message_read_strv(message
, &plus
);
1663 if (!strv_env_name_or_assignment_is_valid(minus
))
1664 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1665 if (!strv_env_is_valid(plus
))
1666 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1668 r
= bus_verify_set_environment_async(m
, message
, error
);
1672 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1674 r
= manager_client_environment_modify(m
, minus
, plus
);
1678 return sd_bus_reply_method_return(message
, NULL
);
1681 static int method_set_exit_code(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1682 Manager
*m
= userdata
;
1689 r
= mac_selinux_access_check(message
, "exit", error
);
1693 r
= sd_bus_message_read_basic(message
, 'y', &code
);
1697 if (MANAGER_IS_SYSTEM(m
) && detect_container() <= 0)
1698 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "ExitCode can only be set for user service managers or in containers.");
1700 m
->return_value
= code
;
1702 return sd_bus_reply_method_return(message
, NULL
);
1705 static int method_lookup_dynamic_user_by_name(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1706 Manager
*m
= userdata
;
1714 r
= sd_bus_message_read_basic(message
, 's', &name
);
1718 if (!MANAGER_IS_SYSTEM(m
))
1719 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1720 if (!valid_user_group_name(name
, VALID_USER_RELAX
))
1721 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User name invalid: %s", name
);
1723 r
= dynamic_user_lookup_name(m
, name
, &uid
);
1725 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user %s does not exist.", name
);
1729 return sd_bus_reply_method_return(message
, "u", (uint32_t) uid
);
1732 static int method_lookup_dynamic_user_by_uid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1733 _cleanup_free_
char *name
= NULL
;
1734 Manager
*m
= userdata
;
1741 assert_cc(sizeof(uid_t
) == sizeof(uint32_t));
1742 r
= sd_bus_message_read_basic(message
, 'u', &uid
);
1746 if (!MANAGER_IS_SYSTEM(m
))
1747 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1748 if (!uid_is_valid(uid
))
1749 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User ID invalid: " UID_FMT
, uid
);
1751 r
= dynamic_user_lookup_uid(m
, uid
, &name
);
1753 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user ID " UID_FMT
" does not exist.", uid
);
1757 return sd_bus_reply_method_return(message
, "s", name
);
1760 static int method_get_dynamic_users(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1761 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1762 Manager
*m
= userdata
;
1770 assert_cc(sizeof(uid_t
) == sizeof(uint32_t));
1772 if (!MANAGER_IS_SYSTEM(m
))
1773 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1775 r
= sd_bus_message_new_method_return(message
, &reply
);
1779 r
= sd_bus_message_open_container(reply
, 'a', "(us)");
1783 HASHMAP_FOREACH(d
, m
->dynamic_users
, i
) {
1786 r
= dynamic_user_current(d
, &uid
);
1787 if (r
== -EAGAIN
) /* not realized yet? */
1790 return sd_bus_error_setf(error
, SD_BUS_ERROR_FAILED
, "Failed to look up a dynamic user.");
1792 r
= sd_bus_message_append(reply
, "(us)", uid
, d
->name
);
1797 r
= sd_bus_message_close_container(reply
);
1801 return sd_bus_send(NULL
, reply
, NULL
);
1804 static int list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1805 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1806 Manager
*m
= userdata
;
1815 /* Anyone can call this method */
1817 r
= mac_selinux_access_check(message
, "status", error
);
1821 r
= sd_bus_message_new_method_return(message
, &reply
);
1825 h
= hashmap_new(&string_hash_ops
);
1829 r
= unit_file_get_list(m
->unit_file_scope
, NULL
, h
, states
, patterns
);
1833 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1837 HASHMAP_FOREACH(item
, h
, i
) {
1839 r
= sd_bus_message_append(reply
, "(ss)", item
->path
, unit_file_state_to_string(item
->state
));
1844 unit_file_list_free(h
);
1846 r
= sd_bus_message_close_container(reply
);
1850 return sd_bus_send(NULL
, reply
, NULL
);
1853 unit_file_list_free(h
);
1857 static int method_list_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1858 return list_unit_files_by_patterns(message
, userdata
, error
, NULL
, NULL
);
1861 static int method_list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1862 _cleanup_strv_free_
char **states
= NULL
;
1863 _cleanup_strv_free_
char **patterns
= NULL
;
1866 r
= sd_bus_message_read_strv(message
, &states
);
1870 r
= sd_bus_message_read_strv(message
, &patterns
);
1874 return list_unit_files_by_patterns(message
, userdata
, error
, states
, patterns
);
1877 static int method_get_unit_file_state(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1878 Manager
*m
= userdata
;
1880 UnitFileState state
;
1886 /* Anyone can call this method */
1888 r
= mac_selinux_access_check(message
, "status", error
);
1892 r
= sd_bus_message_read(message
, "s", &name
);
1896 r
= unit_file_get_state(m
->unit_file_scope
, NULL
, name
, &state
);
1900 return sd_bus_reply_method_return(message
, "s", unit_file_state_to_string(state
));
1903 static int method_get_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1904 _cleanup_free_
char *default_target
= NULL
;
1905 Manager
*m
= userdata
;
1911 /* Anyone can call this method */
1913 r
= mac_selinux_access_check(message
, "status", error
);
1917 r
= unit_file_get_default(m
->unit_file_scope
, NULL
, &default_target
);
1921 return sd_bus_reply_method_return(message
, "s", default_target
);
1924 static int send_unit_files_changed(sd_bus
*bus
, void *userdata
) {
1925 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
1930 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
1934 return sd_bus_send(bus
, message
, NULL
);
1937 /* Create an error reply, using the error information from changes[]
1938 * if possible, and fall back to generating an error from error code c.
1939 * The error message only describes the first error.
1941 * Coordinate with unit_file_dump_changes() in install.c.
1943 static int install_error(
1944 sd_bus_error
*error
,
1946 UnitFileChange
*changes
,
1952 for (i
= 0; i
< n_changes
; i
++)
1954 switch(changes
[i
].type
) {
1960 if (changes
[i
].source
)
1961 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1962 "File %s already exists and is a symlink to %s.",
1963 changes
[i
].path
, changes
[i
].source
);
1965 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1966 "File %s already exists.",
1971 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_MASKED
,
1972 "Unit file %s is masked.", changes
[i
].path
);
1975 case -EADDRNOTAVAIL
:
1976 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_GENERATED
,
1977 "Unit %s is transient or generated.", changes
[i
].path
);
1981 r
= sd_bus_error_setf(error
, BUS_ERROR_BAD_UNIT_SETTING
,
1982 "\"%s\" is not a valid unit name.",
1987 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_LINKED
,
1988 "Refusing to operate on alias name or linked unit file: %s",
1993 r
= sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
,
1994 "Unit file %s does not exist.", changes
[i
].path
);
1998 r
= sd_bus_error_set_errnof(error
, changes
[i
].type
, "File %s: %m", changes
[i
].path
);
2002 r
= c
< 0 ? c
: -EINVAL
;
2005 unit_file_changes_free(changes
, n_changes
);
2009 static int reply_unit_file_changes_and_free(
2011 sd_bus_message
*message
,
2012 int carries_install_info
,
2013 UnitFileChange
*changes
,
2015 sd_bus_error
*error
) {
2017 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
2018 bool bad
= false, good
= false;
2022 if (unit_file_changes_have_modification(changes
, n_changes
)) {
2023 r
= bus_foreach_bus(m
, NULL
, send_unit_files_changed
, NULL
);
2025 log_debug_errno(r
, "Failed to send UnitFilesChanged signal: %m");
2028 r
= sd_bus_message_new_method_return(message
, &reply
);
2032 if (carries_install_info
>= 0) {
2033 r
= sd_bus_message_append(reply
, "b", carries_install_info
);
2038 r
= sd_bus_message_open_container(reply
, 'a', "(sss)");
2042 for (i
= 0; i
< n_changes
; i
++) {
2044 if (changes
[i
].type
< 0) {
2049 r
= sd_bus_message_append(
2051 unit_file_change_type_to_string(changes
[i
].type
),
2060 /* If there was a failed change, and no successful change, then return the first failure as proper method call
2063 return install_error(error
, 0, changes
, n_changes
);
2065 r
= sd_bus_message_close_container(reply
);
2069 unit_file_changes_free(changes
, n_changes
);
2070 return sd_bus_send(NULL
, reply
, NULL
);
2073 unit_file_changes_free(changes
, n_changes
);
2077 static int method_enable_unit_files_generic(
2078 sd_bus_message
*message
,
2080 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, size_t *n_changes
),
2081 bool carries_install_info
,
2082 sd_bus_error
*error
) {
2084 _cleanup_strv_free_
char **l
= NULL
;
2085 UnitFileChange
*changes
= NULL
;
2086 size_t n_changes
= 0;
2087 UnitFileFlags flags
;
2088 int runtime
, force
, r
;
2093 r
= sd_bus_message_read_strv(message
, &l
);
2097 r
= sd_bus_message_read(message
, "bb", &runtime
, &force
);
2101 flags
= unit_file_bools_to_flags(runtime
, force
);
2103 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2107 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2109 r
= call(m
->unit_file_scope
, flags
, NULL
, l
, &changes
, &n_changes
);
2111 return install_error(error
, r
, changes
, n_changes
);
2113 return reply_unit_file_changes_and_free(m
, message
, carries_install_info
? r
: -1, changes
, n_changes
, error
);
2116 static int method_enable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2117 return method_enable_unit_files_generic(message
, userdata
, unit_file_enable
, true, error
);
2120 static int method_reenable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2121 return method_enable_unit_files_generic(message
, userdata
, unit_file_reenable
, true, error
);
2124 static int method_link_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2125 return method_enable_unit_files_generic(message
, userdata
, unit_file_link
, false, error
);
2128 static int unit_file_preset_without_mode(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char **files
, UnitFileChange
**changes
, size_t *n_changes
) {
2129 return unit_file_preset(scope
, flags
, root_dir
, files
, UNIT_FILE_PRESET_FULL
, changes
, n_changes
);
2132 static int method_preset_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2133 return method_enable_unit_files_generic(message
, userdata
, unit_file_preset_without_mode
, true, error
);
2136 static int method_mask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2137 return method_enable_unit_files_generic(message
, userdata
, unit_file_mask
, false, error
);
2140 static int method_preset_unit_files_with_mode(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2142 _cleanup_strv_free_
char **l
= NULL
;
2143 UnitFileChange
*changes
= NULL
;
2144 size_t n_changes
= 0;
2145 Manager
*m
= userdata
;
2146 UnitFilePresetMode mm
;
2147 int runtime
, force
, r
;
2148 UnitFileFlags flags
;
2154 r
= sd_bus_message_read_strv(message
, &l
);
2158 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2162 flags
= unit_file_bools_to_flags(runtime
, force
);
2165 mm
= UNIT_FILE_PRESET_FULL
;
2167 mm
= unit_file_preset_mode_from_string(mode
);
2172 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2176 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2178 r
= unit_file_preset(m
->unit_file_scope
, flags
, NULL
, l
, mm
, &changes
, &n_changes
);
2180 return install_error(error
, r
, changes
, n_changes
);
2182 return reply_unit_file_changes_and_free(m
, message
, r
, changes
, n_changes
, error
);
2185 static int method_disable_unit_files_generic(
2186 sd_bus_message
*message
,
2188 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, size_t *n_changes
),
2189 sd_bus_error
*error
) {
2191 _cleanup_strv_free_
char **l
= NULL
;
2192 UnitFileChange
*changes
= NULL
;
2193 size_t n_changes
= 0;
2199 r
= sd_bus_message_read_strv(message
, &l
);
2203 r
= sd_bus_message_read(message
, "b", &runtime
);
2207 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2211 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2213 r
= call(m
->unit_file_scope
, runtime
? UNIT_FILE_RUNTIME
: 0, NULL
, l
, &changes
, &n_changes
);
2215 return install_error(error
, r
, changes
, n_changes
);
2217 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2220 static int method_disable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2221 return method_disable_unit_files_generic(message
, userdata
, unit_file_disable
, error
);
2224 static int method_unmask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2225 return method_disable_unit_files_generic(message
, userdata
, unit_file_unmask
, error
);
2228 static int method_revert_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2229 _cleanup_strv_free_
char **l
= NULL
;
2230 UnitFileChange
*changes
= NULL
;
2231 size_t n_changes
= 0;
2232 Manager
*m
= userdata
;
2238 r
= sd_bus_message_read_strv(message
, &l
);
2242 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2246 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2248 r
= unit_file_revert(m
->unit_file_scope
, NULL
, l
, &changes
, &n_changes
);
2250 return install_error(error
, r
, changes
, n_changes
);
2252 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2255 static int method_set_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2256 UnitFileChange
*changes
= NULL
;
2257 size_t n_changes
= 0;
2258 Manager
*m
= userdata
;
2265 r
= mac_selinux_access_check(message
, "enable", error
);
2269 r
= sd_bus_message_read(message
, "sb", &name
, &force
);
2273 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2277 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2279 r
= unit_file_set_default(m
->unit_file_scope
, force
? UNIT_FILE_FORCE
: 0, NULL
, name
, &changes
, &n_changes
);
2281 return install_error(error
, r
, changes
, n_changes
);
2283 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2286 static int method_preset_all_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2287 UnitFileChange
*changes
= NULL
;
2288 size_t n_changes
= 0;
2289 Manager
*m
= userdata
;
2290 UnitFilePresetMode mm
;
2292 UnitFileFlags flags
;
2293 int force
, runtime
, r
;
2298 r
= mac_selinux_access_check(message
, "enable", error
);
2302 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2306 flags
= unit_file_bools_to_flags(runtime
, force
);
2309 mm
= UNIT_FILE_PRESET_FULL
;
2311 mm
= unit_file_preset_mode_from_string(mode
);
2316 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2320 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2322 r
= unit_file_preset_all(m
->unit_file_scope
, flags
, NULL
, mm
, &changes
, &n_changes
);
2324 return install_error(error
, r
, changes
, n_changes
);
2326 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2329 static int method_add_dependency_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2330 _cleanup_strv_free_
char **l
= NULL
;
2331 Manager
*m
= userdata
;
2332 UnitFileChange
*changes
= NULL
;
2333 size_t n_changes
= 0;
2334 int runtime
, force
, r
;
2335 char *target
, *type
;
2337 UnitFileFlags flags
;
2342 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2346 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2348 r
= sd_bus_message_read_strv(message
, &l
);
2352 r
= sd_bus_message_read(message
, "ssbb", &target
, &type
, &runtime
, &force
);
2356 flags
= unit_file_bools_to_flags(runtime
, force
);
2358 dep
= unit_dependency_from_string(type
);
2362 r
= unit_file_add_dependency(m
->unit_file_scope
, flags
, NULL
, l
, target
, dep
, &changes
, &n_changes
);
2364 return install_error(error
, r
, changes
, n_changes
);
2366 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2369 static int method_get_unit_file_links(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2370 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
2371 UnitFileChange
*changes
= NULL
;
2372 size_t n_changes
= 0, i
;
2373 UnitFileFlags flags
;
2378 r
= sd_bus_message_read(message
, "sb", &name
, &runtime
);
2382 r
= sd_bus_message_new_method_return(message
, &reply
);
2386 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_ARRAY
, "s");
2390 p
= STRV_MAKE(name
);
2391 flags
= UNIT_FILE_DRY_RUN
|
2392 (runtime
? UNIT_FILE_RUNTIME
: 0);
2394 r
= unit_file_disable(UNIT_FILE_SYSTEM
, flags
, NULL
, p
, &changes
, &n_changes
);
2396 return log_error_errno(r
, "Failed to get file links for %s: %m", name
);
2398 for (i
= 0; i
< n_changes
; i
++)
2399 if (changes
[i
].type
== UNIT_FILE_UNLINK
) {
2400 r
= sd_bus_message_append(reply
, "s", changes
[i
].path
);
2405 r
= sd_bus_message_close_container(reply
);
2409 return sd_bus_send(NULL
, reply
, NULL
);
2412 static int method_get_job_waiting(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2413 Manager
*m
= userdata
;
2421 r
= sd_bus_message_read(message
, "u", &id
);
2425 j
= manager_get_job(m
, id
);
2427 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
2429 return bus_job_method_get_waiting_jobs(message
, j
, error
);
2432 static int method_abandon_scope(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2433 Manager
*m
= userdata
;
2441 r
= sd_bus_message_read(message
, "s", &name
);
2445 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
2449 if (u
->type
!= UNIT_SCOPE
)
2450 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unit '%s' is not a scope unit, refusing.", name
);
2452 return bus_scope_method_abandon(message
, u
, error
);
2455 const sd_bus_vtable bus_manager_vtable
[] = {
2456 SD_BUS_VTABLE_START(0),
2458 SD_BUS_PROPERTY("Version", "s", property_get_version
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2459 SD_BUS_PROPERTY("Features", "s", property_get_features
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2460 SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2461 SD_BUS_PROPERTY("Architecture", "s", property_get_architecture
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2462 SD_BUS_PROPERTY("Tainted", "s", property_get_tainted
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2463 BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_FIRMWARE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2464 BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_LOADER
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2465 BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_KERNEL
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2466 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_INITRD
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2467 BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_USERSPACE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2468 BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2469 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_SECURITY_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2470 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_SECURITY_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2471 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_GENERATORS_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2472 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_GENERATORS_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2473 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_UNITS_LOAD_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2474 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_UNITS_LOAD_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2475 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDSecurityStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_INITRD_SECURITY_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2476 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDSecurityFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_INITRD_SECURITY_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2477 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_INITRD_GENERATORS_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2478 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_INITRD_GENERATORS_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2479 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2480 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2481 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level
, property_set_log_level
, 0, 0),
2482 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target
, property_set_log_target
, 0, 0),
2483 SD_BUS_PROPERTY("NNames", "u", property_get_hashmap_size
, offsetof(Manager
, units
), 0),
2484 SD_BUS_PROPERTY("NFailedUnits", "u", property_get_set_size
, offsetof(Manager
, failed_units
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
2485 SD_BUS_PROPERTY("NJobs", "u", property_get_hashmap_size
, offsetof(Manager
, jobs
), 0),
2486 SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_installed_jobs
), 0),
2487 SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_failed_jobs
), 0),
2488 SD_BUS_PROPERTY("Progress", "d", property_get_progress
, 0, 0),
2489 SD_BUS_PROPERTY("Environment", "as", property_get_environment
, 0, 0),
2490 SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool
, offsetof(Manager
, confirm_spawn
), SD_BUS_VTABLE_PROPERTY_CONST
),
2491 SD_BUS_PROPERTY("ShowStatus", "b", property_get_show_status
, 0, 0),
2492 SD_BUS_PROPERTY("UnitPath", "as", NULL
, offsetof(Manager
, lookup_paths
.search_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
2493 SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2494 SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2495 SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", property_get_runtime_watchdog
, property_set_runtime_watchdog
, 0, 0),
2496 SD_BUS_WRITABLE_PROPERTY("RebootWatchdogUSec", "t", property_get_reboot_watchdog
, property_set_reboot_watchdog
, 0, 0),
2497 /* The following item is an obsolete alias */
2498 SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", property_get_reboot_watchdog
, property_set_reboot_watchdog
, 0, SD_BUS_VTABLE_HIDDEN
),
2499 SD_BUS_WRITABLE_PROPERTY("KExecWatchdogUSec", "t", property_get_kexec_watchdog
, property_set_kexec_watchdog
, 0, 0),
2500 SD_BUS_WRITABLE_PROPERTY("ServiceWatchdogs", "b", bus_property_get_bool
, bus_property_set_bool
, offsetof(Manager
, service_watchdogs
), 0),
2501 SD_BUS_PROPERTY("ControlGroup", "s", NULL
, offsetof(Manager
, cgroup_root
), 0),
2502 SD_BUS_PROPERTY("SystemState", "s", property_get_system_state
, 0, 0),
2503 SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned
, offsetof(Manager
, return_value
), 0),
2504 SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timer_accuracy_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2505 SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_start_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2506 SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_stop_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2507 SD_BUS_PROPERTY("DefaultTimeoutAbortUSec", "t", property_get_default_timeout_abort_usec
, 0, 0),
2508 SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_restart_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2509 SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
),
2510 /* The following two items are obsolete alias */
2511 SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
2512 SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
2513 SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned
, offsetof(Manager
, default_start_limit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
2514 SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_cpu_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2515 SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_blockio_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2516 SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_memory_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2517 SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_tasks_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2518 SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2519 SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2520 SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2521 SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2522 SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2523 SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2524 SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2525 SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2526 SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2527 SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2528 SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2529 SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2530 SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2531 SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2532 SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2533 SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2534 SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2535 SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2536 SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2537 SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2538 SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2539 SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2540 SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2541 SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2542 SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2543 SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2544 SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2545 SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2546 SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2547 SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2548 SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2549 SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2550 SD_BUS_PROPERTY("DefaultTasksMax", "t", bus_property_get_tasks_max
, offsetof(Manager
, default_tasks_max
), 0),
2551 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2552 SD_BUS_PROPERTY("DefaultOOMPolicy", "s", bus_property_get_oom_policy
, offsetof(Manager
, default_oom_policy
), SD_BUS_VTABLE_PROPERTY_CONST
),
2554 SD_BUS_METHOD_WITH_NAMES("GetUnit",
2560 SD_BUS_VTABLE_UNPRIVILEGED
),
2561 SD_BUS_METHOD_WITH_NAMES("GetUnitByPID",
2566 method_get_unit_by_pid
,
2567 SD_BUS_VTABLE_UNPRIVILEGED
),
2568 SD_BUS_METHOD_WITH_NAMES("GetUnitByInvocationID",
2570 SD_BUS_PARAM(invocation_id
),
2573 method_get_unit_by_invocation_id
,
2574 SD_BUS_VTABLE_UNPRIVILEGED
),
2575 SD_BUS_METHOD_WITH_NAMES("GetUnitByControlGroup",
2577 SD_BUS_PARAM(cgroup
),
2580 method_get_unit_by_control_group
,
2581 SD_BUS_VTABLE_UNPRIVILEGED
),
2582 SD_BUS_METHOD_WITH_NAMES("LoadUnit",
2588 SD_BUS_VTABLE_UNPRIVILEGED
),
2589 SD_BUS_METHOD_WITH_NAMES("StartUnit",
2596 SD_BUS_VTABLE_UNPRIVILEGED
),
2597 SD_BUS_METHOD_WITH_NAMES("StartUnitReplace",
2599 SD_BUS_PARAM(old_unit
)
2600 SD_BUS_PARAM(new_unit
)
2604 method_start_unit_replace
,
2605 SD_BUS_VTABLE_UNPRIVILEGED
),
2606 SD_BUS_METHOD_WITH_NAMES("StopUnit",
2613 SD_BUS_VTABLE_UNPRIVILEGED
),
2614 SD_BUS_METHOD_WITH_NAMES("ReloadUnit",
2621 SD_BUS_VTABLE_UNPRIVILEGED
),
2622 SD_BUS_METHOD_WITH_NAMES("RestartUnit",
2628 method_restart_unit
,
2629 SD_BUS_VTABLE_UNPRIVILEGED
),
2630 SD_BUS_METHOD_WITH_NAMES("TryRestartUnit",
2636 method_try_restart_unit
,
2637 SD_BUS_VTABLE_UNPRIVILEGED
),
2638 SD_BUS_METHOD_WITH_NAMES("ReloadOrRestartUnit",
2644 method_reload_or_restart_unit
,
2645 SD_BUS_VTABLE_UNPRIVILEGED
),
2646 SD_BUS_METHOD_WITH_NAMES("ReloadOrTryRestartUnit",
2652 method_reload_or_try_restart_unit
,
2653 SD_BUS_VTABLE_UNPRIVILEGED
),
2654 SD_BUS_METHOD_WITH_NAMES("EnqueueUnitJob",
2657 SD_BUS_PARAM(job_type
)
2658 SD_BUS_PARAM(job_mode
),
2660 SD_BUS_PARAM(job_id
)
2661 SD_BUS_PARAM(job_path
)
2662 SD_BUS_PARAM(unit_id
)
2663 SD_BUS_PARAM(unit_path
)
2664 SD_BUS_PARAM(job_type
)
2665 SD_BUS_PARAM(affected_jobs
),
2666 method_enqueue_unit_job
,
2667 SD_BUS_VTABLE_UNPRIVILEGED
),
2668 SD_BUS_METHOD_WITH_NAMES("KillUnit",
2672 SD_BUS_PARAM(signal
),
2675 SD_BUS_VTABLE_UNPRIVILEGED
),
2676 SD_BUS_METHOD_WITH_NAMES("CleanUnit",
2682 SD_BUS_VTABLE_UNPRIVILEGED
),
2683 SD_BUS_METHOD_WITH_NAMES("FreezeUnit",
2688 SD_BUS_VTABLE_UNPRIVILEGED
),
2689 SD_BUS_METHOD_WITH_NAMES("ThawUnit",
2694 SD_BUS_VTABLE_UNPRIVILEGED
),
2695 SD_BUS_METHOD_WITH_NAMES("ResetFailedUnit",
2699 method_reset_failed_unit
,
2700 SD_BUS_VTABLE_UNPRIVILEGED
),
2701 SD_BUS_METHOD_WITH_NAMES("SetUnitProperties",
2704 SD_BUS_PARAM(runtime
)
2705 SD_BUS_PARAM(properties
),
2707 method_set_unit_properties
,
2708 SD_BUS_VTABLE_UNPRIVILEGED
),
2709 SD_BUS_METHOD_WITH_NAMES("RefUnit",
2714 SD_BUS_VTABLE_UNPRIVILEGED
),
2715 SD_BUS_METHOD_WITH_NAMES("UnrefUnit",
2720 SD_BUS_VTABLE_UNPRIVILEGED
),
2721 SD_BUS_METHOD_WITH_NAMES("StartTransientUnit",
2725 SD_BUS_PARAM(properties
)
2729 method_start_transient_unit
,
2730 SD_BUS_VTABLE_UNPRIVILEGED
),
2731 SD_BUS_METHOD_WITH_NAMES("GetUnitProcesses",
2735 SD_BUS_PARAM(processes
),
2736 method_get_unit_processes
,
2737 SD_BUS_VTABLE_UNPRIVILEGED
),
2738 SD_BUS_METHOD_WITH_NAMES("AttachProcessesToUnit",
2740 SD_BUS_PARAM(unit_name
)
2741 SD_BUS_PARAM(subcgroup
)
2744 method_attach_processes_to_unit
,
2745 SD_BUS_VTABLE_UNPRIVILEGED
),
2746 SD_BUS_METHOD_WITH_NAMES("AbandonScope",
2750 method_abandon_scope
,
2751 SD_BUS_VTABLE_UNPRIVILEGED
),
2752 SD_BUS_METHOD_WITH_NAMES("GetJob",
2758 SD_BUS_VTABLE_UNPRIVILEGED
),
2759 SD_BUS_METHOD_WITH_NAMES("GetJobAfter",
2764 method_get_job_waiting
,
2765 SD_BUS_VTABLE_UNPRIVILEGED
),
2766 SD_BUS_METHOD_WITH_NAMES("GetJobBefore",
2771 method_get_job_waiting
,
2772 SD_BUS_VTABLE_UNPRIVILEGED
),
2773 SD_BUS_METHOD_WITH_NAMES("CancelJob",
2778 SD_BUS_VTABLE_UNPRIVILEGED
),
2779 SD_BUS_METHOD("ClearJobs",
2783 SD_BUS_VTABLE_UNPRIVILEGED
),
2784 SD_BUS_METHOD("ResetFailed",
2787 method_reset_failed
,
2788 SD_BUS_VTABLE_UNPRIVILEGED
),
2789 SD_BUS_METHOD_WITH_NAMES("ListUnits",
2792 SD_BUS_PARAM(units
),
2794 SD_BUS_VTABLE_UNPRIVILEGED
),
2795 SD_BUS_METHOD_WITH_NAMES("ListUnitsFiltered",
2797 SD_BUS_PARAM(states
),
2799 SD_BUS_PARAM(units
),
2800 method_list_units_filtered
,
2801 SD_BUS_VTABLE_UNPRIVILEGED
),
2802 SD_BUS_METHOD_WITH_NAMES("ListUnitsByPatterns",
2804 SD_BUS_PARAM(states
)
2805 SD_BUS_PARAM(patterns
),
2807 SD_BUS_PARAM(units
),
2808 method_list_units_by_patterns
,
2809 SD_BUS_VTABLE_UNPRIVILEGED
),
2810 SD_BUS_METHOD_WITH_NAMES("ListUnitsByNames",
2812 SD_BUS_PARAM(names
),
2814 SD_BUS_PARAM(units
),
2815 method_list_units_by_names
,
2816 SD_BUS_VTABLE_UNPRIVILEGED
),
2817 SD_BUS_METHOD_WITH_NAMES("ListJobs",
2822 SD_BUS_VTABLE_UNPRIVILEGED
),
2823 SD_BUS_METHOD("Subscribe",
2827 SD_BUS_VTABLE_UNPRIVILEGED
),
2828 SD_BUS_METHOD("Unsubscribe",
2832 SD_BUS_VTABLE_UNPRIVILEGED
),
2833 SD_BUS_METHOD_WITH_NAMES("Dump",
2836 SD_BUS_PARAM(output
),
2838 SD_BUS_VTABLE_UNPRIVILEGED
),
2839 SD_BUS_METHOD_WITH_NAMES("DumpByFileDescriptor",
2844 SD_BUS_VTABLE_UNPRIVILEGED
),
2845 SD_BUS_METHOD_WITH_NAMES("CreateSnapshot",
2848 SD_BUS_PARAM(cleanup
),
2851 method_refuse_snapshot
,
2852 SD_BUS_VTABLE_UNPRIVILEGED
|SD_BUS_VTABLE_HIDDEN
),
2853 SD_BUS_METHOD_WITH_NAMES("RemoveSnapshot",
2857 method_refuse_snapshot
,
2858 SD_BUS_VTABLE_UNPRIVILEGED
|SD_BUS_VTABLE_HIDDEN
),
2859 SD_BUS_METHOD("Reload",
2863 SD_BUS_VTABLE_UNPRIVILEGED
),
2864 SD_BUS_METHOD("Reexecute",
2868 SD_BUS_VTABLE_UNPRIVILEGED
),
2869 SD_BUS_METHOD("Exit",
2874 SD_BUS_METHOD("Reboot",
2878 SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2879 SD_BUS_METHOD("PowerOff",
2883 SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2884 SD_BUS_METHOD("Halt",
2888 SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2889 SD_BUS_METHOD("KExec",
2893 SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2894 SD_BUS_METHOD_WITH_NAMES("SwitchRoot",
2896 SD_BUS_PARAM(new_root
)
2900 SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2901 SD_BUS_METHOD_WITH_NAMES("SetEnvironment",
2903 SD_BUS_PARAM(assignments
),
2905 method_set_environment
,
2906 SD_BUS_VTABLE_UNPRIVILEGED
),
2907 SD_BUS_METHOD_WITH_NAMES("UnsetEnvironment",
2909 SD_BUS_PARAM(names
),
2911 method_unset_environment
,
2912 SD_BUS_VTABLE_UNPRIVILEGED
),
2913 SD_BUS_METHOD_WITH_NAMES("UnsetAndSetEnvironment",
2916 SD_BUS_PARAM(assignments
),
2918 method_unset_and_set_environment
,
2919 SD_BUS_VTABLE_UNPRIVILEGED
),
2920 SD_BUS_METHOD_WITH_NAMES("ListUnitFiles",
2923 SD_BUS_PARAM(unit_files
),
2924 method_list_unit_files
,
2925 SD_BUS_VTABLE_UNPRIVILEGED
),
2926 SD_BUS_METHOD_WITH_NAMES("ListUnitFilesByPatterns",
2928 SD_BUS_PARAM(states
)
2929 SD_BUS_PARAM(patterns
),
2931 SD_BUS_PARAM(unit_files
),
2932 method_list_unit_files_by_patterns
,
2933 SD_BUS_VTABLE_UNPRIVILEGED
),
2934 SD_BUS_METHOD_WITH_NAMES("GetUnitFileState",
2938 SD_BUS_PARAM(state
),
2939 method_get_unit_file_state
,
2940 SD_BUS_VTABLE_UNPRIVILEGED
),
2941 SD_BUS_METHOD_WITH_NAMES("EnableUnitFiles",
2944 SD_BUS_PARAM(runtime
)
2945 SD_BUS_PARAM(force
),
2947 SD_BUS_PARAM(carries_install_info
)
2948 SD_BUS_PARAM(changes
),
2949 method_enable_unit_files
,
2950 SD_BUS_VTABLE_UNPRIVILEGED
),
2951 SD_BUS_METHOD_WITH_NAMES("DisableUnitFiles",
2954 SD_BUS_PARAM(runtime
),
2956 SD_BUS_PARAM(changes
),
2957 method_disable_unit_files
,
2958 SD_BUS_VTABLE_UNPRIVILEGED
),
2959 SD_BUS_METHOD_WITH_NAMES("ReenableUnitFiles",
2962 SD_BUS_PARAM(runtime
)
2963 SD_BUS_PARAM(force
),
2965 SD_BUS_PARAM(carries_install_info
)
2966 SD_BUS_PARAM(changes
),
2967 method_reenable_unit_files
,
2968 SD_BUS_VTABLE_UNPRIVILEGED
),
2969 SD_BUS_METHOD_WITH_NAMES("LinkUnitFiles",
2972 SD_BUS_PARAM(runtime
)
2973 SD_BUS_PARAM(force
),
2975 SD_BUS_PARAM(changes
),
2976 method_link_unit_files
,
2977 SD_BUS_VTABLE_UNPRIVILEGED
),
2978 SD_BUS_METHOD_WITH_NAMES("PresetUnitFiles",
2981 SD_BUS_PARAM(runtime
)
2982 SD_BUS_PARAM(force
),
2984 SD_BUS_PARAM(carries_install_info
)
2985 SD_BUS_PARAM(changes
),
2986 method_preset_unit_files
,
2987 SD_BUS_VTABLE_UNPRIVILEGED
),
2988 SD_BUS_METHOD_WITH_NAMES("PresetUnitFilesWithMode",
2992 SD_BUS_PARAM(runtime
)
2993 SD_BUS_PARAM(force
),
2995 SD_BUS_PARAM(carries_install_info
)
2996 SD_BUS_PARAM(changes
),
2997 method_preset_unit_files_with_mode
,
2998 SD_BUS_VTABLE_UNPRIVILEGED
),
2999 SD_BUS_METHOD_WITH_NAMES("MaskUnitFiles",
3002 SD_BUS_PARAM(runtime
)
3003 SD_BUS_PARAM(force
),
3005 SD_BUS_PARAM(changes
),
3006 method_mask_unit_files
,
3007 SD_BUS_VTABLE_UNPRIVILEGED
),
3008 SD_BUS_METHOD_WITH_NAMES("UnmaskUnitFiles",
3011 SD_BUS_PARAM(runtime
),
3013 SD_BUS_PARAM(changes
),
3014 method_unmask_unit_files
,
3015 SD_BUS_VTABLE_UNPRIVILEGED
),
3016 SD_BUS_METHOD_WITH_NAMES("RevertUnitFiles",
3018 SD_BUS_PARAM(files
),
3020 SD_BUS_PARAM(changes
),
3021 method_revert_unit_files
,
3022 SD_BUS_VTABLE_UNPRIVILEGED
),
3023 SD_BUS_METHOD_WITH_NAMES("SetDefaultTarget",
3026 SD_BUS_PARAM(force
),
3028 SD_BUS_PARAM(changes
),
3029 method_set_default_target
,
3030 SD_BUS_VTABLE_UNPRIVILEGED
),
3031 SD_BUS_METHOD_WITH_NAMES("GetDefaultTarget",
3035 method_get_default_target
,
3036 SD_BUS_VTABLE_UNPRIVILEGED
),
3037 SD_BUS_METHOD_WITH_NAMES("PresetAllUnitFiles",
3040 SD_BUS_PARAM(runtime
)
3041 SD_BUS_PARAM(force
),
3043 SD_BUS_PARAM(changes
),
3044 method_preset_all_unit_files
,
3045 SD_BUS_VTABLE_UNPRIVILEGED
),
3046 SD_BUS_METHOD_WITH_NAMES("AddDependencyUnitFiles",
3049 SD_BUS_PARAM(target
)
3051 SD_BUS_PARAM(runtime
)
3052 SD_BUS_PARAM(force
),
3054 SD_BUS_PARAM(changes
),
3055 method_add_dependency_unit_files
,
3056 SD_BUS_VTABLE_UNPRIVILEGED
),
3057 SD_BUS_METHOD_WITH_NAMES("GetUnitFileLinks",
3060 SD_BUS_PARAM(runtime
),
3062 SD_BUS_PARAM(links
),
3063 method_get_unit_file_links
,
3064 SD_BUS_VTABLE_UNPRIVILEGED
),
3065 SD_BUS_METHOD_WITH_NAMES("SetExitCode",
3067 SD_BUS_PARAM(number
),
3069 method_set_exit_code
,
3070 SD_BUS_VTABLE_UNPRIVILEGED
),
3071 SD_BUS_METHOD_WITH_NAMES("LookupDynamicUserByName",
3076 method_lookup_dynamic_user_by_name
,
3077 SD_BUS_VTABLE_UNPRIVILEGED
),
3078 SD_BUS_METHOD_WITH_NAMES("LookupDynamicUserByUID",
3083 method_lookup_dynamic_user_by_uid
,
3084 SD_BUS_VTABLE_UNPRIVILEGED
),
3085 SD_BUS_METHOD_WITH_NAMES("GetDynamicUsers",
3088 SD_BUS_PARAM(users
),
3089 method_get_dynamic_users
,
3090 SD_BUS_VTABLE_UNPRIVILEGED
),
3092 SD_BUS_SIGNAL_WITH_NAMES("UnitNew",
3097 SD_BUS_SIGNAL_WITH_NAMES("UnitRemoved",
3102 SD_BUS_SIGNAL_WITH_NAMES("JobNew",
3108 SD_BUS_SIGNAL_WITH_NAMES("JobRemoved",
3113 SD_BUS_PARAM(result
),
3115 SD_BUS_SIGNAL_WITH_NAMES("StartupFinished",
3117 SD_BUS_PARAM(firmware
)
3118 SD_BUS_PARAM(loader
)
3119 SD_BUS_PARAM(kernel
)
3120 SD_BUS_PARAM(initrd
)
3121 SD_BUS_PARAM(userspace
)
3122 SD_BUS_PARAM(total
),
3124 SD_BUS_SIGNAL("UnitFilesChanged", NULL
, 0),
3125 SD_BUS_SIGNAL_WITH_NAMES("Reloading",
3127 SD_BUS_PARAM(active
),
3133 const sd_bus_vtable bus_manager_log_control_vtable
[] = {
3134 SD_BUS_VTABLE_START(0),
3136 /* We define a private version of this interface here, since we want slightly different
3137 * implementations for the setters. We'll still use the generic getters however, and we share the
3138 * setters with the implementations for the Manager interface above (which pre-dates the generic
3139 * service API interface). */
3141 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level
, property_set_log_level
, 0, 0),
3142 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target
, property_set_log_target
, 0, 0),
3143 SD_BUS_PROPERTY("SyslogIdentifier", "s", bus_property_get_syslog_identifier
, 0, 0),
3148 static int send_finished(sd_bus
*bus
, void *userdata
) {
3149 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
3150 usec_t
*times
= userdata
;
3156 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
3160 r
= sd_bus_message_append(message
, "tttttt", times
[0], times
[1], times
[2], times
[3], times
[4], times
[5]);
3164 return sd_bus_send(bus
, message
, NULL
);
3167 void bus_manager_send_finished(
3169 usec_t firmware_usec
,
3173 usec_t userspace_usec
,
3174 usec_t total_usec
) {
3180 r
= bus_foreach_bus(
3193 log_debug_errno(r
, "Failed to send finished signal: %m");
3196 static int send_reloading(sd_bus
*bus
, void *userdata
) {
3197 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
3202 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
3206 r
= sd_bus_message_append(message
, "b", PTR_TO_INT(userdata
));
3210 return sd_bus_send(bus
, message
, NULL
);
3213 void bus_manager_send_reloading(Manager
*m
, bool active
) {
3218 r
= bus_foreach_bus(m
, NULL
, send_reloading
, INT_TO_PTR(active
));
3220 log_debug_errno(r
, "Failed to send reloading signal: %m");
3223 static int send_changed_signal(sd_bus
*bus
, void *userdata
) {
3226 return sd_bus_emit_properties_changed_strv(bus
,
3227 "/org/freedesktop/systemd1",
3228 "org.freedesktop.systemd1.Manager",
3232 void bus_manager_send_change_signal(Manager
*m
) {
3237 r
= bus_foreach_bus(m
, NULL
, send_changed_signal
, NULL
);
3239 log_debug_errno(r
, "Failed to send manager change signal: %m");