1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include <sys/prctl.h>
23 #include <sys/statvfs.h>
26 #include "alloc-util.h"
27 #include "architecture.h"
29 #include "bus-common-errors.h"
30 #include "clock-util.h"
31 #include "dbus-execute.h"
33 #include "dbus-manager.h"
34 #include "dbus-unit.h"
39 #include "format-util.h"
43 #include "parse-util.h"
44 #include "path-util.h"
45 #include "selinux-access.h"
46 #include "stat-util.h"
47 #include "string-util.h"
49 #include "syslog-util.h"
50 #include "user-util.h"
54 /* Require 16MiB free in /run/systemd for reloading/reexecing. After all we need to serialize our state there, and if
55 * we can't we'll fail badly. */
56 #define RELOAD_DISK_SPACE_MIN (UINT64_C(16) * UINT64_C(1024) * UINT64_C(1024))
58 static UnitFileFlags
unit_file_bools_to_flags(bool runtime
, bool force
) {
59 return (runtime
? UNIT_FILE_RUNTIME
: 0) |
60 (force
? UNIT_FILE_FORCE
: 0);
63 static int property_get_version(
66 const char *interface
,
68 sd_bus_message
*reply
,
70 sd_bus_error
*error
) {
75 return sd_bus_message_append(reply
, "s", PACKAGE_VERSION
);
78 static int property_get_features(
81 const char *interface
,
83 sd_bus_message
*reply
,
85 sd_bus_error
*error
) {
90 return sd_bus_message_append(reply
, "s", SYSTEMD_FEATURES
);
93 static int property_get_virtualization(
96 const char *interface
,
98 sd_bus_message
*reply
,
100 sd_bus_error
*error
) {
107 v
= detect_virtualization();
109 /* Make sure to return the empty string when we detect no virtualization, as that is the API.
111 * https://github.com/systemd/systemd/issues/1423
114 return sd_bus_message_append(
116 v
== VIRTUALIZATION_NONE
? "" : virtualization_to_string(v
));
119 static int property_get_architecture(
122 const char *interface
,
123 const char *property
,
124 sd_bus_message
*reply
,
126 sd_bus_error
*error
) {
131 return sd_bus_message_append(reply
, "s", architecture_to_string(uname_architecture()));
134 static int property_get_tainted(
137 const char *interface
,
138 const char *property
,
139 sd_bus_message
*reply
,
141 sd_bus_error
*error
) {
143 char buf
[sizeof("split-usr:cgroups-missing:local-hwclock:var-run-bad:")] = "", *e
= buf
;
144 _cleanup_free_
char *destination
= NULL
;
145 Manager
*m
= userdata
;
153 e
= stpcpy(e
, "split-usr:");
155 if (access("/proc/cgroups", F_OK
) < 0)
156 e
= stpcpy(e
, "cgroups-missing:");
158 if (clock_is_localtime(NULL
) > 0)
159 e
= stpcpy(e
, "local-hwclock:");
161 r
= readlink_malloc("/var/run", &destination
);
162 if (r
< 0 || !PATH_IN_SET(destination
, "../run", "/run"))
163 e
= stpcpy(e
, "var-run-bad:");
165 /* remove the last ':' */
169 return sd_bus_message_append(reply
, "s", buf
);
172 static int property_get_log_target(
175 const char *interface
,
176 const char *property
,
177 sd_bus_message
*reply
,
179 sd_bus_error
*error
) {
184 return sd_bus_message_append(reply
, "s", log_target_to_string(log_get_target()));
187 static int property_set_log_target(
190 const char *interface
,
191 const char *property
,
192 sd_bus_message
*value
,
194 sd_bus_error
*error
) {
202 r
= sd_bus_message_read(value
, "s", &t
);
206 return log_set_target_from_string(t
);
209 static int property_get_log_level(
212 const char *interface
,
213 const char *property
,
214 sd_bus_message
*reply
,
216 sd_bus_error
*error
) {
218 _cleanup_free_
char *t
= NULL
;
224 r
= log_level_to_string_alloc(log_get_max_level(), &t
);
228 return sd_bus_message_append(reply
, "s", t
);
231 static int property_set_log_level(
234 const char *interface
,
235 const char *property
,
236 sd_bus_message
*value
,
238 sd_bus_error
*error
) {
246 r
= sd_bus_message_read(value
, "s", &t
);
250 r
= log_set_max_level_from_string(t
);
252 log_info("Setting log level to %s.", t
);
256 static int property_get_n_names(
259 const char *interface
,
260 const char *property
,
261 sd_bus_message
*reply
,
263 sd_bus_error
*error
) {
265 Manager
*m
= userdata
;
271 return sd_bus_message_append(reply
, "u", (uint32_t) hashmap_size(m
->units
));
274 static int property_get_n_failed_units(
277 const char *interface
,
278 const char *property
,
279 sd_bus_message
*reply
,
281 sd_bus_error
*error
) {
283 Manager
*m
= userdata
;
289 return sd_bus_message_append(reply
, "u", (uint32_t) set_size(m
->failed_units
));
292 static int property_get_n_jobs(
295 const char *interface
,
296 const char *property
,
297 sd_bus_message
*reply
,
299 sd_bus_error
*error
) {
301 Manager
*m
= userdata
;
307 return sd_bus_message_append(reply
, "u", (uint32_t) hashmap_size(m
->jobs
));
310 static int property_get_progress(
313 const char *interface
,
314 const char *property
,
315 sd_bus_message
*reply
,
317 sd_bus_error
*error
) {
319 Manager
*m
= userdata
;
326 if (dual_timestamp_is_set(&m
->finish_timestamp
))
329 d
= 1.0 - ((double) hashmap_size(m
->jobs
) / (double) m
->n_installed_jobs
);
331 return sd_bus_message_append(reply
, "d", d
);
334 static int property_get_system_state(
337 const char *interface
,
338 const char *property
,
339 sd_bus_message
*reply
,
341 sd_bus_error
*error
) {
343 Manager
*m
= userdata
;
349 return sd_bus_message_append(reply
, "s", manager_state_to_string(manager_state(m
)));
352 static int property_set_runtime_watchdog(
355 const char *interface
,
356 const char *property
,
357 sd_bus_message
*value
,
359 sd_bus_error
*error
) {
361 usec_t
*t
= userdata
;
367 assert_cc(sizeof(usec_t
) == sizeof(uint64_t));
369 r
= sd_bus_message_read(value
, "t", t
);
373 return watchdog_set_timeout(t
);
376 static int property_get_timer_slack_nsec(
379 const char *interface
,
380 const char *property
,
381 sd_bus_message
*reply
,
383 sd_bus_error
*error
) {
388 return sd_bus_message_append(reply
, "t", (uint64_t) prctl(PR_GET_TIMERSLACK
));
391 static int method_get_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
392 _cleanup_free_
char *path
= NULL
;
393 Manager
*m
= userdata
;
401 /* Anyone can call this method */
403 r
= sd_bus_message_read(message
, "s", &name
);
408 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
411 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
415 r
= sd_bus_creds_get_pid(creds
, &pid
);
419 u
= manager_get_unit_by_pid(m
, pid
);
421 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
423 u
= manager_get_unit(m
, name
);
425 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s not loaded.", name
);
428 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
432 path
= unit_dbus_path(u
);
436 return sd_bus_reply_method_return(message
, "o", path
);
439 static int method_get_unit_by_pid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
440 _cleanup_free_
char *path
= NULL
;
441 Manager
*m
= userdata
;
449 assert_cc(sizeof(pid_t
) == sizeof(uint32_t));
451 /* Anyone can call this method */
453 r
= sd_bus_message_read(message
, "u", &pid
);
457 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PID " PID_FMT
, pid
);
460 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
462 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
466 r
= sd_bus_creds_get_pid(creds
, &pid
);
471 u
= manager_get_unit_by_pid(m
, pid
);
473 return sd_bus_error_setf(error
, BUS_ERROR_NO_UNIT_FOR_PID
, "PID "PID_FMT
" does not belong to any loaded unit.", pid
);
475 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
479 path
= unit_dbus_path(u
);
483 return sd_bus_reply_method_return(message
, "o", path
);
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_load_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
545 _cleanup_free_
char *path
= NULL
;
546 Manager
*m
= userdata
;
554 /* Anyone can call this method */
556 r
= sd_bus_message_read(message
, "s", &name
);
561 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
564 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
568 r
= sd_bus_creds_get_pid(creds
, &pid
);
572 u
= manager_get_unit_by_pid(m
, pid
);
574 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
576 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
581 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
585 path
= unit_dbus_path(u
);
589 return sd_bus_reply_method_return(message
, "o", path
);
592 static int method_start_unit_generic(sd_bus_message
*message
, Manager
*m
, JobType job_type
, bool reload_if_possible
, sd_bus_error
*error
) {
600 r
= sd_bus_message_read(message
, "s", &name
);
604 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
608 return bus_unit_method_start_generic(message
, u
, job_type
, reload_if_possible
, error
);
611 static int method_start_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
612 return method_start_unit_generic(message
, userdata
, JOB_START
, false, error
);
615 static int method_stop_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
616 return method_start_unit_generic(message
, userdata
, JOB_STOP
, false, error
);
619 static int method_reload_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
620 return method_start_unit_generic(message
, userdata
, JOB_RELOAD
, false, error
);
623 static int method_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
624 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, false, error
);
627 static int method_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
628 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, false, error
);
631 static int method_reload_or_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
632 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, true, error
);
635 static int method_reload_or_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
636 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, true, error
);
639 static int method_start_unit_replace(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
640 Manager
*m
= userdata
;
641 const char *old_name
;
648 r
= sd_bus_message_read(message
, "s", &old_name
);
652 u
= manager_get_unit(m
, old_name
);
653 if (!u
|| !u
->job
|| u
->job
->type
!= JOB_START
)
654 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "No job queued for unit %s", old_name
);
656 return method_start_unit_generic(message
, m
, JOB_START
, false, error
);
659 static int method_kill_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
660 Manager
*m
= userdata
;
668 r
= sd_bus_message_read(message
, "s", &name
);
672 u
= manager_get_unit(m
, name
);
674 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not loaded.", name
);
676 return bus_unit_method_kill(message
, u
, error
);
679 static int method_reset_failed_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
680 Manager
*m
= userdata
;
688 r
= sd_bus_message_read(message
, "s", &name
);
692 u
= manager_get_unit(m
, name
);
694 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not loaded.", name
);
696 return bus_unit_method_reset_failed(message
, u
, error
);
699 static int method_set_unit_properties(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
700 Manager
*m
= userdata
;
708 r
= sd_bus_message_read(message
, "s", &name
);
712 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
716 r
= bus_unit_check_load_state(u
, error
);
720 return bus_unit_method_set_properties(message
, u
, error
);
723 static int method_ref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
724 Manager
*m
= userdata
;
732 r
= sd_bus_message_read(message
, "s", &name
);
736 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
740 r
= bus_unit_check_load_state(u
, error
);
744 return bus_unit_method_ref(message
, u
, error
);
747 static int method_unref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
748 Manager
*m
= userdata
;
756 r
= sd_bus_message_read(message
, "s", &name
);
760 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
764 r
= bus_unit_check_load_state(u
, error
);
768 return bus_unit_method_unref(message
, u
, error
);
771 static int reply_unit_info(sd_bus_message
*reply
, Unit
*u
) {
772 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
775 following
= unit_following(u
);
777 unit_path
= unit_dbus_path(u
);
782 job_path
= job_dbus_path(u
->job
);
787 return sd_bus_message_append(
788 reply
, "(ssssssouso)",
791 unit_load_state_to_string(u
->load_state
),
792 unit_active_state_to_string(unit_active_state(u
)),
793 unit_sub_state_to_string(u
),
794 following
? following
->id
: "",
796 u
->job
? u
->job
->id
: 0,
797 u
->job
? job_type_to_string(u
->job
->type
) : "",
798 job_path
? job_path
: "/");
801 static int method_list_units_by_names(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
802 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
803 Manager
*m
= userdata
;
806 _cleanup_strv_free_
char **units
= NULL
;
811 r
= sd_bus_message_read_strv(message
, &units
);
815 r
= sd_bus_message_new_method_return(message
, &reply
);
819 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
823 STRV_FOREACH(unit
, units
) {
826 if (!unit_name_is_valid(*unit
, UNIT_NAME_ANY
))
829 r
= manager_load_unit(m
, *unit
, NULL
, error
, &u
);
833 r
= reply_unit_info(reply
, u
);
838 r
= sd_bus_message_close_container(reply
);
842 return sd_bus_send(NULL
, reply
, NULL
);
845 static int method_get_unit_processes(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
846 Manager
*m
= userdata
;
854 r
= sd_bus_message_read(message
, "s", &name
);
858 u
= manager_get_unit(m
, name
);
860 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s not loaded.", name
);
862 return bus_unit_method_get_processes(message
, u
, error
);
865 static int transient_unit_from_message(
867 sd_bus_message
*message
,
870 sd_bus_error
*error
) {
880 t
= unit_name_to_type(name
);
882 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid unit name or type.");
884 if (!unit_vtable
[t
]->can_transient
)
885 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unit type %s does not support transient units.", unit_type_to_string(t
));
887 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
891 if (!unit_is_pristine(u
))
892 return sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
, "Unit %s already exists.", name
);
894 /* OK, the unit failed to load and is unreferenced, now let's
895 * fill in the transient data instead */
896 r
= unit_make_transient(u
);
900 /* Set our properties */
901 r
= bus_unit_set_properties(u
, message
, UNIT_RUNTIME
, false, error
);
905 /* If the client asked for it, automatically add a reference to this unit. */
906 if (u
->bus_track_add
) {
907 r
= bus_unit_track_add_sender(u
, message
);
909 return log_error_errno(r
, "Failed to watch sender: %m");
912 /* Now load the missing bits of the unit we just created */
913 unit_add_to_load_queue(u
);
914 manager_dispatch_load_queue(m
);
921 static int transient_aux_units_from_message(
923 sd_bus_message
*message
,
924 sd_bus_error
*error
) {
931 r
= sd_bus_message_enter_container(message
, 'a', "(sa(sv))");
935 while ((r
= sd_bus_message_enter_container(message
, 'r', "sa(sv)")) > 0) {
936 const char *name
= NULL
;
939 r
= sd_bus_message_read(message
, "s", &name
);
943 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
947 r
= sd_bus_message_exit_container(message
);
954 r
= sd_bus_message_exit_container(message
);
961 static int method_start_transient_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
962 const char *name
, *smode
;
963 Manager
*m
= userdata
;
971 r
= mac_selinux_access_check(message
, "start", error
);
975 r
= sd_bus_message_read(message
, "ss", &name
, &smode
);
979 mode
= job_mode_from_string(smode
);
981 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Job mode %s is invalid.", smode
);
983 r
= bus_verify_manage_units_async(m
, message
, error
);
987 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
989 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
993 r
= transient_aux_units_from_message(m
, message
, error
);
997 /* Finally, start it */
998 return bus_unit_queue_job(message
, u
, JOB_START
, mode
, false, error
);
1001 static int method_get_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1002 _cleanup_free_
char *path
= NULL
;
1003 Manager
*m
= userdata
;
1011 /* Anyone can call this method */
1013 r
= sd_bus_message_read(message
, "u", &id
);
1017 j
= manager_get_job(m
, id
);
1019 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
1021 r
= mac_selinux_unit_access_check(j
->unit
, message
, "status", error
);
1025 path
= job_dbus_path(j
);
1029 return sd_bus_reply_method_return(message
, "o", path
);
1032 static int method_cancel_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1033 Manager
*m
= userdata
;
1041 r
= sd_bus_message_read(message
, "u", &id
);
1045 j
= manager_get_job(m
, id
);
1047 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
1049 return bus_job_method_cancel(message
, j
, error
);
1052 static int method_clear_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1053 Manager
*m
= userdata
;
1059 r
= mac_selinux_access_check(message
, "reload", error
);
1063 r
= bus_verify_manage_units_async(m
, message
, error
);
1067 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1069 manager_clear_jobs(m
);
1071 return sd_bus_reply_method_return(message
, NULL
);
1074 static int method_reset_failed(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1075 Manager
*m
= userdata
;
1081 r
= mac_selinux_access_check(message
, "reload", error
);
1085 r
= bus_verify_manage_units_async(m
, message
, error
);
1089 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1091 manager_reset_failed(m
);
1093 return sd_bus_reply_method_return(message
, NULL
);
1096 static int list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1097 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1098 Manager
*m
= userdata
;
1107 /* Anyone can call this method */
1109 r
= mac_selinux_access_check(message
, "status", error
);
1113 r
= sd_bus_message_new_method_return(message
, &reply
);
1117 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
1121 HASHMAP_FOREACH_KEY(u
, k
, m
->units
, i
) {
1125 if (!strv_isempty(states
) &&
1126 !strv_contains(states
, unit_load_state_to_string(u
->load_state
)) &&
1127 !strv_contains(states
, unit_active_state_to_string(unit_active_state(u
))) &&
1128 !strv_contains(states
, unit_sub_state_to_string(u
)))
1131 if (!strv_isempty(patterns
) &&
1132 !strv_fnmatch_or_empty(patterns
, u
->id
, FNM_NOESCAPE
))
1135 r
= reply_unit_info(reply
, u
);
1140 r
= sd_bus_message_close_container(reply
);
1144 return sd_bus_send(NULL
, reply
, NULL
);
1147 static int method_list_units(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1148 return list_units_filtered(message
, userdata
, error
, NULL
, NULL
);
1151 static int method_list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1152 _cleanup_strv_free_
char **states
= NULL
;
1155 r
= sd_bus_message_read_strv(message
, &states
);
1159 return list_units_filtered(message
, userdata
, error
, states
, NULL
);
1162 static int method_list_units_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1163 _cleanup_strv_free_
char **states
= NULL
;
1164 _cleanup_strv_free_
char **patterns
= NULL
;
1167 r
= sd_bus_message_read_strv(message
, &states
);
1171 r
= sd_bus_message_read_strv(message
, &patterns
);
1175 return list_units_filtered(message
, userdata
, error
, states
, patterns
);
1178 static int method_list_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1179 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1180 Manager
*m
= userdata
;
1188 /* Anyone can call this method */
1190 r
= mac_selinux_access_check(message
, "status", error
);
1194 r
= sd_bus_message_new_method_return(message
, &reply
);
1198 r
= sd_bus_message_open_container(reply
, 'a', "(usssoo)");
1202 HASHMAP_FOREACH(j
, m
->jobs
, i
) {
1203 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
1205 job_path
= job_dbus_path(j
);
1209 unit_path
= unit_dbus_path(j
->unit
);
1213 r
= sd_bus_message_append(
1217 job_type_to_string(j
->type
),
1218 job_state_to_string(j
->state
),
1225 r
= sd_bus_message_close_container(reply
);
1229 return sd_bus_send(NULL
, reply
, NULL
);
1232 static int method_subscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1233 Manager
*m
= userdata
;
1239 /* Anyone can call this method */
1241 r
= mac_selinux_access_check(message
, "status", error
);
1245 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1247 /* Note that direct bus connection subscribe by
1248 * default, we only track peers on the API bus here */
1250 if (!m
->subscribed
) {
1251 r
= sd_bus_track_new(sd_bus_message_get_bus(message
), &m
->subscribed
, NULL
, NULL
);
1256 r
= sd_bus_track_add_sender(m
->subscribed
, message
);
1260 return sd_bus_error_setf(error
, BUS_ERROR_ALREADY_SUBSCRIBED
, "Client is already subscribed.");
1263 return sd_bus_reply_method_return(message
, NULL
);
1266 static int method_unsubscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1267 Manager
*m
= userdata
;
1273 /* Anyone can call this method */
1275 r
= mac_selinux_access_check(message
, "status", error
);
1279 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1280 r
= sd_bus_track_remove_sender(m
->subscribed
, message
);
1284 return sd_bus_error_setf(error
, BUS_ERROR_NOT_SUBSCRIBED
, "Client is not subscribed.");
1287 return sd_bus_reply_method_return(message
, NULL
);
1290 static int method_dump(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1291 _cleanup_free_
char *dump
= NULL
;
1292 _cleanup_fclose_
FILE *f
= NULL
;
1293 Manager
*m
= userdata
;
1300 /* Anyone can call this method */
1302 r
= mac_selinux_access_check(message
, "status", error
);
1306 f
= open_memstream(&dump
, &size
);
1310 manager_dump_units(m
, f
, NULL
);
1311 manager_dump_jobs(m
, f
, NULL
);
1313 r
= fflush_and_check(f
);
1317 return sd_bus_reply_method_return(message
, "s", dump
);
1320 static int method_refuse_snapshot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1321 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Support for snapshots has been removed.");
1324 static int verify_run_space(const char *message
, sd_bus_error
*error
) {
1325 struct statvfs svfs
;
1328 if (statvfs("/run/systemd", &svfs
) < 0)
1329 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1331 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1333 if (available
< RELOAD_DISK_SPACE_MIN
) {
1334 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1335 return sd_bus_error_setf(error
,
1336 BUS_ERROR_DISK_FULL
,
1337 "%s, not enough space available on /run/systemd. "
1338 "Currently, %s are free, but a safety buffer of %s is enforced.",
1340 format_bytes(fb_available
, sizeof(fb_available
), available
),
1341 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1347 int verify_run_space_and_log(const char *message
) {
1348 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1351 r
= verify_run_space(message
, &error
);
1353 log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1358 static int method_reload(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1359 Manager
*m
= userdata
;
1365 r
= verify_run_space("Refusing to reload", error
);
1369 r
= mac_selinux_access_check(message
, "reload", error
);
1373 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1377 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1379 /* Instead of sending the reply back right away, we just
1380 * remember that we need to and then send it after the reload
1381 * is finished. That way the caller knows when the reload
1384 assert(!m
->queued_message
);
1385 r
= sd_bus_message_new_method_return(message
, &m
->queued_message
);
1389 m
->exit_code
= MANAGER_RELOAD
;
1394 static int method_reexecute(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1395 Manager
*m
= userdata
;
1401 r
= verify_run_space("Refusing to reexecute", error
);
1405 r
= mac_selinux_access_check(message
, "reload", error
);
1409 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1413 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1415 /* We don't send a reply back here, the client should
1416 * just wait for us disconnecting. */
1418 m
->exit_code
= MANAGER_REEXECUTE
;
1422 static int method_exit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1423 Manager
*m
= userdata
;
1429 r
= mac_selinux_access_check(message
, "halt", error
);
1433 /* Exit() (in contrast to SetExitCode()) is actually allowed even if
1434 * we are running on the host. It will fall back on reboot() in
1435 * systemd-shutdown if it cannot do the exit() because it isn't a
1438 m
->exit_code
= MANAGER_EXIT
;
1440 return sd_bus_reply_method_return(message
, NULL
);
1443 static int method_reboot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1444 Manager
*m
= userdata
;
1450 r
= mac_selinux_access_check(message
, "reboot", error
);
1454 if (!MANAGER_IS_SYSTEM(m
))
1455 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Reboot is only supported for system managers.");
1457 m
->exit_code
= MANAGER_REBOOT
;
1459 return sd_bus_reply_method_return(message
, NULL
);
1462 static int method_poweroff(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1463 Manager
*m
= userdata
;
1469 r
= mac_selinux_access_check(message
, "halt", error
);
1473 if (!MANAGER_IS_SYSTEM(m
))
1474 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Powering off is only supported for system managers.");
1476 m
->exit_code
= MANAGER_POWEROFF
;
1478 return sd_bus_reply_method_return(message
, NULL
);
1481 static int method_halt(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1482 Manager
*m
= userdata
;
1488 r
= mac_selinux_access_check(message
, "halt", error
);
1492 if (!MANAGER_IS_SYSTEM(m
))
1493 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Halt is only supported for system managers.");
1495 m
->exit_code
= MANAGER_HALT
;
1497 return sd_bus_reply_method_return(message
, NULL
);
1500 static int method_kexec(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1501 Manager
*m
= userdata
;
1507 r
= mac_selinux_access_check(message
, "reboot", error
);
1511 if (!MANAGER_IS_SYSTEM(m
))
1512 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "KExec is only supported for system managers.");
1514 m
->exit_code
= MANAGER_KEXEC
;
1516 return sd_bus_reply_method_return(message
, NULL
);
1519 static int method_switch_root(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1520 char *ri
= NULL
, *rt
= NULL
;
1521 const char *root
, *init
;
1522 Manager
*m
= userdata
;
1523 struct statvfs svfs
;
1530 if (statvfs("/run/systemd", &svfs
) < 0)
1531 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1533 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1535 if (available
< RELOAD_DISK_SPACE_MIN
) {
1536 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1537 log_warning("Dangerously low amount of free space on /run/systemd, root switching operation might not complete successfuly. "
1538 "Currently, %s are free, but %s are suggested. Proceeding anyway.",
1539 format_bytes(fb_available
, sizeof(fb_available
), available
),
1540 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1543 r
= mac_selinux_access_check(message
, "reboot", error
);
1547 if (!MANAGER_IS_SYSTEM(m
))
1548 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Root switching is only supported by system manager.");
1550 r
= sd_bus_message_read(message
, "ss", &root
, &init
);
1555 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory may not be the empty string.");
1556 if (!path_is_absolute(root
))
1557 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root path '%s' is not absolute.", root
);
1558 if (path_equal(root
, "/"))
1559 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory cannot be the old root directory.");
1562 if (isempty(init
)) {
1563 r
= path_is_os_tree(root
);
1565 return sd_bus_error_set_errnof(error
, r
, "Failed to determine whether root path '%s' contains an OS tree: %m", root
);
1567 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
);
1569 _cleanup_free_
char *chased
= NULL
;
1571 if (!path_is_absolute(init
))
1572 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path to init binary '%s' not absolute.", init
);
1574 r
= chase_symlinks(init
, root
, CHASE_PREFIX_ROOT
, &chased
);
1576 return sd_bus_error_set_errnof(error
, r
, "Could not resolve init executable %s: %m", init
);
1578 if (laccess(chased
, X_OK
) < 0) {
1579 if (errno
== EACCES
)
1580 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Init binary %s is not executable.", init
);
1582 return sd_bus_error_set_errnof(error
, r
, "Could not check whether init binary %s is executable: %m", init
);
1590 if (!isempty(init
)) {
1598 free(m
->switch_root
);
1599 m
->switch_root
= rt
;
1601 free(m
->switch_root_init
);
1602 m
->switch_root_init
= ri
;
1604 m
->exit_code
= MANAGER_SWITCH_ROOT
;
1606 return sd_bus_reply_method_return(message
, NULL
);
1609 static int method_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1610 _cleanup_strv_free_
char **plus
= NULL
;
1611 Manager
*m
= userdata
;
1617 r
= mac_selinux_access_check(message
, "reload", error
);
1621 r
= sd_bus_message_read_strv(message
, &plus
);
1624 if (!strv_env_is_valid(plus
))
1625 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1627 r
= bus_verify_set_environment_async(m
, message
, error
);
1631 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1633 r
= manager_environment_add(m
, NULL
, plus
);
1637 return sd_bus_reply_method_return(message
, NULL
);
1640 static int method_unset_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1641 _cleanup_strv_free_
char **minus
= NULL
;
1642 Manager
*m
= userdata
;
1648 r
= mac_selinux_access_check(message
, "reload", error
);
1652 r
= sd_bus_message_read_strv(message
, &minus
);
1656 if (!strv_env_name_or_assignment_is_valid(minus
))
1657 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1659 r
= bus_verify_set_environment_async(m
, message
, error
);
1663 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1665 r
= manager_environment_add(m
, minus
, NULL
);
1669 return sd_bus_reply_method_return(message
, NULL
);
1672 static int method_unset_and_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1673 _cleanup_strv_free_
char **minus
= NULL
, **plus
= NULL
;
1674 Manager
*m
= userdata
;
1680 r
= mac_selinux_access_check(message
, "reload", error
);
1684 r
= sd_bus_message_read_strv(message
, &minus
);
1688 r
= sd_bus_message_read_strv(message
, &plus
);
1692 if (!strv_env_name_or_assignment_is_valid(minus
))
1693 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1694 if (!strv_env_is_valid(plus
))
1695 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1697 r
= bus_verify_set_environment_async(m
, message
, error
);
1701 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1703 r
= manager_environment_add(m
, minus
, plus
);
1707 return sd_bus_reply_method_return(message
, NULL
);
1710 static int method_set_exit_code(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1711 Manager
*m
= userdata
;
1718 r
= mac_selinux_access_check(message
, "exit", error
);
1722 r
= sd_bus_message_read_basic(message
, 'y', &code
);
1726 if (MANAGER_IS_SYSTEM(m
) && detect_container() <= 0)
1727 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "ExitCode can only be set for user service managers or in containers.");
1729 m
->return_value
= code
;
1731 return sd_bus_reply_method_return(message
, NULL
);
1734 static int method_lookup_dynamic_user_by_name(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1735 Manager
*m
= userdata
;
1743 r
= sd_bus_message_read_basic(message
, 's', &name
);
1747 if (!MANAGER_IS_SYSTEM(m
))
1748 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1749 if (!valid_user_group_name(name
))
1750 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User name invalid: %s", name
);
1752 r
= dynamic_user_lookup_name(m
, name
, &uid
);
1754 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user %s does not exist.", name
);
1758 return sd_bus_reply_method_return(message
, "u", (uint32_t) uid
);
1761 static int method_lookup_dynamic_user_by_uid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1762 _cleanup_free_
char *name
= NULL
;
1763 Manager
*m
= userdata
;
1770 assert_cc(sizeof(uid
) == sizeof(uint32_t));
1771 r
= sd_bus_message_read_basic(message
, 'u', &uid
);
1775 if (!MANAGER_IS_SYSTEM(m
))
1776 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1777 if (!uid_is_valid(uid
))
1778 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User ID invalid: " UID_FMT
, uid
);
1780 r
= dynamic_user_lookup_uid(m
, uid
, &name
);
1782 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user ID " UID_FMT
" does not exist.", uid
);
1786 return sd_bus_reply_method_return(message
, "s", name
);
1789 static int list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1790 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1791 Manager
*m
= userdata
;
1800 /* Anyone can call this method */
1802 r
= mac_selinux_access_check(message
, "status", error
);
1806 r
= sd_bus_message_new_method_return(message
, &reply
);
1810 h
= hashmap_new(&string_hash_ops
);
1814 r
= unit_file_get_list(m
->unit_file_scope
, NULL
, h
, states
, patterns
);
1818 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1822 HASHMAP_FOREACH(item
, h
, i
) {
1824 r
= sd_bus_message_append(reply
, "(ss)", item
->path
, unit_file_state_to_string(item
->state
));
1829 unit_file_list_free(h
);
1831 r
= sd_bus_message_close_container(reply
);
1835 return sd_bus_send(NULL
, reply
, NULL
);
1838 unit_file_list_free(h
);
1842 static int method_list_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1843 return list_unit_files_by_patterns(message
, userdata
, error
, NULL
, NULL
);
1846 static int method_list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1847 _cleanup_strv_free_
char **states
= NULL
;
1848 _cleanup_strv_free_
char **patterns
= NULL
;
1851 r
= sd_bus_message_read_strv(message
, &states
);
1855 r
= sd_bus_message_read_strv(message
, &patterns
);
1859 return list_unit_files_by_patterns(message
, userdata
, error
, states
, patterns
);
1862 static int method_get_unit_file_state(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1863 Manager
*m
= userdata
;
1865 UnitFileState state
;
1871 /* Anyone can call this method */
1873 r
= mac_selinux_access_check(message
, "status", error
);
1877 r
= sd_bus_message_read(message
, "s", &name
);
1881 r
= unit_file_get_state(m
->unit_file_scope
, NULL
, name
, &state
);
1885 return sd_bus_reply_method_return(message
, "s", unit_file_state_to_string(state
));
1888 static int method_get_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1889 _cleanup_free_
char *default_target
= NULL
;
1890 Manager
*m
= userdata
;
1896 /* Anyone can call this method */
1898 r
= mac_selinux_access_check(message
, "status", error
);
1902 r
= unit_file_get_default(m
->unit_file_scope
, NULL
, &default_target
);
1906 return sd_bus_reply_method_return(message
, "s", default_target
);
1909 static int send_unit_files_changed(sd_bus
*bus
, void *userdata
) {
1910 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
1915 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
1919 return sd_bus_send(bus
, message
, NULL
);
1922 /* Create an error reply, using the error information from changes[]
1923 * if possible, and fall back to generating an error from error code c.
1924 * The error message only describes the first error.
1926 * Coordinate with unit_file_dump_changes() in install.c.
1928 static int install_error(
1929 sd_bus_error
*error
,
1931 UnitFileChange
*changes
,
1932 unsigned n_changes
) {
1936 for (i
= 0; i
< n_changes
; i
++)
1938 switch(changes
[i
].type
) {
1944 if (changes
[i
].source
)
1945 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1946 "File %s already exists and is a symlink to %s.",
1947 changes
[i
].path
, changes
[i
].source
);
1949 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1950 "File %s already exists.",
1955 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_MASKED
,
1956 "Unit file %s is masked.", changes
[i
].path
);
1959 case -EADDRNOTAVAIL
:
1960 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_GENERATED
,
1961 "Unit %s is transient or generated.", changes
[i
].path
);
1965 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_LINKED
,
1966 "Refusing to operate on linked unit file %s", changes
[i
].path
);
1970 r
= sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit file %s does not exist.", changes
[i
].path
);
1974 r
= sd_bus_error_set_errnof(error
, changes
[i
].type
, "File %s: %m", changes
[i
].path
);
1978 r
= c
< 0 ? c
: -EINVAL
;
1981 unit_file_changes_free(changes
, n_changes
);
1985 static int reply_unit_file_changes_and_free(
1987 sd_bus_message
*message
,
1988 int carries_install_info
,
1989 UnitFileChange
*changes
,
1991 sd_bus_error
*error
) {
1993 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1994 bool bad
= false, good
= false;
1998 if (unit_file_changes_have_modification(changes
, n_changes
)) {
1999 r
= bus_foreach_bus(m
, NULL
, send_unit_files_changed
, NULL
);
2001 log_debug_errno(r
, "Failed to send UnitFilesChanged signal: %m");
2004 r
= sd_bus_message_new_method_return(message
, &reply
);
2008 if (carries_install_info
>= 0) {
2009 r
= sd_bus_message_append(reply
, "b", carries_install_info
);
2014 r
= sd_bus_message_open_container(reply
, 'a', "(sss)");
2018 for (i
= 0; i
< n_changes
; i
++) {
2020 if (changes
[i
].type
< 0) {
2025 r
= sd_bus_message_append(
2027 unit_file_change_type_to_string(changes
[i
].type
),
2036 /* If there was a failed change, and no successful change, then return the first failure as proper method call
2039 return install_error(error
, 0, changes
, n_changes
);
2041 r
= sd_bus_message_close_container(reply
);
2045 unit_file_changes_free(changes
, n_changes
);
2046 return sd_bus_send(NULL
, reply
, NULL
);
2049 unit_file_changes_free(changes
, n_changes
);
2053 static int method_enable_unit_files_generic(
2054 sd_bus_message
*message
,
2056 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, unsigned *n_changes
),
2057 bool carries_install_info
,
2058 sd_bus_error
*error
) {
2060 _cleanup_strv_free_
char **l
= NULL
;
2061 UnitFileChange
*changes
= NULL
;
2062 unsigned n_changes
= 0;
2063 UnitFileFlags flags
;
2064 int runtime
, force
, r
;
2069 r
= sd_bus_message_read_strv(message
, &l
);
2073 r
= sd_bus_message_read(message
, "bb", &runtime
, &force
);
2077 flags
= unit_file_bools_to_flags(runtime
, force
);
2079 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2083 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2085 r
= call(m
->unit_file_scope
, flags
, NULL
, l
, &changes
, &n_changes
);
2087 return install_error(error
, r
, changes
, n_changes
);
2089 return reply_unit_file_changes_and_free(m
, message
, carries_install_info
? r
: -1, changes
, n_changes
, error
);
2092 static int method_enable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2093 return method_enable_unit_files_generic(message
, userdata
, unit_file_enable
, true, error
);
2096 static int method_reenable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2097 return method_enable_unit_files_generic(message
, userdata
, unit_file_reenable
, true, error
);
2100 static int method_link_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2101 return method_enable_unit_files_generic(message
, userdata
, unit_file_link
, false, error
);
2104 static int unit_file_preset_without_mode(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char **files
, UnitFileChange
**changes
, unsigned *n_changes
) {
2105 return unit_file_preset(scope
, flags
, root_dir
, files
, UNIT_FILE_PRESET_FULL
, changes
, n_changes
);
2108 static int method_preset_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2109 return method_enable_unit_files_generic(message
, userdata
, unit_file_preset_without_mode
, true, error
);
2112 static int method_mask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2113 return method_enable_unit_files_generic(message
, userdata
, unit_file_mask
, false, error
);
2116 static int method_preset_unit_files_with_mode(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2118 _cleanup_strv_free_
char **l
= NULL
;
2119 UnitFileChange
*changes
= NULL
;
2120 unsigned n_changes
= 0;
2121 Manager
*m
= userdata
;
2122 UnitFilePresetMode mm
;
2123 int runtime
, force
, r
;
2124 UnitFileFlags flags
;
2130 r
= sd_bus_message_read_strv(message
, &l
);
2134 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2138 flags
= unit_file_bools_to_flags(runtime
, force
);
2141 mm
= UNIT_FILE_PRESET_FULL
;
2143 mm
= unit_file_preset_mode_from_string(mode
);
2148 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2152 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2154 r
= unit_file_preset(m
->unit_file_scope
, flags
, NULL
, l
, mm
, &changes
, &n_changes
);
2156 return install_error(error
, r
, changes
, n_changes
);
2158 return reply_unit_file_changes_and_free(m
, message
, r
, changes
, n_changes
, error
);
2161 static int method_disable_unit_files_generic(
2162 sd_bus_message
*message
,
2164 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, unsigned *n_changes
),
2165 sd_bus_error
*error
) {
2167 _cleanup_strv_free_
char **l
= NULL
;
2168 UnitFileChange
*changes
= NULL
;
2169 unsigned n_changes
= 0;
2175 r
= sd_bus_message_read_strv(message
, &l
);
2179 r
= sd_bus_message_read(message
, "b", &runtime
);
2183 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2187 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2189 r
= call(m
->unit_file_scope
, runtime
? UNIT_FILE_RUNTIME
: 0, NULL
, l
, &changes
, &n_changes
);
2191 return install_error(error
, r
, changes
, n_changes
);
2193 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2196 static int method_disable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2197 return method_disable_unit_files_generic(message
, userdata
, unit_file_disable
, error
);
2200 static int method_unmask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2201 return method_disable_unit_files_generic(message
, userdata
, unit_file_unmask
, error
);
2204 static int method_revert_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2205 _cleanup_strv_free_
char **l
= NULL
;
2206 UnitFileChange
*changes
= NULL
;
2207 unsigned n_changes
= 0;
2208 Manager
*m
= userdata
;
2214 r
= sd_bus_message_read_strv(message
, &l
);
2218 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2222 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2224 r
= unit_file_revert(m
->unit_file_scope
, NULL
, l
, &changes
, &n_changes
);
2226 return install_error(error
, r
, changes
, n_changes
);
2228 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2231 static int method_set_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2232 UnitFileChange
*changes
= NULL
;
2233 unsigned n_changes
= 0;
2234 Manager
*m
= userdata
;
2241 r
= mac_selinux_access_check(message
, "enable", error
);
2245 r
= sd_bus_message_read(message
, "sb", &name
, &force
);
2249 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2253 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2255 r
= unit_file_set_default(m
->unit_file_scope
, force
? UNIT_FILE_FORCE
: 0, NULL
, name
, &changes
, &n_changes
);
2257 return install_error(error
, r
, changes
, n_changes
);
2259 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2262 static int method_preset_all_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2263 UnitFileChange
*changes
= NULL
;
2264 unsigned n_changes
= 0;
2265 Manager
*m
= userdata
;
2266 UnitFilePresetMode mm
;
2268 UnitFileFlags flags
;
2269 int force
, runtime
, r
;
2274 r
= mac_selinux_access_check(message
, "enable", error
);
2278 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2282 flags
= unit_file_bools_to_flags(runtime
, force
);
2285 mm
= UNIT_FILE_PRESET_FULL
;
2287 mm
= unit_file_preset_mode_from_string(mode
);
2292 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2296 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2298 r
= unit_file_preset_all(m
->unit_file_scope
, flags
, NULL
, mm
, &changes
, &n_changes
);
2300 return install_error(error
, r
, changes
, n_changes
);
2302 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2305 static int method_add_dependency_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2306 _cleanup_strv_free_
char **l
= NULL
;
2307 Manager
*m
= userdata
;
2308 UnitFileChange
*changes
= NULL
;
2309 unsigned n_changes
= 0;
2310 int runtime
, force
, r
;
2311 char *target
, *type
;
2313 UnitFileFlags flags
;
2318 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2322 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2324 r
= sd_bus_message_read_strv(message
, &l
);
2328 r
= sd_bus_message_read(message
, "ssbb", &target
, &type
, &runtime
, &force
);
2332 flags
= unit_file_bools_to_flags(runtime
, force
);
2334 dep
= unit_dependency_from_string(type
);
2338 r
= unit_file_add_dependency(m
->unit_file_scope
, flags
, NULL
, l
, target
, dep
, &changes
, &n_changes
);
2340 return install_error(error
, r
, changes
, n_changes
);
2342 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2345 static int method_get_unit_file_links(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2346 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
2347 UnitFileChange
*changes
= NULL
;
2348 unsigned n_changes
= 0, i
;
2349 UnitFileFlags flags
;
2354 r
= sd_bus_message_read(message
, "sb", &name
, &runtime
);
2358 r
= sd_bus_message_new_method_return(message
, &reply
);
2362 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_ARRAY
, "s");
2366 p
= STRV_MAKE(name
);
2367 flags
= UNIT_FILE_DRY_RUN
|
2368 (runtime
? UNIT_FILE_RUNTIME
: 0);
2370 r
= unit_file_disable(UNIT_FILE_SYSTEM
, flags
, NULL
, p
, &changes
, &n_changes
);
2372 return log_error_errno(r
, "Failed to get file links for %s: %m", name
);
2374 for (i
= 0; i
< n_changes
; i
++)
2375 if (changes
[i
].type
== UNIT_FILE_UNLINK
) {
2376 r
= sd_bus_message_append(reply
, "s", changes
[i
].path
);
2381 r
= sd_bus_message_close_container(reply
);
2385 return sd_bus_send(NULL
, reply
, NULL
);
2388 static int method_get_job_waiting(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2389 Manager
*m
= userdata
;
2397 r
= sd_bus_message_read(message
, "u", &id
);
2401 j
= manager_get_job(m
, id
);
2403 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
2405 return bus_job_method_get_waiting_jobs(message
, j
, error
);
2408 const sd_bus_vtable bus_manager_vtable
[] = {
2409 SD_BUS_VTABLE_START(0),
2411 SD_BUS_PROPERTY("Version", "s", property_get_version
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2412 SD_BUS_PROPERTY("Features", "s", property_get_features
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2413 SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2414 SD_BUS_PROPERTY("Architecture", "s", property_get_architecture
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2415 SD_BUS_PROPERTY("Tainted", "s", property_get_tainted
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2416 BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager
, firmware_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2417 BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager
, loader_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2418 BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager
, kernel_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2419 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager
, initrd_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2420 BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager
, userspace_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2421 BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager
, finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2422 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager
, security_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2423 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager
, security_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2424 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager
, generators_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2425 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager
, generators_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2426 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager
, units_load_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2427 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager
, units_load_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2428 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level
, property_set_log_level
, 0, 0),
2429 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target
, property_set_log_target
, 0, 0),
2430 SD_BUS_PROPERTY("NNames", "u", property_get_n_names
, 0, 0),
2431 SD_BUS_PROPERTY("NFailedUnits", "u", property_get_n_failed_units
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
2432 SD_BUS_PROPERTY("NJobs", "u", property_get_n_jobs
, 0, 0),
2433 SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_installed_jobs
), 0),
2434 SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_failed_jobs
), 0),
2435 SD_BUS_PROPERTY("Progress", "d", property_get_progress
, 0, 0),
2436 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(Manager
, environment
), 0),
2437 SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool
, offsetof(Manager
, confirm_spawn
), SD_BUS_VTABLE_PROPERTY_CONST
),
2438 SD_BUS_PROPERTY("ShowStatus", "b", bus_property_get_bool
, offsetof(Manager
, show_status
), SD_BUS_VTABLE_PROPERTY_CONST
),
2439 SD_BUS_PROPERTY("UnitPath", "as", NULL
, offsetof(Manager
, lookup_paths
.search_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
2440 SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2441 SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2442 SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec
, property_set_runtime_watchdog
, offsetof(Manager
, runtime_watchdog
), 0),
2443 SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec
, bus_property_set_usec
, offsetof(Manager
, shutdown_watchdog
), 0),
2444 SD_BUS_PROPERTY("ControlGroup", "s", NULL
, offsetof(Manager
, cgroup_root
), 0),
2445 SD_BUS_PROPERTY("SystemState", "s", property_get_system_state
, 0, 0),
2446 SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned
, offsetof(Manager
, return_value
), 0),
2447 SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timer_accuracy_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2448 SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_start_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2449 SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_stop_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2450 SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_restart_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2451 SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
),
2452 SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
), /* obsolete alias name */
2453 SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned
, offsetof(Manager
, default_start_limit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
2454 SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_cpu_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2455 SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_blockio_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2456 SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_memory_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2457 SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_tasks_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2458 SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2459 SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2460 SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2461 SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2462 SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2463 SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2464 SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2465 SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2466 SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2467 SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2468 SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2469 SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2470 SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2471 SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2472 SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2473 SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2474 SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2475 SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2476 SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2477 SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2478 SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2479 SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2480 SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2481 SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2482 SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2483 SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2484 SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2485 SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2486 SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2487 SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2488 SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2489 SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2490 SD_BUS_PROPERTY("DefaultTasksMax", "t", NULL
, offsetof(Manager
, default_tasks_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
2491 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2493 SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2494 SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2495 SD_BUS_METHOD("GetUnitByInvocationID", "ay", "o", method_get_unit_by_invocation_id
, SD_BUS_VTABLE_UNPRIVILEGED
),
2496 SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2497 SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2498 SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace
, SD_BUS_VTABLE_UNPRIVILEGED
),
2499 SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2500 SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2501 SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2502 SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2503 SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2504 SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2505 SD_BUS_METHOD("KillUnit", "ssi", NULL
, method_kill_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2506 SD_BUS_METHOD("ResetFailedUnit", "s", NULL
, method_reset_failed_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2507 SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL
, method_set_unit_properties
, SD_BUS_VTABLE_UNPRIVILEGED
),
2508 SD_BUS_METHOD("RefUnit", "s", NULL
, method_ref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2509 SD_BUS_METHOD("UnrefUnit", "s", NULL
, method_unref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2510 SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2511 SD_BUS_METHOD("GetUnitProcesses", "s", "a(sus)", method_get_unit_processes
, SD_BUS_VTABLE_UNPRIVILEGED
),
2512 SD_BUS_METHOD("GetJob", "u", "o", method_get_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2513 SD_BUS_METHOD("GetJobAfter", "u", "a(usssoo)", method_get_job_waiting
, SD_BUS_VTABLE_UNPRIVILEGED
),
2514 SD_BUS_METHOD("GetJobBefore", "u", "a(usssoo)", method_get_job_waiting
, SD_BUS_VTABLE_UNPRIVILEGED
),
2515 SD_BUS_METHOD("CancelJob", "u", NULL
, method_cancel_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2516 SD_BUS_METHOD("ClearJobs", NULL
, NULL
, method_clear_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2517 SD_BUS_METHOD("ResetFailed", NULL
, NULL
, method_reset_failed
, SD_BUS_VTABLE_UNPRIVILEGED
),
2518 SD_BUS_METHOD("ListUnits", NULL
, "a(ssssssouso)", method_list_units
, SD_BUS_VTABLE_UNPRIVILEGED
),
2519 SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered
, SD_BUS_VTABLE_UNPRIVILEGED
),
2520 SD_BUS_METHOD("ListUnitsByPatterns", "asas", "a(ssssssouso)", method_list_units_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2521 SD_BUS_METHOD("ListUnitsByNames", "as", "a(ssssssouso)", method_list_units_by_names
, SD_BUS_VTABLE_UNPRIVILEGED
),
2522 SD_BUS_METHOD("ListJobs", NULL
, "a(usssoo)", method_list_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2523 SD_BUS_METHOD("Subscribe", NULL
, NULL
, method_subscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2524 SD_BUS_METHOD("Unsubscribe", NULL
, NULL
, method_unsubscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2525 SD_BUS_METHOD("Dump", NULL
, "s", method_dump
, SD_BUS_VTABLE_UNPRIVILEGED
),
2526 SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
),
2527 SD_BUS_METHOD("RemoveSnapshot", "s", NULL
, method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
),
2528 SD_BUS_METHOD("Reload", NULL
, NULL
, method_reload
, SD_BUS_VTABLE_UNPRIVILEGED
),
2529 SD_BUS_METHOD("Reexecute", NULL
, NULL
, method_reexecute
, SD_BUS_VTABLE_UNPRIVILEGED
),
2530 SD_BUS_METHOD("Exit", NULL
, NULL
, method_exit
, 0),
2531 SD_BUS_METHOD("Reboot", NULL
, NULL
, method_reboot
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2532 SD_BUS_METHOD("PowerOff", NULL
, NULL
, method_poweroff
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2533 SD_BUS_METHOD("Halt", NULL
, NULL
, method_halt
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2534 SD_BUS_METHOD("KExec", NULL
, NULL
, method_kexec
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2535 SD_BUS_METHOD("SwitchRoot", "ss", NULL
, method_switch_root
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2536 SD_BUS_METHOD("SetEnvironment", "as", NULL
, method_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2537 SD_BUS_METHOD("UnsetEnvironment", "as", NULL
, method_unset_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2538 SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL
, method_unset_and_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2539 SD_BUS_METHOD("ListUnitFiles", NULL
, "a(ss)", method_list_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2540 SD_BUS_METHOD("ListUnitFilesByPatterns", "asas", "a(ss)", method_list_unit_files_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2541 SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state
, SD_BUS_VTABLE_UNPRIVILEGED
),
2542 SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2543 SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2544 SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2545 SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2546 SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2547 SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode
, SD_BUS_VTABLE_UNPRIVILEGED
),
2548 SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2549 SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2550 SD_BUS_METHOD("RevertUnitFiles", "as", "a(sss)", method_revert_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2551 SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2552 SD_BUS_METHOD("GetDefaultTarget", NULL
, "s", method_get_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2553 SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2554 SD_BUS_METHOD("AddDependencyUnitFiles", "asssbb", "a(sss)", method_add_dependency_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2555 SD_BUS_METHOD("GetUnitFileLinks", "sb", "as", method_get_unit_file_links
, SD_BUS_VTABLE_UNPRIVILEGED
),
2556 SD_BUS_METHOD("SetExitCode", "y", NULL
, method_set_exit_code
, SD_BUS_VTABLE_UNPRIVILEGED
),
2557 SD_BUS_METHOD("LookupDynamicUserByName", "s", "u", method_lookup_dynamic_user_by_name
, SD_BUS_VTABLE_UNPRIVILEGED
),
2558 SD_BUS_METHOD("LookupDynamicUserByUID", "u", "s", method_lookup_dynamic_user_by_uid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2560 SD_BUS_SIGNAL("UnitNew", "so", 0),
2561 SD_BUS_SIGNAL("UnitRemoved", "so", 0),
2562 SD_BUS_SIGNAL("JobNew", "uos", 0),
2563 SD_BUS_SIGNAL("JobRemoved", "uoss", 0),
2564 SD_BUS_SIGNAL("StartupFinished", "tttttt", 0),
2565 SD_BUS_SIGNAL("UnitFilesChanged", NULL
, 0),
2566 SD_BUS_SIGNAL("Reloading", "b", 0),
2571 static int send_finished(sd_bus
*bus
, void *userdata
) {
2572 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2573 usec_t
*times
= userdata
;
2579 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
2583 r
= sd_bus_message_append(message
, "tttttt", times
[0], times
[1], times
[2], times
[3], times
[4], times
[5]);
2587 return sd_bus_send(bus
, message
, NULL
);
2590 void bus_manager_send_finished(
2592 usec_t firmware_usec
,
2596 usec_t userspace_usec
,
2597 usec_t total_usec
) {
2603 r
= bus_foreach_bus(
2616 log_debug_errno(r
, "Failed to send finished signal: %m");
2619 static int send_reloading(sd_bus
*bus
, void *userdata
) {
2620 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2625 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
2629 r
= sd_bus_message_append(message
, "b", PTR_TO_INT(userdata
));
2633 return sd_bus_send(bus
, message
, NULL
);
2636 void bus_manager_send_reloading(Manager
*m
, bool active
) {
2641 r
= bus_foreach_bus(m
, NULL
, send_reloading
, INT_TO_PTR(active
));
2643 log_debug_errno(r
, "Failed to send reloading signal: %m");
2646 static int send_changed_signal(sd_bus
*bus
, void *userdata
) {
2649 return sd_bus_emit_properties_changed_strv(bus
,
2650 "/org/freedesktop/systemd1",
2651 "org.freedesktop.systemd1.Manager",
2655 void bus_manager_send_change_signal(Manager
*m
) {
2660 r
= bus_foreach_bus(m
, NULL
, send_changed_signal
, NULL
);
2662 log_debug_errno(r
, "Failed to send manager change signal: %m");