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 "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 _cleanup_free_
char *s
= NULL
;
143 Manager
*m
= userdata
;
149 s
= manager_taint_string(m
);
153 return sd_bus_message_append(reply
, "s", s
);
156 static int property_get_log_target(
159 const char *interface
,
160 const char *property
,
161 sd_bus_message
*reply
,
163 sd_bus_error
*error
) {
168 return sd_bus_message_append(reply
, "s", log_target_to_string(log_get_target()));
171 static int property_set_log_target(
174 const char *interface
,
175 const char *property
,
176 sd_bus_message
*value
,
178 sd_bus_error
*error
) {
186 r
= sd_bus_message_read(value
, "s", &t
);
190 return log_set_target_from_string(t
);
193 static int property_get_log_level(
196 const char *interface
,
197 const char *property
,
198 sd_bus_message
*reply
,
200 sd_bus_error
*error
) {
202 _cleanup_free_
char *t
= NULL
;
208 r
= log_level_to_string_alloc(log_get_max_level(), &t
);
212 return sd_bus_message_append(reply
, "s", t
);
215 static int property_set_log_level(
218 const char *interface
,
219 const char *property
,
220 sd_bus_message
*value
,
222 sd_bus_error
*error
) {
230 r
= sd_bus_message_read(value
, "s", &t
);
234 r
= log_set_max_level_from_string(t
);
236 log_info("Setting log level to %s.", t
);
240 static int property_get_n_names(
243 const char *interface
,
244 const char *property
,
245 sd_bus_message
*reply
,
247 sd_bus_error
*error
) {
249 Manager
*m
= userdata
;
255 return sd_bus_message_append(reply
, "u", (uint32_t) hashmap_size(m
->units
));
258 static int property_get_n_failed_units(
261 const char *interface
,
262 const char *property
,
263 sd_bus_message
*reply
,
265 sd_bus_error
*error
) {
267 Manager
*m
= userdata
;
273 return sd_bus_message_append(reply
, "u", (uint32_t) set_size(m
->failed_units
));
276 static int property_get_n_jobs(
279 const char *interface
,
280 const char *property
,
281 sd_bus_message
*reply
,
283 sd_bus_error
*error
) {
285 Manager
*m
= userdata
;
291 return sd_bus_message_append(reply
, "u", (uint32_t) hashmap_size(m
->jobs
));
294 static int property_get_progress(
297 const char *interface
,
298 const char *property
,
299 sd_bus_message
*reply
,
301 sd_bus_error
*error
) {
303 Manager
*m
= userdata
;
310 if (MANAGER_IS_FINISHED(m
))
313 d
= 1.0 - ((double) hashmap_size(m
->jobs
) / (double) m
->n_installed_jobs
);
315 return sd_bus_message_append(reply
, "d", d
);
318 static int property_get_system_state(
321 const char *interface
,
322 const char *property
,
323 sd_bus_message
*reply
,
325 sd_bus_error
*error
) {
327 Manager
*m
= userdata
;
333 return sd_bus_message_append(reply
, "s", manager_state_to_string(manager_state(m
)));
336 static int property_set_runtime_watchdog(
339 const char *interface
,
340 const char *property
,
341 sd_bus_message
*value
,
343 sd_bus_error
*error
) {
345 usec_t
*t
= userdata
;
351 assert_cc(sizeof(usec_t
) == sizeof(uint64_t));
353 r
= sd_bus_message_read(value
, "t", t
);
357 return watchdog_set_timeout(t
);
360 static int property_get_timer_slack_nsec(
363 const char *interface
,
364 const char *property
,
365 sd_bus_message
*reply
,
367 sd_bus_error
*error
) {
372 return sd_bus_message_append(reply
, "t", (uint64_t) prctl(PR_GET_TIMERSLACK
));
375 static int bus_get_unit_by_name(Manager
*m
, sd_bus_message
*message
, const char *name
, Unit
**ret_unit
, sd_bus_error
*error
) {
383 /* More or less a wrapper around manager_get_unit() that generates nice errors and has one trick up its sleeve:
384 * if the name is specified empty we use the client's unit. */
387 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
390 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
394 r
= sd_bus_creds_get_pid(creds
, &pid
);
398 u
= manager_get_unit_by_pid(m
, pid
);
400 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
402 u
= manager_get_unit(m
, name
);
404 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s not loaded.", name
);
411 static int bus_load_unit_by_name(Manager
*m
, sd_bus_message
*message
, const char *name
, Unit
**ret_unit
, sd_bus_error
*error
) {
416 /* Pretty much the same as bus_get_unit_by_name(), but we also load the unit if necessary. */
419 return bus_get_unit_by_name(m
, message
, name
, ret_unit
, error
);
421 return manager_load_unit(m
, name
, NULL
, error
, ret_unit
);
424 static int method_get_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
425 _cleanup_free_
char *path
= NULL
;
426 Manager
*m
= userdata
;
434 /* Anyone can call this method */
436 r
= sd_bus_message_read(message
, "s", &name
);
440 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
444 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
448 path
= unit_dbus_path(u
);
452 return sd_bus_reply_method_return(message
, "o", path
);
455 static int method_get_unit_by_pid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
456 _cleanup_free_
char *path
= NULL
;
457 Manager
*m
= userdata
;
465 assert_cc(sizeof(pid_t
) == sizeof(uint32_t));
467 /* Anyone can call this method */
469 r
= sd_bus_message_read(message
, "u", &pid
);
473 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PID " PID_FMT
, pid
);
476 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
478 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
482 r
= sd_bus_creds_get_pid(creds
, &pid
);
487 u
= manager_get_unit_by_pid(m
, pid
);
489 return sd_bus_error_setf(error
, BUS_ERROR_NO_UNIT_FOR_PID
, "PID "PID_FMT
" does not belong to any loaded unit.", pid
);
491 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
495 path
= unit_dbus_path(u
);
499 return sd_bus_reply_method_return(message
, "o", path
);
502 static int method_get_unit_by_invocation_id(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
503 _cleanup_free_
char *path
= NULL
;
504 Manager
*m
= userdata
;
514 /* Anyone can call this method */
516 r
= sd_bus_message_read_array(message
, 'y', &a
, &sz
);
524 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid invocation ID");
526 if (sd_id128_is_null(id
)) {
527 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
530 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
534 r
= sd_bus_creds_get_pid(creds
, &pid
);
538 u
= manager_get_unit_by_pid(m
, pid
);
540 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client " PID_FMT
" not member of any unit.", pid
);
542 u
= hashmap_get(m
->units_by_invocation_id
, &id
);
544 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
));
547 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
551 /* So here's a special trick: the bus path we return actually references the unit by its invocation ID instead
552 * of the unit name. This means it stays valid only as long as the invocation ID stays the same. */
553 path
= unit_dbus_path_invocation_id(u
);
557 return sd_bus_reply_method_return(message
, "o", path
);
560 static int method_load_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
561 _cleanup_free_
char *path
= NULL
;
562 Manager
*m
= userdata
;
570 /* Anyone can call this method */
572 r
= sd_bus_message_read(message
, "s", &name
);
576 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
580 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 r
= bus_get_unit_by_name(m
, message
, old_name
, &u
, error
);
654 if (!u
->job
|| u
->job
->type
!= JOB_START
)
655 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "No job queued for unit %s", old_name
);
657 return method_start_unit_generic(message
, m
, JOB_START
, false, error
);
660 static int method_kill_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
661 Manager
*m
= userdata
;
669 r
= sd_bus_message_read(message
, "s", &name
);
673 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
677 return bus_unit_method_kill(message
, u
, error
);
680 static int method_reset_failed_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
681 Manager
*m
= userdata
;
689 r
= sd_bus_message_read(message
, "s", &name
);
693 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
697 return bus_unit_method_reset_failed(message
, u
, error
);
700 static int method_set_unit_properties(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
701 Manager
*m
= userdata
;
709 r
= sd_bus_message_read(message
, "s", &name
);
713 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
717 r
= bus_unit_check_load_state(u
, error
);
721 return bus_unit_method_set_properties(message
, u
, error
);
724 static int method_ref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
725 Manager
*m
= userdata
;
733 r
= sd_bus_message_read(message
, "s", &name
);
737 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
741 r
= bus_unit_check_load_state(u
, error
);
745 return bus_unit_method_ref(message
, u
, error
);
748 static int method_unref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
749 Manager
*m
= userdata
;
757 r
= sd_bus_message_read(message
, "s", &name
);
761 r
= bus_load_unit_by_name(m
, message
, name
, &u
, error
);
765 r
= bus_unit_check_load_state(u
, error
);
769 return bus_unit_method_unref(message
, u
, error
);
772 static int reply_unit_info(sd_bus_message
*reply
, Unit
*u
) {
773 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
776 following
= unit_following(u
);
778 unit_path
= unit_dbus_path(u
);
783 job_path
= job_dbus_path(u
->job
);
788 return sd_bus_message_append(
789 reply
, "(ssssssouso)",
792 unit_load_state_to_string(u
->load_state
),
793 unit_active_state_to_string(unit_active_state(u
)),
794 unit_sub_state_to_string(u
),
795 following
? following
->id
: "",
797 u
->job
? u
->job
->id
: 0,
798 u
->job
? job_type_to_string(u
->job
->type
) : "",
799 job_path
? job_path
: "/");
802 static int method_list_units_by_names(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
803 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
804 Manager
*m
= userdata
;
807 _cleanup_strv_free_
char **units
= NULL
;
812 r
= sd_bus_message_read_strv(message
, &units
);
816 r
= sd_bus_message_new_method_return(message
, &reply
);
820 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
824 STRV_FOREACH(unit
, units
) {
827 if (!unit_name_is_valid(*unit
, UNIT_NAME_ANY
))
830 r
= bus_load_unit_by_name(m
, message
, *unit
, &u
, error
);
834 r
= reply_unit_info(reply
, u
);
839 r
= sd_bus_message_close_container(reply
);
843 return sd_bus_send(NULL
, reply
, NULL
);
846 static int method_get_unit_processes(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
847 Manager
*m
= userdata
;
855 r
= sd_bus_message_read(message
, "s", &name
);
859 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
863 return bus_unit_method_get_processes(message
, u
, error
);
866 static int method_attach_processes_to_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
867 Manager
*m
= userdata
;
875 r
= sd_bus_message_read(message
, "s", &name
);
879 r
= bus_get_unit_by_name(m
, message
, name
, &u
, error
);
883 return bus_unit_method_attach_processes(message
, u
, error
);
886 static int transient_unit_from_message(
888 sd_bus_message
*message
,
891 sd_bus_error
*error
) {
901 t
= unit_name_to_type(name
);
903 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid unit name or type.");
905 if (!unit_vtable
[t
]->can_transient
)
906 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unit type %s does not support transient units.", unit_type_to_string(t
));
908 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
912 if (!unit_is_pristine(u
))
913 return sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
, "Unit %s already exists.", name
);
915 /* OK, the unit failed to load and is unreferenced, now let's
916 * fill in the transient data instead */
917 r
= unit_make_transient(u
);
921 /* Set our properties */
922 r
= bus_unit_set_properties(u
, message
, UNIT_RUNTIME
, false, error
);
926 /* If the client asked for it, automatically add a reference to this unit. */
927 if (u
->bus_track_add
) {
928 r
= bus_unit_track_add_sender(u
, message
);
930 return log_error_errno(r
, "Failed to watch sender: %m");
933 /* Now load the missing bits of the unit we just created */
934 unit_add_to_load_queue(u
);
935 manager_dispatch_load_queue(m
);
942 static int transient_aux_units_from_message(
944 sd_bus_message
*message
,
945 sd_bus_error
*error
) {
952 r
= sd_bus_message_enter_container(message
, 'a', "(sa(sv))");
956 while ((r
= sd_bus_message_enter_container(message
, 'r', "sa(sv)")) > 0) {
957 const char *name
= NULL
;
960 r
= sd_bus_message_read(message
, "s", &name
);
964 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
968 r
= sd_bus_message_exit_container(message
);
975 r
= sd_bus_message_exit_container(message
);
982 static int method_start_transient_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
983 const char *name
, *smode
;
984 Manager
*m
= userdata
;
992 r
= mac_selinux_access_check(message
, "start", error
);
996 r
= sd_bus_message_read(message
, "ss", &name
, &smode
);
1000 mode
= job_mode_from_string(smode
);
1002 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Job mode %s is invalid.", smode
);
1004 r
= bus_verify_manage_units_async(m
, message
, error
);
1008 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1010 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
1014 r
= transient_aux_units_from_message(m
, message
, error
);
1018 /* Finally, start it */
1019 return bus_unit_queue_job(message
, u
, JOB_START
, mode
, false, error
);
1022 static int method_get_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1023 _cleanup_free_
char *path
= NULL
;
1024 Manager
*m
= userdata
;
1032 /* Anyone can call this method */
1034 r
= sd_bus_message_read(message
, "u", &id
);
1038 j
= manager_get_job(m
, id
);
1040 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
1042 r
= mac_selinux_unit_access_check(j
->unit
, message
, "status", error
);
1046 path
= job_dbus_path(j
);
1050 return sd_bus_reply_method_return(message
, "o", path
);
1053 static int method_cancel_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1054 Manager
*m
= userdata
;
1062 r
= sd_bus_message_read(message
, "u", &id
);
1066 j
= manager_get_job(m
, id
);
1068 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
1070 return bus_job_method_cancel(message
, j
, error
);
1073 static int method_clear_jobs(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_clear_jobs(m
);
1092 return sd_bus_reply_method_return(message
, NULL
);
1095 static int method_reset_failed(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1096 Manager
*m
= userdata
;
1102 r
= mac_selinux_access_check(message
, "reload", error
);
1106 r
= bus_verify_manage_units_async(m
, message
, error
);
1110 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1112 manager_reset_failed(m
);
1114 return sd_bus_reply_method_return(message
, NULL
);
1117 static int list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1118 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1119 Manager
*m
= userdata
;
1128 /* Anyone can call this method */
1130 r
= mac_selinux_access_check(message
, "status", error
);
1134 r
= sd_bus_message_new_method_return(message
, &reply
);
1138 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
1142 HASHMAP_FOREACH_KEY(u
, k
, m
->units
, i
) {
1146 if (!strv_isempty(states
) &&
1147 !strv_contains(states
, unit_load_state_to_string(u
->load_state
)) &&
1148 !strv_contains(states
, unit_active_state_to_string(unit_active_state(u
))) &&
1149 !strv_contains(states
, unit_sub_state_to_string(u
)))
1152 if (!strv_isempty(patterns
) &&
1153 !strv_fnmatch_or_empty(patterns
, u
->id
, FNM_NOESCAPE
))
1156 r
= reply_unit_info(reply
, u
);
1161 r
= sd_bus_message_close_container(reply
);
1165 return sd_bus_send(NULL
, reply
, NULL
);
1168 static int method_list_units(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1169 return list_units_filtered(message
, userdata
, error
, NULL
, NULL
);
1172 static int method_list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1173 _cleanup_strv_free_
char **states
= NULL
;
1176 r
= sd_bus_message_read_strv(message
, &states
);
1180 return list_units_filtered(message
, userdata
, error
, states
, NULL
);
1183 static int method_list_units_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1184 _cleanup_strv_free_
char **states
= NULL
;
1185 _cleanup_strv_free_
char **patterns
= NULL
;
1188 r
= sd_bus_message_read_strv(message
, &states
);
1192 r
= sd_bus_message_read_strv(message
, &patterns
);
1196 return list_units_filtered(message
, userdata
, error
, states
, patterns
);
1199 static int method_list_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1200 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1201 Manager
*m
= userdata
;
1209 /* Anyone can call this method */
1211 r
= mac_selinux_access_check(message
, "status", error
);
1215 r
= sd_bus_message_new_method_return(message
, &reply
);
1219 r
= sd_bus_message_open_container(reply
, 'a', "(usssoo)");
1223 HASHMAP_FOREACH(j
, m
->jobs
, i
) {
1224 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
1226 job_path
= job_dbus_path(j
);
1230 unit_path
= unit_dbus_path(j
->unit
);
1234 r
= sd_bus_message_append(
1238 job_type_to_string(j
->type
),
1239 job_state_to_string(j
->state
),
1246 r
= sd_bus_message_close_container(reply
);
1250 return sd_bus_send(NULL
, reply
, NULL
);
1253 static int method_subscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1254 Manager
*m
= userdata
;
1260 /* Anyone can call this method */
1262 r
= mac_selinux_access_check(message
, "status", error
);
1266 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1268 /* Note that direct bus connection subscribe by
1269 * default, we only track peers on the API bus here */
1271 if (!m
->subscribed
) {
1272 r
= sd_bus_track_new(sd_bus_message_get_bus(message
), &m
->subscribed
, NULL
, NULL
);
1277 r
= sd_bus_track_add_sender(m
->subscribed
, message
);
1281 return sd_bus_error_setf(error
, BUS_ERROR_ALREADY_SUBSCRIBED
, "Client is already subscribed.");
1284 return sd_bus_reply_method_return(message
, NULL
);
1287 static int method_unsubscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1288 Manager
*m
= userdata
;
1294 /* Anyone can call this method */
1296 r
= mac_selinux_access_check(message
, "status", error
);
1300 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1301 r
= sd_bus_track_remove_sender(m
->subscribed
, message
);
1305 return sd_bus_error_setf(error
, BUS_ERROR_NOT_SUBSCRIBED
, "Client is not subscribed.");
1308 return sd_bus_reply_method_return(message
, NULL
);
1311 static int method_dump(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1312 _cleanup_free_
char *dump
= NULL
;
1313 Manager
*m
= userdata
;
1319 /* Anyone can call this method */
1321 r
= mac_selinux_access_check(message
, "status", error
);
1325 r
= manager_get_dump_string(m
, &dump
);
1329 return sd_bus_reply_method_return(message
, "s", dump
);
1332 static int method_refuse_snapshot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1333 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Support for snapshots has been removed.");
1336 static int verify_run_space(const char *message
, sd_bus_error
*error
) {
1337 struct statvfs svfs
;
1340 if (statvfs("/run/systemd", &svfs
) < 0)
1341 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1343 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1345 if (available
< RELOAD_DISK_SPACE_MIN
) {
1346 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1347 return sd_bus_error_setf(error
,
1348 BUS_ERROR_DISK_FULL
,
1349 "%s, not enough space available on /run/systemd. "
1350 "Currently, %s are free, but a safety buffer of %s is enforced.",
1352 format_bytes(fb_available
, sizeof(fb_available
), available
),
1353 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1359 int verify_run_space_and_log(const char *message
) {
1360 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1363 r
= verify_run_space(message
, &error
);
1365 log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1370 static int method_reload(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1371 Manager
*m
= userdata
;
1377 r
= verify_run_space("Refusing to reload", error
);
1381 r
= mac_selinux_access_check(message
, "reload", error
);
1385 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1389 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1391 /* Instead of sending the reply back right away, we just
1392 * remember that we need to and then send it after the reload
1393 * is finished. That way the caller knows when the reload
1396 assert(!m
->queued_message
);
1397 r
= sd_bus_message_new_method_return(message
, &m
->queued_message
);
1401 m
->exit_code
= MANAGER_RELOAD
;
1406 static int method_reexecute(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1407 Manager
*m
= userdata
;
1413 r
= verify_run_space("Refusing to reexecute", error
);
1417 r
= mac_selinux_access_check(message
, "reload", error
);
1421 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1425 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1427 /* We don't send a reply back here, the client should
1428 * just wait for us disconnecting. */
1430 m
->exit_code
= MANAGER_REEXECUTE
;
1434 static int method_exit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1435 Manager
*m
= userdata
;
1441 r
= mac_selinux_access_check(message
, "halt", error
);
1445 /* Exit() (in contrast to SetExitCode()) is actually allowed even if
1446 * we are running on the host. It will fall back on reboot() in
1447 * systemd-shutdown if it cannot do the exit() because it isn't a
1450 m
->exit_code
= MANAGER_EXIT
;
1452 return sd_bus_reply_method_return(message
, NULL
);
1455 static int method_reboot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1456 Manager
*m
= userdata
;
1462 r
= mac_selinux_access_check(message
, "reboot", error
);
1466 if (!MANAGER_IS_SYSTEM(m
))
1467 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Reboot is only supported for system managers.");
1469 m
->exit_code
= MANAGER_REBOOT
;
1471 return sd_bus_reply_method_return(message
, NULL
);
1474 static int method_poweroff(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1475 Manager
*m
= userdata
;
1481 r
= mac_selinux_access_check(message
, "halt", error
);
1485 if (!MANAGER_IS_SYSTEM(m
))
1486 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Powering off is only supported for system managers.");
1488 m
->exit_code
= MANAGER_POWEROFF
;
1490 return sd_bus_reply_method_return(message
, NULL
);
1493 static int method_halt(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1494 Manager
*m
= userdata
;
1500 r
= mac_selinux_access_check(message
, "halt", error
);
1504 if (!MANAGER_IS_SYSTEM(m
))
1505 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Halt is only supported for system managers.");
1507 m
->exit_code
= MANAGER_HALT
;
1509 return sd_bus_reply_method_return(message
, NULL
);
1512 static int method_kexec(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1513 Manager
*m
= userdata
;
1519 r
= mac_selinux_access_check(message
, "reboot", error
);
1523 if (!MANAGER_IS_SYSTEM(m
))
1524 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "KExec is only supported for system managers.");
1526 m
->exit_code
= MANAGER_KEXEC
;
1528 return sd_bus_reply_method_return(message
, NULL
);
1531 static int method_switch_root(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1532 char *ri
= NULL
, *rt
= NULL
;
1533 const char *root
, *init
;
1534 Manager
*m
= userdata
;
1535 struct statvfs svfs
;
1542 if (statvfs("/run/systemd", &svfs
) < 0)
1543 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1545 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1547 if (available
< RELOAD_DISK_SPACE_MIN
) {
1548 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1549 log_warning("Dangerously low amount of free space on /run/systemd, root switching operation might not complete successfuly. "
1550 "Currently, %s are free, but %s are suggested. Proceeding anyway.",
1551 format_bytes(fb_available
, sizeof(fb_available
), available
),
1552 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1555 r
= mac_selinux_access_check(message
, "reboot", error
);
1559 if (!MANAGER_IS_SYSTEM(m
))
1560 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Root switching is only supported by system manager.");
1562 r
= sd_bus_message_read(message
, "ss", &root
, &init
);
1567 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory may not be the empty string.");
1568 if (!path_is_absolute(root
))
1569 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root path '%s' is not absolute.", root
);
1570 if (path_equal(root
, "/"))
1571 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory cannot be the old root directory.");
1574 if (isempty(init
)) {
1575 r
= path_is_os_tree(root
);
1577 return sd_bus_error_set_errnof(error
, r
, "Failed to determine whether root path '%s' contains an OS tree: %m", root
);
1579 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
);
1581 _cleanup_free_
char *chased
= NULL
;
1583 if (!path_is_absolute(init
))
1584 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path to init binary '%s' not absolute.", init
);
1586 r
= chase_symlinks(init
, root
, CHASE_PREFIX_ROOT
, &chased
);
1588 return sd_bus_error_set_errnof(error
, r
, "Could not resolve init executable %s: %m", init
);
1590 if (laccess(chased
, X_OK
) < 0) {
1591 if (errno
== EACCES
)
1592 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Init binary %s is not executable.", init
);
1594 return sd_bus_error_set_errnof(error
, r
, "Could not check whether init binary %s is executable: %m", init
);
1602 if (!isempty(init
)) {
1610 free(m
->switch_root
);
1611 m
->switch_root
= rt
;
1613 free(m
->switch_root_init
);
1614 m
->switch_root_init
= ri
;
1616 m
->exit_code
= MANAGER_SWITCH_ROOT
;
1618 return sd_bus_reply_method_return(message
, NULL
);
1621 static int method_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1622 _cleanup_strv_free_
char **plus
= NULL
;
1623 Manager
*m
= userdata
;
1629 r
= mac_selinux_access_check(message
, "reload", error
);
1633 r
= sd_bus_message_read_strv(message
, &plus
);
1636 if (!strv_env_is_valid(plus
))
1637 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1639 r
= bus_verify_set_environment_async(m
, message
, error
);
1643 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1645 r
= manager_environment_add(m
, NULL
, plus
);
1649 return sd_bus_reply_method_return(message
, NULL
);
1652 static int method_unset_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1653 _cleanup_strv_free_
char **minus
= NULL
;
1654 Manager
*m
= userdata
;
1660 r
= mac_selinux_access_check(message
, "reload", error
);
1664 r
= sd_bus_message_read_strv(message
, &minus
);
1668 if (!strv_env_name_or_assignment_is_valid(minus
))
1669 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1671 r
= bus_verify_set_environment_async(m
, message
, error
);
1675 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1677 r
= manager_environment_add(m
, minus
, NULL
);
1681 return sd_bus_reply_method_return(message
, NULL
);
1684 static int method_unset_and_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1685 _cleanup_strv_free_
char **minus
= NULL
, **plus
= NULL
;
1686 Manager
*m
= userdata
;
1692 r
= mac_selinux_access_check(message
, "reload", error
);
1696 r
= sd_bus_message_read_strv(message
, &minus
);
1700 r
= sd_bus_message_read_strv(message
, &plus
);
1704 if (!strv_env_name_or_assignment_is_valid(minus
))
1705 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1706 if (!strv_env_is_valid(plus
))
1707 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1709 r
= bus_verify_set_environment_async(m
, message
, error
);
1713 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1715 r
= manager_environment_add(m
, minus
, plus
);
1719 return sd_bus_reply_method_return(message
, NULL
);
1722 static int method_set_exit_code(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1723 Manager
*m
= userdata
;
1730 r
= mac_selinux_access_check(message
, "exit", error
);
1734 r
= sd_bus_message_read_basic(message
, 'y', &code
);
1738 if (MANAGER_IS_SYSTEM(m
) && detect_container() <= 0)
1739 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "ExitCode can only be set for user service managers or in containers.");
1741 m
->return_value
= code
;
1743 return sd_bus_reply_method_return(message
, NULL
);
1746 static int method_lookup_dynamic_user_by_name(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1747 Manager
*m
= userdata
;
1755 r
= sd_bus_message_read_basic(message
, 's', &name
);
1759 if (!MANAGER_IS_SYSTEM(m
))
1760 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1761 if (!valid_user_group_name(name
))
1762 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User name invalid: %s", name
);
1764 r
= dynamic_user_lookup_name(m
, name
, &uid
);
1766 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user %s does not exist.", name
);
1770 return sd_bus_reply_method_return(message
, "u", (uint32_t) uid
);
1773 static int method_lookup_dynamic_user_by_uid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1774 _cleanup_free_
char *name
= NULL
;
1775 Manager
*m
= userdata
;
1782 assert_cc(sizeof(uid
) == sizeof(uint32_t));
1783 r
= sd_bus_message_read_basic(message
, 'u', &uid
);
1787 if (!MANAGER_IS_SYSTEM(m
))
1788 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1789 if (!uid_is_valid(uid
))
1790 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User ID invalid: " UID_FMT
, uid
);
1792 r
= dynamic_user_lookup_uid(m
, uid
, &name
);
1794 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user ID " UID_FMT
" does not exist.", uid
);
1798 return sd_bus_reply_method_return(message
, "s", name
);
1801 static int method_get_dynamic_users(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1802 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1803 Manager
*m
= userdata
;
1811 assert_cc(sizeof(uid_t
) == sizeof(uint32_t));
1813 if (!MANAGER_IS_SYSTEM(m
))
1814 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1816 r
= sd_bus_message_new_method_return(message
, &reply
);
1820 r
= sd_bus_message_open_container(reply
, 'a', "(us)");
1824 HASHMAP_FOREACH(d
, m
->dynamic_users
, i
) {
1827 r
= dynamic_user_current(d
, &uid
);
1828 if (r
== -EAGAIN
) /* not realized yet? */
1831 return sd_bus_error_setf(error
, SD_BUS_ERROR_FAILED
, "Failed to lookup a dynamic user.");
1833 r
= sd_bus_message_append(reply
, "(us)", uid
, d
->name
);
1838 r
= sd_bus_message_close_container(reply
);
1842 return sd_bus_send(NULL
, reply
, NULL
);
1845 static int list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1846 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1847 Manager
*m
= userdata
;
1856 /* Anyone can call this method */
1858 r
= mac_selinux_access_check(message
, "status", error
);
1862 r
= sd_bus_message_new_method_return(message
, &reply
);
1866 h
= hashmap_new(&string_hash_ops
);
1870 r
= unit_file_get_list(m
->unit_file_scope
, NULL
, h
, states
, patterns
);
1874 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1878 HASHMAP_FOREACH(item
, h
, i
) {
1880 r
= sd_bus_message_append(reply
, "(ss)", item
->path
, unit_file_state_to_string(item
->state
));
1885 unit_file_list_free(h
);
1887 r
= sd_bus_message_close_container(reply
);
1891 return sd_bus_send(NULL
, reply
, NULL
);
1894 unit_file_list_free(h
);
1898 static int method_list_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1899 return list_unit_files_by_patterns(message
, userdata
, error
, NULL
, NULL
);
1902 static int method_list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1903 _cleanup_strv_free_
char **states
= NULL
;
1904 _cleanup_strv_free_
char **patterns
= NULL
;
1907 r
= sd_bus_message_read_strv(message
, &states
);
1911 r
= sd_bus_message_read_strv(message
, &patterns
);
1915 return list_unit_files_by_patterns(message
, userdata
, error
, states
, patterns
);
1918 static int method_get_unit_file_state(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1919 Manager
*m
= userdata
;
1921 UnitFileState state
;
1927 /* Anyone can call this method */
1929 r
= mac_selinux_access_check(message
, "status", error
);
1933 r
= sd_bus_message_read(message
, "s", &name
);
1937 r
= unit_file_get_state(m
->unit_file_scope
, NULL
, name
, &state
);
1941 return sd_bus_reply_method_return(message
, "s", unit_file_state_to_string(state
));
1944 static int method_get_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1945 _cleanup_free_
char *default_target
= NULL
;
1946 Manager
*m
= userdata
;
1952 /* Anyone can call this method */
1954 r
= mac_selinux_access_check(message
, "status", error
);
1958 r
= unit_file_get_default(m
->unit_file_scope
, NULL
, &default_target
);
1962 return sd_bus_reply_method_return(message
, "s", default_target
);
1965 static int send_unit_files_changed(sd_bus
*bus
, void *userdata
) {
1966 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
1971 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
1975 return sd_bus_send(bus
, message
, NULL
);
1978 /* Create an error reply, using the error information from changes[]
1979 * if possible, and fall back to generating an error from error code c.
1980 * The error message only describes the first error.
1982 * Coordinate with unit_file_dump_changes() in install.c.
1984 static int install_error(
1985 sd_bus_error
*error
,
1987 UnitFileChange
*changes
,
1988 unsigned n_changes
) {
1992 for (i
= 0; i
< n_changes
; i
++)
1994 switch(changes
[i
].type
) {
2000 if (changes
[i
].source
)
2001 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
2002 "File %s already exists and is a symlink to %s.",
2003 changes
[i
].path
, changes
[i
].source
);
2005 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
2006 "File %s already exists.",
2011 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_MASKED
,
2012 "Unit file %s is masked.", changes
[i
].path
);
2015 case -EADDRNOTAVAIL
:
2016 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_GENERATED
,
2017 "Unit %s is transient or generated.", changes
[i
].path
);
2021 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_LINKED
,
2022 "Refusing to operate on linked unit file %s", changes
[i
].path
);
2026 r
= sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit file %s does not exist.", changes
[i
].path
);
2030 r
= sd_bus_error_set_errnof(error
, changes
[i
].type
, "File %s: %m", changes
[i
].path
);
2034 r
= c
< 0 ? c
: -EINVAL
;
2037 unit_file_changes_free(changes
, n_changes
);
2041 static int reply_unit_file_changes_and_free(
2043 sd_bus_message
*message
,
2044 int carries_install_info
,
2045 UnitFileChange
*changes
,
2047 sd_bus_error
*error
) {
2049 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
2050 bool bad
= false, good
= false;
2054 if (unit_file_changes_have_modification(changes
, n_changes
)) {
2055 r
= bus_foreach_bus(m
, NULL
, send_unit_files_changed
, NULL
);
2057 log_debug_errno(r
, "Failed to send UnitFilesChanged signal: %m");
2060 r
= sd_bus_message_new_method_return(message
, &reply
);
2064 if (carries_install_info
>= 0) {
2065 r
= sd_bus_message_append(reply
, "b", carries_install_info
);
2070 r
= sd_bus_message_open_container(reply
, 'a', "(sss)");
2074 for (i
= 0; i
< n_changes
; i
++) {
2076 if (changes
[i
].type
< 0) {
2081 r
= sd_bus_message_append(
2083 unit_file_change_type_to_string(changes
[i
].type
),
2092 /* If there was a failed change, and no successful change, then return the first failure as proper method call
2095 return install_error(error
, 0, changes
, n_changes
);
2097 r
= sd_bus_message_close_container(reply
);
2101 unit_file_changes_free(changes
, n_changes
);
2102 return sd_bus_send(NULL
, reply
, NULL
);
2105 unit_file_changes_free(changes
, n_changes
);
2109 static int method_enable_unit_files_generic(
2110 sd_bus_message
*message
,
2112 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, unsigned *n_changes
),
2113 bool carries_install_info
,
2114 sd_bus_error
*error
) {
2116 _cleanup_strv_free_
char **l
= NULL
;
2117 UnitFileChange
*changes
= NULL
;
2118 unsigned n_changes
= 0;
2119 UnitFileFlags flags
;
2120 int runtime
, force
, r
;
2125 r
= sd_bus_message_read_strv(message
, &l
);
2129 r
= sd_bus_message_read(message
, "bb", &runtime
, &force
);
2133 flags
= unit_file_bools_to_flags(runtime
, force
);
2135 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2139 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2141 r
= call(m
->unit_file_scope
, flags
, NULL
, l
, &changes
, &n_changes
);
2143 return install_error(error
, r
, changes
, n_changes
);
2145 return reply_unit_file_changes_and_free(m
, message
, carries_install_info
? r
: -1, changes
, n_changes
, error
);
2148 static int method_enable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2149 return method_enable_unit_files_generic(message
, userdata
, unit_file_enable
, true, error
);
2152 static int method_reenable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2153 return method_enable_unit_files_generic(message
, userdata
, unit_file_reenable
, true, error
);
2156 static int method_link_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2157 return method_enable_unit_files_generic(message
, userdata
, unit_file_link
, false, error
);
2160 static int unit_file_preset_without_mode(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char **files
, UnitFileChange
**changes
, unsigned *n_changes
) {
2161 return unit_file_preset(scope
, flags
, root_dir
, files
, UNIT_FILE_PRESET_FULL
, changes
, n_changes
);
2164 static int method_preset_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2165 return method_enable_unit_files_generic(message
, userdata
, unit_file_preset_without_mode
, true, error
);
2168 static int method_mask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2169 return method_enable_unit_files_generic(message
, userdata
, unit_file_mask
, false, error
);
2172 static int method_preset_unit_files_with_mode(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2174 _cleanup_strv_free_
char **l
= NULL
;
2175 UnitFileChange
*changes
= NULL
;
2176 unsigned n_changes
= 0;
2177 Manager
*m
= userdata
;
2178 UnitFilePresetMode mm
;
2179 int runtime
, force
, r
;
2180 UnitFileFlags flags
;
2186 r
= sd_bus_message_read_strv(message
, &l
);
2190 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2194 flags
= unit_file_bools_to_flags(runtime
, force
);
2197 mm
= UNIT_FILE_PRESET_FULL
;
2199 mm
= unit_file_preset_mode_from_string(mode
);
2204 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2208 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2210 r
= unit_file_preset(m
->unit_file_scope
, flags
, NULL
, l
, mm
, &changes
, &n_changes
);
2212 return install_error(error
, r
, changes
, n_changes
);
2214 return reply_unit_file_changes_and_free(m
, message
, r
, changes
, n_changes
, error
);
2217 static int method_disable_unit_files_generic(
2218 sd_bus_message
*message
,
2220 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, unsigned *n_changes
),
2221 sd_bus_error
*error
) {
2223 _cleanup_strv_free_
char **l
= NULL
;
2224 UnitFileChange
*changes
= NULL
;
2225 unsigned n_changes
= 0;
2231 r
= sd_bus_message_read_strv(message
, &l
);
2235 r
= sd_bus_message_read(message
, "b", &runtime
);
2239 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2243 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2245 r
= call(m
->unit_file_scope
, runtime
? UNIT_FILE_RUNTIME
: 0, NULL
, l
, &changes
, &n_changes
);
2247 return install_error(error
, r
, changes
, n_changes
);
2249 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2252 static int method_disable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2253 return method_disable_unit_files_generic(message
, userdata
, unit_file_disable
, error
);
2256 static int method_unmask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2257 return method_disable_unit_files_generic(message
, userdata
, unit_file_unmask
, error
);
2260 static int method_revert_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2261 _cleanup_strv_free_
char **l
= NULL
;
2262 UnitFileChange
*changes
= NULL
;
2263 unsigned n_changes
= 0;
2264 Manager
*m
= userdata
;
2270 r
= sd_bus_message_read_strv(message
, &l
);
2274 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2278 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2280 r
= unit_file_revert(m
->unit_file_scope
, NULL
, l
, &changes
, &n_changes
);
2282 return install_error(error
, r
, changes
, n_changes
);
2284 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2287 static int method_set_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2288 UnitFileChange
*changes
= NULL
;
2289 unsigned n_changes
= 0;
2290 Manager
*m
= userdata
;
2297 r
= mac_selinux_access_check(message
, "enable", error
);
2301 r
= sd_bus_message_read(message
, "sb", &name
, &force
);
2305 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2309 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2311 r
= unit_file_set_default(m
->unit_file_scope
, force
? UNIT_FILE_FORCE
: 0, NULL
, name
, &changes
, &n_changes
);
2313 return install_error(error
, r
, changes
, n_changes
);
2315 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2318 static int method_preset_all_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2319 UnitFileChange
*changes
= NULL
;
2320 unsigned n_changes
= 0;
2321 Manager
*m
= userdata
;
2322 UnitFilePresetMode mm
;
2324 UnitFileFlags flags
;
2325 int force
, runtime
, r
;
2330 r
= mac_selinux_access_check(message
, "enable", error
);
2334 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2338 flags
= unit_file_bools_to_flags(runtime
, force
);
2341 mm
= UNIT_FILE_PRESET_FULL
;
2343 mm
= unit_file_preset_mode_from_string(mode
);
2348 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2352 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2354 r
= unit_file_preset_all(m
->unit_file_scope
, flags
, NULL
, mm
, &changes
, &n_changes
);
2356 return install_error(error
, r
, changes
, n_changes
);
2358 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2361 static int method_add_dependency_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2362 _cleanup_strv_free_
char **l
= NULL
;
2363 Manager
*m
= userdata
;
2364 UnitFileChange
*changes
= NULL
;
2365 unsigned n_changes
= 0;
2366 int runtime
, force
, r
;
2367 char *target
, *type
;
2369 UnitFileFlags flags
;
2374 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2378 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2380 r
= sd_bus_message_read_strv(message
, &l
);
2384 r
= sd_bus_message_read(message
, "ssbb", &target
, &type
, &runtime
, &force
);
2388 flags
= unit_file_bools_to_flags(runtime
, force
);
2390 dep
= unit_dependency_from_string(type
);
2394 r
= unit_file_add_dependency(m
->unit_file_scope
, flags
, NULL
, l
, target
, dep
, &changes
, &n_changes
);
2396 return install_error(error
, r
, changes
, n_changes
);
2398 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2401 static int method_get_unit_file_links(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2402 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
2403 UnitFileChange
*changes
= NULL
;
2404 unsigned n_changes
= 0, i
;
2405 UnitFileFlags flags
;
2410 r
= sd_bus_message_read(message
, "sb", &name
, &runtime
);
2414 r
= sd_bus_message_new_method_return(message
, &reply
);
2418 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_ARRAY
, "s");
2422 p
= STRV_MAKE(name
);
2423 flags
= UNIT_FILE_DRY_RUN
|
2424 (runtime
? UNIT_FILE_RUNTIME
: 0);
2426 r
= unit_file_disable(UNIT_FILE_SYSTEM
, flags
, NULL
, p
, &changes
, &n_changes
);
2428 return log_error_errno(r
, "Failed to get file links for %s: %m", name
);
2430 for (i
= 0; i
< n_changes
; i
++)
2431 if (changes
[i
].type
== UNIT_FILE_UNLINK
) {
2432 r
= sd_bus_message_append(reply
, "s", changes
[i
].path
);
2437 r
= sd_bus_message_close_container(reply
);
2441 return sd_bus_send(NULL
, reply
, NULL
);
2444 static int method_get_job_waiting(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2445 Manager
*m
= userdata
;
2453 r
= sd_bus_message_read(message
, "u", &id
);
2457 j
= manager_get_job(m
, id
);
2459 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
2461 return bus_job_method_get_waiting_jobs(message
, j
, error
);
2464 const sd_bus_vtable bus_manager_vtable
[] = {
2465 SD_BUS_VTABLE_START(0),
2467 SD_BUS_PROPERTY("Version", "s", property_get_version
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2468 SD_BUS_PROPERTY("Features", "s", property_get_features
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2469 SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2470 SD_BUS_PROPERTY("Architecture", "s", property_get_architecture
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2471 SD_BUS_PROPERTY("Tainted", "s", property_get_tainted
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2472 BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_FIRMWARE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2473 BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_LOADER
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2474 BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_KERNEL
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2475 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_INITRD
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2476 BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_USERSPACE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2477 BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2478 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_SECURITY_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2479 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_SECURITY_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2480 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_GENERATORS_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2481 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_GENERATORS_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2482 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_UNITS_LOAD_START
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2483 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager
, timestamps
[MANAGER_TIMESTAMP_UNITS_LOAD_FINISH
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2484 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level
, property_set_log_level
, 0, 0),
2485 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target
, property_set_log_target
, 0, 0),
2486 SD_BUS_PROPERTY("NNames", "u", property_get_n_names
, 0, 0),
2487 SD_BUS_PROPERTY("NFailedUnits", "u", property_get_n_failed_units
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
2488 SD_BUS_PROPERTY("NJobs", "u", property_get_n_jobs
, 0, 0),
2489 SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_installed_jobs
), 0),
2490 SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_failed_jobs
), 0),
2491 SD_BUS_PROPERTY("Progress", "d", property_get_progress
, 0, 0),
2492 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(Manager
, environment
), 0),
2493 SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool
, offsetof(Manager
, confirm_spawn
), SD_BUS_VTABLE_PROPERTY_CONST
),
2494 SD_BUS_PROPERTY("ShowStatus", "b", bus_property_get_bool
, offsetof(Manager
, show_status
), SD_BUS_VTABLE_PROPERTY_CONST
),
2495 SD_BUS_PROPERTY("UnitPath", "as", NULL
, offsetof(Manager
, lookup_paths
.search_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
2496 SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2497 SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2498 SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec
, property_set_runtime_watchdog
, offsetof(Manager
, runtime_watchdog
), 0),
2499 SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec
, bus_property_set_usec
, offsetof(Manager
, shutdown_watchdog
), 0),
2500 SD_BUS_WRITABLE_PROPERTY("ServiceWatchdogs", "b", bus_property_get_bool
, bus_property_set_bool
, offsetof(Manager
, service_watchdogs
), 0),
2501 SD_BUS_PROPERTY("ControlGroup", "s", NULL
, offsetof(Manager
, cgroup_root
), 0),
2502 SD_BUS_PROPERTY("SystemState", "s", property_get_system_state
, 0, 0),
2503 SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned
, offsetof(Manager
, return_value
), 0),
2504 SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timer_accuracy_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2505 SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_start_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2506 SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_stop_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2507 SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_restart_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2508 SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
),
2509 /* The following two items are obsolete alias */
2510 SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
2511 SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
2512 SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned
, offsetof(Manager
, default_start_limit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
2513 SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_cpu_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2514 SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_blockio_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2515 SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_memory_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2516 SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_tasks_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2517 SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2518 SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2519 SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2520 SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2521 SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2522 SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2523 SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2524 SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2525 SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2526 SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2527 SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2528 SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2529 SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2530 SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2531 SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2532 SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2533 SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2534 SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2535 SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2536 SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2537 SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2538 SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2539 SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2540 SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2541 SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2542 SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2543 SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2544 SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2545 SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2546 SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2547 SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2548 SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2549 SD_BUS_PROPERTY("DefaultTasksMax", "t", NULL
, offsetof(Manager
, default_tasks_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
2550 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2552 SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2553 SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2554 SD_BUS_METHOD("GetUnitByInvocationID", "ay", "o", method_get_unit_by_invocation_id
, SD_BUS_VTABLE_UNPRIVILEGED
),
2555 SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2556 SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2557 SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace
, SD_BUS_VTABLE_UNPRIVILEGED
),
2558 SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2559 SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2560 SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2561 SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2562 SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2563 SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2564 SD_BUS_METHOD("KillUnit", "ssi", NULL
, method_kill_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2565 SD_BUS_METHOD("ResetFailedUnit", "s", NULL
, method_reset_failed_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2566 SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL
, method_set_unit_properties
, SD_BUS_VTABLE_UNPRIVILEGED
),
2567 SD_BUS_METHOD("RefUnit", "s", NULL
, method_ref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2568 SD_BUS_METHOD("UnrefUnit", "s", NULL
, method_unref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2569 SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2570 SD_BUS_METHOD("GetUnitProcesses", "s", "a(sus)", method_get_unit_processes
, SD_BUS_VTABLE_UNPRIVILEGED
),
2571 SD_BUS_METHOD("AttachProcessesToUnit", "ssau", NULL
, method_attach_processes_to_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2572 SD_BUS_METHOD("GetJob", "u", "o", method_get_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2573 SD_BUS_METHOD("GetJobAfter", "u", "a(usssoo)", method_get_job_waiting
, SD_BUS_VTABLE_UNPRIVILEGED
),
2574 SD_BUS_METHOD("GetJobBefore", "u", "a(usssoo)", method_get_job_waiting
, SD_BUS_VTABLE_UNPRIVILEGED
),
2575 SD_BUS_METHOD("CancelJob", "u", NULL
, method_cancel_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2576 SD_BUS_METHOD("ClearJobs", NULL
, NULL
, method_clear_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2577 SD_BUS_METHOD("ResetFailed", NULL
, NULL
, method_reset_failed
, SD_BUS_VTABLE_UNPRIVILEGED
),
2578 SD_BUS_METHOD("ListUnits", NULL
, "a(ssssssouso)", method_list_units
, SD_BUS_VTABLE_UNPRIVILEGED
),
2579 SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered
, SD_BUS_VTABLE_UNPRIVILEGED
),
2580 SD_BUS_METHOD("ListUnitsByPatterns", "asas", "a(ssssssouso)", method_list_units_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2581 SD_BUS_METHOD("ListUnitsByNames", "as", "a(ssssssouso)", method_list_units_by_names
, SD_BUS_VTABLE_UNPRIVILEGED
),
2582 SD_BUS_METHOD("ListJobs", NULL
, "a(usssoo)", method_list_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2583 SD_BUS_METHOD("Subscribe", NULL
, NULL
, method_subscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2584 SD_BUS_METHOD("Unsubscribe", NULL
, NULL
, method_unsubscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2585 SD_BUS_METHOD("Dump", NULL
, "s", method_dump
, SD_BUS_VTABLE_UNPRIVILEGED
),
2586 SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
),
2587 SD_BUS_METHOD("RemoveSnapshot", "s", NULL
, method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
),
2588 SD_BUS_METHOD("Reload", NULL
, NULL
, method_reload
, SD_BUS_VTABLE_UNPRIVILEGED
),
2589 SD_BUS_METHOD("Reexecute", NULL
, NULL
, method_reexecute
, SD_BUS_VTABLE_UNPRIVILEGED
),
2590 SD_BUS_METHOD("Exit", NULL
, NULL
, method_exit
, 0),
2591 SD_BUS_METHOD("Reboot", NULL
, NULL
, method_reboot
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2592 SD_BUS_METHOD("PowerOff", NULL
, NULL
, method_poweroff
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2593 SD_BUS_METHOD("Halt", NULL
, NULL
, method_halt
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2594 SD_BUS_METHOD("KExec", NULL
, NULL
, method_kexec
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2595 SD_BUS_METHOD("SwitchRoot", "ss", NULL
, method_switch_root
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2596 SD_BUS_METHOD("SetEnvironment", "as", NULL
, method_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2597 SD_BUS_METHOD("UnsetEnvironment", "as", NULL
, method_unset_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2598 SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL
, method_unset_and_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2599 SD_BUS_METHOD("ListUnitFiles", NULL
, "a(ss)", method_list_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2600 SD_BUS_METHOD("ListUnitFilesByPatterns", "asas", "a(ss)", method_list_unit_files_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2601 SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state
, SD_BUS_VTABLE_UNPRIVILEGED
),
2602 SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2603 SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2604 SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2605 SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2606 SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2607 SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode
, SD_BUS_VTABLE_UNPRIVILEGED
),
2608 SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2609 SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2610 SD_BUS_METHOD("RevertUnitFiles", "as", "a(sss)", method_revert_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2611 SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2612 SD_BUS_METHOD("GetDefaultTarget", NULL
, "s", method_get_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2613 SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2614 SD_BUS_METHOD("AddDependencyUnitFiles", "asssbb", "a(sss)", method_add_dependency_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2615 SD_BUS_METHOD("GetUnitFileLinks", "sb", "as", method_get_unit_file_links
, SD_BUS_VTABLE_UNPRIVILEGED
),
2616 SD_BUS_METHOD("SetExitCode", "y", NULL
, method_set_exit_code
, SD_BUS_VTABLE_UNPRIVILEGED
),
2617 SD_BUS_METHOD("LookupDynamicUserByName", "s", "u", method_lookup_dynamic_user_by_name
, SD_BUS_VTABLE_UNPRIVILEGED
),
2618 SD_BUS_METHOD("LookupDynamicUserByUID", "u", "s", method_lookup_dynamic_user_by_uid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2619 SD_BUS_METHOD("GetDynamicUsers", NULL
, "a(us)", method_get_dynamic_users
, SD_BUS_VTABLE_UNPRIVILEGED
),
2621 SD_BUS_SIGNAL("UnitNew", "so", 0),
2622 SD_BUS_SIGNAL("UnitRemoved", "so", 0),
2623 SD_BUS_SIGNAL("JobNew", "uos", 0),
2624 SD_BUS_SIGNAL("JobRemoved", "uoss", 0),
2625 SD_BUS_SIGNAL("StartupFinished", "tttttt", 0),
2626 SD_BUS_SIGNAL("UnitFilesChanged", NULL
, 0),
2627 SD_BUS_SIGNAL("Reloading", "b", 0),
2632 static int send_finished(sd_bus
*bus
, void *userdata
) {
2633 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2634 usec_t
*times
= userdata
;
2640 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
2644 r
= sd_bus_message_append(message
, "tttttt", times
[0], times
[1], times
[2], times
[3], times
[4], times
[5]);
2648 return sd_bus_send(bus
, message
, NULL
);
2651 void bus_manager_send_finished(
2653 usec_t firmware_usec
,
2657 usec_t userspace_usec
,
2658 usec_t total_usec
) {
2664 r
= bus_foreach_bus(
2677 log_debug_errno(r
, "Failed to send finished signal: %m");
2680 static int send_reloading(sd_bus
*bus
, void *userdata
) {
2681 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2686 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
2690 r
= sd_bus_message_append(message
, "b", PTR_TO_INT(userdata
));
2694 return sd_bus_send(bus
, message
, NULL
);
2697 void bus_manager_send_reloading(Manager
*m
, bool active
) {
2702 r
= bus_foreach_bus(m
, NULL
, send_reloading
, INT_TO_PTR(active
));
2704 log_debug_errno(r
, "Failed to send reloading signal: %m");
2707 static int send_changed_signal(sd_bus
*bus
, void *userdata
) {
2710 return sd_bus_emit_properties_changed_strv(bus
,
2711 "/org/freedesktop/systemd1",
2712 "org.freedesktop.systemd1.Manager",
2716 void bus_manager_send_change_signal(Manager
*m
) {
2721 r
= bus_foreach_bus(m
, NULL
, send_changed_signal
, NULL
);
2723 log_debug_errno(r
, "Failed to send manager change signal: %m");