2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 #include <sys/prctl.h>
22 #include <sys/statvfs.h>
25 #include "alloc-util.h"
26 #include "architecture.h"
28 #include "bus-common-errors.h"
29 #include "clock-util.h"
30 #include "dbus-execute.h"
32 #include "dbus-manager.h"
33 #include "dbus-unit.h"
38 #include "format-util.h"
42 #include "parse-util.h"
43 #include "path-util.h"
44 #include "selinux-access.h"
45 #include "stat-util.h"
46 #include "string-util.h"
48 #include "syslog-util.h"
49 #include "user-util.h"
53 /* Require 16MiB free in /run/systemd for reloading/reexecing. After all we need to serialize our state there, and if
54 * we can't we'll fail badly. */
55 #define RELOAD_DISK_SPACE_MIN (UINT64_C(16) * UINT64_C(1024) * UINT64_C(1024))
57 static UnitFileFlags
unit_file_bools_to_flags(bool runtime
, bool force
) {
58 return (runtime
? UNIT_FILE_RUNTIME
: 0) |
59 (force
? UNIT_FILE_FORCE
: 0);
62 static int property_get_version(
65 const char *interface
,
67 sd_bus_message
*reply
,
69 sd_bus_error
*error
) {
74 return sd_bus_message_append(reply
, "s", PACKAGE_VERSION
);
77 static int property_get_features(
80 const char *interface
,
82 sd_bus_message
*reply
,
84 sd_bus_error
*error
) {
89 return sd_bus_message_append(reply
, "s", SYSTEMD_FEATURES
);
92 static int property_get_virtualization(
95 const char *interface
,
97 sd_bus_message
*reply
,
99 sd_bus_error
*error
) {
106 v
= detect_virtualization();
108 /* Make sure to return the empty string when we detect no virtualization, as that is the API.
110 * https://github.com/systemd/systemd/issues/1423
113 return sd_bus_message_append(
115 v
== VIRTUALIZATION_NONE
? "" : virtualization_to_string(v
));
118 static int property_get_architecture(
121 const char *interface
,
122 const char *property
,
123 sd_bus_message
*reply
,
125 sd_bus_error
*error
) {
130 return sd_bus_message_append(reply
, "s", architecture_to_string(uname_architecture()));
133 static int property_get_tainted(
136 const char *interface
,
137 const char *property
,
138 sd_bus_message
*reply
,
140 sd_bus_error
*error
) {
142 char buf
[sizeof("split-usr:cgroups-missing:local-hwclock:var-run-bad:")] = "", *e
= buf
;
143 _cleanup_free_
char *destination
= NULL
;
144 Manager
*m
= userdata
;
152 e
= stpcpy(e
, "split-usr:");
154 if (access("/proc/cgroups", F_OK
) < 0)
155 e
= stpcpy(e
, "cgroups-missing:");
157 if (clock_is_localtime(NULL
) > 0)
158 e
= stpcpy(e
, "local-hwclock:");
160 r
= readlink_malloc("/var/run", &destination
);
161 if (r
< 0 || !PATH_IN_SET(destination
, "../run", "/run"))
162 e
= stpcpy(e
, "var-run-bad:");
164 /* remove the last ':' */
168 return sd_bus_message_append(reply
, "s", buf
);
171 static int property_get_log_target(
174 const char *interface
,
175 const char *property
,
176 sd_bus_message
*reply
,
178 sd_bus_error
*error
) {
183 return sd_bus_message_append(reply
, "s", log_target_to_string(log_get_target()));
186 static int property_set_log_target(
189 const char *interface
,
190 const char *property
,
191 sd_bus_message
*value
,
193 sd_bus_error
*error
) {
201 r
= sd_bus_message_read(value
, "s", &t
);
205 return log_set_target_from_string(t
);
208 static int property_get_log_level(
211 const char *interface
,
212 const char *property
,
213 sd_bus_message
*reply
,
215 sd_bus_error
*error
) {
217 _cleanup_free_
char *t
= NULL
;
223 r
= log_level_to_string_alloc(log_get_max_level(), &t
);
227 return sd_bus_message_append(reply
, "s", t
);
230 static int property_set_log_level(
233 const char *interface
,
234 const char *property
,
235 sd_bus_message
*value
,
237 sd_bus_error
*error
) {
245 r
= sd_bus_message_read(value
, "s", &t
);
249 r
= log_set_max_level_from_string(t
);
251 log_info("Setting log level to %s.", t
);
255 static int property_get_n_names(
258 const char *interface
,
259 const char *property
,
260 sd_bus_message
*reply
,
262 sd_bus_error
*error
) {
264 Manager
*m
= userdata
;
270 return sd_bus_message_append(reply
, "u", (uint32_t) hashmap_size(m
->units
));
273 static int property_get_n_failed_units(
276 const char *interface
,
277 const char *property
,
278 sd_bus_message
*reply
,
280 sd_bus_error
*error
) {
282 Manager
*m
= userdata
;
288 return sd_bus_message_append(reply
, "u", (uint32_t) set_size(m
->failed_units
));
291 static int property_get_n_jobs(
294 const char *interface
,
295 const char *property
,
296 sd_bus_message
*reply
,
298 sd_bus_error
*error
) {
300 Manager
*m
= userdata
;
306 return sd_bus_message_append(reply
, "u", (uint32_t) hashmap_size(m
->jobs
));
309 static int property_get_progress(
312 const char *interface
,
313 const char *property
,
314 sd_bus_message
*reply
,
316 sd_bus_error
*error
) {
318 Manager
*m
= userdata
;
325 if (dual_timestamp_is_set(&m
->finish_timestamp
))
328 d
= 1.0 - ((double) hashmap_size(m
->jobs
) / (double) m
->n_installed_jobs
);
330 return sd_bus_message_append(reply
, "d", d
);
333 static int property_get_system_state(
336 const char *interface
,
337 const char *property
,
338 sd_bus_message
*reply
,
340 sd_bus_error
*error
) {
342 Manager
*m
= userdata
;
348 return sd_bus_message_append(reply
, "s", manager_state_to_string(manager_state(m
)));
351 static int property_set_runtime_watchdog(
354 const char *interface
,
355 const char *property
,
356 sd_bus_message
*value
,
358 sd_bus_error
*error
) {
360 usec_t
*t
= userdata
;
366 assert_cc(sizeof(usec_t
) == sizeof(uint64_t));
368 r
= sd_bus_message_read(value
, "t", t
);
372 return watchdog_set_timeout(t
);
375 static int property_get_timer_slack_nsec(
378 const char *interface
,
379 const char *property
,
380 sd_bus_message
*reply
,
382 sd_bus_error
*error
) {
387 return sd_bus_message_append(reply
, "t", (uint64_t) prctl(PR_GET_TIMERSLACK
));
390 static int method_get_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
391 _cleanup_free_
char *path
= NULL
;
392 Manager
*m
= userdata
;
400 /* Anyone can call this method */
402 r
= sd_bus_message_read(message
, "s", &name
);
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 not member of any unit.");
422 u
= manager_get_unit(m
, name
);
424 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s not loaded.", name
);
427 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
431 path
= unit_dbus_path(u
);
435 return sd_bus_reply_method_return(message
, "o", path
);
438 static int method_get_unit_by_pid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
439 _cleanup_free_
char *path
= NULL
;
440 Manager
*m
= userdata
;
448 assert_cc(sizeof(pid_t
) == sizeof(uint32_t));
450 /* Anyone can call this method */
452 r
= sd_bus_message_read(message
, "u", &pid
);
456 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PID " PID_FMT
, pid
);
459 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
461 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
465 r
= sd_bus_creds_get_pid(creds
, &pid
);
470 u
= manager_get_unit_by_pid(m
, pid
);
472 return sd_bus_error_setf(error
, BUS_ERROR_NO_UNIT_FOR_PID
, "PID "PID_FMT
" does not belong to any loaded unit.", pid
);
474 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
478 path
= unit_dbus_path(u
);
482 return sd_bus_reply_method_return(message
, "o", path
);
485 static int method_get_unit_by_invocation_id(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
486 _cleanup_free_
char *path
= NULL
;
487 Manager
*m
= userdata
;
497 /* Anyone can call this method */
499 r
= sd_bus_message_read_array(message
, 'y', &a
, &sz
);
507 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid invocation ID");
509 if (sd_id128_is_null(id
)) {
510 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
513 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
517 r
= sd_bus_creds_get_pid(creds
, &pid
);
521 u
= manager_get_unit_by_pid(m
, pid
);
523 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client " PID_FMT
" not member of any unit.", pid
);
525 u
= hashmap_get(m
->units_by_invocation_id
, &id
);
527 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
));
530 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
534 /* So here's a special trick: the bus path we return actually references the unit by its invocation ID instead
535 * of the unit name. This means it stays valid only as long as the invocation ID stays the same. */
536 path
= unit_dbus_path_invocation_id(u
);
540 return sd_bus_reply_method_return(message
, "o", path
);
543 static int method_load_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
544 _cleanup_free_
char *path
= NULL
;
545 Manager
*m
= userdata
;
553 /* Anyone can call this method */
555 r
= sd_bus_message_read(message
, "s", &name
);
560 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
563 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
567 r
= sd_bus_creds_get_pid(creds
, &pid
);
571 u
= manager_get_unit_by_pid(m
, pid
);
573 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
575 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
580 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
584 path
= unit_dbus_path(u
);
588 return sd_bus_reply_method_return(message
, "o", path
);
591 static int method_start_unit_generic(sd_bus_message
*message
, Manager
*m
, JobType job_type
, bool reload_if_possible
, sd_bus_error
*error
) {
599 r
= sd_bus_message_read(message
, "s", &name
);
603 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
607 return bus_unit_method_start_generic(message
, u
, job_type
, reload_if_possible
, error
);
610 static int method_start_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
611 return method_start_unit_generic(message
, userdata
, JOB_START
, false, error
);
614 static int method_stop_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
615 return method_start_unit_generic(message
, userdata
, JOB_STOP
, false, error
);
618 static int method_reload_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
619 return method_start_unit_generic(message
, userdata
, JOB_RELOAD
, false, error
);
622 static int method_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
623 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, false, error
);
626 static int method_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
627 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, false, error
);
630 static int method_reload_or_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
631 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, true, error
);
634 static int method_reload_or_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
635 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, true, error
);
638 static int method_start_unit_replace(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
639 Manager
*m
= userdata
;
640 const char *old_name
;
647 r
= sd_bus_message_read(message
, "s", &old_name
);
651 u
= manager_get_unit(m
, old_name
);
652 if (!u
|| !u
->job
|| u
->job
->type
!= JOB_START
)
653 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "No job queued for unit %s", old_name
);
655 return method_start_unit_generic(message
, m
, JOB_START
, false, error
);
658 static int method_kill_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
659 Manager
*m
= userdata
;
667 r
= sd_bus_message_read(message
, "s", &name
);
671 u
= manager_get_unit(m
, name
);
673 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not loaded.", name
);
675 return bus_unit_method_kill(message
, u
, error
);
678 static int method_reset_failed_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
679 Manager
*m
= userdata
;
687 r
= sd_bus_message_read(message
, "s", &name
);
691 u
= manager_get_unit(m
, name
);
693 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not loaded.", name
);
695 return bus_unit_method_reset_failed(message
, u
, error
);
698 static int method_set_unit_properties(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
699 Manager
*m
= userdata
;
707 r
= sd_bus_message_read(message
, "s", &name
);
711 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
715 r
= bus_unit_check_load_state(u
, error
);
719 return bus_unit_method_set_properties(message
, u
, error
);
722 static int method_ref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
723 Manager
*m
= userdata
;
731 r
= sd_bus_message_read(message
, "s", &name
);
735 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
739 r
= bus_unit_check_load_state(u
, error
);
743 return bus_unit_method_ref(message
, u
, error
);
746 static int method_unref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
747 Manager
*m
= userdata
;
755 r
= sd_bus_message_read(message
, "s", &name
);
759 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
763 r
= bus_unit_check_load_state(u
, error
);
767 return bus_unit_method_unref(message
, u
, error
);
770 static int reply_unit_info(sd_bus_message
*reply
, Unit
*u
) {
771 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
774 following
= unit_following(u
);
776 unit_path
= unit_dbus_path(u
);
781 job_path
= job_dbus_path(u
->job
);
786 return sd_bus_message_append(
787 reply
, "(ssssssouso)",
790 unit_load_state_to_string(u
->load_state
),
791 unit_active_state_to_string(unit_active_state(u
)),
792 unit_sub_state_to_string(u
),
793 following
? following
->id
: "",
795 u
->job
? u
->job
->id
: 0,
796 u
->job
? job_type_to_string(u
->job
->type
) : "",
797 job_path
? job_path
: "/");
800 static int method_list_units_by_names(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
801 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
802 Manager
*m
= userdata
;
805 _cleanup_strv_free_
char **units
= NULL
;
810 r
= sd_bus_message_read_strv(message
, &units
);
814 r
= sd_bus_message_new_method_return(message
, &reply
);
818 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
822 STRV_FOREACH(unit
, units
) {
825 if (!unit_name_is_valid(*unit
, UNIT_NAME_ANY
))
828 r
= manager_load_unit(m
, *unit
, NULL
, error
, &u
);
832 r
= reply_unit_info(reply
, u
);
837 r
= sd_bus_message_close_container(reply
);
841 return sd_bus_send(NULL
, reply
, NULL
);
844 static int method_get_unit_processes(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
845 Manager
*m
= userdata
;
853 r
= sd_bus_message_read(message
, "s", &name
);
857 u
= manager_get_unit(m
, name
);
859 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s not loaded.", name
);
861 return bus_unit_method_get_processes(message
, u
, error
);
864 static int transient_unit_from_message(
866 sd_bus_message
*message
,
869 sd_bus_error
*error
) {
879 t
= unit_name_to_type(name
);
881 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid unit name or type.");
883 if (!unit_vtable
[t
]->can_transient
)
884 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unit type %s does not support transient units.", unit_type_to_string(t
));
886 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
890 if (!unit_is_pristine(u
))
891 return sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
, "Unit %s already exists.", name
);
893 /* OK, the unit failed to load and is unreferenced, now let's
894 * fill in the transient data instead */
895 r
= unit_make_transient(u
);
899 /* Set our properties */
900 r
= bus_unit_set_properties(u
, message
, UNIT_RUNTIME
, false, error
);
904 /* If the client asked for it, automatically add a reference to this unit. */
905 if (u
->bus_track_add
) {
906 r
= bus_unit_track_add_sender(u
, message
);
908 return log_error_errno(r
, "Failed to watch sender: %m");
911 /* Now load the missing bits of the unit we just created */
912 unit_add_to_load_queue(u
);
913 manager_dispatch_load_queue(m
);
920 static int transient_aux_units_from_message(
922 sd_bus_message
*message
,
923 sd_bus_error
*error
) {
930 r
= sd_bus_message_enter_container(message
, 'a', "(sa(sv))");
934 while ((r
= sd_bus_message_enter_container(message
, 'r', "sa(sv)")) > 0) {
935 const char *name
= NULL
;
938 r
= sd_bus_message_read(message
, "s", &name
);
942 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
946 r
= sd_bus_message_exit_container(message
);
953 r
= sd_bus_message_exit_container(message
);
960 static int method_start_transient_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
961 const char *name
, *smode
;
962 Manager
*m
= userdata
;
970 r
= mac_selinux_access_check(message
, "start", error
);
974 r
= sd_bus_message_read(message
, "ss", &name
, &smode
);
978 mode
= job_mode_from_string(smode
);
980 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Job mode %s is invalid.", smode
);
982 r
= bus_verify_manage_units_async(m
, message
, error
);
986 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
988 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
992 r
= transient_aux_units_from_message(m
, message
, error
);
996 /* Finally, start it */
997 return bus_unit_queue_job(message
, u
, JOB_START
, mode
, false, error
);
1000 static int method_get_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1001 _cleanup_free_
char *path
= NULL
;
1002 Manager
*m
= userdata
;
1010 /* Anyone can call this method */
1012 r
= sd_bus_message_read(message
, "u", &id
);
1016 j
= manager_get_job(m
, id
);
1018 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
1020 r
= mac_selinux_unit_access_check(j
->unit
, message
, "status", error
);
1024 path
= job_dbus_path(j
);
1028 return sd_bus_reply_method_return(message
, "o", path
);
1031 static int method_cancel_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1032 Manager
*m
= userdata
;
1040 r
= sd_bus_message_read(message
, "u", &id
);
1044 j
= manager_get_job(m
, id
);
1046 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
1048 return bus_job_method_cancel(message
, j
, error
);
1051 static int method_clear_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1052 Manager
*m
= userdata
;
1058 r
= mac_selinux_access_check(message
, "reload", error
);
1062 r
= bus_verify_manage_units_async(m
, message
, error
);
1066 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1068 manager_clear_jobs(m
);
1070 return sd_bus_reply_method_return(message
, NULL
);
1073 static int method_reset_failed(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1074 Manager
*m
= userdata
;
1080 r
= mac_selinux_access_check(message
, "reload", error
);
1084 r
= bus_verify_manage_units_async(m
, message
, error
);
1088 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1090 manager_reset_failed(m
);
1092 return sd_bus_reply_method_return(message
, NULL
);
1095 static int list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1096 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1097 Manager
*m
= userdata
;
1106 /* Anyone can call this method */
1108 r
= mac_selinux_access_check(message
, "status", error
);
1112 r
= sd_bus_message_new_method_return(message
, &reply
);
1116 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
1120 HASHMAP_FOREACH_KEY(u
, k
, m
->units
, i
) {
1124 if (!strv_isempty(states
) &&
1125 !strv_contains(states
, unit_load_state_to_string(u
->load_state
)) &&
1126 !strv_contains(states
, unit_active_state_to_string(unit_active_state(u
))) &&
1127 !strv_contains(states
, unit_sub_state_to_string(u
)))
1130 if (!strv_isempty(patterns
) &&
1131 !strv_fnmatch_or_empty(patterns
, u
->id
, FNM_NOESCAPE
))
1134 r
= reply_unit_info(reply
, u
);
1139 r
= sd_bus_message_close_container(reply
);
1143 return sd_bus_send(NULL
, reply
, NULL
);
1146 static int method_list_units(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1147 return list_units_filtered(message
, userdata
, error
, NULL
, NULL
);
1150 static int method_list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1151 _cleanup_strv_free_
char **states
= NULL
;
1154 r
= sd_bus_message_read_strv(message
, &states
);
1158 return list_units_filtered(message
, userdata
, error
, states
, NULL
);
1161 static int method_list_units_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1162 _cleanup_strv_free_
char **states
= NULL
;
1163 _cleanup_strv_free_
char **patterns
= NULL
;
1166 r
= sd_bus_message_read_strv(message
, &states
);
1170 r
= sd_bus_message_read_strv(message
, &patterns
);
1174 return list_units_filtered(message
, userdata
, error
, states
, patterns
);
1177 static int method_list_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1178 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1179 Manager
*m
= userdata
;
1187 /* Anyone can call this method */
1189 r
= mac_selinux_access_check(message
, "status", error
);
1193 r
= sd_bus_message_new_method_return(message
, &reply
);
1197 r
= sd_bus_message_open_container(reply
, 'a', "(usssoo)");
1201 HASHMAP_FOREACH(j
, m
->jobs
, i
) {
1202 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
1204 job_path
= job_dbus_path(j
);
1208 unit_path
= unit_dbus_path(j
->unit
);
1212 r
= sd_bus_message_append(
1216 job_type_to_string(j
->type
),
1217 job_state_to_string(j
->state
),
1224 r
= sd_bus_message_close_container(reply
);
1228 return sd_bus_send(NULL
, reply
, NULL
);
1231 static int method_subscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1232 Manager
*m
= userdata
;
1238 /* Anyone can call this method */
1240 r
= mac_selinux_access_check(message
, "status", error
);
1244 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1246 /* Note that direct bus connection subscribe by
1247 * default, we only track peers on the API bus here */
1249 if (!m
->subscribed
) {
1250 r
= sd_bus_track_new(sd_bus_message_get_bus(message
), &m
->subscribed
, NULL
, NULL
);
1255 r
= sd_bus_track_add_sender(m
->subscribed
, message
);
1259 return sd_bus_error_setf(error
, BUS_ERROR_ALREADY_SUBSCRIBED
, "Client is already subscribed.");
1262 return sd_bus_reply_method_return(message
, NULL
);
1265 static int method_unsubscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1266 Manager
*m
= userdata
;
1272 /* Anyone can call this method */
1274 r
= mac_selinux_access_check(message
, "status", error
);
1278 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1279 r
= sd_bus_track_remove_sender(m
->subscribed
, message
);
1283 return sd_bus_error_setf(error
, BUS_ERROR_NOT_SUBSCRIBED
, "Client is not subscribed.");
1286 return sd_bus_reply_method_return(message
, NULL
);
1289 static int method_dump(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1290 _cleanup_free_
char *dump
= NULL
;
1291 _cleanup_fclose_
FILE *f
= NULL
;
1292 Manager
*m
= userdata
;
1299 /* Anyone can call this method */
1301 r
= mac_selinux_access_check(message
, "status", error
);
1305 f
= open_memstream(&dump
, &size
);
1309 manager_dump_units(m
, f
, NULL
);
1310 manager_dump_jobs(m
, f
, NULL
);
1312 r
= fflush_and_check(f
);
1316 return sd_bus_reply_method_return(message
, "s", dump
);
1319 static int method_refuse_snapshot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1320 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Support for snapshots has been removed.");
1323 static int verify_run_space(const char *message
, sd_bus_error
*error
) {
1324 struct statvfs svfs
;
1327 if (statvfs("/run/systemd", &svfs
) < 0)
1328 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1330 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1332 if (available
< RELOAD_DISK_SPACE_MIN
) {
1333 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1334 return sd_bus_error_setf(error
,
1335 BUS_ERROR_DISK_FULL
,
1336 "%s, not enough space available on /run/systemd. "
1337 "Currently, %s are free, but a safety buffer of %s is enforced.",
1339 format_bytes(fb_available
, sizeof(fb_available
), available
),
1340 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1346 int verify_run_space_and_log(const char *message
) {
1347 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1350 r
= verify_run_space(message
, &error
);
1352 log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1357 static int method_reload(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1358 Manager
*m
= userdata
;
1364 r
= verify_run_space("Refusing to reload", error
);
1368 r
= mac_selinux_access_check(message
, "reload", error
);
1372 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1376 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1378 /* Instead of sending the reply back right away, we just
1379 * remember that we need to and then send it after the reload
1380 * is finished. That way the caller knows when the reload
1383 assert(!m
->queued_message
);
1384 r
= sd_bus_message_new_method_return(message
, &m
->queued_message
);
1388 m
->exit_code
= MANAGER_RELOAD
;
1393 static int method_reexecute(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1394 Manager
*m
= userdata
;
1400 r
= verify_run_space("Refusing to reexecute", error
);
1404 r
= mac_selinux_access_check(message
, "reload", error
);
1408 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1412 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1414 /* We don't send a reply back here, the client should
1415 * just wait for us disconnecting. */
1417 m
->exit_code
= MANAGER_REEXECUTE
;
1421 static int method_exit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1422 Manager
*m
= userdata
;
1428 r
= mac_selinux_access_check(message
, "halt", error
);
1432 /* Exit() (in contrast to SetExitCode()) is actually allowed even if
1433 * we are running on the host. It will fall back on reboot() in
1434 * systemd-shutdown if it cannot do the exit() because it isn't a
1437 m
->exit_code
= MANAGER_EXIT
;
1439 return sd_bus_reply_method_return(message
, NULL
);
1442 static int method_reboot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1443 Manager
*m
= userdata
;
1449 r
= mac_selinux_access_check(message
, "reboot", error
);
1453 if (!MANAGER_IS_SYSTEM(m
))
1454 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Reboot is only supported for system managers.");
1456 m
->exit_code
= MANAGER_REBOOT
;
1458 return sd_bus_reply_method_return(message
, NULL
);
1461 static int method_poweroff(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1462 Manager
*m
= userdata
;
1468 r
= mac_selinux_access_check(message
, "halt", error
);
1472 if (!MANAGER_IS_SYSTEM(m
))
1473 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Powering off is only supported for system managers.");
1475 m
->exit_code
= MANAGER_POWEROFF
;
1477 return sd_bus_reply_method_return(message
, NULL
);
1480 static int method_halt(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1481 Manager
*m
= userdata
;
1487 r
= mac_selinux_access_check(message
, "halt", error
);
1491 if (!MANAGER_IS_SYSTEM(m
))
1492 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Halt is only supported for system managers.");
1494 m
->exit_code
= MANAGER_HALT
;
1496 return sd_bus_reply_method_return(message
, NULL
);
1499 static int method_kexec(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1500 Manager
*m
= userdata
;
1506 r
= mac_selinux_access_check(message
, "reboot", error
);
1510 if (!MANAGER_IS_SYSTEM(m
))
1511 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "KExec is only supported for system managers.");
1513 m
->exit_code
= MANAGER_KEXEC
;
1515 return sd_bus_reply_method_return(message
, NULL
);
1518 static int method_switch_root(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1519 char *ri
= NULL
, *rt
= NULL
;
1520 const char *root
, *init
;
1521 Manager
*m
= userdata
;
1522 struct statvfs svfs
;
1529 if (statvfs("/run/systemd", &svfs
) < 0)
1530 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1532 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1534 if (available
< RELOAD_DISK_SPACE_MIN
) {
1535 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1536 log_warning("Dangerously low amount of free space on /run/systemd, root switching operation might not complete successfuly. "
1537 "Currently, %s are free, but %s are suggested. Proceeding anyway.",
1538 format_bytes(fb_available
, sizeof(fb_available
), available
),
1539 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1542 r
= mac_selinux_access_check(message
, "reboot", error
);
1546 if (!MANAGER_IS_SYSTEM(m
))
1547 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Root switching is only supported by system manager.");
1549 r
= sd_bus_message_read(message
, "ss", &root
, &init
);
1554 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory may not be the empty string.");
1555 if (!path_is_absolute(root
))
1556 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root path '%s' is not absolute.", root
);
1557 if (path_equal(root
, "/"))
1558 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory cannot be the old root directory.");
1561 if (isempty(init
)) {
1562 r
= path_is_os_tree(root
);
1564 return sd_bus_error_set_errnof(error
, r
, "Failed to determine whether root path '%s' contains an OS tree: %m", root
);
1566 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
);
1568 _cleanup_free_
char *chased
= NULL
;
1570 if (!path_is_absolute(init
))
1571 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path to init binary '%s' not absolute.", init
);
1573 r
= chase_symlinks(init
, root
, CHASE_PREFIX_ROOT
, &chased
);
1575 return sd_bus_error_set_errnof(error
, r
, "Could not resolve init executable %s: %m", init
);
1577 if (laccess(chased
, X_OK
) < 0) {
1578 if (errno
== EACCES
)
1579 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Init binary %s is not executable.", init
);
1581 return sd_bus_error_set_errnof(error
, r
, "Could not check whether init binary %s is executable: %m", init
);
1589 if (!isempty(init
)) {
1597 free(m
->switch_root
);
1598 m
->switch_root
= rt
;
1600 free(m
->switch_root_init
);
1601 m
->switch_root_init
= ri
;
1603 m
->exit_code
= MANAGER_SWITCH_ROOT
;
1605 return sd_bus_reply_method_return(message
, NULL
);
1608 static int method_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1609 _cleanup_strv_free_
char **plus
= NULL
;
1610 Manager
*m
= userdata
;
1616 r
= mac_selinux_access_check(message
, "reload", error
);
1620 r
= sd_bus_message_read_strv(message
, &plus
);
1623 if (!strv_env_is_valid(plus
))
1624 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1626 r
= bus_verify_set_environment_async(m
, message
, error
);
1630 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1632 r
= manager_environment_add(m
, NULL
, plus
);
1636 return sd_bus_reply_method_return(message
, NULL
);
1639 static int method_unset_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1640 _cleanup_strv_free_
char **minus
= NULL
;
1641 Manager
*m
= userdata
;
1647 r
= mac_selinux_access_check(message
, "reload", error
);
1651 r
= sd_bus_message_read_strv(message
, &minus
);
1655 if (!strv_env_name_or_assignment_is_valid(minus
))
1656 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1658 r
= bus_verify_set_environment_async(m
, message
, error
);
1662 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1664 r
= manager_environment_add(m
, minus
, NULL
);
1668 return sd_bus_reply_method_return(message
, NULL
);
1671 static int method_unset_and_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1672 _cleanup_strv_free_
char **minus
= NULL
, **plus
= NULL
;
1673 Manager
*m
= userdata
;
1679 r
= mac_selinux_access_check(message
, "reload", error
);
1683 r
= sd_bus_message_read_strv(message
, &minus
);
1687 r
= sd_bus_message_read_strv(message
, &plus
);
1691 if (!strv_env_name_or_assignment_is_valid(minus
))
1692 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1693 if (!strv_env_is_valid(plus
))
1694 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1696 r
= bus_verify_set_environment_async(m
, message
, error
);
1700 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1702 r
= manager_environment_add(m
, minus
, plus
);
1706 return sd_bus_reply_method_return(message
, NULL
);
1709 static int method_set_exit_code(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1710 Manager
*m
= userdata
;
1717 r
= mac_selinux_access_check(message
, "exit", error
);
1721 r
= sd_bus_message_read_basic(message
, 'y', &code
);
1725 if (MANAGER_IS_SYSTEM(m
) && detect_container() <= 0)
1726 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "ExitCode can only be set for user service managers or in containers.");
1728 m
->return_value
= code
;
1730 return sd_bus_reply_method_return(message
, NULL
);
1733 static int method_lookup_dynamic_user_by_name(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1734 Manager
*m
= userdata
;
1742 r
= sd_bus_message_read_basic(message
, 's', &name
);
1746 if (!MANAGER_IS_SYSTEM(m
))
1747 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1748 if (!valid_user_group_name(name
))
1749 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User name invalid: %s", name
);
1751 r
= dynamic_user_lookup_name(m
, name
, &uid
);
1753 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user %s does not exist.", name
);
1757 return sd_bus_reply_method_return(message
, "u", (uint32_t) uid
);
1760 static int method_lookup_dynamic_user_by_uid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1761 _cleanup_free_
char *name
= NULL
;
1762 Manager
*m
= userdata
;
1769 assert_cc(sizeof(uid
) == sizeof(uint32_t));
1770 r
= sd_bus_message_read_basic(message
, 'u', &uid
);
1774 if (!MANAGER_IS_SYSTEM(m
))
1775 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1776 if (!uid_is_valid(uid
))
1777 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User ID invalid: " UID_FMT
, uid
);
1779 r
= dynamic_user_lookup_uid(m
, uid
, &name
);
1781 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user ID " UID_FMT
" does not exist.", uid
);
1785 return sd_bus_reply_method_return(message
, "s", name
);
1788 static int list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1789 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1790 Manager
*m
= userdata
;
1799 /* Anyone can call this method */
1801 r
= mac_selinux_access_check(message
, "status", error
);
1805 r
= sd_bus_message_new_method_return(message
, &reply
);
1809 h
= hashmap_new(&string_hash_ops
);
1813 r
= unit_file_get_list(m
->unit_file_scope
, NULL
, h
, states
, patterns
);
1817 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1821 HASHMAP_FOREACH(item
, h
, i
) {
1823 r
= sd_bus_message_append(reply
, "(ss)", item
->path
, unit_file_state_to_string(item
->state
));
1828 unit_file_list_free(h
);
1830 r
= sd_bus_message_close_container(reply
);
1834 return sd_bus_send(NULL
, reply
, NULL
);
1837 unit_file_list_free(h
);
1841 static int method_list_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1842 return list_unit_files_by_patterns(message
, userdata
, error
, NULL
, NULL
);
1845 static int method_list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1846 _cleanup_strv_free_
char **states
= NULL
;
1847 _cleanup_strv_free_
char **patterns
= NULL
;
1850 r
= sd_bus_message_read_strv(message
, &states
);
1854 r
= sd_bus_message_read_strv(message
, &patterns
);
1858 return list_unit_files_by_patterns(message
, userdata
, error
, states
, patterns
);
1861 static int method_get_unit_file_state(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1862 Manager
*m
= userdata
;
1864 UnitFileState state
;
1870 /* Anyone can call this method */
1872 r
= mac_selinux_access_check(message
, "status", error
);
1876 r
= sd_bus_message_read(message
, "s", &name
);
1880 r
= unit_file_get_state(m
->unit_file_scope
, NULL
, name
, &state
);
1884 return sd_bus_reply_method_return(message
, "s", unit_file_state_to_string(state
));
1887 static int method_get_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1888 _cleanup_free_
char *default_target
= NULL
;
1889 Manager
*m
= userdata
;
1895 /* Anyone can call this method */
1897 r
= mac_selinux_access_check(message
, "status", error
);
1901 r
= unit_file_get_default(m
->unit_file_scope
, NULL
, &default_target
);
1905 return sd_bus_reply_method_return(message
, "s", default_target
);
1908 static int send_unit_files_changed(sd_bus
*bus
, void *userdata
) {
1909 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
1914 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
1918 return sd_bus_send(bus
, message
, NULL
);
1921 /* Create an error reply, using the error information from changes[]
1922 * if possible, and fall back to generating an error from error code c.
1923 * The error message only describes the first error.
1925 * Coordinate with unit_file_dump_changes() in install.c.
1927 static int install_error(
1928 sd_bus_error
*error
,
1930 UnitFileChange
*changes
,
1931 unsigned n_changes
) {
1935 for (i
= 0; i
< n_changes
; i
++)
1937 switch(changes
[i
].type
) {
1943 if (changes
[i
].source
)
1944 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1945 "File %s already exists and is a symlink to %s.",
1946 changes
[i
].path
, changes
[i
].source
);
1948 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1949 "File %s already exists.",
1954 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_MASKED
,
1955 "Unit file %s is masked.", changes
[i
].path
);
1958 case -EADDRNOTAVAIL
:
1959 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_GENERATED
,
1960 "Unit %s is transient or generated.", changes
[i
].path
);
1964 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_LINKED
,
1965 "Refusing to operate on linked unit file %s", changes
[i
].path
);
1969 r
= sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit file %s does not exist.", changes
[i
].path
);
1973 r
= sd_bus_error_set_errnof(error
, changes
[i
].type
, "File %s: %m", changes
[i
].path
);
1977 r
= c
< 0 ? c
: -EINVAL
;
1980 unit_file_changes_free(changes
, n_changes
);
1984 static int reply_unit_file_changes_and_free(
1986 sd_bus_message
*message
,
1987 int carries_install_info
,
1988 UnitFileChange
*changes
,
1990 sd_bus_error
*error
) {
1992 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1993 bool bad
= false, good
= false;
1997 if (unit_file_changes_have_modification(changes
, n_changes
)) {
1998 r
= bus_foreach_bus(m
, NULL
, send_unit_files_changed
, NULL
);
2000 log_debug_errno(r
, "Failed to send UnitFilesChanged signal: %m");
2003 r
= sd_bus_message_new_method_return(message
, &reply
);
2007 if (carries_install_info
>= 0) {
2008 r
= sd_bus_message_append(reply
, "b", carries_install_info
);
2013 r
= sd_bus_message_open_container(reply
, 'a', "(sss)");
2017 for (i
= 0; i
< n_changes
; i
++) {
2019 if (changes
[i
].type
< 0) {
2024 r
= sd_bus_message_append(
2026 unit_file_change_type_to_string(changes
[i
].type
),
2035 /* If there was a failed change, and no successful change, then return the first failure as proper method call
2038 return install_error(error
, 0, changes
, n_changes
);
2040 r
= sd_bus_message_close_container(reply
);
2044 unit_file_changes_free(changes
, n_changes
);
2045 return sd_bus_send(NULL
, reply
, NULL
);
2048 unit_file_changes_free(changes
, n_changes
);
2052 static int method_enable_unit_files_generic(
2053 sd_bus_message
*message
,
2055 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, unsigned *n_changes
),
2056 bool carries_install_info
,
2057 sd_bus_error
*error
) {
2059 _cleanup_strv_free_
char **l
= NULL
;
2060 UnitFileChange
*changes
= NULL
;
2061 unsigned n_changes
= 0;
2062 UnitFileFlags flags
;
2063 int runtime
, force
, r
;
2068 r
= sd_bus_message_read_strv(message
, &l
);
2072 r
= sd_bus_message_read(message
, "bb", &runtime
, &force
);
2076 flags
= unit_file_bools_to_flags(runtime
, force
);
2078 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2082 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2084 r
= call(m
->unit_file_scope
, flags
, NULL
, l
, &changes
, &n_changes
);
2086 return install_error(error
, r
, changes
, n_changes
);
2088 return reply_unit_file_changes_and_free(m
, message
, carries_install_info
? r
: -1, changes
, n_changes
, error
);
2091 static int method_enable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2092 return method_enable_unit_files_generic(message
, userdata
, unit_file_enable
, true, error
);
2095 static int method_reenable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2096 return method_enable_unit_files_generic(message
, userdata
, unit_file_reenable
, true, error
);
2099 static int method_link_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2100 return method_enable_unit_files_generic(message
, userdata
, unit_file_link
, false, error
);
2103 static int unit_file_preset_without_mode(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char **files
, UnitFileChange
**changes
, unsigned *n_changes
) {
2104 return unit_file_preset(scope
, flags
, root_dir
, files
, UNIT_FILE_PRESET_FULL
, changes
, n_changes
);
2107 static int method_preset_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2108 return method_enable_unit_files_generic(message
, userdata
, unit_file_preset_without_mode
, true, error
);
2111 static int method_mask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2112 return method_enable_unit_files_generic(message
, userdata
, unit_file_mask
, false, error
);
2115 static int method_preset_unit_files_with_mode(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2117 _cleanup_strv_free_
char **l
= NULL
;
2118 UnitFileChange
*changes
= NULL
;
2119 unsigned n_changes
= 0;
2120 Manager
*m
= userdata
;
2121 UnitFilePresetMode mm
;
2122 int runtime
, force
, r
;
2123 UnitFileFlags flags
;
2129 r
= sd_bus_message_read_strv(message
, &l
);
2133 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2137 flags
= unit_file_bools_to_flags(runtime
, force
);
2140 mm
= UNIT_FILE_PRESET_FULL
;
2142 mm
= unit_file_preset_mode_from_string(mode
);
2147 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2151 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2153 r
= unit_file_preset(m
->unit_file_scope
, flags
, NULL
, l
, mm
, &changes
, &n_changes
);
2155 return install_error(error
, r
, changes
, n_changes
);
2157 return reply_unit_file_changes_and_free(m
, message
, r
, changes
, n_changes
, error
);
2160 static int method_disable_unit_files_generic(
2161 sd_bus_message
*message
,
2163 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, unsigned *n_changes
),
2164 sd_bus_error
*error
) {
2166 _cleanup_strv_free_
char **l
= NULL
;
2167 UnitFileChange
*changes
= NULL
;
2168 unsigned n_changes
= 0;
2174 r
= sd_bus_message_read_strv(message
, &l
);
2178 r
= sd_bus_message_read(message
, "b", &runtime
);
2182 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2186 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2188 r
= call(m
->unit_file_scope
, runtime
? UNIT_FILE_RUNTIME
: 0, NULL
, l
, &changes
, &n_changes
);
2190 return install_error(error
, r
, changes
, n_changes
);
2192 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2195 static int method_disable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2196 return method_disable_unit_files_generic(message
, userdata
, unit_file_disable
, error
);
2199 static int method_unmask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2200 return method_disable_unit_files_generic(message
, userdata
, unit_file_unmask
, error
);
2203 static int method_revert_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2204 _cleanup_strv_free_
char **l
= NULL
;
2205 UnitFileChange
*changes
= NULL
;
2206 unsigned n_changes
= 0;
2207 Manager
*m
= userdata
;
2213 r
= sd_bus_message_read_strv(message
, &l
);
2217 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2221 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2223 r
= unit_file_revert(m
->unit_file_scope
, NULL
, l
, &changes
, &n_changes
);
2225 return install_error(error
, r
, changes
, n_changes
);
2227 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2230 static int method_set_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2231 UnitFileChange
*changes
= NULL
;
2232 unsigned n_changes
= 0;
2233 Manager
*m
= userdata
;
2240 r
= mac_selinux_access_check(message
, "enable", error
);
2244 r
= sd_bus_message_read(message
, "sb", &name
, &force
);
2248 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2252 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2254 r
= unit_file_set_default(m
->unit_file_scope
, force
? UNIT_FILE_FORCE
: 0, NULL
, name
, &changes
, &n_changes
);
2256 return install_error(error
, r
, changes
, n_changes
);
2258 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2261 static int method_preset_all_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2262 UnitFileChange
*changes
= NULL
;
2263 unsigned n_changes
= 0;
2264 Manager
*m
= userdata
;
2265 UnitFilePresetMode mm
;
2267 UnitFileFlags flags
;
2268 int force
, runtime
, r
;
2273 r
= mac_selinux_access_check(message
, "enable", error
);
2277 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2281 flags
= unit_file_bools_to_flags(runtime
, force
);
2284 mm
= UNIT_FILE_PRESET_FULL
;
2286 mm
= unit_file_preset_mode_from_string(mode
);
2291 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2295 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2297 r
= unit_file_preset_all(m
->unit_file_scope
, flags
, NULL
, mm
, &changes
, &n_changes
);
2299 return install_error(error
, r
, changes
, n_changes
);
2301 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2304 static int method_add_dependency_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2305 _cleanup_strv_free_
char **l
= NULL
;
2306 Manager
*m
= userdata
;
2307 UnitFileChange
*changes
= NULL
;
2308 unsigned n_changes
= 0;
2309 int runtime
, force
, r
;
2310 char *target
, *type
;
2312 UnitFileFlags flags
;
2317 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2321 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2323 r
= sd_bus_message_read_strv(message
, &l
);
2327 r
= sd_bus_message_read(message
, "ssbb", &target
, &type
, &runtime
, &force
);
2331 flags
= unit_file_bools_to_flags(runtime
, force
);
2333 dep
= unit_dependency_from_string(type
);
2337 r
= unit_file_add_dependency(m
->unit_file_scope
, flags
, NULL
, l
, target
, dep
, &changes
, &n_changes
);
2339 return install_error(error
, r
, changes
, n_changes
);
2341 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2344 static int method_get_unit_file_links(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2345 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
2346 UnitFileChange
*changes
= NULL
;
2347 unsigned n_changes
= 0, i
;
2348 UnitFileFlags flags
;
2353 r
= sd_bus_message_read(message
, "sb", &name
, &runtime
);
2357 r
= sd_bus_message_new_method_return(message
, &reply
);
2361 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_ARRAY
, "s");
2365 p
= STRV_MAKE(name
);
2366 flags
= UNIT_FILE_DRY_RUN
|
2367 (runtime
? UNIT_FILE_RUNTIME
: 0);
2369 r
= unit_file_disable(UNIT_FILE_SYSTEM
, flags
, NULL
, p
, &changes
, &n_changes
);
2371 return log_error_errno(r
, "Failed to get file links for %s: %m", name
);
2373 for (i
= 0; i
< n_changes
; i
++)
2374 if (changes
[i
].type
== UNIT_FILE_UNLINK
) {
2375 r
= sd_bus_message_append(reply
, "s", changes
[i
].path
);
2380 r
= sd_bus_message_close_container(reply
);
2384 return sd_bus_send(NULL
, reply
, NULL
);
2387 static int method_get_job_waiting(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2388 Manager
*m
= userdata
;
2396 r
= sd_bus_message_read(message
, "u", &id
);
2400 j
= manager_get_job(m
, id
);
2402 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
2404 return bus_job_method_get_waiting_jobs(message
, j
, error
);
2407 const sd_bus_vtable bus_manager_vtable
[] = {
2408 SD_BUS_VTABLE_START(0),
2410 SD_BUS_PROPERTY("Version", "s", property_get_version
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2411 SD_BUS_PROPERTY("Features", "s", property_get_features
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2412 SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2413 SD_BUS_PROPERTY("Architecture", "s", property_get_architecture
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2414 SD_BUS_PROPERTY("Tainted", "s", property_get_tainted
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2415 BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager
, firmware_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2416 BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager
, loader_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2417 BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager
, kernel_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2418 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager
, initrd_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2419 BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager
, userspace_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2420 BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager
, finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2421 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager
, security_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2422 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager
, security_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2423 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager
, generators_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2424 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager
, generators_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2425 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager
, units_load_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2426 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager
, units_load_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2427 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level
, property_set_log_level
, 0, 0),
2428 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target
, property_set_log_target
, 0, 0),
2429 SD_BUS_PROPERTY("NNames", "u", property_get_n_names
, 0, 0),
2430 SD_BUS_PROPERTY("NFailedUnits", "u", property_get_n_failed_units
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
2431 SD_BUS_PROPERTY("NJobs", "u", property_get_n_jobs
, 0, 0),
2432 SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_installed_jobs
), 0),
2433 SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_failed_jobs
), 0),
2434 SD_BUS_PROPERTY("Progress", "d", property_get_progress
, 0, 0),
2435 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(Manager
, environment
), 0),
2436 SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool
, offsetof(Manager
, confirm_spawn
), SD_BUS_VTABLE_PROPERTY_CONST
),
2437 SD_BUS_PROPERTY("ShowStatus", "b", bus_property_get_bool
, offsetof(Manager
, show_status
), SD_BUS_VTABLE_PROPERTY_CONST
),
2438 SD_BUS_PROPERTY("UnitPath", "as", NULL
, offsetof(Manager
, lookup_paths
.search_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
2439 SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2440 SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2441 SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec
, property_set_runtime_watchdog
, offsetof(Manager
, runtime_watchdog
), 0),
2442 SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec
, bus_property_set_usec
, offsetof(Manager
, shutdown_watchdog
), 0),
2443 SD_BUS_PROPERTY("ControlGroup", "s", NULL
, offsetof(Manager
, cgroup_root
), 0),
2444 SD_BUS_PROPERTY("SystemState", "s", property_get_system_state
, 0, 0),
2445 SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned
, offsetof(Manager
, return_value
), 0),
2446 SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timer_accuracy_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2447 SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_start_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2448 SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_stop_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2449 SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_restart_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2450 SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
),
2451 SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
), /* obsolete alias name */
2452 SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned
, offsetof(Manager
, default_start_limit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
2453 SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_cpu_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2454 SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_blockio_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2455 SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_memory_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2456 SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_tasks_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2457 SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2458 SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2459 SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2460 SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2461 SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2462 SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2463 SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2464 SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2465 SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2466 SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2467 SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2468 SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2469 SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2470 SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2471 SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2472 SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2473 SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2474 SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2475 SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2476 SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2477 SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2478 SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2479 SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2480 SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2481 SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2482 SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2483 SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2484 SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2485 SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2486 SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2487 SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2488 SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2489 SD_BUS_PROPERTY("DefaultTasksMax", "t", NULL
, offsetof(Manager
, default_tasks_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
2490 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2492 SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2493 SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2494 SD_BUS_METHOD("GetUnitByInvocationID", "ay", "o", method_get_unit_by_invocation_id
, SD_BUS_VTABLE_UNPRIVILEGED
),
2495 SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2496 SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2497 SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace
, SD_BUS_VTABLE_UNPRIVILEGED
),
2498 SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2499 SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2500 SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2501 SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2502 SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2503 SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2504 SD_BUS_METHOD("KillUnit", "ssi", NULL
, method_kill_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2505 SD_BUS_METHOD("ResetFailedUnit", "s", NULL
, method_reset_failed_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2506 SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL
, method_set_unit_properties
, SD_BUS_VTABLE_UNPRIVILEGED
),
2507 SD_BUS_METHOD("RefUnit", "s", NULL
, method_ref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2508 SD_BUS_METHOD("UnrefUnit", "s", NULL
, method_unref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2509 SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2510 SD_BUS_METHOD("GetUnitProcesses", "s", "a(sus)", method_get_unit_processes
, SD_BUS_VTABLE_UNPRIVILEGED
),
2511 SD_BUS_METHOD("GetJob", "u", "o", method_get_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2512 SD_BUS_METHOD("GetJobAfter", "u", "a(usssoo)", method_get_job_waiting
, SD_BUS_VTABLE_UNPRIVILEGED
),
2513 SD_BUS_METHOD("GetJobBefore", "u", "a(usssoo)", method_get_job_waiting
, SD_BUS_VTABLE_UNPRIVILEGED
),
2514 SD_BUS_METHOD("CancelJob", "u", NULL
, method_cancel_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2515 SD_BUS_METHOD("ClearJobs", NULL
, NULL
, method_clear_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2516 SD_BUS_METHOD("ResetFailed", NULL
, NULL
, method_reset_failed
, SD_BUS_VTABLE_UNPRIVILEGED
),
2517 SD_BUS_METHOD("ListUnits", NULL
, "a(ssssssouso)", method_list_units
, SD_BUS_VTABLE_UNPRIVILEGED
),
2518 SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered
, SD_BUS_VTABLE_UNPRIVILEGED
),
2519 SD_BUS_METHOD("ListUnitsByPatterns", "asas", "a(ssssssouso)", method_list_units_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2520 SD_BUS_METHOD("ListUnitsByNames", "as", "a(ssssssouso)", method_list_units_by_names
, SD_BUS_VTABLE_UNPRIVILEGED
),
2521 SD_BUS_METHOD("ListJobs", NULL
, "a(usssoo)", method_list_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2522 SD_BUS_METHOD("Subscribe", NULL
, NULL
, method_subscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2523 SD_BUS_METHOD("Unsubscribe", NULL
, NULL
, method_unsubscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2524 SD_BUS_METHOD("Dump", NULL
, "s", method_dump
, SD_BUS_VTABLE_UNPRIVILEGED
),
2525 SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
),
2526 SD_BUS_METHOD("RemoveSnapshot", "s", NULL
, method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
),
2527 SD_BUS_METHOD("Reload", NULL
, NULL
, method_reload
, SD_BUS_VTABLE_UNPRIVILEGED
),
2528 SD_BUS_METHOD("Reexecute", NULL
, NULL
, method_reexecute
, SD_BUS_VTABLE_UNPRIVILEGED
),
2529 SD_BUS_METHOD("Exit", NULL
, NULL
, method_exit
, 0),
2530 SD_BUS_METHOD("Reboot", NULL
, NULL
, method_reboot
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2531 SD_BUS_METHOD("PowerOff", NULL
, NULL
, method_poweroff
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2532 SD_BUS_METHOD("Halt", NULL
, NULL
, method_halt
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2533 SD_BUS_METHOD("KExec", NULL
, NULL
, method_kexec
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2534 SD_BUS_METHOD("SwitchRoot", "ss", NULL
, method_switch_root
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2535 SD_BUS_METHOD("SetEnvironment", "as", NULL
, method_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2536 SD_BUS_METHOD("UnsetEnvironment", "as", NULL
, method_unset_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2537 SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL
, method_unset_and_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2538 SD_BUS_METHOD("ListUnitFiles", NULL
, "a(ss)", method_list_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2539 SD_BUS_METHOD("ListUnitFilesByPatterns", "asas", "a(ss)", method_list_unit_files_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2540 SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state
, SD_BUS_VTABLE_UNPRIVILEGED
),
2541 SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2542 SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2543 SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2544 SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2545 SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2546 SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode
, SD_BUS_VTABLE_UNPRIVILEGED
),
2547 SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2548 SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2549 SD_BUS_METHOD("RevertUnitFiles", "as", "a(sss)", method_revert_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2550 SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2551 SD_BUS_METHOD("GetDefaultTarget", NULL
, "s", method_get_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2552 SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2553 SD_BUS_METHOD("AddDependencyUnitFiles", "asssbb", "a(sss)", method_add_dependency_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2554 SD_BUS_METHOD("GetUnitFileLinks", "sb", "as", method_get_unit_file_links
, SD_BUS_VTABLE_UNPRIVILEGED
),
2555 SD_BUS_METHOD("SetExitCode", "y", NULL
, method_set_exit_code
, SD_BUS_VTABLE_UNPRIVILEGED
),
2556 SD_BUS_METHOD("LookupDynamicUserByName", "s", "u", method_lookup_dynamic_user_by_name
, SD_BUS_VTABLE_UNPRIVILEGED
),
2557 SD_BUS_METHOD("LookupDynamicUserByUID", "u", "s", method_lookup_dynamic_user_by_uid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2559 SD_BUS_SIGNAL("UnitNew", "so", 0),
2560 SD_BUS_SIGNAL("UnitRemoved", "so", 0),
2561 SD_BUS_SIGNAL("JobNew", "uos", 0),
2562 SD_BUS_SIGNAL("JobRemoved", "uoss", 0),
2563 SD_BUS_SIGNAL("StartupFinished", "tttttt", 0),
2564 SD_BUS_SIGNAL("UnitFilesChanged", NULL
, 0),
2565 SD_BUS_SIGNAL("Reloading", "b", 0),
2570 static int send_finished(sd_bus
*bus
, void *userdata
) {
2571 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2572 usec_t
*times
= userdata
;
2578 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
2582 r
= sd_bus_message_append(message
, "tttttt", times
[0], times
[1], times
[2], times
[3], times
[4], times
[5]);
2586 return sd_bus_send(bus
, message
, NULL
);
2589 void bus_manager_send_finished(
2591 usec_t firmware_usec
,
2595 usec_t userspace_usec
,
2596 usec_t total_usec
) {
2602 r
= bus_foreach_bus(
2615 log_debug_errno(r
, "Failed to send finished signal: %m");
2618 static int send_reloading(sd_bus
*bus
, void *userdata
) {
2619 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2624 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
2628 r
= sd_bus_message_append(message
, "b", PTR_TO_INT(userdata
));
2632 return sd_bus_send(bus
, message
, NULL
);
2635 void bus_manager_send_reloading(Manager
*m
, bool active
) {
2640 r
= bus_foreach_bus(m
, NULL
, send_reloading
, INT_TO_PTR(active
));
2642 log_debug_errno(r
, "Failed to send reloading signal: %m");
2645 static int send_changed_signal(sd_bus
*bus
, void *userdata
) {
2648 return sd_bus_emit_properties_changed_strv(bus
,
2649 "/org/freedesktop/systemd1",
2650 "org.freedesktop.systemd1.Manager",
2654 void bus_manager_send_change_signal(Manager
*m
) {
2659 r
= bus_foreach_bus(m
, NULL
, send_changed_signal
, NULL
);
2661 log_debug_errno(r
, "Failed to send manager change signal: %m");