1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
10 #include <sys/statvfs.h>
13 #include "alloc-util.h"
14 #include "architecture.h"
16 #include "bus-common-errors.h"
17 #include "dbus-execute.h"
19 #include "dbus-manager.h"
20 #include "dbus-unit.h"
25 #include "format-util.h"
30 #include "parse-util.h"
31 #include "path-util.h"
32 #include "selinux-access.h"
33 #include "stat-util.h"
34 #include "string-util.h"
36 #include "syslog-util.h"
37 #include "user-util.h"
41 /* Require 16MiB free in /run/systemd for reloading/reexecing. After all we need to serialize our state there, and if
42 * we can't we'll fail badly. */
43 #define RELOAD_DISK_SPACE_MIN (UINT64_C(16) * UINT64_C(1024) * UINT64_C(1024))
45 static UnitFileFlags
unit_file_bools_to_flags(bool runtime
, bool force
) {
46 return (runtime
? UNIT_FILE_RUNTIME
: 0) |
47 (force
? UNIT_FILE_FORCE
: 0);
50 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_version
, "s", PACKAGE_VERSION
);
51 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_features
, "s", SYSTEMD_FEATURES
);
52 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_architecture
, "s", architecture_to_string(uname_architecture()));
53 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_log_target
, "s", log_target_to_string(log_get_target()));
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
);
59 static int property_get_virtualization(
62 const char *interface
,
64 sd_bus_message
*reply
,
66 sd_bus_error
*error
) {
73 v
= detect_virtualization();
75 /* Make sure to return the empty string when we detect no virtualization, as that is the API.
77 * https://github.com/systemd/systemd/issues/1423
80 return sd_bus_message_append(
82 v
== VIRTUALIZATION_NONE
? NULL
: virtualization_to_string(v
));
85 static int property_get_tainted(
88 const char *interface
,
90 sd_bus_message
*reply
,
92 sd_bus_error
*error
) {
94 _cleanup_free_
char *s
= NULL
;
95 Manager
*m
= userdata
;
101 s
= manager_taint_string(m
);
105 return sd_bus_message_append(reply
, "s", s
);
108 static int property_set_log_target(
111 const char *interface
,
112 const char *property
,
113 sd_bus_message
*value
,
115 sd_bus_error
*error
) {
123 r
= sd_bus_message_read(value
, "s", &t
);
127 return log_set_target_from_string(t
);
130 static int property_get_log_level(
133 const char *interface
,
134 const char *property
,
135 sd_bus_message
*reply
,
137 sd_bus_error
*error
) {
139 _cleanup_free_
char *t
= NULL
;
145 r
= log_level_to_string_alloc(log_get_max_level(), &t
);
149 return sd_bus_message_append(reply
, "s", t
);
152 static int property_set_log_level(
155 const char *interface
,
156 const char *property
,
157 sd_bus_message
*value
,
159 sd_bus_error
*error
) {
161 Manager
*m
= userdata
;
168 r
= sd_bus_message_read(value
, "s", &t
);
173 manager_restore_original_log_level(m
);
177 level
= log_level_from_string(t
);
179 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid log level '%s'", t
);
181 manager_override_log_level(m
, level
);
187 static int property_get_progress(
190 const char *interface
,
191 const char *property
,
192 sd_bus_message
*reply
,
194 sd_bus_error
*error
) {
196 Manager
*m
= userdata
;
203 if (MANAGER_IS_FINISHED(m
))
206 d
= 1.0 - ((double) hashmap_size(m
->jobs
) / (double) m
->n_installed_jobs
);
208 return sd_bus_message_append(reply
, "d", d
);
211 static int property_get_show_status(
214 const char *interface
,
215 const char *property
,
216 sd_bus_message
*reply
,
218 sd_bus_error
*error
) {
220 Manager
*m
= userdata
;
227 b
= m
->show_status
> 0;
228 return sd_bus_message_append_basic(reply
, 'b', &b
);
231 static int property_set_runtime_watchdog(
234 const char *interface
,
235 const char *property
,
236 sd_bus_message
*value
,
238 sd_bus_error
*error
) {
240 usec_t
*t
= userdata
;
246 assert_cc(sizeof(usec_t
) == sizeof(uint64_t));
248 r
= sd_bus_message_read(value
, "t", t
);
252 return watchdog_set_timeout(t
);
255 static int bus_get_unit_by_name(Manager
*m
, sd_bus_message
*message
, const char *name
, Unit
**ret_unit
, sd_bus_error
*error
) {
263 /* More or less a wrapper around manager_get_unit() that generates nice errors and has one trick up its sleeve:
264 * if the name is specified empty we use the client's unit. */
267 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
270 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
274 r
= sd_bus_creds_get_pid(creds
, &pid
);
278 u
= manager_get_unit_by_pid(m
, pid
);
280 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
282 u
= manager_get_unit(m
, name
);
284 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s not loaded.", name
);
291 static int bus_load_unit_by_name(Manager
*m
, sd_bus_message
*message
, const char *name
, Unit
**ret_unit
, sd_bus_error
*error
) {
296 /* Pretty much the same as bus_get_unit_by_name(), but we also load the unit if necessary. */
299 return bus_get_unit_by_name(m
, message
, name
, ret_unit
, error
);
301 return manager_load_unit(m
, name
, NULL
, error
, ret_unit
);
304 static int method_get_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
305 _cleanup_free_
char *path
= NULL
;
306 Manager
*m
= userdata
;
314 /* Anyone can call this method */
316 r
= sd_bus_message_read(message
, "s", &name
);
320 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
324 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
328 path
= unit_dbus_path(u
);
332 return sd_bus_reply_method_return(message
, "o", path
);
335 static int method_get_unit_by_pid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
336 _cleanup_free_
char *path
= NULL
;
337 Manager
*m
= userdata
;
345 assert_cc(sizeof(pid_t
) == sizeof(uint32_t));
347 /* Anyone can call this method */
349 r
= sd_bus_message_read(message
, "u", &pid
);
353 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PID " PID_FMT
, pid
);
356 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
358 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
362 r
= sd_bus_creds_get_pid(creds
, &pid
);
367 u
= manager_get_unit_by_pid(m
, pid
);
369 return sd_bus_error_setf(error
, BUS_ERROR_NO_UNIT_FOR_PID
, "PID "PID_FMT
" does not belong to any loaded unit.", pid
);
371 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
375 path
= unit_dbus_path(u
);
379 return sd_bus_reply_method_return(message
, "o", path
);
382 static int method_get_unit_by_invocation_id(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
383 _cleanup_free_
char *path
= NULL
;
384 Manager
*m
= userdata
;
394 /* Anyone can call this method */
396 r
= sd_bus_message_read_array(message
, 'y', &a
, &sz
);
404 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid invocation ID");
406 if (sd_id128_is_null(id
)) {
407 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
410 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
414 r
= sd_bus_creds_get_pid(creds
, &pid
);
418 u
= manager_get_unit_by_pid(m
, pid
);
420 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client " PID_FMT
" not member of any unit.", pid
);
422 u
= hashmap_get(m
->units_by_invocation_id
, &id
);
424 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
));
427 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
431 /* So here's a special trick: the bus path we return actually references the unit by its invocation ID instead
432 * of the unit name. This means it stays valid only as long as the invocation ID stays the same. */
433 path
= unit_dbus_path_invocation_id(u
);
437 return sd_bus_reply_method_return(message
, "o", path
);
440 static int method_get_unit_by_control_group(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
441 _cleanup_free_
char *path
= NULL
;
442 Manager
*m
= userdata
;
447 r
= sd_bus_message_read(message
, "s", &cgroup
);
451 u
= manager_get_unit_by_cgroup(m
, cgroup
);
453 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Control group '%s' is not valid or not managed by this instance", cgroup
);
455 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
459 path
= unit_dbus_path(u
);
463 return sd_bus_reply_method_return(message
, "o", path
);
466 static int method_load_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
467 _cleanup_free_
char *path
= NULL
;
468 Manager
*m
= userdata
;
476 /* Anyone can call this method */
478 r
= sd_bus_message_read(message
, "s", &name
);
482 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
486 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
490 path
= unit_dbus_path(u
);
494 return sd_bus_reply_method_return(message
, "o", path
);
497 static int method_start_unit_generic(sd_bus_message
*message
, Manager
*m
, JobType job_type
, bool reload_if_possible
, sd_bus_error
*error
) {
505 r
= sd_bus_message_read(message
, "s", &name
);
509 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
513 return bus_unit_method_start_generic(message
, u
, job_type
, reload_if_possible
, error
);
516 static int method_start_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
517 return method_start_unit_generic(message
, userdata
, JOB_START
, false, error
);
520 static int method_stop_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
521 return method_start_unit_generic(message
, userdata
, JOB_STOP
, false, error
);
524 static int method_reload_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
525 return method_start_unit_generic(message
, userdata
, JOB_RELOAD
, false, error
);
528 static int method_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
529 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, false, error
);
532 static int method_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
533 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, false, error
);
536 static int method_reload_or_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
537 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, true, error
);
540 static int method_reload_or_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
541 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, true, error
);
544 static int method_start_unit_replace(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
545 Manager
*m
= userdata
;
546 const char *old_name
;
553 r
= sd_bus_message_read(message
, "s", &old_name
);
557 r
= bus_get_unit_by_name(m
, message
, old_name
, &u
, error
);
560 if (!u
->job
|| u
->job
->type
!= JOB_START
)
561 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "No job queued for unit %s", old_name
);
563 return method_start_unit_generic(message
, m
, JOB_START
, false, error
);
566 static int method_kill_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
567 Manager
*m
= userdata
;
575 r
= sd_bus_message_read(message
, "s", &name
);
579 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
583 return bus_unit_method_kill(message
, u
, error
);
586 static int method_reset_failed_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
587 Manager
*m
= userdata
;
595 r
= sd_bus_message_read(message
, "s", &name
);
599 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
603 return bus_unit_method_reset_failed(message
, u
, error
);
606 static int method_set_unit_properties(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
607 Manager
*m
= userdata
;
615 r
= sd_bus_message_read(message
, "s", &name
);
619 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
623 r
= bus_unit_validate_load_state(u
, error
);
627 return bus_unit_method_set_properties(message
, u
, error
);
630 static int method_ref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
631 Manager
*m
= userdata
;
639 r
= sd_bus_message_read(message
, "s", &name
);
643 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
647 r
= bus_unit_validate_load_state(u
, error
);
651 return bus_unit_method_ref(message
, u
, error
);
654 static int method_unref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
655 Manager
*m
= userdata
;
663 r
= sd_bus_message_read(message
, "s", &name
);
667 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
671 r
= bus_unit_validate_load_state(u
, error
);
675 return bus_unit_method_unref(message
, u
, error
);
678 static int reply_unit_info(sd_bus_message
*reply
, Unit
*u
) {
679 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
682 following
= unit_following(u
);
684 unit_path
= unit_dbus_path(u
);
689 job_path
= job_dbus_path(u
->job
);
694 return sd_bus_message_append(
695 reply
, "(ssssssouso)",
698 unit_load_state_to_string(u
->load_state
),
699 unit_active_state_to_string(unit_active_state(u
)),
700 unit_sub_state_to_string(u
),
701 following
? following
->id
: "",
703 u
->job
? u
->job
->id
: 0,
704 u
->job
? job_type_to_string(u
->job
->type
) : "",
705 job_path
? job_path
: "/");
708 static int method_list_units_by_names(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
709 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
710 Manager
*m
= userdata
;
713 _cleanup_strv_free_
char **units
= NULL
;
718 r
= sd_bus_message_read_strv(message
, &units
);
722 r
= sd_bus_message_new_method_return(message
, &reply
);
726 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
730 STRV_FOREACH(unit
, units
) {
733 if (!unit_name_is_valid(*unit
, UNIT_NAME_ANY
))
736 r
= bus_load_unit_by_name(m
, message
, *unit
, &u
, error
);
740 r
= reply_unit_info(reply
, u
);
745 r
= sd_bus_message_close_container(reply
);
749 return sd_bus_send(NULL
, reply
, NULL
);
752 static int method_get_unit_processes(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
753 Manager
*m
= userdata
;
761 r
= sd_bus_message_read(message
, "s", &name
);
765 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
769 return bus_unit_method_get_processes(message
, u
, error
);
772 static int method_attach_processes_to_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
773 Manager
*m
= userdata
;
781 r
= sd_bus_message_read(message
, "s", &name
);
785 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
789 return bus_unit_method_attach_processes(message
, u
, error
);
792 static int transient_unit_from_message(
794 sd_bus_message
*message
,
797 sd_bus_error
*error
) {
807 t
= unit_name_to_type(name
);
809 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid unit name or type.");
811 if (!unit_vtable
[t
]->can_transient
)
812 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unit type %s does not support transient units.", unit_type_to_string(t
));
814 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
818 if (!unit_is_pristine(u
))
819 return sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
, "Unit %s already exists.", name
);
821 /* OK, the unit failed to load and is unreferenced, now let's
822 * fill in the transient data instead */
823 r
= unit_make_transient(u
);
827 /* Set our properties */
828 r
= bus_unit_set_properties(u
, message
, UNIT_RUNTIME
, false, error
);
832 /* If the client asked for it, automatically add a reference to this unit. */
833 if (u
->bus_track_add
) {
834 r
= bus_unit_track_add_sender(u
, message
);
836 return log_error_errno(r
, "Failed to watch sender: %m");
839 /* Now load the missing bits of the unit we just created */
840 unit_add_to_load_queue(u
);
841 manager_dispatch_load_queue(m
);
848 static int transient_aux_units_from_message(
850 sd_bus_message
*message
,
851 sd_bus_error
*error
) {
858 r
= sd_bus_message_enter_container(message
, 'a', "(sa(sv))");
862 while ((r
= sd_bus_message_enter_container(message
, 'r', "sa(sv)")) > 0) {
863 const char *name
= NULL
;
866 r
= sd_bus_message_read(message
, "s", &name
);
870 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
874 r
= sd_bus_message_exit_container(message
);
881 r
= sd_bus_message_exit_container(message
);
888 static int method_start_transient_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
889 const char *name
, *smode
;
890 Manager
*m
= userdata
;
898 r
= mac_selinux_access_check(message
, "start", error
);
902 r
= sd_bus_message_read(message
, "ss", &name
, &smode
);
906 mode
= job_mode_from_string(smode
);
908 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Job mode %s is invalid.", smode
);
910 r
= bus_verify_manage_units_async(m
, message
, error
);
914 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
916 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
920 r
= transient_aux_units_from_message(m
, message
, error
);
924 /* Finally, start it */
925 return bus_unit_queue_job(message
, u
, JOB_START
, mode
, false, error
);
928 static int method_get_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
929 _cleanup_free_
char *path
= NULL
;
930 Manager
*m
= userdata
;
938 /* Anyone can call this method */
940 r
= sd_bus_message_read(message
, "u", &id
);
944 j
= manager_get_job(m
, id
);
946 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
948 r
= mac_selinux_unit_access_check(j
->unit
, message
, "status", error
);
952 path
= job_dbus_path(j
);
956 return sd_bus_reply_method_return(message
, "o", path
);
959 static int method_cancel_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
960 Manager
*m
= userdata
;
968 r
= sd_bus_message_read(message
, "u", &id
);
972 j
= manager_get_job(m
, id
);
974 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
976 return bus_job_method_cancel(message
, j
, error
);
979 static int method_clear_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
980 Manager
*m
= userdata
;
986 r
= mac_selinux_access_check(message
, "reload", error
);
990 r
= bus_verify_manage_units_async(m
, message
, error
);
994 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
996 manager_clear_jobs(m
);
998 return sd_bus_reply_method_return(message
, NULL
);
1001 static int method_reset_failed(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1002 Manager
*m
= userdata
;
1008 r
= mac_selinux_access_check(message
, "reload", error
);
1012 r
= bus_verify_manage_units_async(m
, message
, error
);
1016 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1018 manager_reset_failed(m
);
1020 return sd_bus_reply_method_return(message
, NULL
);
1023 static int list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1024 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1025 Manager
*m
= userdata
;
1034 /* Anyone can call this method */
1036 r
= mac_selinux_access_check(message
, "status", error
);
1040 r
= sd_bus_message_new_method_return(message
, &reply
);
1044 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
1048 HASHMAP_FOREACH_KEY(u
, k
, m
->units
, i
) {
1052 if (!strv_isempty(states
) &&
1053 !strv_contains(states
, unit_load_state_to_string(u
->load_state
)) &&
1054 !strv_contains(states
, unit_active_state_to_string(unit_active_state(u
))) &&
1055 !strv_contains(states
, unit_sub_state_to_string(u
)))
1058 if (!strv_isempty(patterns
) &&
1059 !strv_fnmatch_or_empty(patterns
, u
->id
, FNM_NOESCAPE
))
1062 r
= reply_unit_info(reply
, u
);
1067 r
= sd_bus_message_close_container(reply
);
1071 return sd_bus_send(NULL
, reply
, NULL
);
1074 static int method_list_units(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1075 return list_units_filtered(message
, userdata
, error
, NULL
, NULL
);
1078 static int method_list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1079 _cleanup_strv_free_
char **states
= NULL
;
1082 r
= sd_bus_message_read_strv(message
, &states
);
1086 return list_units_filtered(message
, userdata
, error
, states
, NULL
);
1089 static int method_list_units_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1090 _cleanup_strv_free_
char **states
= NULL
;
1091 _cleanup_strv_free_
char **patterns
= NULL
;
1094 r
= sd_bus_message_read_strv(message
, &states
);
1098 r
= sd_bus_message_read_strv(message
, &patterns
);
1102 return list_units_filtered(message
, userdata
, error
, states
, patterns
);
1105 static int method_list_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1106 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1107 Manager
*m
= userdata
;
1115 /* Anyone can call this method */
1117 r
= mac_selinux_access_check(message
, "status", error
);
1121 r
= sd_bus_message_new_method_return(message
, &reply
);
1125 r
= sd_bus_message_open_container(reply
, 'a', "(usssoo)");
1129 HASHMAP_FOREACH(j
, m
->jobs
, i
) {
1130 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
1132 job_path
= job_dbus_path(j
);
1136 unit_path
= unit_dbus_path(j
->unit
);
1140 r
= sd_bus_message_append(
1144 job_type_to_string(j
->type
),
1145 job_state_to_string(j
->state
),
1152 r
= sd_bus_message_close_container(reply
);
1156 return sd_bus_send(NULL
, reply
, NULL
);
1159 static int method_subscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1160 Manager
*m
= userdata
;
1166 /* Anyone can call this method */
1168 r
= mac_selinux_access_check(message
, "status", error
);
1172 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1174 /* Note that direct bus connection subscribe by
1175 * default, we only track peers on the API bus here */
1177 if (!m
->subscribed
) {
1178 r
= sd_bus_track_new(sd_bus_message_get_bus(message
), &m
->subscribed
, NULL
, NULL
);
1183 r
= sd_bus_track_add_sender(m
->subscribed
, message
);
1187 return sd_bus_error_setf(error
, BUS_ERROR_ALREADY_SUBSCRIBED
, "Client is already subscribed.");
1190 return sd_bus_reply_method_return(message
, NULL
);
1193 static int method_unsubscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1194 Manager
*m
= userdata
;
1200 /* Anyone can call this method */
1202 r
= mac_selinux_access_check(message
, "status", error
);
1206 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1207 r
= sd_bus_track_remove_sender(m
->subscribed
, message
);
1211 return sd_bus_error_setf(error
, BUS_ERROR_NOT_SUBSCRIBED
, "Client is not subscribed.");
1214 return sd_bus_reply_method_return(message
, NULL
);
1217 static int dump_impl(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, int (*reply
)(sd_bus_message
*, char *)) {
1218 _cleanup_free_
char *dump
= NULL
;
1219 Manager
*m
= userdata
;
1225 /* Anyone can call this method */
1227 r
= mac_selinux_access_check(message
, "status", error
);
1231 r
= manager_get_dump_string(m
, &dump
);
1235 return reply(message
, dump
);
1238 static int reply_dump(sd_bus_message
*message
, char *dump
) {
1239 return sd_bus_reply_method_return(message
, "s", dump
);
1242 static int method_dump(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1243 return dump_impl(message
, userdata
, error
, reply_dump
);
1246 static int reply_dump_by_fd(sd_bus_message
*message
, char *dump
) {
1247 _cleanup_close_
int fd
= -1;
1249 fd
= acquire_data_fd(dump
, strlen(dump
), 0);
1253 return sd_bus_reply_method_return(message
, "h", fd
);
1256 static int method_dump_by_fd(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1257 return dump_impl(message
, userdata
, error
, reply_dump_by_fd
);
1260 static int method_refuse_snapshot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1261 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Support for snapshots has been removed.");
1264 static int verify_run_space(const char *message
, sd_bus_error
*error
) {
1265 struct statvfs svfs
;
1268 if (statvfs("/run/systemd", &svfs
) < 0)
1269 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1271 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1273 if (available
< RELOAD_DISK_SPACE_MIN
) {
1274 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1275 return sd_bus_error_setf(error
,
1276 BUS_ERROR_DISK_FULL
,
1277 "%s, not enough space available on /run/systemd. "
1278 "Currently, %s are free, but a safety buffer of %s is enforced.",
1280 format_bytes(fb_available
, sizeof(fb_available
), available
),
1281 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1287 int verify_run_space_and_log(const char *message
) {
1288 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1291 r
= verify_run_space(message
, &error
);
1293 log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1298 static int method_reload(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1299 Manager
*m
= userdata
;
1305 r
= verify_run_space("Refusing to reload", error
);
1309 r
= mac_selinux_access_check(message
, "reload", error
);
1313 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1317 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1319 /* Instead of sending the reply back right away, we just
1320 * remember that we need to and then send it after the reload
1321 * is finished. That way the caller knows when the reload
1324 assert(!m
->queued_message
);
1325 r
= sd_bus_message_new_method_return(message
, &m
->queued_message
);
1329 m
->exit_code
= MANAGER_RELOAD
;
1334 static int method_reexecute(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1335 Manager
*m
= userdata
;
1341 r
= verify_run_space("Refusing to reexecute", 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 /* We don't send a reply back here, the client should
1356 * just wait for us disconnecting. */
1358 m
->exit_code
= MANAGER_REEXECUTE
;
1362 static int method_exit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1363 Manager
*m
= userdata
;
1369 r
= mac_selinux_access_check(message
, "halt", error
);
1373 /* Exit() (in contrast to SetExitCode()) is actually allowed even if
1374 * we are running on the host. It will fall back on reboot() in
1375 * systemd-shutdown if it cannot do the exit() because it isn't a
1378 m
->exit_code
= MANAGER_EXIT
;
1380 return sd_bus_reply_method_return(message
, NULL
);
1383 static int method_reboot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1384 Manager
*m
= userdata
;
1390 r
= mac_selinux_access_check(message
, "reboot", error
);
1394 if (!MANAGER_IS_SYSTEM(m
))
1395 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Reboot is only supported for system managers.");
1397 m
->exit_code
= MANAGER_REBOOT
;
1399 return sd_bus_reply_method_return(message
, NULL
);
1402 static int method_poweroff(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1403 Manager
*m
= userdata
;
1409 r
= mac_selinux_access_check(message
, "halt", error
);
1413 if (!MANAGER_IS_SYSTEM(m
))
1414 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Powering off is only supported for system managers.");
1416 m
->exit_code
= MANAGER_POWEROFF
;
1418 return sd_bus_reply_method_return(message
, NULL
);
1421 static int method_halt(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1422 Manager
*m
= userdata
;
1428 r
= mac_selinux_access_check(message
, "halt", error
);
1432 if (!MANAGER_IS_SYSTEM(m
))
1433 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Halt is only supported for system managers.");
1435 m
->exit_code
= MANAGER_HALT
;
1437 return sd_bus_reply_method_return(message
, NULL
);
1440 static int method_kexec(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1441 Manager
*m
= userdata
;
1447 r
= mac_selinux_access_check(message
, "reboot", error
);
1451 if (!MANAGER_IS_SYSTEM(m
))
1452 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "KExec is only supported for system managers.");
1454 m
->exit_code
= MANAGER_KEXEC
;
1456 return sd_bus_reply_method_return(message
, NULL
);
1459 static int method_switch_root(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1460 char *ri
= NULL
, *rt
= NULL
;
1461 const char *root
, *init
;
1462 Manager
*m
= userdata
;
1463 struct statvfs svfs
;
1470 if (statvfs("/run/systemd", &svfs
) < 0)
1471 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1473 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1475 if (available
< RELOAD_DISK_SPACE_MIN
) {
1476 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1477 log_warning("Dangerously low amount of free space on /run/systemd, root switching operation might not complete successfuly. "
1478 "Currently, %s are free, but %s are suggested. Proceeding anyway.",
1479 format_bytes(fb_available
, sizeof(fb_available
), available
),
1480 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
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
, "Root switching is only supported by system manager.");
1490 r
= sd_bus_message_read(message
, "ss", &root
, &init
);
1495 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory may not be the empty string.");
1496 if (!path_is_absolute(root
))
1497 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root path '%s' is not absolute.", root
);
1498 if (path_equal(root
, "/"))
1499 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory cannot be the old root directory.");
1502 if (isempty(init
)) {
1503 r
= path_is_os_tree(root
);
1505 return sd_bus_error_set_errnof(error
, r
, "Failed to determine whether root path '%s' contains an OS tree: %m", root
);
1507 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
);
1509 _cleanup_free_
char *chased
= NULL
;
1511 if (!path_is_absolute(init
))
1512 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path to init binary '%s' not absolute.", init
);
1514 r
= chase_symlinks(init
, root
, CHASE_PREFIX_ROOT
|CHASE_TRAIL_SLASH
, &chased
);
1516 return sd_bus_error_set_errnof(error
, r
, "Could not resolve init executable %s: %m", init
);
1518 if (laccess(chased
, X_OK
) < 0) {
1519 if (errno
== EACCES
)
1520 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Init binary %s is not executable.", init
);
1522 return sd_bus_error_set_errnof(error
, r
, "Could not check whether init binary %s is executable: %m", init
);
1530 if (!isempty(init
)) {
1538 free(m
->switch_root
);
1539 m
->switch_root
= rt
;
1541 free(m
->switch_root_init
);
1542 m
->switch_root_init
= ri
;
1544 m
->exit_code
= MANAGER_SWITCH_ROOT
;
1546 return sd_bus_reply_method_return(message
, NULL
);
1549 static int method_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1550 _cleanup_strv_free_
char **plus
= NULL
;
1551 Manager
*m
= userdata
;
1557 r
= mac_selinux_access_check(message
, "reload", error
);
1561 r
= sd_bus_message_read_strv(message
, &plus
);
1564 if (!strv_env_is_valid(plus
))
1565 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1567 r
= bus_verify_set_environment_async(m
, message
, error
);
1571 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1573 r
= manager_environment_add(m
, NULL
, plus
);
1577 return sd_bus_reply_method_return(message
, NULL
);
1580 static int method_unset_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1581 _cleanup_strv_free_
char **minus
= NULL
;
1582 Manager
*m
= userdata
;
1588 r
= mac_selinux_access_check(message
, "reload", error
);
1592 r
= sd_bus_message_read_strv(message
, &minus
);
1596 if (!strv_env_name_or_assignment_is_valid(minus
))
1597 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1599 r
= bus_verify_set_environment_async(m
, message
, error
);
1603 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1605 r
= manager_environment_add(m
, minus
, NULL
);
1609 return sd_bus_reply_method_return(message
, NULL
);
1612 static int method_unset_and_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1613 _cleanup_strv_free_
char **minus
= NULL
, **plus
= NULL
;
1614 Manager
*m
= userdata
;
1620 r
= mac_selinux_access_check(message
, "reload", error
);
1624 r
= sd_bus_message_read_strv(message
, &minus
);
1628 r
= sd_bus_message_read_strv(message
, &plus
);
1632 if (!strv_env_name_or_assignment_is_valid(minus
))
1633 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1634 if (!strv_env_is_valid(plus
))
1635 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1637 r
= bus_verify_set_environment_async(m
, message
, error
);
1641 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1643 r
= manager_environment_add(m
, minus
, plus
);
1647 return sd_bus_reply_method_return(message
, NULL
);
1650 static int method_set_exit_code(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1651 Manager
*m
= userdata
;
1658 r
= mac_selinux_access_check(message
, "exit", error
);
1662 r
= sd_bus_message_read_basic(message
, 'y', &code
);
1666 if (MANAGER_IS_SYSTEM(m
) && detect_container() <= 0)
1667 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "ExitCode can only be set for user service managers or in containers.");
1669 m
->return_value
= code
;
1671 return sd_bus_reply_method_return(message
, NULL
);
1674 static int method_lookup_dynamic_user_by_name(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1675 Manager
*m
= userdata
;
1683 r
= sd_bus_message_read_basic(message
, 's', &name
);
1687 if (!MANAGER_IS_SYSTEM(m
))
1688 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1689 if (!valid_user_group_name(name
))
1690 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User name invalid: %s", name
);
1692 r
= dynamic_user_lookup_name(m
, name
, &uid
);
1694 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user %s does not exist.", name
);
1698 return sd_bus_reply_method_return(message
, "u", (uint32_t) uid
);
1701 static int method_lookup_dynamic_user_by_uid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1702 _cleanup_free_
char *name
= NULL
;
1703 Manager
*m
= userdata
;
1710 assert_cc(sizeof(uid
) == sizeof(uint32_t));
1711 r
= sd_bus_message_read_basic(message
, 'u', &uid
);
1715 if (!MANAGER_IS_SYSTEM(m
))
1716 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1717 if (!uid_is_valid(uid
))
1718 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User ID invalid: " UID_FMT
, uid
);
1720 r
= dynamic_user_lookup_uid(m
, uid
, &name
);
1722 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user ID " UID_FMT
" does not exist.", uid
);
1726 return sd_bus_reply_method_return(message
, "s", name
);
1729 static int method_get_dynamic_users(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1730 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1731 Manager
*m
= userdata
;
1739 assert_cc(sizeof(uid_t
) == sizeof(uint32_t));
1741 if (!MANAGER_IS_SYSTEM(m
))
1742 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1744 r
= sd_bus_message_new_method_return(message
, &reply
);
1748 r
= sd_bus_message_open_container(reply
, 'a', "(us)");
1752 HASHMAP_FOREACH(d
, m
->dynamic_users
, i
) {
1755 r
= dynamic_user_current(d
, &uid
);
1756 if (r
== -EAGAIN
) /* not realized yet? */
1759 return sd_bus_error_setf(error
, SD_BUS_ERROR_FAILED
, "Failed to lookup a dynamic user.");
1761 r
= sd_bus_message_append(reply
, "(us)", uid
, d
->name
);
1766 r
= sd_bus_message_close_container(reply
);
1770 return sd_bus_send(NULL
, reply
, NULL
);
1773 static int list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1774 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1775 Manager
*m
= userdata
;
1784 /* Anyone can call this method */
1786 r
= mac_selinux_access_check(message
, "status", error
);
1790 r
= sd_bus_message_new_method_return(message
, &reply
);
1794 h
= hashmap_new(&string_hash_ops
);
1798 r
= unit_file_get_list(m
->unit_file_scope
, NULL
, h
, states
, patterns
);
1802 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1806 HASHMAP_FOREACH(item
, h
, i
) {
1808 r
= sd_bus_message_append(reply
, "(ss)", item
->path
, unit_file_state_to_string(item
->state
));
1813 unit_file_list_free(h
);
1815 r
= sd_bus_message_close_container(reply
);
1819 return sd_bus_send(NULL
, reply
, NULL
);
1822 unit_file_list_free(h
);
1826 static int method_list_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1827 return list_unit_files_by_patterns(message
, userdata
, error
, NULL
, NULL
);
1830 static int method_list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1831 _cleanup_strv_free_
char **states
= NULL
;
1832 _cleanup_strv_free_
char **patterns
= NULL
;
1835 r
= sd_bus_message_read_strv(message
, &states
);
1839 r
= sd_bus_message_read_strv(message
, &patterns
);
1843 return list_unit_files_by_patterns(message
, userdata
, error
, states
, patterns
);
1846 static int method_get_unit_file_state(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1847 Manager
*m
= userdata
;
1849 UnitFileState state
;
1855 /* Anyone can call this method */
1857 r
= mac_selinux_access_check(message
, "status", error
);
1861 r
= sd_bus_message_read(message
, "s", &name
);
1865 r
= unit_file_get_state(m
->unit_file_scope
, NULL
, name
, &state
);
1869 return sd_bus_reply_method_return(message
, "s", unit_file_state_to_string(state
));
1872 static int method_get_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1873 _cleanup_free_
char *default_target
= NULL
;
1874 Manager
*m
= userdata
;
1880 /* Anyone can call this method */
1882 r
= mac_selinux_access_check(message
, "status", error
);
1886 r
= unit_file_get_default(m
->unit_file_scope
, NULL
, &default_target
);
1890 return sd_bus_reply_method_return(message
, "s", default_target
);
1893 static int send_unit_files_changed(sd_bus
*bus
, void *userdata
) {
1894 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
1899 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
1903 return sd_bus_send(bus
, message
, NULL
);
1906 /* Create an error reply, using the error information from changes[]
1907 * if possible, and fall back to generating an error from error code c.
1908 * The error message only describes the first error.
1910 * Coordinate with unit_file_dump_changes() in install.c.
1912 static int install_error(
1913 sd_bus_error
*error
,
1915 UnitFileChange
*changes
,
1921 for (i
= 0; i
< n_changes
; i
++)
1923 switch(changes
[i
].type
) {
1929 if (changes
[i
].source
)
1930 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1931 "File %s already exists and is a symlink to %s.",
1932 changes
[i
].path
, changes
[i
].source
);
1934 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1935 "File %s already exists.",
1940 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_MASKED
,
1941 "Unit file %s is masked.", changes
[i
].path
);
1944 case -EADDRNOTAVAIL
:
1945 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_GENERATED
,
1946 "Unit %s is transient or generated.", changes
[i
].path
);
1950 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_LINKED
,
1951 "Refusing to operate on linked unit file %s", changes
[i
].path
);
1955 r
= sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit file %s does not exist.", changes
[i
].path
);
1959 r
= sd_bus_error_set_errnof(error
, changes
[i
].type
, "File %s: %m", changes
[i
].path
);
1963 r
= c
< 0 ? c
: -EINVAL
;
1966 unit_file_changes_free(changes
, n_changes
);
1970 static int reply_unit_file_changes_and_free(
1972 sd_bus_message
*message
,
1973 int carries_install_info
,
1974 UnitFileChange
*changes
,
1976 sd_bus_error
*error
) {
1978 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1979 bool bad
= false, good
= false;
1983 if (unit_file_changes_have_modification(changes
, n_changes
)) {
1984 r
= bus_foreach_bus(m
, NULL
, send_unit_files_changed
, NULL
);
1986 log_debug_errno(r
, "Failed to send UnitFilesChanged signal: %m");
1989 r
= sd_bus_message_new_method_return(message
, &reply
);
1993 if (carries_install_info
>= 0) {
1994 r
= sd_bus_message_append(reply
, "b", carries_install_info
);
1999 r
= sd_bus_message_open_container(reply
, 'a', "(sss)");
2003 for (i
= 0; i
< n_changes
; i
++) {
2005 if (changes
[i
].type
< 0) {
2010 r
= sd_bus_message_append(
2012 unit_file_change_type_to_string(changes
[i
].type
),
2021 /* If there was a failed change, and no successful change, then return the first failure as proper method call
2024 return install_error(error
, 0, changes
, n_changes
);
2026 r
= sd_bus_message_close_container(reply
);
2030 unit_file_changes_free(changes
, n_changes
);
2031 return sd_bus_send(NULL
, reply
, NULL
);
2034 unit_file_changes_free(changes
, n_changes
);
2038 static int method_enable_unit_files_generic(
2039 sd_bus_message
*message
,
2041 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, size_t *n_changes
),
2042 bool carries_install_info
,
2043 sd_bus_error
*error
) {
2045 _cleanup_strv_free_
char **l
= NULL
;
2046 UnitFileChange
*changes
= NULL
;
2047 size_t n_changes
= 0;
2048 UnitFileFlags flags
;
2049 int runtime
, force
, r
;
2054 r
= sd_bus_message_read_strv(message
, &l
);
2058 r
= sd_bus_message_read(message
, "bb", &runtime
, &force
);
2062 flags
= unit_file_bools_to_flags(runtime
, force
);
2064 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2068 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2070 r
= call(m
->unit_file_scope
, flags
, NULL
, l
, &changes
, &n_changes
);
2072 return install_error(error
, r
, changes
, n_changes
);
2074 return reply_unit_file_changes_and_free(m
, message
, carries_install_info
? r
: -1, changes
, n_changes
, error
);
2077 static int method_enable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2078 return method_enable_unit_files_generic(message
, userdata
, unit_file_enable
, true, error
);
2081 static int method_reenable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2082 return method_enable_unit_files_generic(message
, userdata
, unit_file_reenable
, true, error
);
2085 static int method_link_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2086 return method_enable_unit_files_generic(message
, userdata
, unit_file_link
, false, error
);
2089 static int unit_file_preset_without_mode(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char **files
, UnitFileChange
**changes
, size_t *n_changes
) {
2090 return unit_file_preset(scope
, flags
, root_dir
, files
, UNIT_FILE_PRESET_FULL
, changes
, n_changes
);
2093 static int method_preset_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2094 return method_enable_unit_files_generic(message
, userdata
, unit_file_preset_without_mode
, true, error
);
2097 static int method_mask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2098 return method_enable_unit_files_generic(message
, userdata
, unit_file_mask
, false, error
);
2101 static int method_preset_unit_files_with_mode(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2103 _cleanup_strv_free_
char **l
= NULL
;
2104 UnitFileChange
*changes
= NULL
;
2105 size_t n_changes
= 0;
2106 Manager
*m
= userdata
;
2107 UnitFilePresetMode mm
;
2108 int runtime
, force
, r
;
2109 UnitFileFlags flags
;
2115 r
= sd_bus_message_read_strv(message
, &l
);
2119 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2123 flags
= unit_file_bools_to_flags(runtime
, force
);
2126 mm
= UNIT_FILE_PRESET_FULL
;
2128 mm
= unit_file_preset_mode_from_string(mode
);
2133 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2137 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2139 r
= unit_file_preset(m
->unit_file_scope
, flags
, NULL
, l
, mm
, &changes
, &n_changes
);
2141 return install_error(error
, r
, changes
, n_changes
);
2143 return reply_unit_file_changes_and_free(m
, message
, r
, changes
, n_changes
, error
);
2146 static int method_disable_unit_files_generic(
2147 sd_bus_message
*message
,
2149 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, size_t *n_changes
),
2150 sd_bus_error
*error
) {
2152 _cleanup_strv_free_
char **l
= NULL
;
2153 UnitFileChange
*changes
= NULL
;
2154 size_t n_changes
= 0;
2160 r
= sd_bus_message_read_strv(message
, &l
);
2164 r
= sd_bus_message_read(message
, "b", &runtime
);
2168 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2172 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2174 r
= call(m
->unit_file_scope
, runtime
? UNIT_FILE_RUNTIME
: 0, NULL
, l
, &changes
, &n_changes
);
2176 return install_error(error
, r
, changes
, n_changes
);
2178 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2181 static int method_disable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2182 return method_disable_unit_files_generic(message
, userdata
, unit_file_disable
, error
);
2185 static int method_unmask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2186 return method_disable_unit_files_generic(message
, userdata
, unit_file_unmask
, error
);
2189 static int method_revert_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2190 _cleanup_strv_free_
char **l
= NULL
;
2191 UnitFileChange
*changes
= NULL
;
2192 size_t n_changes
= 0;
2193 Manager
*m
= userdata
;
2199 r
= sd_bus_message_read_strv(message
, &l
);
2203 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2207 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2209 r
= unit_file_revert(m
->unit_file_scope
, NULL
, l
, &changes
, &n_changes
);
2211 return install_error(error
, r
, changes
, n_changes
);
2213 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2216 static int method_set_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2217 UnitFileChange
*changes
= NULL
;
2218 size_t n_changes
= 0;
2219 Manager
*m
= userdata
;
2226 r
= mac_selinux_access_check(message
, "enable", error
);
2230 r
= sd_bus_message_read(message
, "sb", &name
, &force
);
2234 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2238 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2240 r
= unit_file_set_default(m
->unit_file_scope
, force
? UNIT_FILE_FORCE
: 0, NULL
, name
, &changes
, &n_changes
);
2242 return install_error(error
, r
, changes
, n_changes
);
2244 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2247 static int method_preset_all_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2248 UnitFileChange
*changes
= NULL
;
2249 size_t n_changes
= 0;
2250 Manager
*m
= userdata
;
2251 UnitFilePresetMode mm
;
2253 UnitFileFlags flags
;
2254 int force
, runtime
, r
;
2259 r
= mac_selinux_access_check(message
, "enable", error
);
2263 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2267 flags
= unit_file_bools_to_flags(runtime
, force
);
2270 mm
= UNIT_FILE_PRESET_FULL
;
2272 mm
= unit_file_preset_mode_from_string(mode
);
2277 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2281 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2283 r
= unit_file_preset_all(m
->unit_file_scope
, flags
, NULL
, mm
, &changes
, &n_changes
);
2285 return install_error(error
, r
, changes
, n_changes
);
2287 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2290 static int method_add_dependency_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2291 _cleanup_strv_free_
char **l
= NULL
;
2292 Manager
*m
= userdata
;
2293 UnitFileChange
*changes
= NULL
;
2294 size_t n_changes
= 0;
2295 int runtime
, force
, r
;
2296 char *target
, *type
;
2298 UnitFileFlags flags
;
2303 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2307 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2309 r
= sd_bus_message_read_strv(message
, &l
);
2313 r
= sd_bus_message_read(message
, "ssbb", &target
, &type
, &runtime
, &force
);
2317 flags
= unit_file_bools_to_flags(runtime
, force
);
2319 dep
= unit_dependency_from_string(type
);
2323 r
= unit_file_add_dependency(m
->unit_file_scope
, flags
, NULL
, l
, target
, dep
, &changes
, &n_changes
);
2325 return install_error(error
, r
, changes
, n_changes
);
2327 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2330 static int method_get_unit_file_links(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2331 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
2332 UnitFileChange
*changes
= NULL
;
2333 size_t n_changes
= 0, i
;
2334 UnitFileFlags flags
;
2339 r
= sd_bus_message_read(message
, "sb", &name
, &runtime
);
2343 r
= sd_bus_message_new_method_return(message
, &reply
);
2347 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_ARRAY
, "s");
2351 p
= STRV_MAKE(name
);
2352 flags
= UNIT_FILE_DRY_RUN
|
2353 (runtime
? UNIT_FILE_RUNTIME
: 0);
2355 r
= unit_file_disable(UNIT_FILE_SYSTEM
, flags
, NULL
, p
, &changes
, &n_changes
);
2357 return log_error_errno(r
, "Failed to get file links for %s: %m", name
);
2359 for (i
= 0; i
< n_changes
; i
++)
2360 if (changes
[i
].type
== UNIT_FILE_UNLINK
) {
2361 r
= sd_bus_message_append(reply
, "s", changes
[i
].path
);
2366 r
= sd_bus_message_close_container(reply
);
2370 return sd_bus_send(NULL
, reply
, NULL
);
2373 static int method_get_job_waiting(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2374 Manager
*m
= userdata
;
2382 r
= sd_bus_message_read(message
, "u", &id
);
2386 j
= manager_get_job(m
, id
);
2388 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
2390 return bus_job_method_get_waiting_jobs(message
, j
, error
);
2393 const sd_bus_vtable bus_manager_vtable
[] = {
2394 SD_BUS_VTABLE_START(0),
2396 SD_BUS_PROPERTY("Version", "s", property_get_version
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2397 SD_BUS_PROPERTY("Features", "s", property_get_features
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2398 SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2399 SD_BUS_PROPERTY("Architecture", "s", property_get_architecture
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2400 SD_BUS_PROPERTY("Tainted", "s", property_get_tainted
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2401 BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_FIRMWARE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2402 BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_LOADER
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2403 BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_KERNEL
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2404 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_INITRD
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2405 BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_USERSPACE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2406 BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2407 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_SECURITY_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2408 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_SECURITY_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2409 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_GENERATORS_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2410 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_GENERATORS_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2411 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_UNITS_LOAD_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2412 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_UNITS_LOAD_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2413 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level
, property_set_log_level
, 0, 0),
2414 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target
, property_set_log_target
, 0, 0),
2415 SD_BUS_PROPERTY("NNames", "u", property_get_hashmap_size
, offsetof(Manager
, units
), 0),
2416 SD_BUS_PROPERTY("NFailedUnits", "u", property_get_set_size
, offsetof(Manager
, failed_units
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
2417 SD_BUS_PROPERTY("NJobs", "u", property_get_hashmap_size
, offsetof(Manager
, jobs
), 0),
2418 SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_installed_jobs
), 0),
2419 SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_failed_jobs
), 0),
2420 SD_BUS_PROPERTY("Progress", "d", property_get_progress
, 0, 0),
2421 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(Manager
, environment
), 0),
2422 SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool
, offsetof(Manager
, confirm_spawn
), SD_BUS_VTABLE_PROPERTY_CONST
),
2423 SD_BUS_PROPERTY("ShowStatus", "b", property_get_show_status
, 0, 0),
2424 SD_BUS_PROPERTY("UnitPath", "as", NULL
, offsetof(Manager
, lookup_paths
.search_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
2425 SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2426 SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2427 SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec
, property_set_runtime_watchdog
, offsetof(Manager
, runtime_watchdog
), 0),
2428 SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec
, bus_property_set_usec
, offsetof(Manager
, shutdown_watchdog
), 0),
2429 SD_BUS_WRITABLE_PROPERTY("ServiceWatchdogs", "b", bus_property_get_bool
, bus_property_set_bool
, offsetof(Manager
, service_watchdogs
), 0),
2430 SD_BUS_PROPERTY("ControlGroup", "s", NULL
, offsetof(Manager
, cgroup_root
), 0),
2431 SD_BUS_PROPERTY("SystemState", "s", property_get_system_state
, 0, 0),
2432 SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned
, offsetof(Manager
, return_value
), 0),
2433 SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timer_accuracy_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2434 SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_start_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2435 SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_stop_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2436 SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_restart_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2437 SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
),
2438 /* The following two items are obsolete alias */
2439 SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
2440 SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
2441 SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned
, offsetof(Manager
, default_start_limit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
2442 SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_cpu_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2443 SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_blockio_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2444 SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_memory_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2445 SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_tasks_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2446 SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2447 SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2448 SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2449 SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2450 SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2451 SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2452 SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2453 SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2454 SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2455 SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2456 SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2457 SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2458 SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2459 SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2460 SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2461 SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2462 SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2463 SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2464 SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2465 SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2466 SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2467 SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2468 SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2469 SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2470 SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2471 SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2472 SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2473 SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2474 SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2475 SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2476 SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2477 SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2478 SD_BUS_PROPERTY("DefaultTasksMax", "t", NULL
, offsetof(Manager
, default_tasks_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
2479 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2481 SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2482 SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2483 SD_BUS_METHOD("GetUnitByInvocationID", "ay", "o", method_get_unit_by_invocation_id
, SD_BUS_VTABLE_UNPRIVILEGED
),
2484 SD_BUS_METHOD("GetUnitByControlGroup", "s", "o", method_get_unit_by_control_group
, SD_BUS_VTABLE_UNPRIVILEGED
),
2485 SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2486 SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2487 SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace
, SD_BUS_VTABLE_UNPRIVILEGED
),
2488 SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2489 SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2490 SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2491 SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2492 SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2493 SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2494 SD_BUS_METHOD("KillUnit", "ssi", NULL
, method_kill_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2495 SD_BUS_METHOD("ResetFailedUnit", "s", NULL
, method_reset_failed_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2496 SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL
, method_set_unit_properties
, SD_BUS_VTABLE_UNPRIVILEGED
),
2497 SD_BUS_METHOD("RefUnit", "s", NULL
, method_ref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2498 SD_BUS_METHOD("UnrefUnit", "s", NULL
, method_unref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2499 SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2500 SD_BUS_METHOD("GetUnitProcesses", "s", "a(sus)", method_get_unit_processes
, SD_BUS_VTABLE_UNPRIVILEGED
),
2501 SD_BUS_METHOD("AttachProcessesToUnit", "ssau", NULL
, method_attach_processes_to_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2502 SD_BUS_METHOD("GetJob", "u", "o", method_get_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2503 SD_BUS_METHOD("GetJobAfter", "u", "a(usssoo)", method_get_job_waiting
, SD_BUS_VTABLE_UNPRIVILEGED
),
2504 SD_BUS_METHOD("GetJobBefore", "u", "a(usssoo)", method_get_job_waiting
, SD_BUS_VTABLE_UNPRIVILEGED
),
2505 SD_BUS_METHOD("CancelJob", "u", NULL
, method_cancel_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2506 SD_BUS_METHOD("ClearJobs", NULL
, NULL
, method_clear_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2507 SD_BUS_METHOD("ResetFailed", NULL
, NULL
, method_reset_failed
, SD_BUS_VTABLE_UNPRIVILEGED
),
2508 SD_BUS_METHOD("ListUnits", NULL
, "a(ssssssouso)", method_list_units
, SD_BUS_VTABLE_UNPRIVILEGED
),
2509 SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered
, SD_BUS_VTABLE_UNPRIVILEGED
),
2510 SD_BUS_METHOD("ListUnitsByPatterns", "asas", "a(ssssssouso)", method_list_units_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2511 SD_BUS_METHOD("ListUnitsByNames", "as", "a(ssssssouso)", method_list_units_by_names
, SD_BUS_VTABLE_UNPRIVILEGED
),
2512 SD_BUS_METHOD("ListJobs", NULL
, "a(usssoo)", method_list_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2513 SD_BUS_METHOD("Subscribe", NULL
, NULL
, method_subscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2514 SD_BUS_METHOD("Unsubscribe", NULL
, NULL
, method_unsubscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2515 SD_BUS_METHOD("Dump", NULL
, "s", method_dump
, SD_BUS_VTABLE_UNPRIVILEGED
),
2516 SD_BUS_METHOD("DumpByFileDescriptor", NULL
, "h", method_dump_by_fd
, SD_BUS_VTABLE_UNPRIVILEGED
),
2517 SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
|SD_BUS_VTABLE_HIDDEN
),
2518 SD_BUS_METHOD("RemoveSnapshot", "s", NULL
, method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
|SD_BUS_VTABLE_HIDDEN
),
2519 SD_BUS_METHOD("Reload", NULL
, NULL
, method_reload
, SD_BUS_VTABLE_UNPRIVILEGED
),
2520 SD_BUS_METHOD("Reexecute", NULL
, NULL
, method_reexecute
, SD_BUS_VTABLE_UNPRIVILEGED
),
2521 SD_BUS_METHOD("Exit", NULL
, NULL
, method_exit
, 0),
2522 SD_BUS_METHOD("Reboot", NULL
, NULL
, method_reboot
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2523 SD_BUS_METHOD("PowerOff", NULL
, NULL
, method_poweroff
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2524 SD_BUS_METHOD("Halt", NULL
, NULL
, method_halt
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2525 SD_BUS_METHOD("KExec", NULL
, NULL
, method_kexec
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2526 SD_BUS_METHOD("SwitchRoot", "ss", NULL
, method_switch_root
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2527 SD_BUS_METHOD("SetEnvironment", "as", NULL
, method_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2528 SD_BUS_METHOD("UnsetEnvironment", "as", NULL
, method_unset_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2529 SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL
, method_unset_and_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2530 SD_BUS_METHOD("ListUnitFiles", NULL
, "a(ss)", method_list_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2531 SD_BUS_METHOD("ListUnitFilesByPatterns", "asas", "a(ss)", method_list_unit_files_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2532 SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state
, SD_BUS_VTABLE_UNPRIVILEGED
),
2533 SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2534 SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2535 SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2536 SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2537 SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2538 SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode
, SD_BUS_VTABLE_UNPRIVILEGED
),
2539 SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2540 SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2541 SD_BUS_METHOD("RevertUnitFiles", "as", "a(sss)", method_revert_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2542 SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2543 SD_BUS_METHOD("GetDefaultTarget", NULL
, "s", method_get_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2544 SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2545 SD_BUS_METHOD("AddDependencyUnitFiles", "asssbb", "a(sss)", method_add_dependency_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2546 SD_BUS_METHOD("GetUnitFileLinks", "sb", "as", method_get_unit_file_links
, SD_BUS_VTABLE_UNPRIVILEGED
),
2547 SD_BUS_METHOD("SetExitCode", "y", NULL
, method_set_exit_code
, SD_BUS_VTABLE_UNPRIVILEGED
),
2548 SD_BUS_METHOD("LookupDynamicUserByName", "s", "u", method_lookup_dynamic_user_by_name
, SD_BUS_VTABLE_UNPRIVILEGED
),
2549 SD_BUS_METHOD("LookupDynamicUserByUID", "u", "s", method_lookup_dynamic_user_by_uid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2550 SD_BUS_METHOD("GetDynamicUsers", NULL
, "a(us)", method_get_dynamic_users
, SD_BUS_VTABLE_UNPRIVILEGED
),
2552 SD_BUS_SIGNAL("UnitNew", "so", 0),
2553 SD_BUS_SIGNAL("UnitRemoved", "so", 0),
2554 SD_BUS_SIGNAL("JobNew", "uos", 0),
2555 SD_BUS_SIGNAL("JobRemoved", "uoss", 0),
2556 SD_BUS_SIGNAL("StartupFinished", "tttttt", 0),
2557 SD_BUS_SIGNAL("UnitFilesChanged", NULL
, 0),
2558 SD_BUS_SIGNAL("Reloading", "b", 0),
2563 static int send_finished(sd_bus
*bus
, void *userdata
) {
2564 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2565 usec_t
*times
= userdata
;
2571 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
2575 r
= sd_bus_message_append(message
, "tttttt", times
[0], times
[1], times
[2], times
[3], times
[4], times
[5]);
2579 return sd_bus_send(bus
, message
, NULL
);
2582 void bus_manager_send_finished(
2584 usec_t firmware_usec
,
2588 usec_t userspace_usec
,
2589 usec_t total_usec
) {
2595 r
= bus_foreach_bus(
2608 log_debug_errno(r
, "Failed to send finished signal: %m");
2611 static int send_reloading(sd_bus
*bus
, void *userdata
) {
2612 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2617 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
2621 r
= sd_bus_message_append(message
, "b", PTR_TO_INT(userdata
));
2625 return sd_bus_send(bus
, message
, NULL
);
2628 void bus_manager_send_reloading(Manager
*m
, bool active
) {
2633 r
= bus_foreach_bus(m
, NULL
, send_reloading
, INT_TO_PTR(active
));
2635 log_debug_errno(r
, "Failed to send reloading signal: %m");
2638 static int send_changed_signal(sd_bus
*bus
, void *userdata
) {
2641 return sd_bus_emit_properties_changed_strv(bus
,
2642 "/org/freedesktop/systemd1",
2643 "org.freedesktop.systemd1.Manager",
2647 void bus_manager_send_change_signal(Manager
*m
) {
2652 r
= bus_foreach_bus(m
, NULL
, send_changed_signal
, NULL
);
2654 log_debug_errno(r
, "Failed to send manager change signal: %m");