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:")] = "", *e
= buf
;
143 Manager
*m
= userdata
;
150 e
= stpcpy(e
, "split-usr:");
152 if (access("/proc/cgroups", F_OK
) < 0)
153 e
= stpcpy(e
, "cgroups-missing:");
155 if (clock_is_localtime(NULL
) > 0)
156 e
= stpcpy(e
, "local-hwclock:");
158 /* remove the last ':' */
162 return sd_bus_message_append(reply
, "s", buf
);
165 static int property_get_log_target(
168 const char *interface
,
169 const char *property
,
170 sd_bus_message
*reply
,
172 sd_bus_error
*error
) {
177 return sd_bus_message_append(reply
, "s", log_target_to_string(log_get_target()));
180 static int property_set_log_target(
183 const char *interface
,
184 const char *property
,
185 sd_bus_message
*value
,
187 sd_bus_error
*error
) {
195 r
= sd_bus_message_read(value
, "s", &t
);
199 return log_set_target_from_string(t
);
202 static int property_get_log_level(
205 const char *interface
,
206 const char *property
,
207 sd_bus_message
*reply
,
209 sd_bus_error
*error
) {
211 _cleanup_free_
char *t
= NULL
;
217 r
= log_level_to_string_alloc(log_get_max_level(), &t
);
221 return sd_bus_message_append(reply
, "s", t
);
224 static int property_set_log_level(
227 const char *interface
,
228 const char *property
,
229 sd_bus_message
*value
,
231 sd_bus_error
*error
) {
239 r
= sd_bus_message_read(value
, "s", &t
);
243 r
= log_set_max_level_from_string(t
);
245 log_info("Setting log level to %s.", t
);
249 static int property_get_n_names(
252 const char *interface
,
253 const char *property
,
254 sd_bus_message
*reply
,
256 sd_bus_error
*error
) {
258 Manager
*m
= userdata
;
264 return sd_bus_message_append(reply
, "u", (uint32_t) hashmap_size(m
->units
));
267 static int property_get_n_failed_units(
270 const char *interface
,
271 const char *property
,
272 sd_bus_message
*reply
,
274 sd_bus_error
*error
) {
276 Manager
*m
= userdata
;
282 return sd_bus_message_append(reply
, "u", (uint32_t) set_size(m
->failed_units
));
285 static int property_get_n_jobs(
288 const char *interface
,
289 const char *property
,
290 sd_bus_message
*reply
,
292 sd_bus_error
*error
) {
294 Manager
*m
= userdata
;
300 return sd_bus_message_append(reply
, "u", (uint32_t) hashmap_size(m
->jobs
));
303 static int property_get_progress(
306 const char *interface
,
307 const char *property
,
308 sd_bus_message
*reply
,
310 sd_bus_error
*error
) {
312 Manager
*m
= userdata
;
319 if (dual_timestamp_is_set(&m
->finish_timestamp
))
322 d
= 1.0 - ((double) hashmap_size(m
->jobs
) / (double) m
->n_installed_jobs
);
324 return sd_bus_message_append(reply
, "d", d
);
327 static int property_get_system_state(
330 const char *interface
,
331 const char *property
,
332 sd_bus_message
*reply
,
334 sd_bus_error
*error
) {
336 Manager
*m
= userdata
;
342 return sd_bus_message_append(reply
, "s", manager_state_to_string(manager_state(m
)));
345 static int property_set_runtime_watchdog(
348 const char *interface
,
349 const char *property
,
350 sd_bus_message
*value
,
352 sd_bus_error
*error
) {
354 usec_t
*t
= userdata
;
360 assert_cc(sizeof(usec_t
) == sizeof(uint64_t));
362 r
= sd_bus_message_read(value
, "t", t
);
366 return watchdog_set_timeout(t
);
369 static int property_get_timer_slack_nsec(
372 const char *interface
,
373 const char *property
,
374 sd_bus_message
*reply
,
376 sd_bus_error
*error
) {
381 return sd_bus_message_append(reply
, "t", (uint64_t) prctl(PR_GET_TIMERSLACK
));
384 static int method_get_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
385 _cleanup_free_
char *path
= NULL
;
386 Manager
*m
= userdata
;
394 /* Anyone can call this method */
396 r
= sd_bus_message_read(message
, "s", &name
);
401 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
404 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
408 r
= sd_bus_creds_get_pid(creds
, &pid
);
412 u
= manager_get_unit_by_pid(m
, pid
);
414 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
416 u
= manager_get_unit(m
, name
);
418 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s not loaded.", name
);
421 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
425 path
= unit_dbus_path(u
);
429 return sd_bus_reply_method_return(message
, "o", path
);
432 static int method_get_unit_by_pid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
433 _cleanup_free_
char *path
= NULL
;
434 Manager
*m
= userdata
;
442 assert_cc(sizeof(pid_t
) == sizeof(uint32_t));
444 /* Anyone can call this method */
446 r
= sd_bus_message_read(message
, "u", &pid
);
449 if (!pid_is_valid((pid_t
) pid
))
450 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PID " PID_FMT
, pid
);
453 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
455 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
459 r
= sd_bus_creds_get_pid(creds
, &pid
);
464 u
= manager_get_unit_by_pid(m
, pid
);
466 return sd_bus_error_setf(error
, BUS_ERROR_NO_UNIT_FOR_PID
, "PID "PID_FMT
" does not belong to any loaded unit.", pid
);
468 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
472 path
= unit_dbus_path(u
);
476 return sd_bus_reply_method_return(message
, "o", path
);
479 static int method_get_unit_by_invocation_id(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
480 _cleanup_free_
char *path
= NULL
;
481 Manager
*m
= userdata
;
491 /* Anyone can call this method */
493 r
= sd_bus_message_read_array(message
, 'y', &a
, &sz
);
501 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid invocation ID");
503 if (sd_id128_is_null(id
)) {
504 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
507 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
511 r
= sd_bus_creds_get_pid(creds
, &pid
);
515 u
= manager_get_unit_by_pid(m
, pid
);
517 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client " PID_FMT
" not member of any unit.", pid
);
519 u
= hashmap_get(m
->units_by_invocation_id
, &id
);
521 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
));
524 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
528 /* So here's a special trick: the bus path we return actually references the unit by its invocation ID instead
529 * of the unit name. This means it stays valid only as long as the invocation ID stays the same. */
530 path
= unit_dbus_path_invocation_id(u
);
534 return sd_bus_reply_method_return(message
, "o", path
);
537 static int method_load_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
538 _cleanup_free_
char *path
= NULL
;
539 Manager
*m
= userdata
;
547 /* Anyone can call this method */
549 r
= sd_bus_message_read(message
, "s", &name
);
554 _cleanup_(sd_bus_creds_unrefp
) sd_bus_creds
*creds
= NULL
;
557 r
= sd_bus_query_sender_creds(message
, SD_BUS_CREDS_PID
, &creds
);
561 r
= sd_bus_creds_get_pid(creds
, &pid
);
565 u
= manager_get_unit_by_pid(m
, pid
);
567 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Client not member of any unit.");
569 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
574 r
= mac_selinux_unit_access_check(u
, message
, "status", error
);
578 path
= unit_dbus_path(u
);
582 return sd_bus_reply_method_return(message
, "o", path
);
585 static int method_start_unit_generic(sd_bus_message
*message
, Manager
*m
, JobType job_type
, bool reload_if_possible
, sd_bus_error
*error
) {
593 r
= sd_bus_message_read(message
, "s", &name
);
597 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
601 return bus_unit_method_start_generic(message
, u
, job_type
, reload_if_possible
, error
);
604 static int method_start_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
605 return method_start_unit_generic(message
, userdata
, JOB_START
, false, error
);
608 static int method_stop_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
609 return method_start_unit_generic(message
, userdata
, JOB_STOP
, false, error
);
612 static int method_reload_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
613 return method_start_unit_generic(message
, userdata
, JOB_RELOAD
, false, error
);
616 static int method_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
617 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, false, error
);
620 static int method_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
621 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, false, error
);
624 static int method_reload_or_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
625 return method_start_unit_generic(message
, userdata
, JOB_RESTART
, true, error
);
628 static int method_reload_or_try_restart_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
629 return method_start_unit_generic(message
, userdata
, JOB_TRY_RESTART
, true, error
);
632 static int method_start_unit_replace(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
633 Manager
*m
= userdata
;
634 const char *old_name
;
641 r
= sd_bus_message_read(message
, "s", &old_name
);
645 u
= manager_get_unit(m
, old_name
);
646 if (!u
|| !u
->job
|| u
->job
->type
!= JOB_START
)
647 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "No job queued for unit %s", old_name
);
649 return method_start_unit_generic(message
, m
, JOB_START
, false, error
);
652 static int method_kill_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
653 Manager
*m
= userdata
;
661 r
= sd_bus_message_read(message
, "s", &name
);
665 u
= manager_get_unit(m
, name
);
667 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not loaded.", name
);
669 return bus_unit_method_kill(message
, u
, error
);
672 static int method_reset_failed_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
673 Manager
*m
= userdata
;
681 r
= sd_bus_message_read(message
, "s", &name
);
685 u
= manager_get_unit(m
, name
);
687 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s is not loaded.", name
);
689 return bus_unit_method_reset_failed(message
, u
, error
);
692 static int method_set_unit_properties(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
693 Manager
*m
= userdata
;
701 r
= sd_bus_message_read(message
, "s", &name
);
705 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
709 r
= bus_unit_check_load_state(u
, error
);
713 return bus_unit_method_set_properties(message
, u
, error
);
716 static int method_ref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
717 Manager
*m
= userdata
;
725 r
= sd_bus_message_read(message
, "s", &name
);
729 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
733 r
= bus_unit_check_load_state(u
, error
);
737 return bus_unit_method_ref(message
, u
, error
);
740 static int method_unref_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
741 Manager
*m
= userdata
;
749 r
= sd_bus_message_read(message
, "s", &name
);
753 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
757 r
= bus_unit_check_load_state(u
, error
);
761 return bus_unit_method_unref(message
, u
, error
);
764 static int reply_unit_info(sd_bus_message
*reply
, Unit
*u
) {
765 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
768 following
= unit_following(u
);
770 unit_path
= unit_dbus_path(u
);
775 job_path
= job_dbus_path(u
->job
);
780 return sd_bus_message_append(
781 reply
, "(ssssssouso)",
784 unit_load_state_to_string(u
->load_state
),
785 unit_active_state_to_string(unit_active_state(u
)),
786 unit_sub_state_to_string(u
),
787 following
? following
->id
: "",
789 u
->job
? u
->job
->id
: 0,
790 u
->job
? job_type_to_string(u
->job
->type
) : "",
791 job_path
? job_path
: "/");
794 static int method_list_units_by_names(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
795 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
796 Manager
*m
= userdata
;
799 _cleanup_strv_free_
char **units
= NULL
;
804 r
= sd_bus_message_read_strv(message
, &units
);
808 r
= sd_bus_message_new_method_return(message
, &reply
);
812 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
816 STRV_FOREACH(unit
, units
) {
819 if (!unit_name_is_valid(*unit
, UNIT_NAME_ANY
))
822 r
= manager_load_unit(m
, *unit
, NULL
, error
, &u
);
826 r
= reply_unit_info(reply
, u
);
831 r
= sd_bus_message_close_container(reply
);
835 return sd_bus_send(NULL
, reply
, NULL
);
838 static int method_get_unit_processes(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
839 Manager
*m
= userdata
;
847 r
= sd_bus_message_read(message
, "s", &name
);
851 u
= manager_get_unit(m
, name
);
853 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit %s not loaded.", name
);
855 return bus_unit_method_get_processes(message
, u
, error
);
858 static int transient_unit_from_message(
860 sd_bus_message
*message
,
863 sd_bus_error
*error
) {
873 t
= unit_name_to_type(name
);
875 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid unit name or type.");
877 if (!unit_vtable
[t
]->can_transient
)
878 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unit type %s does not support transient units.", unit_type_to_string(t
));
880 r
= manager_load_unit(m
, name
, NULL
, error
, &u
);
884 if (!unit_is_pristine(u
))
885 return sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
, "Unit %s already exists.", name
);
887 /* OK, the unit failed to load and is unreferenced, now let's
888 * fill in the transient data instead */
889 r
= unit_make_transient(u
);
893 /* Set our properties */
894 r
= bus_unit_set_properties(u
, message
, UNIT_RUNTIME
, false, error
);
898 /* If the client asked for it, automatically add a reference to this unit. */
899 if (u
->bus_track_add
) {
900 r
= bus_unit_track_add_sender(u
, message
);
902 return log_error_errno(r
, "Failed to watch sender: %m");
905 /* Now load the missing bits of the unit we just created */
906 unit_add_to_load_queue(u
);
907 manager_dispatch_load_queue(m
);
914 static int transient_aux_units_from_message(
916 sd_bus_message
*message
,
917 sd_bus_error
*error
) {
924 r
= sd_bus_message_enter_container(message
, 'a', "(sa(sv))");
928 while ((r
= sd_bus_message_enter_container(message
, 'r', "sa(sv)")) > 0) {
929 const char *name
= NULL
;
932 r
= sd_bus_message_read(message
, "s", &name
);
936 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
940 r
= sd_bus_message_exit_container(message
);
947 r
= sd_bus_message_exit_container(message
);
954 static int method_start_transient_unit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
955 const char *name
, *smode
;
956 Manager
*m
= userdata
;
964 r
= mac_selinux_access_check(message
, "start", error
);
968 r
= sd_bus_message_read(message
, "ss", &name
, &smode
);
972 mode
= job_mode_from_string(smode
);
974 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Job mode %s is invalid.", smode
);
976 r
= bus_verify_manage_units_async(m
, message
, error
);
980 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
982 r
= transient_unit_from_message(m
, message
, name
, &u
, error
);
986 r
= transient_aux_units_from_message(m
, message
, error
);
990 /* Finally, start it */
991 return bus_unit_queue_job(message
, u
, JOB_START
, mode
, false, error
);
994 static int method_get_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
995 _cleanup_free_
char *path
= NULL
;
996 Manager
*m
= userdata
;
1004 /* Anyone can call this method */
1006 r
= sd_bus_message_read(message
, "u", &id
);
1010 j
= manager_get_job(m
, id
);
1012 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
1014 r
= mac_selinux_unit_access_check(j
->unit
, message
, "status", error
);
1018 path
= job_dbus_path(j
);
1022 return sd_bus_reply_method_return(message
, "o", path
);
1025 static int method_cancel_job(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1026 Manager
*m
= userdata
;
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 return bus_job_method_cancel(message
, j
, error
);
1045 static int method_clear_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1046 Manager
*m
= userdata
;
1052 r
= mac_selinux_access_check(message
, "reload", error
);
1056 r
= bus_verify_manage_units_async(m
, message
, error
);
1060 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1062 manager_clear_jobs(m
);
1064 return sd_bus_reply_method_return(message
, NULL
);
1067 static int method_reset_failed(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1068 Manager
*m
= userdata
;
1074 r
= mac_selinux_access_check(message
, "reload", error
);
1078 r
= bus_verify_manage_units_async(m
, message
, error
);
1082 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1084 manager_reset_failed(m
);
1086 return sd_bus_reply_method_return(message
, NULL
);
1089 static int list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1090 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1091 Manager
*m
= userdata
;
1100 /* Anyone can call this method */
1102 r
= mac_selinux_access_check(message
, "status", error
);
1106 r
= sd_bus_message_new_method_return(message
, &reply
);
1110 r
= sd_bus_message_open_container(reply
, 'a', "(ssssssouso)");
1114 HASHMAP_FOREACH_KEY(u
, k
, m
->units
, i
) {
1118 if (!strv_isempty(states
) &&
1119 !strv_contains(states
, unit_load_state_to_string(u
->load_state
)) &&
1120 !strv_contains(states
, unit_active_state_to_string(unit_active_state(u
))) &&
1121 !strv_contains(states
, unit_sub_state_to_string(u
)))
1124 if (!strv_isempty(patterns
) &&
1125 !strv_fnmatch_or_empty(patterns
, u
->id
, FNM_NOESCAPE
))
1128 r
= reply_unit_info(reply
, u
);
1133 r
= sd_bus_message_close_container(reply
);
1137 return sd_bus_send(NULL
, reply
, NULL
);
1140 static int method_list_units(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1141 return list_units_filtered(message
, userdata
, error
, NULL
, NULL
);
1144 static int method_list_units_filtered(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1145 _cleanup_strv_free_
char **states
= NULL
;
1148 r
= sd_bus_message_read_strv(message
, &states
);
1152 return list_units_filtered(message
, userdata
, error
, states
, NULL
);
1155 static int method_list_units_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1156 _cleanup_strv_free_
char **states
= NULL
;
1157 _cleanup_strv_free_
char **patterns
= NULL
;
1160 r
= sd_bus_message_read_strv(message
, &states
);
1164 r
= sd_bus_message_read_strv(message
, &patterns
);
1168 return list_units_filtered(message
, userdata
, error
, states
, patterns
);
1171 static int method_list_jobs(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1172 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1173 Manager
*m
= userdata
;
1181 /* Anyone can call this method */
1183 r
= mac_selinux_access_check(message
, "status", error
);
1187 r
= sd_bus_message_new_method_return(message
, &reply
);
1191 r
= sd_bus_message_open_container(reply
, 'a', "(usssoo)");
1195 HASHMAP_FOREACH(j
, m
->jobs
, i
) {
1196 _cleanup_free_
char *unit_path
= NULL
, *job_path
= NULL
;
1198 job_path
= job_dbus_path(j
);
1202 unit_path
= unit_dbus_path(j
->unit
);
1206 r
= sd_bus_message_append(
1210 job_type_to_string(j
->type
),
1211 job_state_to_string(j
->state
),
1218 r
= sd_bus_message_close_container(reply
);
1222 return sd_bus_send(NULL
, reply
, NULL
);
1225 static int method_subscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1226 Manager
*m
= userdata
;
1232 /* Anyone can call this method */
1234 r
= mac_selinux_access_check(message
, "status", error
);
1238 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1240 /* Note that direct bus connection subscribe by
1241 * default, we only track peers on the API bus here */
1243 if (!m
->subscribed
) {
1244 r
= sd_bus_track_new(sd_bus_message_get_bus(message
), &m
->subscribed
, NULL
, NULL
);
1249 r
= sd_bus_track_add_sender(m
->subscribed
, message
);
1253 return sd_bus_error_setf(error
, BUS_ERROR_ALREADY_SUBSCRIBED
, "Client is already subscribed.");
1256 return sd_bus_reply_method_return(message
, NULL
);
1259 static int method_unsubscribe(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1260 Manager
*m
= userdata
;
1266 /* Anyone can call this method */
1268 r
= mac_selinux_access_check(message
, "status", error
);
1272 if (sd_bus_message_get_bus(message
) == m
->api_bus
) {
1273 r
= sd_bus_track_remove_sender(m
->subscribed
, message
);
1277 return sd_bus_error_setf(error
, BUS_ERROR_NOT_SUBSCRIBED
, "Client is not subscribed.");
1280 return sd_bus_reply_method_return(message
, NULL
);
1283 static int method_dump(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1284 _cleanup_free_
char *dump
= NULL
;
1285 _cleanup_fclose_
FILE *f
= NULL
;
1286 Manager
*m
= userdata
;
1293 /* Anyone can call this method */
1295 r
= mac_selinux_access_check(message
, "status", error
);
1299 f
= open_memstream(&dump
, &size
);
1303 manager_dump_units(m
, f
, NULL
);
1304 manager_dump_jobs(m
, f
, NULL
);
1306 r
= fflush_and_check(f
);
1310 return sd_bus_reply_method_return(message
, "s", dump
);
1313 static int method_refuse_snapshot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1314 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Support for snapshots has been removed.");
1317 static int verify_run_space(const char *message
, sd_bus_error
*error
) {
1318 struct statvfs svfs
;
1321 if (statvfs("/run/systemd", &svfs
) < 0)
1322 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1324 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1326 if (available
< RELOAD_DISK_SPACE_MIN
) {
1327 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1328 return sd_bus_error_setf(error
,
1329 BUS_ERROR_DISK_FULL
,
1330 "%s, not enough space available on /run/systemd. "
1331 "Currently, %s are free, but a safety buffer of %s is enforced.",
1333 format_bytes(fb_available
, sizeof(fb_available
), available
),
1334 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1340 int verify_run_space_and_log(const char *message
) {
1341 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1344 r
= verify_run_space(message
, &error
);
1346 log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1351 static int method_reload(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1352 Manager
*m
= userdata
;
1358 r
= verify_run_space("Refusing to reload", error
);
1362 r
= mac_selinux_access_check(message
, "reload", error
);
1366 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1370 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1372 /* Instead of sending the reply back right away, we just
1373 * remember that we need to and then send it after the reload
1374 * is finished. That way the caller knows when the reload
1377 assert(!m
->queued_message
);
1378 r
= sd_bus_message_new_method_return(message
, &m
->queued_message
);
1382 m
->exit_code
= MANAGER_RELOAD
;
1387 static int method_reexecute(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1388 Manager
*m
= userdata
;
1394 r
= verify_run_space("Refusing to reexecute", error
);
1398 r
= mac_selinux_access_check(message
, "reload", error
);
1402 r
= bus_verify_reload_daemon_async(m
, message
, error
);
1406 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1408 /* We don't send a reply back here, the client should
1409 * just wait for us disconnecting. */
1411 m
->exit_code
= MANAGER_REEXECUTE
;
1415 static int method_exit(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1416 Manager
*m
= userdata
;
1422 r
= mac_selinux_access_check(message
, "halt", error
);
1426 /* Exit() (in contrast to SetExitCode()) is actually allowed even if
1427 * we are running on the host. It will fall back on reboot() in
1428 * systemd-shutdown if it cannot do the exit() because it isn't a
1431 m
->exit_code
= MANAGER_EXIT
;
1433 return sd_bus_reply_method_return(message
, NULL
);
1436 static int method_reboot(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1437 Manager
*m
= userdata
;
1443 r
= mac_selinux_access_check(message
, "reboot", error
);
1447 if (!MANAGER_IS_SYSTEM(m
))
1448 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Reboot is only supported for system managers.");
1450 m
->exit_code
= MANAGER_REBOOT
;
1452 return sd_bus_reply_method_return(message
, NULL
);
1455 static int method_poweroff(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1456 Manager
*m
= userdata
;
1462 r
= mac_selinux_access_check(message
, "halt", error
);
1466 if (!MANAGER_IS_SYSTEM(m
))
1467 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Powering off is only supported for system managers.");
1469 m
->exit_code
= MANAGER_POWEROFF
;
1471 return sd_bus_reply_method_return(message
, NULL
);
1474 static int method_halt(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
, "Halt is only supported for system managers.");
1488 m
->exit_code
= MANAGER_HALT
;
1490 return sd_bus_reply_method_return(message
, NULL
);
1493 static int method_kexec(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1494 Manager
*m
= userdata
;
1500 r
= mac_selinux_access_check(message
, "reboot", error
);
1504 if (!MANAGER_IS_SYSTEM(m
))
1505 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "KExec is only supported for system managers.");
1507 m
->exit_code
= MANAGER_KEXEC
;
1509 return sd_bus_reply_method_return(message
, NULL
);
1512 static int method_switch_root(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1513 char *ri
= NULL
, *rt
= NULL
;
1514 const char *root
, *init
;
1515 Manager
*m
= userdata
;
1516 struct statvfs svfs
;
1523 if (statvfs("/run/systemd", &svfs
) < 0)
1524 return sd_bus_error_set_errnof(error
, errno
, "Failed to statvfs(/run/systemd): %m");
1526 available
= (uint64_t) svfs
.f_bfree
* (uint64_t) svfs
.f_bsize
;
1528 if (available
< RELOAD_DISK_SPACE_MIN
) {
1529 char fb_available
[FORMAT_BYTES_MAX
], fb_need
[FORMAT_BYTES_MAX
];
1530 log_warning("Dangerously low amount of free space on /run/systemd, root switching operation might not complete successfuly. "
1531 "Currently, %s are free, but %s are suggested. Proceeding anyway.",
1532 format_bytes(fb_available
, sizeof(fb_available
), available
),
1533 format_bytes(fb_need
, sizeof(fb_need
), RELOAD_DISK_SPACE_MIN
));
1536 r
= mac_selinux_access_check(message
, "reboot", error
);
1540 if (!MANAGER_IS_SYSTEM(m
))
1541 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Root switching is only supported by system manager.");
1543 r
= sd_bus_message_read(message
, "ss", &root
, &init
);
1548 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory may not be the empty string.");
1549 if (!path_is_absolute(root
))
1550 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root path '%s' is not absolute.", root
);
1551 if (path_equal(root
, "/"))
1552 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "New root directory cannot be the old root directory.");
1555 if (isempty(init
)) {
1556 r
= path_is_os_tree(root
);
1558 return sd_bus_error_set_errnof(error
, r
, "Failed to determine whether root path '%s' contains an OS tree: %m", root
);
1560 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
);
1562 _cleanup_free_
char *chased
= NULL
;
1564 if (!path_is_absolute(init
))
1565 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path to init binary '%s' not absolute.", init
);
1567 r
= chase_symlinks(init
, root
, CHASE_PREFIX_ROOT
, &chased
);
1569 return sd_bus_error_set_errnof(error
, r
, "Could not resolve init executable %s: %m", init
);
1571 if (laccess(chased
, X_OK
) < 0) {
1572 if (errno
== EACCES
)
1573 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Init binary %s is not executable.", init
);
1575 return sd_bus_error_set_errnof(error
, r
, "Could not check whether init binary %s is executable: %m", init
);
1583 if (!isempty(init
)) {
1591 free(m
->switch_root
);
1592 m
->switch_root
= rt
;
1594 free(m
->switch_root_init
);
1595 m
->switch_root_init
= ri
;
1597 m
->exit_code
= MANAGER_SWITCH_ROOT
;
1599 return sd_bus_reply_method_return(message
, NULL
);
1602 static int method_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1603 _cleanup_strv_free_
char **plus
= NULL
;
1604 Manager
*m
= userdata
;
1610 r
= mac_selinux_access_check(message
, "reload", error
);
1614 r
= sd_bus_message_read_strv(message
, &plus
);
1617 if (!strv_env_is_valid(plus
))
1618 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1620 r
= bus_verify_set_environment_async(m
, message
, error
);
1624 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1626 r
= manager_environment_add(m
, NULL
, plus
);
1630 return sd_bus_reply_method_return(message
, NULL
);
1633 static int method_unset_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1634 _cleanup_strv_free_
char **minus
= NULL
;
1635 Manager
*m
= userdata
;
1641 r
= mac_selinux_access_check(message
, "reload", error
);
1645 r
= sd_bus_message_read_strv(message
, &minus
);
1649 if (!strv_env_name_or_assignment_is_valid(minus
))
1650 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1652 r
= bus_verify_set_environment_async(m
, message
, error
);
1656 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1658 r
= manager_environment_add(m
, minus
, NULL
);
1662 return sd_bus_reply_method_return(message
, NULL
);
1665 static int method_unset_and_set_environment(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1666 _cleanup_strv_free_
char **minus
= NULL
, **plus
= NULL
;
1667 Manager
*m
= userdata
;
1673 r
= mac_selinux_access_check(message
, "reload", error
);
1677 r
= sd_bus_message_read_strv(message
, &minus
);
1681 r
= sd_bus_message_read_strv(message
, &plus
);
1685 if (!strv_env_name_or_assignment_is_valid(minus
))
1686 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment variable names or assignments");
1687 if (!strv_env_is_valid(plus
))
1688 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment assignments");
1690 r
= bus_verify_set_environment_async(m
, message
, error
);
1694 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
1696 r
= manager_environment_add(m
, minus
, plus
);
1700 return sd_bus_reply_method_return(message
, NULL
);
1703 static int method_set_exit_code(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1704 Manager
*m
= userdata
;
1711 r
= mac_selinux_access_check(message
, "exit", error
);
1715 r
= sd_bus_message_read_basic(message
, 'y', &code
);
1719 if (MANAGER_IS_SYSTEM(m
) && detect_container() <= 0)
1720 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "ExitCode can only be set for user service managers or in containers.");
1722 m
->return_value
= code
;
1724 return sd_bus_reply_method_return(message
, NULL
);
1727 static int method_lookup_dynamic_user_by_name(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1728 Manager
*m
= userdata
;
1736 r
= sd_bus_message_read_basic(message
, 's', &name
);
1740 if (!MANAGER_IS_SYSTEM(m
))
1741 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1742 if (!valid_user_group_name(name
))
1743 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User name invalid: %s", name
);
1745 r
= dynamic_user_lookup_name(m
, name
, &uid
);
1747 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user %s does not exist.", name
);
1751 return sd_bus_reply_method_return(message
, "u", (uint32_t) uid
);
1754 static int method_lookup_dynamic_user_by_uid(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1755 _cleanup_free_
char *name
= NULL
;
1756 Manager
*m
= userdata
;
1763 assert_cc(sizeof(uid
) == sizeof(uint32_t));
1764 r
= sd_bus_message_read_basic(message
, 'u', &uid
);
1768 if (!MANAGER_IS_SYSTEM(m
))
1769 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Dynamic users are only supported in the system instance.");
1770 if (!uid_is_valid(uid
))
1771 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "User ID invalid: " UID_FMT
, uid
);
1773 r
= dynamic_user_lookup_uid(m
, uid
, &name
);
1775 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_DYNAMIC_USER
, "Dynamic user ID " UID_FMT
" does not exist.", uid
);
1779 return sd_bus_reply_method_return(message
, "s", name
);
1782 static int list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
, char **states
, char **patterns
) {
1783 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1784 Manager
*m
= userdata
;
1793 /* Anyone can call this method */
1795 r
= mac_selinux_access_check(message
, "status", error
);
1799 r
= sd_bus_message_new_method_return(message
, &reply
);
1803 h
= hashmap_new(&string_hash_ops
);
1807 r
= unit_file_get_list(m
->unit_file_scope
, NULL
, h
, states
, patterns
);
1811 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1815 HASHMAP_FOREACH(item
, h
, i
) {
1817 r
= sd_bus_message_append(reply
, "(ss)", item
->path
, unit_file_state_to_string(item
->state
));
1822 unit_file_list_free(h
);
1824 r
= sd_bus_message_close_container(reply
);
1828 return sd_bus_send(NULL
, reply
, NULL
);
1831 unit_file_list_free(h
);
1835 static int method_list_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1836 return list_unit_files_by_patterns(message
, userdata
, error
, NULL
, NULL
);
1839 static int method_list_unit_files_by_patterns(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1840 _cleanup_strv_free_
char **states
= NULL
;
1841 _cleanup_strv_free_
char **patterns
= NULL
;
1844 r
= sd_bus_message_read_strv(message
, &states
);
1848 r
= sd_bus_message_read_strv(message
, &patterns
);
1852 return list_unit_files_by_patterns(message
, userdata
, error
, states
, patterns
);
1855 static int method_get_unit_file_state(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1856 Manager
*m
= userdata
;
1858 UnitFileState state
;
1864 /* Anyone can call this method */
1866 r
= mac_selinux_access_check(message
, "status", error
);
1870 r
= sd_bus_message_read(message
, "s", &name
);
1874 r
= unit_file_get_state(m
->unit_file_scope
, NULL
, name
, &state
);
1878 return sd_bus_reply_method_return(message
, "s", unit_file_state_to_string(state
));
1881 static int method_get_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
1882 _cleanup_free_
char *default_target
= NULL
;
1883 Manager
*m
= userdata
;
1889 /* Anyone can call this method */
1891 r
= mac_selinux_access_check(message
, "status", error
);
1895 r
= unit_file_get_default(m
->unit_file_scope
, NULL
, &default_target
);
1899 return sd_bus_reply_method_return(message
, "s", default_target
);
1902 static int send_unit_files_changed(sd_bus
*bus
, void *userdata
) {
1903 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
1908 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
1912 return sd_bus_send(bus
, message
, NULL
);
1915 /* Create an error reply, using the error information from changes[]
1916 * if possible, and fall back to generating an error from error code c.
1917 * The error message only describes the first error.
1919 * Coordinate with unit_file_dump_changes() in install.c.
1921 static int install_error(
1922 sd_bus_error
*error
,
1924 UnitFileChange
*changes
,
1925 unsigned n_changes
) {
1929 for (i
= 0; i
< n_changes
; i
++)
1931 switch(changes
[i
].type
) {
1937 if (changes
[i
].source
)
1938 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1939 "File %s already exists and is a symlink to %s.",
1940 changes
[i
].path
, changes
[i
].source
);
1942 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_EXISTS
,
1943 "File %s already exists.",
1948 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_MASKED
,
1949 "Unit file %s is masked.", changes
[i
].path
);
1952 case -EADDRNOTAVAIL
:
1953 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_GENERATED
,
1954 "Unit %s is transient or generated.", changes
[i
].path
);
1958 r
= sd_bus_error_setf(error
, BUS_ERROR_UNIT_LINKED
,
1959 "Refusing to operate on linked unit file %s", changes
[i
].path
);
1963 r
= sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_UNIT
, "Unit file %s does not exist.", changes
[i
].path
);
1967 r
= sd_bus_error_set_errnof(error
, changes
[i
].type
, "File %s: %m", changes
[i
].path
);
1971 r
= c
< 0 ? c
: -EINVAL
;
1974 unit_file_changes_free(changes
, n_changes
);
1978 static int reply_unit_file_changes_and_free(
1980 sd_bus_message
*message
,
1981 int carries_install_info
,
1982 UnitFileChange
*changes
,
1984 sd_bus_error
*error
) {
1986 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1987 bool bad
= false, good
= false;
1991 if (unit_file_changes_have_modification(changes
, n_changes
)) {
1992 r
= bus_foreach_bus(m
, NULL
, send_unit_files_changed
, NULL
);
1994 log_debug_errno(r
, "Failed to send UnitFilesChanged signal: %m");
1997 r
= sd_bus_message_new_method_return(message
, &reply
);
2001 if (carries_install_info
>= 0) {
2002 r
= sd_bus_message_append(reply
, "b", carries_install_info
);
2007 r
= sd_bus_message_open_container(reply
, 'a', "(sss)");
2011 for (i
= 0; i
< n_changes
; i
++) {
2013 if (changes
[i
].type
< 0) {
2018 r
= sd_bus_message_append(
2020 unit_file_change_type_to_string(changes
[i
].type
),
2029 /* If there was a failed change, and no successful change, then return the first failure as proper method call
2032 return install_error(error
, 0, changes
, n_changes
);
2034 r
= sd_bus_message_close_container(reply
);
2038 unit_file_changes_free(changes
, n_changes
);
2039 return sd_bus_send(NULL
, reply
, NULL
);
2042 unit_file_changes_free(changes
, n_changes
);
2046 static int method_enable_unit_files_generic(
2047 sd_bus_message
*message
,
2049 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, unsigned *n_changes
),
2050 bool carries_install_info
,
2051 sd_bus_error
*error
) {
2053 _cleanup_strv_free_
char **l
= NULL
;
2054 UnitFileChange
*changes
= NULL
;
2055 unsigned n_changes
= 0;
2056 UnitFileFlags flags
;
2057 int runtime
, force
, r
;
2062 r
= sd_bus_message_read_strv(message
, &l
);
2066 r
= sd_bus_message_read(message
, "bb", &runtime
, &force
);
2070 flags
= unit_file_bools_to_flags(runtime
, force
);
2072 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2076 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2078 r
= call(m
->unit_file_scope
, flags
, NULL
, l
, &changes
, &n_changes
);
2080 return install_error(error
, r
, changes
, n_changes
);
2082 return reply_unit_file_changes_and_free(m
, message
, carries_install_info
? r
: -1, changes
, n_changes
, error
);
2085 static int method_enable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2086 return method_enable_unit_files_generic(message
, userdata
, unit_file_enable
, true, error
);
2089 static int method_reenable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2090 return method_enable_unit_files_generic(message
, userdata
, unit_file_reenable
, true, error
);
2093 static int method_link_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2094 return method_enable_unit_files_generic(message
, userdata
, unit_file_link
, false, error
);
2097 static int unit_file_preset_without_mode(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char **files
, UnitFileChange
**changes
, unsigned *n_changes
) {
2098 return unit_file_preset(scope
, flags
, root_dir
, files
, UNIT_FILE_PRESET_FULL
, changes
, n_changes
);
2101 static int method_preset_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2102 return method_enable_unit_files_generic(message
, userdata
, unit_file_preset_without_mode
, true, error
);
2105 static int method_mask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2106 return method_enable_unit_files_generic(message
, userdata
, unit_file_mask
, false, error
);
2109 static int method_preset_unit_files_with_mode(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2111 _cleanup_strv_free_
char **l
= NULL
;
2112 UnitFileChange
*changes
= NULL
;
2113 unsigned n_changes
= 0;
2114 Manager
*m
= userdata
;
2115 UnitFilePresetMode mm
;
2116 int runtime
, force
, r
;
2117 UnitFileFlags flags
;
2123 r
= sd_bus_message_read_strv(message
, &l
);
2127 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2131 flags
= unit_file_bools_to_flags(runtime
, force
);
2134 mm
= UNIT_FILE_PRESET_FULL
;
2136 mm
= unit_file_preset_mode_from_string(mode
);
2141 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2145 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2147 r
= unit_file_preset(m
->unit_file_scope
, flags
, NULL
, l
, mm
, &changes
, &n_changes
);
2149 return install_error(error
, r
, changes
, n_changes
);
2151 return reply_unit_file_changes_and_free(m
, message
, r
, changes
, n_changes
, error
);
2154 static int method_disable_unit_files_generic(
2155 sd_bus_message
*message
,
2157 int (*call
)(UnitFileScope scope
, UnitFileFlags flags
, const char *root_dir
, char *files
[], UnitFileChange
**changes
, unsigned *n_changes
),
2158 sd_bus_error
*error
) {
2160 _cleanup_strv_free_
char **l
= NULL
;
2161 UnitFileChange
*changes
= NULL
;
2162 unsigned n_changes
= 0;
2168 r
= sd_bus_message_read_strv(message
, &l
);
2172 r
= sd_bus_message_read(message
, "b", &runtime
);
2176 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2180 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2182 r
= call(m
->unit_file_scope
, runtime
? UNIT_FILE_RUNTIME
: 0, NULL
, l
, &changes
, &n_changes
);
2184 return install_error(error
, r
, changes
, n_changes
);
2186 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2189 static int method_disable_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2190 return method_disable_unit_files_generic(message
, userdata
, unit_file_disable
, error
);
2193 static int method_unmask_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2194 return method_disable_unit_files_generic(message
, userdata
, unit_file_unmask
, error
);
2197 static int method_revert_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2198 _cleanup_strv_free_
char **l
= NULL
;
2199 UnitFileChange
*changes
= NULL
;
2200 unsigned n_changes
= 0;
2201 Manager
*m
= userdata
;
2207 r
= sd_bus_message_read_strv(message
, &l
);
2211 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2215 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2217 r
= unit_file_revert(m
->unit_file_scope
, NULL
, l
, &changes
, &n_changes
);
2219 return install_error(error
, r
, changes
, n_changes
);
2221 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2224 static int method_set_default_target(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2225 UnitFileChange
*changes
= NULL
;
2226 unsigned n_changes
= 0;
2227 Manager
*m
= userdata
;
2234 r
= mac_selinux_access_check(message
, "enable", error
);
2238 r
= sd_bus_message_read(message
, "sb", &name
, &force
);
2242 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2246 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2248 r
= unit_file_set_default(m
->unit_file_scope
, force
? UNIT_FILE_FORCE
: 0, NULL
, name
, &changes
, &n_changes
);
2250 return install_error(error
, r
, changes
, n_changes
);
2252 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2255 static int method_preset_all_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2256 UnitFileChange
*changes
= NULL
;
2257 unsigned n_changes
= 0;
2258 Manager
*m
= userdata
;
2259 UnitFilePresetMode mm
;
2261 UnitFileFlags flags
;
2262 int force
, runtime
, r
;
2267 r
= mac_selinux_access_check(message
, "enable", error
);
2271 r
= sd_bus_message_read(message
, "sbb", &mode
, &runtime
, &force
);
2275 flags
= unit_file_bools_to_flags(runtime
, force
);
2278 mm
= UNIT_FILE_PRESET_FULL
;
2280 mm
= unit_file_preset_mode_from_string(mode
);
2285 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2289 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2291 r
= unit_file_preset_all(m
->unit_file_scope
, flags
, NULL
, mm
, &changes
, &n_changes
);
2293 return install_error(error
, r
, changes
, n_changes
);
2295 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2298 static int method_add_dependency_unit_files(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2299 _cleanup_strv_free_
char **l
= NULL
;
2300 Manager
*m
= userdata
;
2301 UnitFileChange
*changes
= NULL
;
2302 unsigned n_changes
= 0;
2303 int runtime
, force
, r
;
2304 char *target
, *type
;
2306 UnitFileFlags flags
;
2311 r
= bus_verify_manage_unit_files_async(m
, message
, error
);
2315 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
2317 r
= sd_bus_message_read_strv(message
, &l
);
2321 r
= sd_bus_message_read(message
, "ssbb", &target
, &type
, &runtime
, &force
);
2325 flags
= unit_file_bools_to_flags(runtime
, force
);
2327 dep
= unit_dependency_from_string(type
);
2331 r
= unit_file_add_dependency(m
->unit_file_scope
, flags
, NULL
, l
, target
, dep
, &changes
, &n_changes
);
2333 return install_error(error
, r
, changes
, n_changes
);
2335 return reply_unit_file_changes_and_free(m
, message
, -1, changes
, n_changes
, error
);
2338 static int method_get_unit_file_links(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2339 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
2340 UnitFileChange
*changes
= NULL
;
2341 unsigned n_changes
= 0, i
;
2342 UnitFileFlags flags
;
2347 r
= sd_bus_message_read(message
, "sb", &name
, &runtime
);
2351 r
= sd_bus_message_new_method_return(message
, &reply
);
2355 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_ARRAY
, "s");
2359 p
= STRV_MAKE(name
);
2360 flags
= UNIT_FILE_DRY_RUN
|
2361 (runtime
? UNIT_FILE_RUNTIME
: 0);
2363 r
= unit_file_disable(UNIT_FILE_SYSTEM
, flags
, NULL
, p
, &changes
, &n_changes
);
2365 return log_error_errno(r
, "Failed to get file links for %s: %m", name
);
2367 for (i
= 0; i
< n_changes
; i
++)
2368 if (changes
[i
].type
== UNIT_FILE_UNLINK
) {
2369 r
= sd_bus_message_append(reply
, "s", changes
[i
].path
);
2374 r
= sd_bus_message_close_container(reply
);
2378 return sd_bus_send(NULL
, reply
, NULL
);
2381 static int method_get_job_waiting(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
2382 Manager
*m
= userdata
;
2390 r
= sd_bus_message_read(message
, "u", &id
);
2394 j
= manager_get_job(m
, id
);
2396 return sd_bus_error_setf(error
, BUS_ERROR_NO_SUCH_JOB
, "Job %u does not exist.", (unsigned) id
);
2398 return bus_job_method_get_waiting_jobs(message
, j
, error
);
2401 const sd_bus_vtable bus_manager_vtable
[] = {
2402 SD_BUS_VTABLE_START(0),
2404 SD_BUS_PROPERTY("Version", "s", property_get_version
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2405 SD_BUS_PROPERTY("Features", "s", property_get_features
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2406 SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2407 SD_BUS_PROPERTY("Architecture", "s", property_get_architecture
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2408 SD_BUS_PROPERTY("Tainted", "s", property_get_tainted
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2409 BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager
, firmware_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2410 BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager
, loader_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2411 BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager
, kernel_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2412 BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager
, initrd_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2413 BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager
, userspace_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2414 BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager
, finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2415 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager
, security_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2416 BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager
, security_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2417 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager
, generators_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2418 BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager
, generators_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2419 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager
, units_load_start_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2420 BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager
, units_load_finish_timestamp
), SD_BUS_VTABLE_PROPERTY_CONST
),
2421 SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level
, property_set_log_level
, 0, 0),
2422 SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target
, property_set_log_target
, 0, 0),
2423 SD_BUS_PROPERTY("NNames", "u", property_get_n_names
, 0, 0),
2424 SD_BUS_PROPERTY("NFailedUnits", "u", property_get_n_failed_units
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
2425 SD_BUS_PROPERTY("NJobs", "u", property_get_n_jobs
, 0, 0),
2426 SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_installed_jobs
), 0),
2427 SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned
, offsetof(Manager
, n_failed_jobs
), 0),
2428 SD_BUS_PROPERTY("Progress", "d", property_get_progress
, 0, 0),
2429 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(Manager
, environment
), 0),
2430 SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool
, offsetof(Manager
, confirm_spawn
), SD_BUS_VTABLE_PROPERTY_CONST
),
2431 SD_BUS_PROPERTY("ShowStatus", "b", bus_property_get_bool
, offsetof(Manager
, show_status
), SD_BUS_VTABLE_PROPERTY_CONST
),
2432 SD_BUS_PROPERTY("UnitPath", "as", NULL
, offsetof(Manager
, lookup_paths
.search_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
2433 SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2434 SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output
, offsetof(Manager
, default_std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
2435 SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec
, property_set_runtime_watchdog
, offsetof(Manager
, runtime_watchdog
), 0),
2436 SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec
, bus_property_set_usec
, offsetof(Manager
, shutdown_watchdog
), 0),
2437 SD_BUS_PROPERTY("ControlGroup", "s", NULL
, offsetof(Manager
, cgroup_root
), 0),
2438 SD_BUS_PROPERTY("SystemState", "s", property_get_system_state
, 0, 0),
2439 SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned
, offsetof(Manager
, return_value
), 0),
2440 SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timer_accuracy_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2441 SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_start_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2442 SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_timeout_stop_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2443 SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec
, offsetof(Manager
, default_restart_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
2444 SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec
, offsetof(Manager
, default_start_limit_interval
), SD_BUS_VTABLE_PROPERTY_CONST
),
2445 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 */
2446 SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned
, offsetof(Manager
, default_start_limit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
2447 SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_cpu_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2448 SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_blockio_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2449 SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_memory_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2450 SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool
, offsetof(Manager
, default_tasks_accounting
), SD_BUS_VTABLE_PROPERTY_CONST
),
2451 SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2452 SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2453 SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2454 SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2455 SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2456 SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2457 SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2458 SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2459 SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2460 SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2461 SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2462 SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2463 SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2464 SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2465 SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2466 SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2467 SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2468 SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2469 SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2470 SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2471 SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2472 SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2473 SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2474 SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2475 SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2476 SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2477 SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2478 SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2479 SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2480 SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2481 SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2482 SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(Manager
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
2483 SD_BUS_PROPERTY("DefaultTasksMax", "t", NULL
, offsetof(Manager
, default_tasks_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
2484 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
2486 SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2487 SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2488 SD_BUS_METHOD("GetUnitByInvocationID", "ay", "o", method_get_unit_by_invocation_id
, SD_BUS_VTABLE_UNPRIVILEGED
),
2489 SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2490 SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2491 SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace
, SD_BUS_VTABLE_UNPRIVILEGED
),
2492 SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2493 SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2494 SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2495 SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2496 SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2497 SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2498 SD_BUS_METHOD("KillUnit", "ssi", NULL
, method_kill_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2499 SD_BUS_METHOD("ResetFailedUnit", "s", NULL
, method_reset_failed_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2500 SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL
, method_set_unit_properties
, SD_BUS_VTABLE_UNPRIVILEGED
),
2501 SD_BUS_METHOD("RefUnit", "s", NULL
, method_ref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2502 SD_BUS_METHOD("UnrefUnit", "s", NULL
, method_unref_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2503 SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit
, SD_BUS_VTABLE_UNPRIVILEGED
),
2504 SD_BUS_METHOD("GetUnitProcesses", "s", "a(sus)", method_get_unit_processes
, SD_BUS_VTABLE_UNPRIVILEGED
),
2505 SD_BUS_METHOD("GetJob", "u", "o", method_get_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2506 SD_BUS_METHOD("GetJobAfter", "u", "a(usssoo)", method_get_job_waiting
, SD_BUS_VTABLE_UNPRIVILEGED
),
2507 SD_BUS_METHOD("GetJobBefore", "u", "a(usssoo)", method_get_job_waiting
, SD_BUS_VTABLE_UNPRIVILEGED
),
2508 SD_BUS_METHOD("CancelJob", "u", NULL
, method_cancel_job
, SD_BUS_VTABLE_UNPRIVILEGED
),
2509 SD_BUS_METHOD("ClearJobs", NULL
, NULL
, method_clear_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2510 SD_BUS_METHOD("ResetFailed", NULL
, NULL
, method_reset_failed
, SD_BUS_VTABLE_UNPRIVILEGED
),
2511 SD_BUS_METHOD("ListUnits", NULL
, "a(ssssssouso)", method_list_units
, SD_BUS_VTABLE_UNPRIVILEGED
),
2512 SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered
, SD_BUS_VTABLE_UNPRIVILEGED
),
2513 SD_BUS_METHOD("ListUnitsByPatterns", "asas", "a(ssssssouso)", method_list_units_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2514 SD_BUS_METHOD("ListUnitsByNames", "as", "a(ssssssouso)", method_list_units_by_names
, SD_BUS_VTABLE_UNPRIVILEGED
),
2515 SD_BUS_METHOD("ListJobs", NULL
, "a(usssoo)", method_list_jobs
, SD_BUS_VTABLE_UNPRIVILEGED
),
2516 SD_BUS_METHOD("Subscribe", NULL
, NULL
, method_subscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2517 SD_BUS_METHOD("Unsubscribe", NULL
, NULL
, method_unsubscribe
, SD_BUS_VTABLE_UNPRIVILEGED
),
2518 SD_BUS_METHOD("Dump", NULL
, "s", method_dump
, SD_BUS_VTABLE_UNPRIVILEGED
),
2519 SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
),
2520 SD_BUS_METHOD("RemoveSnapshot", "s", NULL
, method_refuse_snapshot
, SD_BUS_VTABLE_UNPRIVILEGED
),
2521 SD_BUS_METHOD("Reload", NULL
, NULL
, method_reload
, SD_BUS_VTABLE_UNPRIVILEGED
),
2522 SD_BUS_METHOD("Reexecute", NULL
, NULL
, method_reexecute
, SD_BUS_VTABLE_UNPRIVILEGED
),
2523 SD_BUS_METHOD("Exit", NULL
, NULL
, method_exit
, 0),
2524 SD_BUS_METHOD("Reboot", NULL
, NULL
, method_reboot
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2525 SD_BUS_METHOD("PowerOff", NULL
, NULL
, method_poweroff
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2526 SD_BUS_METHOD("Halt", NULL
, NULL
, method_halt
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2527 SD_BUS_METHOD("KExec", NULL
, NULL
, method_kexec
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2528 SD_BUS_METHOD("SwitchRoot", "ss", NULL
, method_switch_root
, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT
)),
2529 SD_BUS_METHOD("SetEnvironment", "as", NULL
, method_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2530 SD_BUS_METHOD("UnsetEnvironment", "as", NULL
, method_unset_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2531 SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL
, method_unset_and_set_environment
, SD_BUS_VTABLE_UNPRIVILEGED
),
2532 SD_BUS_METHOD("ListUnitFiles", NULL
, "a(ss)", method_list_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2533 SD_BUS_METHOD("ListUnitFilesByPatterns", "asas", "a(ss)", method_list_unit_files_by_patterns
, SD_BUS_VTABLE_UNPRIVILEGED
),
2534 SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state
, SD_BUS_VTABLE_UNPRIVILEGED
),
2535 SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2536 SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2537 SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2538 SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2539 SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2540 SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode
, SD_BUS_VTABLE_UNPRIVILEGED
),
2541 SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2542 SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2543 SD_BUS_METHOD("RevertUnitFiles", "as", "a(sss)", method_revert_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2544 SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2545 SD_BUS_METHOD("GetDefaultTarget", NULL
, "s", method_get_default_target
, SD_BUS_VTABLE_UNPRIVILEGED
),
2546 SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2547 SD_BUS_METHOD("AddDependencyUnitFiles", "asssbb", "a(sss)", method_add_dependency_unit_files
, SD_BUS_VTABLE_UNPRIVILEGED
),
2548 SD_BUS_METHOD("GetUnitFileLinks", "sb", "as", method_get_unit_file_links
, SD_BUS_VTABLE_UNPRIVILEGED
),
2549 SD_BUS_METHOD("SetExitCode", "y", NULL
, method_set_exit_code
, SD_BUS_VTABLE_UNPRIVILEGED
),
2550 SD_BUS_METHOD("LookupDynamicUserByName", "s", "u", method_lookup_dynamic_user_by_name
, SD_BUS_VTABLE_UNPRIVILEGED
),
2551 SD_BUS_METHOD("LookupDynamicUserByUID", "u", "s", method_lookup_dynamic_user_by_uid
, SD_BUS_VTABLE_UNPRIVILEGED
),
2553 SD_BUS_SIGNAL("UnitNew", "so", 0),
2554 SD_BUS_SIGNAL("UnitRemoved", "so", 0),
2555 SD_BUS_SIGNAL("JobNew", "uos", 0),
2556 SD_BUS_SIGNAL("JobRemoved", "uoss", 0),
2557 SD_BUS_SIGNAL("StartupFinished", "tttttt", 0),
2558 SD_BUS_SIGNAL("UnitFilesChanged", NULL
, 0),
2559 SD_BUS_SIGNAL("Reloading", "b", 0),
2564 static int send_finished(sd_bus
*bus
, void *userdata
) {
2565 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2566 usec_t
*times
= userdata
;
2572 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
2576 r
= sd_bus_message_append(message
, "tttttt", times
[0], times
[1], times
[2], times
[3], times
[4], times
[5]);
2580 return sd_bus_send(bus
, message
, NULL
);
2583 void bus_manager_send_finished(
2585 usec_t firmware_usec
,
2589 usec_t userspace_usec
,
2590 usec_t total_usec
) {
2596 r
= bus_foreach_bus(
2609 log_debug_errno(r
, "Failed to send finished signal: %m");
2612 static int send_reloading(sd_bus
*bus
, void *userdata
) {
2613 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*message
= NULL
;
2618 r
= sd_bus_message_new_signal(bus
, &message
, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading");
2622 r
= sd_bus_message_append(message
, "b", PTR_TO_INT(userdata
));
2626 return sd_bus_send(bus
, message
, NULL
);
2629 void bus_manager_send_reloading(Manager
*m
, bool active
) {
2634 r
= bus_foreach_bus(m
, NULL
, send_reloading
, INT_TO_PTR(active
));
2636 log_debug_errno(r
, "Failed to send reloading signal: %m");
2639 static int send_changed_signal(sd_bus
*bus
, void *userdata
) {
2642 return sd_bus_emit_properties_changed_strv(bus
,
2643 "/org/freedesktop/systemd1",
2644 "org.freedesktop.systemd1.Manager",
2648 void bus_manager_send_change_signal(Manager
*m
) {
2653 r
= bus_foreach_bus(m
, NULL
, send_changed_signal
, NULL
);
2655 log_debug_errno(r
, "Failed to send manager change signal: %m");