]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
a7334b09 | 2 | |
ea430986 | 3 | #include <errno.h> |
eed67a30 | 4 | #include <sys/prctl.h> |
ae57dad3 | 5 | #include <sys/statvfs.h> |
871c44a7 | 6 | #include <unistd.h> |
ea430986 | 7 | |
b5efdb8a | 8 | #include "alloc-util.h" |
07630cea | 9 | #include "architecture.h" |
09bde77f | 10 | #include "build.h" |
07630cea | 11 | #include "bus-common-errors.h" |
07630cea | 12 | #include "dbus-execute.h" |
2ea31e5b | 13 | #include "dbus-job.h" |
3ffd4af2 | 14 | #include "dbus-manager.h" |
c20076a8 | 15 | #include "dbus-scope.h" |
07630cea LP |
16 | #include "dbus-unit.h" |
17 | #include "dbus.h" | |
18 | #include "env-util.h" | |
3ffd4af2 | 19 | #include "fd-util.h" |
0d39fa9c | 20 | #include "fileio.h" |
f97b34a6 | 21 | #include "format-util.h" |
710028b4 | 22 | #include "fs-util.h" |
07630cea LP |
23 | #include "install.h" |
24 | #include "log.h" | |
d58ad743 | 25 | #include "os-util.h" |
ae57dad3 | 26 | #include "parse-util.h" |
07630cea LP |
27 | #include "path-util.h" |
28 | #include "selinux-access.h" | |
8fcde012 | 29 | #include "stat-util.h" |
07630cea LP |
30 | #include "string-util.h" |
31 | #include "strv.h" | |
7ccbd1ae | 32 | #include "syslog-util.h" |
29206d46 | 33 | #include "user-util.h" |
07630cea LP |
34 | #include "virt.h" |
35 | #include "watchdog.h" | |
ea430986 | 36 | |
ae57dad3 LP |
37 | /* Require 16MiB free in /run/systemd for reloading/reexecing. After all we need to serialize our state there, and if |
38 | * we can't we'll fail badly. */ | |
39 | #define RELOAD_DISK_SPACE_MIN (UINT64_C(16) * UINT64_C(1024) * UINT64_C(1024)) | |
40 | ||
b3796dd8 JS |
41 | static UnitFileFlags unit_file_bools_to_flags(bool runtime, bool force) { |
42 | return (runtime ? UNIT_FILE_RUNTIME : 0) | | |
43 | (force ? UNIT_FILE_FORCE : 0); | |
44 | } | |
45 | ||
681bd2c5 | 46 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_version, "s", GIT_VERSION); |
23c9a63a YW |
47 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_features, "s", SYSTEMD_FEATURES); |
48 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_architecture, "s", architecture_to_string(uname_architecture())); | |
49 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_log_target, "s", log_target_to_string(log_get_target())); | |
50 | static BUS_DEFINE_PROPERTY_GET2(property_get_system_state, "s", Manager, manager_state, manager_state_to_string); | |
51 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_timer_slack_nsec, "t", (uint64_t) prctl(PR_GET_TIMERSLACK)); | |
92c23c5a YW |
52 | static BUS_DEFINE_PROPERTY_GET_REF(property_get_hashmap_size, "u", Hashmap *, hashmap_size); |
53 | static BUS_DEFINE_PROPERTY_GET_REF(property_get_set_size, "u", Set *, set_size); | |
718db961 LP |
54 | |
55 | static int property_get_virtualization( | |
56 | sd_bus *bus, | |
57 | const char *path, | |
58 | const char *interface, | |
59 | const char *property, | |
60 | sd_bus_message *reply, | |
ebcf1f97 LP |
61 | void *userdata, |
62 | sd_bus_error *error) { | |
718db961 | 63 | |
5c22925a LP |
64 | int v; |
65 | ||
718db961 LP |
66 | assert(bus); |
67 | assert(reply); | |
68 | ||
5c22925a LP |
69 | v = detect_virtualization(); |
70 | ||
71 | /* Make sure to return the empty string when we detect no virtualization, as that is the API. | |
72 | * | |
73 | * https://github.com/systemd/systemd/issues/1423 | |
74 | */ | |
75 | ||
76 | return sd_bus_message_append( | |
77 | reply, "s", | |
79a60375 | 78 | v == VIRTUALIZATION_NONE ? NULL : virtualization_to_string(v)); |
718db961 LP |
79 | } |
80 | ||
81 | static int property_get_tainted( | |
82 | sd_bus *bus, | |
83 | const char *path, | |
84 | const char *interface, | |
85 | const char *property, | |
86 | sd_bus_message *reply, | |
ebcf1f97 LP |
87 | void *userdata, |
88 | sd_bus_error *error) { | |
718db961 | 89 | |
af6b0ecc | 90 | _cleanup_free_ char *s = NULL; |
718db961 LP |
91 | Manager *m = userdata; |
92 | ||
93 | assert(bus); | |
94 | assert(reply); | |
bfebab7f | 95 | assert(m); |
c5d34390 | 96 | |
af6b0ecc LP |
97 | s = manager_taint_string(m); |
98 | if (!s) | |
99 | return log_oom(); | |
c5d34390 | 100 | |
af6b0ecc | 101 | return sd_bus_message_append(reply, "s", s); |
c5d34390 LP |
102 | } |
103 | ||
718db961 LP |
104 | static int property_set_log_target( |
105 | sd_bus *bus, | |
106 | const char *path, | |
107 | const char *interface, | |
108 | const char *property, | |
109 | sd_bus_message *value, | |
ebcf1f97 LP |
110 | void *userdata, |
111 | sd_bus_error *error) { | |
718db961 | 112 | |
bda7d78b | 113 | Manager *m = userdata; |
c826cda4 | 114 | const char *t; |
718db961 | 115 | int r; |
c826cda4 | 116 | |
718db961 LP |
117 | assert(bus); |
118 | assert(value); | |
c826cda4 | 119 | |
718db961 LP |
120 | r = sd_bus_message_read(value, "s", &t); |
121 | if (r < 0) | |
122 | return r; | |
c826cda4 | 123 | |
bda7d78b FB |
124 | if (isempty(t)) |
125 | manager_restore_original_log_target(m); | |
126 | else { | |
127 | LogTarget target; | |
128 | ||
129 | target = log_target_from_string(t); | |
130 | if (target < 0) | |
131 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid log target '%s'", t); | |
132 | ||
133 | manager_override_log_target(m, target); | |
134 | } | |
135 | ||
136 | return 0; | |
c826cda4 AB |
137 | } |
138 | ||
718db961 LP |
139 | static int property_get_log_level( |
140 | sd_bus *bus, | |
141 | const char *path, | |
142 | const char *interface, | |
143 | const char *property, | |
144 | sd_bus_message *reply, | |
ebcf1f97 LP |
145 | void *userdata, |
146 | sd_bus_error *error) { | |
718db961 | 147 | |
68eda4bd | 148 | _cleanup_free_ char *t = NULL; |
f8b69d1d | 149 | int r; |
1adf1049 | 150 | |
718db961 LP |
151 | assert(bus); |
152 | assert(reply); | |
1adf1049 | 153 | |
f8b69d1d MS |
154 | r = log_level_to_string_alloc(log_get_max_level(), &t); |
155 | if (r < 0) | |
156 | return r; | |
1adf1049 | 157 | |
718db961 | 158 | return sd_bus_message_append(reply, "s", t); |
1adf1049 LP |
159 | } |
160 | ||
718db961 LP |
161 | static int property_set_log_level( |
162 | sd_bus *bus, | |
163 | const char *path, | |
164 | const char *interface, | |
165 | const char *property, | |
166 | sd_bus_message *value, | |
ebcf1f97 LP |
167 | void *userdata, |
168 | sd_bus_error *error) { | |
718db961 | 169 | |
a6ecbf83 | 170 | Manager *m = userdata; |
c826cda4 | 171 | const char *t; |
718db961 | 172 | int r; |
c826cda4 | 173 | |
718db961 LP |
174 | assert(bus); |
175 | assert(value); | |
c826cda4 | 176 | |
718db961 LP |
177 | r = sd_bus_message_read(value, "s", &t); |
178 | if (r < 0) | |
179 | return r; | |
c826cda4 | 180 | |
a6ecbf83 FB |
181 | if (isempty(t)) |
182 | manager_restore_original_log_level(m); | |
183 | else { | |
184 | int level; | |
185 | ||
186 | level = log_level_from_string(t); | |
187 | if (level < 0) | |
188 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid log level '%s'", t); | |
189 | ||
190 | manager_override_log_level(m, level); | |
191 | } | |
192 | ||
193 | return 0; | |
c826cda4 AB |
194 | } |
195 | ||
718db961 LP |
196 | static int property_get_progress( |
197 | sd_bus *bus, | |
198 | const char *path, | |
199 | const char *interface, | |
200 | const char *property, | |
201 | sd_bus_message *reply, | |
ebcf1f97 LP |
202 | void *userdata, |
203 | sd_bus_error *error) { | |
718db961 LP |
204 | |
205 | Manager *m = userdata; | |
05d6a3b6 LP |
206 | double d; |
207 | ||
718db961 LP |
208 | assert(bus); |
209 | assert(reply); | |
bfebab7f | 210 | assert(m); |
05d6a3b6 | 211 | |
49d5666c | 212 | if (MANAGER_IS_FINISHED(m)) |
05d6a3b6 LP |
213 | d = 1.0; |
214 | else | |
215 | d = 1.0 - ((double) hashmap_size(m->jobs) / (double) m->n_installed_jobs); | |
216 | ||
718db961 LP |
217 | return sd_bus_message_append(reply, "d", d); |
218 | } | |
219 | ||
1ad6e8b3 LP |
220 | static int property_get_environment( |
221 | sd_bus *bus, | |
222 | const char *path, | |
223 | const char *interface, | |
224 | const char *property, | |
225 | sd_bus_message *reply, | |
226 | void *userdata, | |
227 | sd_bus_error *error) { | |
228 | ||
229 | _cleanup_strv_free_ char **l = NULL; | |
230 | Manager *m = userdata; | |
231 | int r; | |
232 | ||
233 | assert(bus); | |
234 | assert(reply); | |
235 | assert(m); | |
236 | ||
237 | r = manager_get_effective_environment(m, &l); | |
238 | if (r < 0) | |
239 | return r; | |
240 | ||
241 | return sd_bus_message_append_strv(reply, l); | |
242 | } | |
243 | ||
52d2566a ZJS |
244 | static int property_get_show_status( |
245 | sd_bus *bus, | |
246 | const char *path, | |
247 | const char *interface, | |
248 | const char *property, | |
249 | sd_bus_message *reply, | |
250 | void *userdata, | |
251 | sd_bus_error *error) { | |
252 | ||
253 | Manager *m = userdata; | |
254 | int b; | |
255 | ||
256 | assert(bus); | |
257 | assert(reply); | |
258 | assert(m); | |
259 | ||
7a293242 | 260 | b = IN_SET(m->show_status, SHOW_STATUS_TEMPORARY, SHOW_STATUS_YES); |
52d2566a ZJS |
261 | return sd_bus_message_append_basic(reply, 'b', &b); |
262 | } | |
263 | ||
718db961 LP |
264 | static int property_set_runtime_watchdog( |
265 | sd_bus *bus, | |
266 | const char *path, | |
267 | const char *interface, | |
268 | const char *property, | |
269 | sd_bus_message *value, | |
ebcf1f97 LP |
270 | void *userdata, |
271 | sd_bus_error *error) { | |
05d6a3b6 | 272 | |
718db961 LP |
273 | usec_t *t = userdata; |
274 | int r; | |
275 | ||
276 | assert(bus); | |
277 | assert(value); | |
278 | ||
279 | assert_cc(sizeof(usec_t) == sizeof(uint64_t)); | |
280 | ||
281 | r = sd_bus_message_read(value, "t", t); | |
282 | if (r < 0) | |
283 | return r; | |
284 | ||
285 | return watchdog_set_timeout(t); | |
05d6a3b6 LP |
286 | } |
287 | ||
96cc4453 | 288 | static int bus_get_unit_by_name(Manager *m, sd_bus_message *message, const char *name, Unit **ret_unit, sd_bus_error *error) { |
718db961 LP |
289 | Unit *u; |
290 | int r; | |
dfae3488 | 291 | |
dfae3488 | 292 | assert(m); |
96cc4453 LP |
293 | assert(message); |
294 | assert(ret_unit); | |
dfae3488 | 295 | |
96cc4453 LP |
296 | /* More or less a wrapper around manager_get_unit() that generates nice errors and has one trick up its sleeve: |
297 | * if the name is specified empty we use the client's unit. */ | |
dfae3488 | 298 | |
1d22e906 | 299 | if (isempty(name)) { |
4afd3348 | 300 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; |
1d22e906 LP |
301 | pid_t pid; |
302 | ||
303 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); | |
304 | if (r < 0) | |
305 | return r; | |
306 | ||
307 | r = sd_bus_creds_get_pid(creds, &pid); | |
308 | if (r < 0) | |
309 | return r; | |
310 | ||
311 | u = manager_get_unit_by_pid(m, pid); | |
312 | if (!u) | |
313 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Client not member of any unit."); | |
314 | } else { | |
315 | u = manager_get_unit(m, name); | |
316 | if (!u) | |
317 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", name); | |
318 | } | |
dfae3488 | 319 | |
96cc4453 LP |
320 | *ret_unit = u; |
321 | return 0; | |
322 | } | |
323 | ||
324 | static int bus_load_unit_by_name(Manager *m, sd_bus_message *message, const char *name, Unit **ret_unit, sd_bus_error *error) { | |
325 | assert(m); | |
326 | assert(message); | |
327 | assert(ret_unit); | |
328 | ||
329 | /* Pretty much the same as bus_get_unit_by_name(), but we also load the unit if necessary. */ | |
330 | ||
331 | if (isempty(name)) | |
332 | return bus_get_unit_by_name(m, message, name, ret_unit, error); | |
333 | ||
334 | return manager_load_unit(m, name, NULL, error, ret_unit); | |
335 | } | |
336 | ||
337 | static int method_get_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
338 | _cleanup_free_ char *path = NULL; | |
339 | Manager *m = userdata; | |
340 | const char *name; | |
341 | Unit *u; | |
342 | int r; | |
343 | ||
344 | assert(message); | |
345 | assert(m); | |
346 | ||
347 | /* Anyone can call this method */ | |
348 | ||
349 | r = sd_bus_message_read(message, "s", &name); | |
350 | if (r < 0) | |
351 | return r; | |
352 | ||
353 | r = bus_get_unit_by_name(m, message, name, &u, error); | |
354 | if (r < 0) | |
355 | return r; | |
356 | ||
8a188de9 | 357 | r = mac_selinux_unit_access_check(u, message, "status", error); |
ebcf1f97 LP |
358 | if (r < 0) |
359 | return r; | |
dfae3488 | 360 | |
718db961 LP |
361 | path = unit_dbus_path(u); |
362 | if (!path) | |
ebcf1f97 | 363 | return -ENOMEM; |
729e3769 | 364 | |
df2d202e | 365 | return sd_bus_reply_method_return(message, "o", path); |
718db961 | 366 | } |
c0576cd6 | 367 | |
19070062 | 368 | static int method_get_unit_by_pid(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
369 | _cleanup_free_ char *path = NULL; |
370 | Manager *m = userdata; | |
371 | pid_t pid; | |
372 | Unit *u; | |
373 | int r; | |
c0576cd6 | 374 | |
718db961 LP |
375 | assert(message); |
376 | assert(m); | |
c0576cd6 | 377 | |
718db961 | 378 | assert_cc(sizeof(pid_t) == sizeof(uint32_t)); |
729e3769 | 379 | |
283868e1 SW |
380 | /* Anyone can call this method */ |
381 | ||
718db961 LP |
382 | r = sd_bus_message_read(message, "u", &pid); |
383 | if (r < 0) | |
ebcf1f97 | 384 | return r; |
07b38ba5 | 385 | if (pid < 0) |
1d22e906 | 386 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PID " PID_FMT, pid); |
718db961 LP |
387 | |
388 | if (pid == 0) { | |
4afd3348 | 389 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; |
5b12334d LP |
390 | |
391 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); | |
392 | if (r < 0) | |
393 | return r; | |
394 | ||
395 | r = sd_bus_creds_get_pid(creds, &pid); | |
718db961 | 396 | if (r < 0) |
ebcf1f97 | 397 | return r; |
729e3769 LP |
398 | } |
399 | ||
718db961 LP |
400 | u = manager_get_unit_by_pid(m, pid); |
401 | if (!u) | |
1fa2f38f | 402 | return sd_bus_error_setf(error, BUS_ERROR_NO_UNIT_FOR_PID, "PID "PID_FMT" does not belong to any loaded unit.", pid); |
c0576cd6 | 403 | |
8a188de9 | 404 | r = mac_selinux_unit_access_check(u, message, "status", error); |
ebcf1f97 LP |
405 | if (r < 0) |
406 | return r; | |
718db961 LP |
407 | |
408 | path = unit_dbus_path(u); | |
409 | if (!path) | |
ebcf1f97 | 410 | return -ENOMEM; |
718db961 | 411 | |
df2d202e | 412 | return sd_bus_reply_method_return(message, "o", path); |
718db961 LP |
413 | } |
414 | ||
4b58153d LP |
415 | static int method_get_unit_by_invocation_id(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
416 | _cleanup_free_ char *path = NULL; | |
417 | Manager *m = userdata; | |
418 | sd_id128_t id; | |
419 | const void *a; | |
420 | Unit *u; | |
421 | size_t sz; | |
422 | int r; | |
423 | ||
424 | assert(message); | |
425 | assert(m); | |
426 | ||
427 | /* Anyone can call this method */ | |
428 | ||
429 | r = sd_bus_message_read_array(message, 'y', &a, &sz); | |
430 | if (r < 0) | |
431 | return r; | |
432 | if (sz == 0) | |
433 | id = SD_ID128_NULL; | |
434 | else if (sz == 16) | |
435 | memcpy(&id, a, sz); | |
436 | else | |
437 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid invocation ID"); | |
438 | ||
439 | if (sd_id128_is_null(id)) { | |
440 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; | |
441 | pid_t pid; | |
442 | ||
443 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); | |
444 | if (r < 0) | |
445 | return r; | |
446 | ||
447 | r = sd_bus_creds_get_pid(creds, &pid); | |
448 | if (r < 0) | |
449 | return r; | |
450 | ||
451 | u = manager_get_unit_by_pid(m, pid); | |
452 | if (!u) | |
453 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Client " PID_FMT " not member of any unit.", pid); | |
454 | } else { | |
455 | u = hashmap_get(m->units_by_invocation_id, &id); | |
456 | if (!u) | |
457 | 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)); | |
458 | } | |
459 | ||
460 | r = mac_selinux_unit_access_check(u, message, "status", error); | |
461 | if (r < 0) | |
462 | return r; | |
463 | ||
464 | /* So here's a special trick: the bus path we return actually references the unit by its invocation ID instead | |
465 | * of the unit name. This means it stays valid only as long as the invocation ID stays the same. */ | |
466 | path = unit_dbus_path_invocation_id(u); | |
467 | if (!path) | |
468 | return -ENOMEM; | |
469 | ||
470 | return sd_bus_reply_method_return(message, "o", path); | |
471 | } | |
472 | ||
267dd427 LP |
473 | static int method_get_unit_by_control_group(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
474 | _cleanup_free_ char *path = NULL; | |
475 | Manager *m = userdata; | |
476 | const char *cgroup; | |
477 | Unit *u; | |
478 | int r; | |
479 | ||
480 | r = sd_bus_message_read(message, "s", &cgroup); | |
481 | if (r < 0) | |
482 | return r; | |
483 | ||
484 | u = manager_get_unit_by_cgroup(m, cgroup); | |
485 | if (!u) | |
486 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Control group '%s' is not valid or not managed by this instance", cgroup); | |
487 | ||
488 | r = mac_selinux_unit_access_check(u, message, "status", error); | |
489 | if (r < 0) | |
490 | return r; | |
491 | ||
492 | path = unit_dbus_path(u); | |
493 | if (!path) | |
494 | return -ENOMEM; | |
495 | ||
496 | return sd_bus_reply_method_return(message, "o", path); | |
497 | } | |
498 | ||
19070062 | 499 | static int method_load_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
500 | _cleanup_free_ char *path = NULL; |
501 | Manager *m = userdata; | |
502 | const char *name; | |
503 | Unit *u; | |
504 | int r; | |
c0576cd6 | 505 | |
718db961 LP |
506 | assert(message); |
507 | assert(m); | |
508 | ||
283868e1 SW |
509 | /* Anyone can call this method */ |
510 | ||
718db961 LP |
511 | r = sd_bus_message_read(message, "s", &name); |
512 | if (r < 0) | |
ebcf1f97 | 513 | return r; |
c0576cd6 | 514 | |
96cc4453 LP |
515 | r = bus_load_unit_by_name(m, message, name, &u, error); |
516 | if (r < 0) | |
517 | return r; | |
718db961 | 518 | |
8a188de9 | 519 | r = mac_selinux_unit_access_check(u, message, "status", error); |
ebcf1f97 LP |
520 | if (r < 0) |
521 | return r; | |
c0576cd6 | 522 | |
718db961 LP |
523 | path = unit_dbus_path(u); |
524 | if (!path) | |
ebcf1f97 | 525 | return -ENOMEM; |
718db961 | 526 | |
df2d202e | 527 | return sd_bus_reply_method_return(message, "o", path); |
c0576cd6 LP |
528 | } |
529 | ||
19070062 | 530 | static int method_start_unit_generic(sd_bus_message *message, Manager *m, JobType job_type, bool reload_if_possible, sd_bus_error *error) { |
718db961 LP |
531 | const char *name; |
532 | Unit *u; | |
c0576cd6 LP |
533 | int r; |
534 | ||
718db961 LP |
535 | assert(message); |
536 | assert(m); | |
c0576cd6 | 537 | |
718db961 LP |
538 | r = sd_bus_message_read(message, "s", &name); |
539 | if (r < 0) | |
ebcf1f97 | 540 | return r; |
c0576cd6 | 541 | |
ebcf1f97 | 542 | r = manager_load_unit(m, name, NULL, error, &u); |
718db961 | 543 | if (r < 0) |
ebcf1f97 | 544 | return r; |
718db961 | 545 | |
19070062 | 546 | return bus_unit_method_start_generic(message, u, job_type, reload_if_possible, error); |
c0576cd6 LP |
547 | } |
548 | ||
19070062 LP |
549 | static int method_start_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
550 | return method_start_unit_generic(message, userdata, JOB_START, false, error); | |
718db961 | 551 | } |
c757a65b | 552 | |
19070062 LP |
553 | static int method_stop_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
554 | return method_start_unit_generic(message, userdata, JOB_STOP, false, error); | |
718db961 | 555 | } |
c757a65b | 556 | |
19070062 LP |
557 | static int method_reload_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
558 | return method_start_unit_generic(message, userdata, JOB_RELOAD, false, error); | |
718db961 | 559 | } |
c757a65b | 560 | |
19070062 LP |
561 | static int method_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
562 | return method_start_unit_generic(message, userdata, JOB_RESTART, false, error); | |
c757a65b LP |
563 | } |
564 | ||
19070062 LP |
565 | static int method_try_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
566 | return method_start_unit_generic(message, userdata, JOB_TRY_RESTART, false, error); | |
718db961 | 567 | } |
d200735e | 568 | |
19070062 LP |
569 | static int method_reload_or_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
570 | return method_start_unit_generic(message, userdata, JOB_RESTART, true, error); | |
718db961 | 571 | } |
d200735e | 572 | |
19070062 LP |
573 | static int method_reload_or_try_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
574 | return method_start_unit_generic(message, userdata, JOB_TRY_RESTART, true, error); | |
718db961 | 575 | } |
d200735e | 576 | |
50cbaba4 LP |
577 | static int method_enqueue_unit_job(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
578 | Manager *m = userdata; | |
579 | const char *name; | |
580 | Unit *u; | |
581 | int r; | |
582 | ||
583 | assert(message); | |
584 | assert(m); | |
585 | ||
586 | r = sd_bus_message_read(message, "s", &name); | |
587 | if (r < 0) | |
588 | return r; | |
589 | ||
590 | r = manager_load_unit(m, name, NULL, error, &u); | |
591 | if (r < 0) | |
592 | return r; | |
593 | ||
594 | return bus_unit_method_enqueue_job(message, u, error); | |
595 | } | |
596 | ||
19070062 | 597 | static int method_start_unit_replace(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
598 | Manager *m = userdata; |
599 | const char *old_name; | |
600 | Unit *u; | |
1adf1049 | 601 | int r; |
ea430986 | 602 | |
ea430986 LP |
603 | assert(message); |
604 | assert(m); | |
605 | ||
718db961 LP |
606 | r = sd_bus_message_read(message, "s", &old_name); |
607 | if (r < 0) | |
ebcf1f97 | 608 | return r; |
ea430986 | 609 | |
96cc4453 LP |
610 | r = bus_get_unit_by_name(m, message, old_name, &u, error); |
611 | if (r < 0) | |
612 | return r; | |
613 | if (!u->job || u->job->type != JOB_START) | |
ebcf1f97 | 614 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name); |
c0576cd6 | 615 | |
19070062 | 616 | return method_start_unit_generic(message, m, JOB_START, false, error); |
718db961 | 617 | } |
ea430986 | 618 | |
19070062 | 619 | static int method_kill_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
620 | Manager *m = userdata; |
621 | const char *name; | |
622 | Unit *u; | |
623 | int r; | |
ea430986 | 624 | |
718db961 LP |
625 | assert(message); |
626 | assert(m); | |
ea430986 | 627 | |
718db961 LP |
628 | r = sd_bus_message_read(message, "s", &name); |
629 | if (r < 0) | |
ebcf1f97 | 630 | return r; |
598b557b | 631 | |
96cc4453 LP |
632 | r = bus_get_unit_by_name(m, message, name, &u, error); |
633 | if (r < 0) | |
634 | return r; | |
0a524ba7 | 635 | |
19070062 | 636 | return bus_unit_method_kill(message, u, error); |
718db961 | 637 | } |
8a0867d6 | 638 | |
19070062 | 639 | static int method_reset_failed_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
640 | Manager *m = userdata; |
641 | const char *name; | |
642 | Unit *u; | |
643 | int r; | |
8a0867d6 | 644 | |
718db961 LP |
645 | assert(message); |
646 | assert(m); | |
cad45ba1 | 647 | |
718db961 LP |
648 | r = sd_bus_message_read(message, "s", &name); |
649 | if (r < 0) | |
ebcf1f97 | 650 | return r; |
ea430986 | 651 | |
96cc4453 LP |
652 | r = bus_get_unit_by_name(m, message, name, &u, error); |
653 | if (r < 0) | |
654 | return r; | |
5dd9014f | 655 | |
19070062 | 656 | return bus_unit_method_reset_failed(message, u, error); |
718db961 | 657 | } |
5dd9014f | 658 | |
19070062 | 659 | static int method_set_unit_properties(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
660 | Manager *m = userdata; |
661 | const char *name; | |
662 | Unit *u; | |
663 | int r; | |
5dd9014f | 664 | |
718db961 LP |
665 | assert(message); |
666 | assert(m); | |
667 | ||
668 | r = sd_bus_message_read(message, "s", &name); | |
669 | if (r < 0) | |
ebcf1f97 | 670 | return r; |
718db961 | 671 | |
96cc4453 | 672 | r = bus_load_unit_by_name(m, message, name, &u, error); |
e9fd88f2 FB |
673 | if (r < 0) |
674 | return r; | |
675 | ||
e49da001 | 676 | r = bus_unit_validate_load_state(u, error); |
e9fd88f2 FB |
677 | if (r < 0) |
678 | return r; | |
ea430986 | 679 | |
19070062 | 680 | return bus_unit_method_set_properties(message, u, error); |
718db961 LP |
681 | } |
682 | ||
05a98afd LP |
683 | static int method_ref_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
684 | Manager *m = userdata; | |
685 | const char *name; | |
686 | Unit *u; | |
687 | int r; | |
688 | ||
689 | assert(message); | |
690 | assert(m); | |
691 | ||
692 | r = sd_bus_message_read(message, "s", &name); | |
693 | if (r < 0) | |
694 | return r; | |
695 | ||
96cc4453 | 696 | r = bus_load_unit_by_name(m, message, name, &u, error); |
05a98afd LP |
697 | if (r < 0) |
698 | return r; | |
699 | ||
e49da001 | 700 | r = bus_unit_validate_load_state(u, error); |
05a98afd LP |
701 | if (r < 0) |
702 | return r; | |
703 | ||
704 | return bus_unit_method_ref(message, u, error); | |
705 | } | |
706 | ||
707 | static int method_unref_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
708 | Manager *m = userdata; | |
709 | const char *name; | |
710 | Unit *u; | |
711 | int r; | |
712 | ||
713 | assert(message); | |
714 | assert(m); | |
715 | ||
716 | r = sd_bus_message_read(message, "s", &name); | |
717 | if (r < 0) | |
718 | return r; | |
719 | ||
96cc4453 | 720 | r = bus_load_unit_by_name(m, message, name, &u, error); |
05a98afd LP |
721 | if (r < 0) |
722 | return r; | |
723 | ||
e49da001 | 724 | r = bus_unit_validate_load_state(u, error); |
05a98afd LP |
725 | if (r < 0) |
726 | return r; | |
727 | ||
728 | return bus_unit_method_unref(message, u, error); | |
729 | } | |
730 | ||
6900c740 | 731 | static int reply_unit_info(sd_bus_message *reply, Unit *u) { |
732 | _cleanup_free_ char *unit_path = NULL, *job_path = NULL; | |
733 | Unit *following; | |
734 | ||
735 | following = unit_following(u); | |
736 | ||
737 | unit_path = unit_dbus_path(u); | |
738 | if (!unit_path) | |
739 | return -ENOMEM; | |
740 | ||
741 | if (u->job) { | |
742 | job_path = job_dbus_path(u->job); | |
743 | if (!job_path) | |
744 | return -ENOMEM; | |
745 | } | |
746 | ||
747 | return sd_bus_message_append( | |
748 | reply, "(ssssssouso)", | |
749 | u->id, | |
750 | unit_description(u), | |
751 | unit_load_state_to_string(u->load_state), | |
752 | unit_active_state_to_string(unit_active_state(u)), | |
753 | unit_sub_state_to_string(u), | |
754 | following ? following->id : "", | |
755 | unit_path, | |
756 | u->job ? u->job->id : 0, | |
757 | u->job ? job_type_to_string(u->job->type) : "", | |
758 | job_path ? job_path : "/"); | |
759 | } | |
760 | ||
761 | static int method_list_units_by_names(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
762 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
763 | Manager *m = userdata; | |
764 | int r; | |
765 | char **unit; | |
766 | _cleanup_strv_free_ char **units = NULL; | |
767 | ||
768 | assert(message); | |
769 | assert(m); | |
770 | ||
771 | r = sd_bus_message_read_strv(message, &units); | |
772 | if (r < 0) | |
773 | return r; | |
774 | ||
775 | r = sd_bus_message_new_method_return(message, &reply); | |
776 | if (r < 0) | |
777 | return r; | |
778 | ||
779 | r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)"); | |
780 | if (r < 0) | |
781 | return r; | |
782 | ||
783 | STRV_FOREACH(unit, units) { | |
784 | Unit *u; | |
785 | ||
786 | if (!unit_name_is_valid(*unit, UNIT_NAME_ANY)) | |
787 | continue; | |
788 | ||
96cc4453 | 789 | r = bus_load_unit_by_name(m, message, *unit, &u, error); |
6900c740 | 790 | if (r < 0) |
791 | return r; | |
792 | ||
793 | r = reply_unit_info(reply, u); | |
794 | if (r < 0) | |
795 | return r; | |
796 | } | |
797 | ||
798 | r = sd_bus_message_close_container(reply); | |
799 | if (r < 0) | |
800 | return r; | |
801 | ||
802 | return sd_bus_send(NULL, reply, NULL); | |
803 | } | |
804 | ||
291d565a LP |
805 | static int method_get_unit_processes(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
806 | Manager *m = userdata; | |
807 | const char *name; | |
808 | Unit *u; | |
809 | int r; | |
810 | ||
811 | assert(message); | |
812 | assert(m); | |
813 | ||
814 | r = sd_bus_message_read(message, "s", &name); | |
815 | if (r < 0) | |
816 | return r; | |
817 | ||
96cc4453 LP |
818 | r = bus_get_unit_by_name(m, message, name, &u, error); |
819 | if (r < 0) | |
820 | return r; | |
291d565a LP |
821 | |
822 | return bus_unit_method_get_processes(message, u, error); | |
823 | } | |
824 | ||
6592b975 LP |
825 | static int method_attach_processes_to_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
826 | Manager *m = userdata; | |
827 | const char *name; | |
828 | Unit *u; | |
829 | int r; | |
830 | ||
831 | assert(message); | |
832 | assert(m); | |
833 | ||
834 | r = sd_bus_message_read(message, "s", &name); | |
835 | if (r < 0) | |
836 | return r; | |
837 | ||
838 | r = bus_get_unit_by_name(m, message, name, &u, error); | |
839 | if (r < 0) | |
840 | return r; | |
841 | ||
842 | return bus_unit_method_attach_processes(message, u, error); | |
843 | } | |
844 | ||
ab31f6b8 WC |
845 | static int transient_unit_from_message( |
846 | Manager *m, | |
847 | sd_bus_message *message, | |
848 | const char *name, | |
849 | Unit **unit, | |
850 | sd_bus_error *error) { | |
851 | ||
06cc6afa | 852 | UnitType t; |
ab31f6b8 WC |
853 | Unit *u; |
854 | int r; | |
855 | ||
856 | assert(m); | |
857 | assert(message); | |
858 | assert(name); | |
859 | ||
06cc6afa LP |
860 | t = unit_name_to_type(name); |
861 | if (t < 0) | |
862 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit name or type."); | |
863 | ||
864 | if (!unit_vtable[t]->can_transient) | |
865 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit type %s does not support transient units.", unit_type_to_string(t)); | |
866 | ||
ab31f6b8 WC |
867 | r = manager_load_unit(m, name, NULL, error, &u); |
868 | if (r < 0) | |
869 | return r; | |
870 | ||
0f13f3bd | 871 | if (!unit_is_pristine(u)) |
ab31f6b8 WC |
872 | return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name); |
873 | ||
874 | /* OK, the unit failed to load and is unreferenced, now let's | |
875 | * fill in the transient data instead */ | |
876 | r = unit_make_transient(u); | |
877 | if (r < 0) | |
878 | return r; | |
879 | ||
880 | /* Set our properties */ | |
881 | r = bus_unit_set_properties(u, message, UNIT_RUNTIME, false, error); | |
882 | if (r < 0) | |
883 | return r; | |
884 | ||
05a98afd LP |
885 | /* If the client asked for it, automatically add a reference to this unit. */ |
886 | if (u->bus_track_add) { | |
887 | r = bus_unit_track_add_sender(u, message); | |
888 | if (r < 0) | |
889 | return log_error_errno(r, "Failed to watch sender: %m"); | |
890 | } | |
891 | ||
97329d20 | 892 | /* Now load the missing bits of the unit we just created */ |
4f952a3f | 893 | unit_add_to_load_queue(u); |
97329d20 LP |
894 | manager_dispatch_load_queue(m); |
895 | ||
ab31f6b8 WC |
896 | *unit = u; |
897 | ||
898 | return 0; | |
899 | } | |
900 | ||
901 | static int transient_aux_units_from_message( | |
902 | Manager *m, | |
903 | sd_bus_message *message, | |
904 | sd_bus_error *error) { | |
905 | ||
ab31f6b8 WC |
906 | int r; |
907 | ||
908 | assert(m); | |
909 | assert(message); | |
910 | ||
911 | r = sd_bus_message_enter_container(message, 'a', "(sa(sv))"); | |
912 | if (r < 0) | |
913 | return r; | |
914 | ||
915 | while ((r = sd_bus_message_enter_container(message, 'r', "sa(sv)")) > 0) { | |
97329d20 LP |
916 | const char *name = NULL; |
917 | Unit *u; | |
918 | ||
ab31f6b8 WC |
919 | r = sd_bus_message_read(message, "s", &name); |
920 | if (r < 0) | |
921 | return r; | |
922 | ||
923 | r = transient_unit_from_message(m, message, name, &u, error); | |
97329d20 | 924 | if (r < 0) |
ab31f6b8 WC |
925 | return r; |
926 | ||
ab31f6b8 WC |
927 | r = sd_bus_message_exit_container(message); |
928 | if (r < 0) | |
929 | return r; | |
930 | } | |
931 | if (r < 0) | |
932 | return r; | |
933 | ||
934 | r = sd_bus_message_exit_container(message); | |
935 | if (r < 0) | |
936 | return r; | |
937 | ||
938 | return 0; | |
939 | } | |
940 | ||
19070062 | 941 | static int method_start_transient_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
942 | const char *name, *smode; |
943 | Manager *m = userdata; | |
944 | JobMode mode; | |
718db961 LP |
945 | Unit *u; |
946 | int r; | |
ea430986 | 947 | |
718db961 LP |
948 | assert(message); |
949 | assert(m); | |
ea430986 | 950 | |
1d22e906 | 951 | r = mac_selinux_access_check(message, "start", error); |
283868e1 SW |
952 | if (r < 0) |
953 | return r; | |
283868e1 | 954 | |
718db961 LP |
955 | r = sd_bus_message_read(message, "ss", &name, &smode); |
956 | if (r < 0) | |
ebcf1f97 | 957 | return r; |
5632e374 | 958 | |
718db961 LP |
959 | mode = job_mode_from_string(smode); |
960 | if (mode < 0) | |
ebcf1f97 | 961 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s is invalid.", smode); |
5632e374 | 962 | |
1d22e906 | 963 | r = bus_verify_manage_units_async(m, message, error); |
718db961 | 964 | if (r < 0) |
ebcf1f97 | 965 | return r; |
1d22e906 LP |
966 | if (r == 0) |
967 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
5632e374 | 968 | |
ab31f6b8 | 969 | r = transient_unit_from_message(m, message, name, &u, error); |
ebcf1f97 LP |
970 | if (r < 0) |
971 | return r; | |
5632e374 | 972 | |
ab31f6b8 | 973 | r = transient_aux_units_from_message(m, message, error); |
718db961 | 974 | if (r < 0) |
ebcf1f97 | 975 | return r; |
ea430986 | 976 | |
718db961 | 977 | /* Finally, start it */ |
50cbaba4 | 978 | return bus_unit_queue_job(message, u, JOB_START, mode, 0, error); |
718db961 | 979 | } |
ea430986 | 980 | |
19070062 | 981 | static int method_get_job(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
982 | _cleanup_free_ char *path = NULL; |
983 | Manager *m = userdata; | |
984 | uint32_t id; | |
985 | Job *j; | |
986 | int r; | |
ea430986 | 987 | |
718db961 LP |
988 | assert(message); |
989 | assert(m); | |
ea430986 | 990 | |
283868e1 SW |
991 | /* Anyone can call this method */ |
992 | ||
718db961 LP |
993 | r = sd_bus_message_read(message, "u", &id); |
994 | if (r < 0) | |
ebcf1f97 | 995 | return r; |
ea430986 | 996 | |
718db961 LP |
997 | j = manager_get_job(m, id); |
998 | if (!j) | |
ebcf1f97 | 999 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); |
ea430986 | 1000 | |
8a188de9 | 1001 | r = mac_selinux_unit_access_check(j->unit, message, "status", error); |
ebcf1f97 LP |
1002 | if (r < 0) |
1003 | return r; | |
ea430986 | 1004 | |
718db961 LP |
1005 | path = job_dbus_path(j); |
1006 | if (!path) | |
ebcf1f97 | 1007 | return -ENOMEM; |
ea430986 | 1008 | |
df2d202e | 1009 | return sd_bus_reply_method_return(message, "o", path); |
718db961 | 1010 | } |
ea430986 | 1011 | |
19070062 | 1012 | static int method_cancel_job(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1013 | Manager *m = userdata; |
1014 | uint32_t id; | |
1015 | Job *j; | |
1016 | int r; | |
ea430986 | 1017 | |
718db961 LP |
1018 | assert(message); |
1019 | assert(m); | |
ea430986 | 1020 | |
718db961 LP |
1021 | r = sd_bus_message_read(message, "u", &id); |
1022 | if (r < 0) | |
ebcf1f97 | 1023 | return r; |
ea430986 | 1024 | |
718db961 LP |
1025 | j = manager_get_job(m, id); |
1026 | if (!j) | |
ebcf1f97 | 1027 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); |
ea430986 | 1028 | |
19070062 | 1029 | return bus_job_method_cancel(message, j, error); |
718db961 | 1030 | } |
c1e1601e | 1031 | |
19070062 | 1032 | static int method_clear_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1033 | Manager *m = userdata; |
ebcf1f97 | 1034 | int r; |
c1e1601e | 1035 | |
718db961 LP |
1036 | assert(message); |
1037 | assert(m); | |
c1e1601e | 1038 | |
1d22e906 | 1039 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1040 | if (r < 0) |
1041 | return r; | |
1042 | ||
1d22e906 LP |
1043 | r = bus_verify_manage_units_async(m, message, error); |
1044 | if (r < 0) | |
1045 | return r; | |
1046 | if (r == 0) | |
1047 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1048 | ||
718db961 | 1049 | manager_clear_jobs(m); |
c1e1601e | 1050 | |
df2d202e | 1051 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1052 | } |
c1e1601e | 1053 | |
19070062 | 1054 | static int method_reset_failed(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1055 | Manager *m = userdata; |
ebcf1f97 | 1056 | int r; |
cad45ba1 | 1057 | |
718db961 LP |
1058 | assert(message); |
1059 | assert(m); | |
1060 | ||
8a188de9 | 1061 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1062 | if (r < 0) |
1063 | return r; | |
1064 | ||
1d22e906 LP |
1065 | r = bus_verify_manage_units_async(m, message, error); |
1066 | if (r < 0) | |
1067 | return r; | |
1068 | if (r == 0) | |
1069 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1070 | ||
718db961 | 1071 | manager_reset_failed(m); |
c1e1601e | 1072 | |
df2d202e | 1073 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1074 | } |
c1e1601e | 1075 | |
313fe66f | 1076 | static int list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *error, char **states, char **patterns) { |
4afd3348 | 1077 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
718db961 LP |
1078 | Manager *m = userdata; |
1079 | const char *k; | |
1080 | Iterator i; | |
1081 | Unit *u; | |
1082 | int r; | |
c1e1601e | 1083 | |
718db961 LP |
1084 | assert(message); |
1085 | assert(m); | |
b152adec | 1086 | |
283868e1 SW |
1087 | /* Anyone can call this method */ |
1088 | ||
8a188de9 | 1089 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1090 | if (r < 0) |
1091 | return r; | |
cad45ba1 | 1092 | |
df2d202e | 1093 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1094 | if (r < 0) |
ebcf1f97 | 1095 | return r; |
b152adec | 1096 | |
718db961 LP |
1097 | r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)"); |
1098 | if (r < 0) | |
ebcf1f97 | 1099 | return r; |
b152adec | 1100 | |
718db961 | 1101 | HASHMAP_FOREACH_KEY(u, k, m->units, i) { |
718db961 LP |
1102 | if (k != u->id) |
1103 | continue; | |
b152adec | 1104 | |
cdc06ed7 DS |
1105 | if (!strv_isempty(states) && |
1106 | !strv_contains(states, unit_load_state_to_string(u->load_state)) && | |
1107 | !strv_contains(states, unit_active_state_to_string(unit_active_state(u))) && | |
1108 | !strv_contains(states, unit_sub_state_to_string(u))) | |
1109 | continue; | |
1110 | ||
313fe66f | 1111 | if (!strv_isempty(patterns) && |
1112 | !strv_fnmatch_or_empty(patterns, u->id, FNM_NOESCAPE)) | |
1113 | continue; | |
1114 | ||
6900c740 | 1115 | r = reply_unit_info(reply, u); |
718db961 | 1116 | if (r < 0) |
ebcf1f97 | 1117 | return r; |
718db961 | 1118 | } |
4139c1b2 | 1119 | |
718db961 LP |
1120 | r = sd_bus_message_close_container(reply); |
1121 | if (r < 0) | |
ebcf1f97 | 1122 | return r; |
cad45ba1 | 1123 | |
9030ca46 | 1124 | return sd_bus_send(NULL, reply, NULL); |
718db961 | 1125 | } |
4139c1b2 | 1126 | |
19070062 | 1127 | static int method_list_units(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
313fe66f | 1128 | return list_units_filtered(message, userdata, error, NULL, NULL); |
cdc06ed7 DS |
1129 | } |
1130 | ||
19070062 | 1131 | static int method_list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
cdc06ed7 DS |
1132 | _cleanup_strv_free_ char **states = NULL; |
1133 | int r; | |
1134 | ||
1135 | r = sd_bus_message_read_strv(message, &states); | |
1136 | if (r < 0) | |
1137 | return r; | |
1138 | ||
313fe66f | 1139 | return list_units_filtered(message, userdata, error, states, NULL); |
1140 | } | |
1141 | ||
1142 | static int method_list_units_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1143 | _cleanup_strv_free_ char **states = NULL; | |
1144 | _cleanup_strv_free_ char **patterns = NULL; | |
1145 | int r; | |
1146 | ||
1147 | r = sd_bus_message_read_strv(message, &states); | |
1148 | if (r < 0) | |
1149 | return r; | |
1150 | ||
1151 | r = sd_bus_message_read_strv(message, &patterns); | |
1152 | if (r < 0) | |
1153 | return r; | |
1154 | ||
1155 | return list_units_filtered(message, userdata, error, states, patterns); | |
cdc06ed7 DS |
1156 | } |
1157 | ||
19070062 | 1158 | static int method_list_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
4afd3348 | 1159 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
718db961 LP |
1160 | Manager *m = userdata; |
1161 | Iterator i; | |
1162 | Job *j; | |
1163 | int r; | |
4139c1b2 | 1164 | |
718db961 LP |
1165 | assert(message); |
1166 | assert(m); | |
1167 | ||
283868e1 SW |
1168 | /* Anyone can call this method */ |
1169 | ||
8a188de9 | 1170 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1171 | if (r < 0) |
1172 | return r; | |
718db961 | 1173 | |
df2d202e | 1174 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1175 | if (r < 0) |
ebcf1f97 | 1176 | return r; |
718db961 LP |
1177 | |
1178 | r = sd_bus_message_open_container(reply, 'a', "(usssoo)"); | |
1179 | if (r < 0) | |
ebcf1f97 | 1180 | return r; |
718db961 LP |
1181 | |
1182 | HASHMAP_FOREACH(j, m->jobs, i) { | |
1183 | _cleanup_free_ char *unit_path = NULL, *job_path = NULL; | |
1184 | ||
1185 | job_path = job_dbus_path(j); | |
1186 | if (!job_path) | |
ebcf1f97 | 1187 | return -ENOMEM; |
718db961 LP |
1188 | |
1189 | unit_path = unit_dbus_path(j->unit); | |
1190 | if (!unit_path) | |
ebcf1f97 | 1191 | return -ENOMEM; |
718db961 LP |
1192 | |
1193 | r = sd_bus_message_append( | |
1194 | reply, "(usssoo)", | |
1195 | j->id, | |
1302759d | 1196 | j->unit->id, |
718db961 | 1197 | job_type_to_string(j->type), |
1302759d | 1198 | job_state_to_string(j->state), |
718db961 LP |
1199 | job_path, |
1200 | unit_path); | |
cad45ba1 | 1201 | if (r < 0) |
ebcf1f97 | 1202 | return r; |
718db961 | 1203 | } |
5dd9014f | 1204 | |
718db961 LP |
1205 | r = sd_bus_message_close_container(reply); |
1206 | if (r < 0) | |
ebcf1f97 | 1207 | return r; |
5dd9014f | 1208 | |
9030ca46 | 1209 | return sd_bus_send(NULL, reply, NULL); |
718db961 | 1210 | } |
5dd9014f | 1211 | |
19070062 | 1212 | static int method_subscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1213 | Manager *m = userdata; |
1214 | int r; | |
5dd9014f | 1215 | |
718db961 LP |
1216 | assert(message); |
1217 | assert(m); | |
ea430986 | 1218 | |
283868e1 SW |
1219 | /* Anyone can call this method */ |
1220 | ||
8a188de9 | 1221 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1222 | if (r < 0) |
1223 | return r; | |
cad45ba1 | 1224 | |
19070062 | 1225 | if (sd_bus_message_get_bus(message) == m->api_bus) { |
8f8f05a9 LP |
1226 | |
1227 | /* Note that direct bus connection subscribe by | |
1228 | * default, we only track peers on the API bus here */ | |
1229 | ||
1230 | if (!m->subscribed) { | |
19070062 | 1231 | r = sd_bus_track_new(sd_bus_message_get_bus(message), &m->subscribed, NULL, NULL); |
8f8f05a9 LP |
1232 | if (r < 0) |
1233 | return r; | |
1234 | } | |
1235 | ||
1236 | r = sd_bus_track_add_sender(m->subscribed, message); | |
1237 | if (r < 0) | |
1238 | return r; | |
1239 | if (r == 0) | |
1240 | return sd_bus_error_setf(error, BUS_ERROR_ALREADY_SUBSCRIBED, "Client is already subscribed."); | |
1241 | } | |
ea430986 | 1242 | |
df2d202e | 1243 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1244 | } |
ea430986 | 1245 | |
19070062 | 1246 | static int method_unsubscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1247 | Manager *m = userdata; |
1248 | int r; | |
ea430986 | 1249 | |
718db961 LP |
1250 | assert(message); |
1251 | assert(m); | |
ea430986 | 1252 | |
283868e1 SW |
1253 | /* Anyone can call this method */ |
1254 | ||
8a188de9 | 1255 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1256 | if (r < 0) |
1257 | return r; | |
ea430986 | 1258 | |
19070062 | 1259 | if (sd_bus_message_get_bus(message) == m->api_bus) { |
8f8f05a9 LP |
1260 | r = sd_bus_track_remove_sender(m->subscribed, message); |
1261 | if (r < 0) | |
1262 | return r; | |
1263 | if (r == 0) | |
1264 | return sd_bus_error_setf(error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed."); | |
1265 | } | |
ea430986 | 1266 | |
df2d202e | 1267 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1268 | } |
ea430986 | 1269 | |
c0a1bfac | 1270 | static int dump_impl(sd_bus_message *message, void *userdata, sd_bus_error *error, int (*reply)(sd_bus_message *, char *)) { |
718db961 | 1271 | _cleanup_free_ char *dump = NULL; |
718db961 | 1272 | Manager *m = userdata; |
ebcf1f97 | 1273 | int r; |
ea430986 | 1274 | |
718db961 LP |
1275 | assert(message); |
1276 | assert(m); | |
ea430986 | 1277 | |
283868e1 SW |
1278 | /* Anyone can call this method */ |
1279 | ||
8a188de9 | 1280 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1281 | if (r < 0) |
1282 | return r; | |
ea430986 | 1283 | |
713f6f90 | 1284 | r = manager_get_dump_string(m, &dump); |
dacd6cee LP |
1285 | if (r < 0) |
1286 | return r; | |
a16e1123 | 1287 | |
c0a1bfac DT |
1288 | return reply(message, dump); |
1289 | } | |
1290 | ||
1291 | static int reply_dump(sd_bus_message *message, char *dump) { | |
df2d202e | 1292 | return sd_bus_reply_method_return(message, "s", dump); |
718db961 | 1293 | } |
cad45ba1 | 1294 | |
c0a1bfac DT |
1295 | static int method_dump(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1296 | return dump_impl(message, userdata, error, reply_dump); | |
1297 | } | |
1298 | ||
1299 | static int reply_dump_by_fd(sd_bus_message *message, char *dump) { | |
1300 | _cleanup_close_ int fd = -1; | |
1301 | ||
1302 | fd = acquire_data_fd(dump, strlen(dump), 0); | |
1303 | if (fd < 0) | |
1304 | return fd; | |
1305 | ||
1306 | return sd_bus_reply_method_return(message, "h", fd); | |
1307 | } | |
1308 | ||
1309 | static int method_dump_by_fd(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1310 | return dump_impl(message, userdata, error, reply_dump_by_fd); | |
1311 | } | |
1312 | ||
36b4a7ba ZJS |
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."); | |
718db961 | 1315 | } |
cad45ba1 | 1316 | |
ae57dad3 LP |
1317 | static int verify_run_space(const char *message, sd_bus_error *error) { |
1318 | struct statvfs svfs; | |
1319 | uint64_t available; | |
1320 | ||
1321 | if (statvfs("/run/systemd", &svfs) < 0) | |
1322 | return sd_bus_error_set_errnof(error, errno, "Failed to statvfs(/run/systemd): %m"); | |
1323 | ||
1324 | available = (uint64_t) svfs.f_bfree * (uint64_t) svfs.f_bsize; | |
1325 | ||
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.", | |
1332 | message, | |
1333 | format_bytes(fb_available, sizeof(fb_available), available), | |
1334 | format_bytes(fb_need, sizeof(fb_need), RELOAD_DISK_SPACE_MIN)); | |
1335 | } | |
1336 | ||
1337 | return 0; | |
1338 | } | |
1339 | ||
1340 | int verify_run_space_and_log(const char *message) { | |
4dae8ae6 | 1341 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
ae57dad3 LP |
1342 | int r; |
1343 | ||
1344 | r = verify_run_space(message, &error); | |
1345 | if (r < 0) | |
4ae25393 | 1346 | return log_error_errno(r, "%s", bus_error_message(&error, r)); |
ae57dad3 | 1347 | |
4ae25393 | 1348 | return 0; |
ae57dad3 LP |
1349 | } |
1350 | ||
19070062 | 1351 | static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1352 | Manager *m = userdata; |
1353 | int r; | |
6652a2b9 | 1354 | |
718db961 LP |
1355 | assert(message); |
1356 | assert(m); | |
6652a2b9 | 1357 | |
ae57dad3 LP |
1358 | r = verify_run_space("Refusing to reload", error); |
1359 | if (r < 0) | |
1360 | return r; | |
1361 | ||
1d22e906 | 1362 | r = mac_selinux_access_check(message, "reload", error); |
283868e1 SW |
1363 | if (r < 0) |
1364 | return r; | |
283868e1 | 1365 | |
1d22e906 | 1366 | r = bus_verify_reload_daemon_async(m, message, error); |
ebcf1f97 LP |
1367 | if (r < 0) |
1368 | return r; | |
1d22e906 LP |
1369 | if (r == 0) |
1370 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
6652a2b9 | 1371 | |
718db961 LP |
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 | |
1375 | * finished. */ | |
6652a2b9 | 1376 | |
209de525 LP |
1377 | assert(!m->pending_reload_message); |
1378 | r = sd_bus_message_new_method_return(message, &m->pending_reload_message); | |
718db961 | 1379 | if (r < 0) |
ebcf1f97 | 1380 | return r; |
cad45ba1 | 1381 | |
af41e508 | 1382 | m->objective = MANAGER_RELOAD; |
6652a2b9 | 1383 | |
718db961 LP |
1384 | return 1; |
1385 | } | |
6652a2b9 | 1386 | |
19070062 | 1387 | static int method_reexecute(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1388 | Manager *m = userdata; |
ebcf1f97 | 1389 | int r; |
6652a2b9 | 1390 | |
718db961 LP |
1391 | assert(message); |
1392 | assert(m); | |
6652a2b9 | 1393 | |
ae57dad3 LP |
1394 | r = verify_run_space("Refusing to reexecute", error); |
1395 | if (r < 0) | |
1396 | return r; | |
1397 | ||
1d22e906 | 1398 | r = mac_selinux_access_check(message, "reload", error); |
283868e1 SW |
1399 | if (r < 0) |
1400 | return r; | |
283868e1 | 1401 | |
1d22e906 | 1402 | r = bus_verify_reload_daemon_async(m, message, error); |
ebcf1f97 LP |
1403 | if (r < 0) |
1404 | return r; | |
1d22e906 LP |
1405 | if (r == 0) |
1406 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
cad45ba1 | 1407 | |
718db961 LP |
1408 | /* We don't send a reply back here, the client should |
1409 | * just wait for us disconnecting. */ | |
6652a2b9 | 1410 | |
af41e508 | 1411 | m->objective = MANAGER_REEXECUTE; |
718db961 LP |
1412 | return 1; |
1413 | } | |
6652a2b9 | 1414 | |
19070062 | 1415 | static int method_exit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1416 | Manager *m = userdata; |
ebcf1f97 | 1417 | int r; |
6652a2b9 | 1418 | |
718db961 LP |
1419 | assert(message); |
1420 | assert(m); | |
6652a2b9 | 1421 | |
8a188de9 | 1422 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1423 | if (r < 0) |
1424 | return r; | |
cad45ba1 | 1425 | |
287419c1 AC |
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 | |
1429 | * container. */ | |
6652a2b9 | 1430 | |
af41e508 | 1431 | m->objective = MANAGER_EXIT; |
6652a2b9 | 1432 | |
df2d202e | 1433 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1434 | } |
6652a2b9 | 1435 | |
19070062 | 1436 | static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1437 | Manager *m = userdata; |
ebcf1f97 | 1438 | int r; |
664f88a7 | 1439 | |
718db961 LP |
1440 | assert(message); |
1441 | assert(m); | |
cad45ba1 | 1442 | |
8a188de9 | 1443 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1444 | if (r < 0) |
1445 | return r; | |
664f88a7 | 1446 | |
463d0d15 | 1447 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1448 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers."); |
664f88a7 | 1449 | |
af41e508 | 1450 | m->objective = MANAGER_REBOOT; |
664f88a7 | 1451 | |
df2d202e | 1452 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1453 | } |
664f88a7 | 1454 | |
19070062 | 1455 | static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1456 | Manager *m = userdata; |
ebcf1f97 | 1457 | int r; |
50913bc0 | 1458 | |
718db961 LP |
1459 | assert(message); |
1460 | assert(m); | |
1137a57c | 1461 | |
8a188de9 | 1462 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1463 | if (r < 0) |
1464 | return r; | |
1137a57c | 1465 | |
463d0d15 | 1466 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1467 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers."); |
1137a57c | 1468 | |
af41e508 | 1469 | m->objective = MANAGER_POWEROFF; |
1137a57c | 1470 | |
df2d202e | 1471 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1472 | } |
1137a57c | 1473 | |
19070062 | 1474 | static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1475 | Manager *m = userdata; |
ebcf1f97 | 1476 | int r; |
1137a57c | 1477 | |
718db961 LP |
1478 | assert(message); |
1479 | assert(m); | |
8d0e38a2 | 1480 | |
8a188de9 | 1481 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1482 | if (r < 0) |
1483 | return r; | |
cad45ba1 | 1484 | |
463d0d15 | 1485 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1486 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Halt is only supported for system managers."); |
8d0e38a2 | 1487 | |
af41e508 | 1488 | m->objective = MANAGER_HALT; |
8d0e38a2 | 1489 | |
df2d202e | 1490 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1491 | } |
8d0e38a2 | 1492 | |
19070062 | 1493 | static int method_kexec(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1494 | Manager *m = userdata; |
ebcf1f97 | 1495 | int r; |
8d0e38a2 | 1496 | |
718db961 LP |
1497 | assert(message); |
1498 | assert(m); | |
c0576cd6 | 1499 | |
8a188de9 | 1500 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1501 | if (r < 0) |
1502 | return r; | |
cad45ba1 | 1503 | |
463d0d15 | 1504 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1505 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers."); |
c0576cd6 | 1506 | |
af41e508 | 1507 | m->objective = MANAGER_KEXEC; |
c0576cd6 | 1508 | |
df2d202e | 1509 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1510 | } |
c0576cd6 | 1511 | |
19070062 | 1512 | static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1513 | char *ri = NULL, *rt = NULL; |
1514 | const char *root, *init; | |
1515 | Manager *m = userdata; | |
ae57dad3 LP |
1516 | struct statvfs svfs; |
1517 | uint64_t available; | |
718db961 | 1518 | int r; |
c0576cd6 | 1519 | |
718db961 LP |
1520 | assert(message); |
1521 | assert(m); | |
c0576cd6 | 1522 | |
ae57dad3 LP |
1523 | if (statvfs("/run/systemd", &svfs) < 0) |
1524 | return sd_bus_error_set_errnof(error, errno, "Failed to statvfs(/run/systemd): %m"); | |
1525 | ||
1526 | available = (uint64_t) svfs.f_bfree * (uint64_t) svfs.f_bsize; | |
1527 | ||
1528 | if (available < RELOAD_DISK_SPACE_MIN) { | |
1529 | char fb_available[FORMAT_BYTES_MAX], fb_need[FORMAT_BYTES_MAX]; | |
3fe91079 | 1530 | log_warning("Dangerously low amount of free space on /run/systemd, root switching operation might not complete successfully. " |
ae57dad3 LP |
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)); | |
1534 | } | |
1535 | ||
8a188de9 | 1536 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1537 | if (r < 0) |
1538 | return r; | |
c0576cd6 | 1539 | |
463d0d15 | 1540 | if (!MANAGER_IS_SYSTEM(m)) |
6ad3b2b6 | 1541 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Root switching is only supported by system manager."); |
c0576cd6 | 1542 | |
718db961 LP |
1543 | r = sd_bus_message_read(message, "ss", &root, &init); |
1544 | if (r < 0) | |
ebcf1f97 | 1545 | return r; |
c0576cd6 | 1546 | |
710028b4 LP |
1547 | if (isempty(root)) |
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."); | |
c0576cd6 | 1553 | |
718db961 LP |
1554 | /* Safety check */ |
1555 | if (isempty(init)) { | |
710028b4 LP |
1556 | r = path_is_os_tree(root); |
1557 | if (r < 0) | |
1558 | return sd_bus_error_set_errnof(error, r, "Failed to determine whether root path '%s' contains an OS tree: %m", root); | |
1559 | if (r == 0) | |
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); | |
718db961 | 1561 | } else { |
710028b4 | 1562 | _cleanup_free_ char *chased = NULL; |
c0576cd6 | 1563 | |
718db961 | 1564 | if (!path_is_absolute(init)) |
710028b4 | 1565 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path to init binary '%s' not absolute.", init); |
c0576cd6 | 1566 | |
62570f6f | 1567 | r = chase_symlinks(init, root, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &chased); |
710028b4 LP |
1568 | if (r < 0) |
1569 | return sd_bus_error_set_errnof(error, r, "Could not resolve init executable %s: %m", init); | |
1570 | ||
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); | |
c0576cd6 | 1574 | |
710028b4 LP |
1575 | return sd_bus_error_set_errnof(error, r, "Could not check whether init binary %s is executable: %m", init); |
1576 | } | |
718db961 LP |
1577 | } |
1578 | ||
1579 | rt = strdup(root); | |
1580 | if (!rt) | |
ebcf1f97 | 1581 | return -ENOMEM; |
718db961 LP |
1582 | |
1583 | if (!isempty(init)) { | |
1584 | ri = strdup(init); | |
1585 | if (!ri) { | |
92b315df | 1586 | free(rt); |
ebcf1f97 | 1587 | return -ENOMEM; |
c0576cd6 | 1588 | } |
718db961 | 1589 | } |
c0576cd6 | 1590 | |
718db961 LP |
1591 | free(m->switch_root); |
1592 | m->switch_root = rt; | |
c0576cd6 | 1593 | |
718db961 LP |
1594 | free(m->switch_root_init); |
1595 | m->switch_root_init = ri; | |
c0576cd6 | 1596 | |
af41e508 | 1597 | m->objective = MANAGER_SWITCH_ROOT; |
92b315df | 1598 | |
df2d202e | 1599 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1600 | } |
c0576cd6 | 1601 | |
19070062 | 1602 | static int method_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1603 | _cleanup_strv_free_ char **plus = NULL; |
1604 | Manager *m = userdata; | |
1605 | int r; | |
c0576cd6 | 1606 | |
718db961 LP |
1607 | assert(message); |
1608 | assert(m); | |
cad45ba1 | 1609 | |
8a188de9 | 1610 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1611 | if (r < 0) |
1612 | return r; | |
c0576cd6 | 1613 | |
718db961 LP |
1614 | r = sd_bus_message_read_strv(message, &plus); |
1615 | if (r < 0) | |
ebcf1f97 | 1616 | return r; |
718db961 | 1617 | if (!strv_env_is_valid(plus)) |
ebcf1f97 | 1618 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments"); |
c0576cd6 | 1619 | |
1d22e906 LP |
1620 | r = bus_verify_set_environment_async(m, message, error); |
1621 | if (r < 0) | |
1622 | return r; | |
1623 | if (r == 0) | |
1624 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1625 | ||
1ad6e8b3 | 1626 | r = manager_client_environment_modify(m, NULL, plus); |
718db961 | 1627 | if (r < 0) |
ebcf1f97 | 1628 | return r; |
c0576cd6 | 1629 | |
df2d202e | 1630 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1631 | } |
1632 | ||
19070062 | 1633 | static int method_unset_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1634 | _cleanup_strv_free_ char **minus = NULL; |
1635 | Manager *m = userdata; | |
1636 | int r; | |
1637 | ||
718db961 LP |
1638 | assert(message); |
1639 | assert(m); | |
1640 | ||
8a188de9 | 1641 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1642 | if (r < 0) |
1643 | return r; | |
c0576cd6 | 1644 | |
718db961 LP |
1645 | r = sd_bus_message_read_strv(message, &minus); |
1646 | if (r < 0) | |
ebcf1f97 | 1647 | return r; |
718db961 LP |
1648 | |
1649 | if (!strv_env_name_or_assignment_is_valid(minus)) | |
ebcf1f97 | 1650 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments"); |
718db961 | 1651 | |
1d22e906 LP |
1652 | r = bus_verify_set_environment_async(m, message, error); |
1653 | if (r < 0) | |
1654 | return r; | |
1655 | if (r == 0) | |
1656 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1657 | ||
1ad6e8b3 | 1658 | r = manager_client_environment_modify(m, minus, NULL); |
718db961 | 1659 | if (r < 0) |
ebcf1f97 | 1660 | return r; |
718db961 | 1661 | |
df2d202e | 1662 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1663 | } |
1664 | ||
19070062 | 1665 | static int method_unset_and_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1666 | _cleanup_strv_free_ char **minus = NULL, **plus = NULL; |
1667 | Manager *m = userdata; | |
1668 | int r; | |
1669 | ||
718db961 LP |
1670 | assert(message); |
1671 | assert(m); | |
1672 | ||
8a188de9 | 1673 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1674 | if (r < 0) |
1675 | return r; | |
718db961 | 1676 | |
eb6c7d20 | 1677 | r = sd_bus_message_read_strv(message, &minus); |
718db961 | 1678 | if (r < 0) |
ebcf1f97 | 1679 | return r; |
718db961 | 1680 | |
eb6c7d20 | 1681 | r = sd_bus_message_read_strv(message, &plus); |
718db961 | 1682 | if (r < 0) |
ebcf1f97 | 1683 | return r; |
718db961 | 1684 | |
718db961 | 1685 | if (!strv_env_name_or_assignment_is_valid(minus)) |
ebcf1f97 | 1686 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments"); |
eb6c7d20 ZJS |
1687 | if (!strv_env_is_valid(plus)) |
1688 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments"); | |
718db961 | 1689 | |
1d22e906 LP |
1690 | r = bus_verify_set_environment_async(m, message, error); |
1691 | if (r < 0) | |
1692 | return r; | |
1693 | if (r == 0) | |
1694 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1695 | ||
1ad6e8b3 | 1696 | r = manager_client_environment_modify(m, minus, plus); |
718db961 | 1697 | if (r < 0) |
ebcf1f97 | 1698 | return r; |
718db961 | 1699 | |
df2d202e | 1700 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1701 | } |
1702 | ||
287419c1 | 1703 | static int method_set_exit_code(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
287419c1 | 1704 | Manager *m = userdata; |
29206d46 | 1705 | uint8_t code; |
287419c1 AC |
1706 | int r; |
1707 | ||
1708 | assert(message); | |
1709 | assert(m); | |
1710 | ||
1711 | r = mac_selinux_access_check(message, "exit", error); | |
1712 | if (r < 0) | |
1713 | return r; | |
1714 | ||
1715 | r = sd_bus_message_read_basic(message, 'y', &code); | |
1716 | if (r < 0) | |
1717 | return r; | |
1718 | ||
463d0d15 | 1719 | if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0) |
287419c1 AC |
1720 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "ExitCode can only be set for user service managers or in containers."); |
1721 | ||
1722 | m->return_value = code; | |
1723 | ||
1724 | return sd_bus_reply_method_return(message, NULL); | |
1725 | } | |
1726 | ||
29206d46 LP |
1727 | static int method_lookup_dynamic_user_by_name(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1728 | Manager *m = userdata; | |
1729 | const char *name; | |
1730 | uid_t uid; | |
1731 | int r; | |
1732 | ||
1733 | assert(message); | |
1734 | assert(m); | |
1735 | ||
1736 | r = sd_bus_message_read_basic(message, 's', &name); | |
1737 | if (r < 0) | |
1738 | return r; | |
1739 | ||
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); | |
1744 | ||
1745 | r = dynamic_user_lookup_name(m, name, &uid); | |
1746 | if (r == -ESRCH) | |
1747 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, "Dynamic user %s does not exist.", name); | |
1748 | if (r < 0) | |
1749 | return r; | |
1750 | ||
1751 | return sd_bus_reply_method_return(message, "u", (uint32_t) uid); | |
1752 | } | |
1753 | ||
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; | |
1757 | uid_t uid; | |
1758 | int r; | |
1759 | ||
1760 | assert(message); | |
1761 | assert(m); | |
1762 | ||
1763 | assert_cc(sizeof(uid) == sizeof(uint32_t)); | |
1764 | r = sd_bus_message_read_basic(message, 'u', &uid); | |
1765 | if (r < 0) | |
1766 | return r; | |
1767 | ||
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); | |
1772 | ||
1773 | r = dynamic_user_lookup_uid(m, uid, &name); | |
1774 | if (r == -ESRCH) | |
1775 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, "Dynamic user ID " UID_FMT " does not exist.", uid); | |
1776 | if (r < 0) | |
1777 | return r; | |
1778 | ||
1779 | return sd_bus_reply_method_return(message, "s", name); | |
1780 | } | |
1781 | ||
f9bfa696 YW |
1782 | static int method_get_dynamic_users(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1783 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
1784 | Manager *m = userdata; | |
1785 | DynamicUser *d; | |
1786 | Iterator i; | |
1787 | int r; | |
1788 | ||
1789 | assert(message); | |
1790 | assert(m); | |
1791 | ||
1792 | assert_cc(sizeof(uid_t) == sizeof(uint32_t)); | |
1793 | ||
1794 | if (!MANAGER_IS_SYSTEM(m)) | |
1795 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Dynamic users are only supported in the system instance."); | |
1796 | ||
1797 | r = sd_bus_message_new_method_return(message, &reply); | |
1798 | if (r < 0) | |
1799 | return r; | |
1800 | ||
1801 | r = sd_bus_message_open_container(reply, 'a', "(us)"); | |
1802 | if (r < 0) | |
1803 | return r; | |
1804 | ||
1805 | HASHMAP_FOREACH(d, m->dynamic_users, i) { | |
1806 | uid_t uid; | |
1807 | ||
1808 | r = dynamic_user_current(d, &uid); | |
1809 | if (r == -EAGAIN) /* not realized yet? */ | |
1810 | continue; | |
1811 | if (r < 0) | |
1812 | return sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "Failed to lookup a dynamic user."); | |
1813 | ||
1814 | r = sd_bus_message_append(reply, "(us)", uid, d->name); | |
1815 | if (r < 0) | |
1816 | return r; | |
1817 | } | |
1818 | ||
1819 | r = sd_bus_message_close_container(reply); | |
1820 | if (r < 0) | |
1821 | return r; | |
1822 | ||
1823 | return sd_bus_send(NULL, reply, NULL); | |
1824 | } | |
1825 | ||
313fe66f | 1826 | static int list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error, char **states, char **patterns) { |
4afd3348 | 1827 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
718db961 LP |
1828 | Manager *m = userdata; |
1829 | UnitFileList *item; | |
1830 | Hashmap *h; | |
1831 | Iterator i; | |
1832 | int r; | |
1833 | ||
718db961 LP |
1834 | assert(message); |
1835 | assert(m); | |
1836 | ||
283868e1 SW |
1837 | /* Anyone can call this method */ |
1838 | ||
8a188de9 | 1839 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1840 | if (r < 0) |
1841 | return r; | |
718db961 | 1842 | |
df2d202e | 1843 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1844 | if (r < 0) |
ebcf1f97 | 1845 | return r; |
c0576cd6 | 1846 | |
d5099efc | 1847 | h = hashmap_new(&string_hash_ops); |
718db961 | 1848 | if (!h) |
ebcf1f97 | 1849 | return -ENOMEM; |
c0576cd6 | 1850 | |
313fe66f | 1851 | r = unit_file_get_list(m->unit_file_scope, NULL, h, states, patterns); |
ebcf1f97 | 1852 | if (r < 0) |
718db961 | 1853 | goto fail; |
718db961 LP |
1854 | |
1855 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); | |
ebcf1f97 | 1856 | if (r < 0) |
718db961 | 1857 | goto fail; |
718db961 LP |
1858 | |
1859 | HASHMAP_FOREACH(item, h, i) { | |
1860 | ||
1861 | r = sd_bus_message_append(reply, "(ss)", item->path, unit_file_state_to_string(item->state)); | |
ebcf1f97 | 1862 | if (r < 0) |
718db961 | 1863 | goto fail; |
718db961 | 1864 | } |
c0576cd6 | 1865 | |
718db961 | 1866 | unit_file_list_free(h); |
c0576cd6 | 1867 | |
718db961 LP |
1868 | r = sd_bus_message_close_container(reply); |
1869 | if (r < 0) | |
ebcf1f97 | 1870 | return r; |
8d0e38a2 | 1871 | |
9030ca46 | 1872 | return sd_bus_send(NULL, reply, NULL); |
99504dd4 | 1873 | |
718db961 LP |
1874 | fail: |
1875 | unit_file_list_free(h); | |
1876 | return r; | |
1877 | } | |
99504dd4 | 1878 | |
313fe66f | 1879 | static int method_list_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1880 | return list_unit_files_by_patterns(message, userdata, error, NULL, NULL); | |
1881 | } | |
1882 | ||
1883 | static int method_list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1884 | _cleanup_strv_free_ char **states = NULL; | |
1885 | _cleanup_strv_free_ char **patterns = NULL; | |
1886 | int r; | |
1887 | ||
1888 | r = sd_bus_message_read_strv(message, &states); | |
1889 | if (r < 0) | |
1890 | return r; | |
1891 | ||
1892 | r = sd_bus_message_read_strv(message, &patterns); | |
1893 | if (r < 0) | |
1894 | return r; | |
1895 | ||
1896 | return list_unit_files_by_patterns(message, userdata, error, states, patterns); | |
1897 | } | |
1898 | ||
19070062 | 1899 | static int method_get_unit_file_state(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1900 | Manager *m = userdata; |
1901 | const char *name; | |
1902 | UnitFileState state; | |
718db961 | 1903 | int r; |
99504dd4 | 1904 | |
718db961 LP |
1905 | assert(message); |
1906 | assert(m); | |
8e2af478 | 1907 | |
283868e1 SW |
1908 | /* Anyone can call this method */ |
1909 | ||
8a188de9 | 1910 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1911 | if (r < 0) |
1912 | return r; | |
8e2af478 | 1913 | |
718db961 LP |
1914 | r = sd_bus_message_read(message, "s", &name); |
1915 | if (r < 0) | |
ebcf1f97 | 1916 | return r; |
8e2af478 | 1917 | |
463d0d15 | 1918 | r = unit_file_get_state(m->unit_file_scope, NULL, name, &state); |
0ec0deaa LP |
1919 | if (r < 0) |
1920 | return r; | |
8e2af478 | 1921 | |
df2d202e | 1922 | return sd_bus_reply_method_return(message, "s", unit_file_state_to_string(state)); |
718db961 | 1923 | } |
8e2af478 | 1924 | |
19070062 | 1925 | static int method_get_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1926 | _cleanup_free_ char *default_target = NULL; |
1927 | Manager *m = userdata; | |
718db961 | 1928 | int r; |
c2756a68 | 1929 | |
718db961 LP |
1930 | assert(message); |
1931 | assert(m); | |
c2756a68 | 1932 | |
283868e1 SW |
1933 | /* Anyone can call this method */ |
1934 | ||
8a188de9 | 1935 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1936 | if (r < 0) |
1937 | return r; | |
c2756a68 | 1938 | |
463d0d15 | 1939 | r = unit_file_get_default(m->unit_file_scope, NULL, &default_target); |
718db961 | 1940 | if (r < 0) |
ebcf1f97 | 1941 | return r; |
c2756a68 | 1942 | |
df2d202e | 1943 | return sd_bus_reply_method_return(message, "s", default_target); |
718db961 | 1944 | } |
c2756a68 | 1945 | |
8f8f05a9 | 1946 | static int send_unit_files_changed(sd_bus *bus, void *userdata) { |
4afd3348 | 1947 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
1948 | int r; |
1949 | ||
1950 | assert(bus); | |
1951 | ||
151b9b96 | 1952 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged"); |
718db961 LP |
1953 | if (r < 0) |
1954 | return r; | |
1955 | ||
8f8f05a9 | 1956 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
1957 | } |
1958 | ||
af3d8113 ZJS |
1959 | /* Create an error reply, using the error information from changes[] |
1960 | * if possible, and fall back to generating an error from error code c. | |
1961 | * The error message only describes the first error. | |
1962 | * | |
1963 | * Coordinate with unit_file_dump_changes() in install.c. | |
1964 | */ | |
1965 | static int install_error( | |
1966 | sd_bus_error *error, | |
1967 | int c, | |
1968 | UnitFileChange *changes, | |
da6053d0 LP |
1969 | size_t n_changes) { |
1970 | ||
1971 | size_t i; | |
af3d8113 | 1972 | int r; |
8e20adca | 1973 | |
af3d8113 | 1974 | for (i = 0; i < n_changes; i++) |
637d6e5b | 1975 | |
af3d8113 | 1976 | switch(changes[i].type) { |
637d6e5b | 1977 | |
af3d8113 ZJS |
1978 | case 0 ... INT_MAX: |
1979 | continue; | |
637d6e5b | 1980 | |
af3d8113 ZJS |
1981 | case -EEXIST: |
1982 | if (changes[i].source) | |
1983 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, | |
1984 | "File %s already exists and is a symlink to %s.", | |
1985 | changes[i].path, changes[i].source); | |
1986 | else | |
1987 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, | |
1988 | "File %s already exists.", | |
1989 | changes[i].path); | |
1990 | goto found; | |
637d6e5b | 1991 | |
af3d8113 ZJS |
1992 | case -ERFKILL: |
1993 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, | |
1994 | "Unit file %s is masked.", changes[i].path); | |
1995 | goto found; | |
637d6e5b | 1996 | |
af3d8113 ZJS |
1997 | case -EADDRNOTAVAIL: |
1998 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_GENERATED, | |
1999 | "Unit %s is transient or generated.", changes[i].path); | |
2000 | goto found; | |
637d6e5b | 2001 | |
af3d8113 ZJS |
2002 | case -ELOOP: |
2003 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_LINKED, | |
2004 | "Refusing to operate on linked unit file %s", changes[i].path); | |
2005 | goto found; | |
637d6e5b LP |
2006 | |
2007 | case -ENOENT: | |
2008 | r = sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit file %s does not exist.", changes[i].path); | |
2009 | goto found; | |
2010 | ||
af3d8113 ZJS |
2011 | default: |
2012 | r = sd_bus_error_set_errnof(error, changes[i].type, "File %s: %m", changes[i].path); | |
2013 | goto found; | |
2014 | } | |
8e20adca | 2015 | |
637d6e5b LP |
2016 | r = c < 0 ? c : -EINVAL; |
2017 | ||
af3d8113 ZJS |
2018 | found: |
2019 | unit_file_changes_free(changes, n_changes); | |
2020 | return r; | |
8e20adca LP |
2021 | } |
2022 | ||
637d6e5b LP |
2023 | static int reply_unit_file_changes_and_free( |
2024 | Manager *m, | |
2025 | sd_bus_message *message, | |
2026 | int carries_install_info, | |
2027 | UnitFileChange *changes, | |
da6053d0 | 2028 | size_t n_changes, |
637d6e5b LP |
2029 | sd_bus_error *error) { |
2030 | ||
2031 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
2032 | bool bad = false, good = false; | |
da6053d0 | 2033 | size_t i; |
637d6e5b LP |
2034 | int r; |
2035 | ||
2036 | if (unit_file_changes_have_modification(changes, n_changes)) { | |
2037 | r = bus_foreach_bus(m, NULL, send_unit_files_changed, NULL); | |
2038 | if (r < 0) | |
2039 | log_debug_errno(r, "Failed to send UnitFilesChanged signal: %m"); | |
2040 | } | |
2041 | ||
2042 | r = sd_bus_message_new_method_return(message, &reply); | |
2043 | if (r < 0) | |
2044 | goto fail; | |
2045 | ||
2046 | if (carries_install_info >= 0) { | |
2047 | r = sd_bus_message_append(reply, "b", carries_install_info); | |
2048 | if (r < 0) | |
2049 | goto fail; | |
2050 | } | |
2051 | ||
2052 | r = sd_bus_message_open_container(reply, 'a', "(sss)"); | |
2053 | if (r < 0) | |
2054 | goto fail; | |
2055 | ||
2056 | for (i = 0; i < n_changes; i++) { | |
2057 | ||
2058 | if (changes[i].type < 0) { | |
2059 | bad = true; | |
2060 | continue; | |
2061 | } | |
2062 | ||
2063 | r = sd_bus_message_append( | |
2064 | reply, "(sss)", | |
2065 | unit_file_change_type_to_string(changes[i].type), | |
2066 | changes[i].path, | |
2067 | changes[i].source); | |
2068 | if (r < 0) | |
2069 | goto fail; | |
2070 | ||
2071 | good = true; | |
2072 | } | |
2073 | ||
2074 | /* If there was a failed change, and no successful change, then return the first failure as proper method call | |
2075 | * error. */ | |
2076 | if (bad && !good) | |
2077 | return install_error(error, 0, changes, n_changes); | |
2078 | ||
2079 | r = sd_bus_message_close_container(reply); | |
2080 | if (r < 0) | |
2081 | goto fail; | |
2082 | ||
2083 | unit_file_changes_free(changes, n_changes); | |
2084 | return sd_bus_send(NULL, reply, NULL); | |
2085 | ||
2086 | fail: | |
2087 | unit_file_changes_free(changes, n_changes); | |
2088 | return r; | |
2089 | } | |
2090 | ||
718db961 | 2091 | static int method_enable_unit_files_generic( |
718db961 | 2092 | sd_bus_message *message, |
d309c1c3 | 2093 | Manager *m, |
da6053d0 | 2094 | int (*call)(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, size_t *n_changes), |
ebcf1f97 LP |
2095 | bool carries_install_info, |
2096 | sd_bus_error *error) { | |
718db961 LP |
2097 | |
2098 | _cleanup_strv_free_ char **l = NULL; | |
2099 | UnitFileChange *changes = NULL; | |
da6053d0 | 2100 | size_t n_changes = 0; |
b3796dd8 | 2101 | UnitFileFlags flags; |
718db961 LP |
2102 | int runtime, force, r; |
2103 | ||
718db961 LP |
2104 | assert(message); |
2105 | assert(m); | |
cad45ba1 | 2106 | |
718db961 LP |
2107 | r = sd_bus_message_read_strv(message, &l); |
2108 | if (r < 0) | |
ebcf1f97 | 2109 | return r; |
90bb85e1 | 2110 | |
d309c1c3 LP |
2111 | r = sd_bus_message_read(message, "bb", &runtime, &force); |
2112 | if (r < 0) | |
2113 | return r; | |
2114 | ||
b3796dd8 JS |
2115 | flags = unit_file_bools_to_flags(runtime, force); |
2116 | ||
1d22e906 LP |
2117 | r = bus_verify_manage_unit_files_async(m, message, error); |
2118 | if (r < 0) | |
2119 | return r; | |
2120 | if (r == 0) | |
2121 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2122 | ||
b3796dd8 | 2123 | r = call(m->unit_file_scope, flags, NULL, l, &changes, &n_changes); |
af3d8113 ZJS |
2124 | if (r < 0) |
2125 | return install_error(error, r, changes, n_changes); | |
718db961 | 2126 | |
637d6e5b | 2127 | return reply_unit_file_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes, error); |
718db961 | 2128 | } |
c87eba54 | 2129 | |
19070062 | 2130 | static int method_enable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2131 | return method_enable_unit_files_generic(message, userdata, unit_file_enable, true, error); |
718db961 | 2132 | } |
ea430986 | 2133 | |
19070062 | 2134 | static int method_reenable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2135 | return method_enable_unit_files_generic(message, userdata, unit_file_reenable, true, error); |
718db961 LP |
2136 | } |
2137 | ||
19070062 | 2138 | static int method_link_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2139 | return method_enable_unit_files_generic(message, userdata, unit_file_link, false, error); |
718db961 LP |
2140 | } |
2141 | ||
da6053d0 | 2142 | static int unit_file_preset_without_mode(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char **files, UnitFileChange **changes, size_t *n_changes) { |
b3796dd8 | 2143 | return unit_file_preset(scope, flags, root_dir, files, UNIT_FILE_PRESET_FULL, changes, n_changes); |
d309c1c3 LP |
2144 | } |
2145 | ||
19070062 | 2146 | static int method_preset_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2147 | return method_enable_unit_files_generic(message, userdata, unit_file_preset_without_mode, true, error); |
718db961 LP |
2148 | } |
2149 | ||
19070062 | 2150 | static int method_mask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2151 | return method_enable_unit_files_generic(message, userdata, unit_file_mask, false, error); |
718db961 | 2152 | } |
ea430986 | 2153 | |
19070062 | 2154 | static int method_preset_unit_files_with_mode(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
d309c1c3 LP |
2155 | |
2156 | _cleanup_strv_free_ char **l = NULL; | |
d309c1c3 | 2157 | UnitFileChange *changes = NULL; |
da6053d0 | 2158 | size_t n_changes = 0; |
d309c1c3 LP |
2159 | Manager *m = userdata; |
2160 | UnitFilePresetMode mm; | |
d309c1c3 | 2161 | int runtime, force, r; |
b3796dd8 | 2162 | UnitFileFlags flags; |
d309c1c3 LP |
2163 | const char *mode; |
2164 | ||
d309c1c3 LP |
2165 | assert(message); |
2166 | assert(m); | |
2167 | ||
2168 | r = sd_bus_message_read_strv(message, &l); | |
2169 | if (r < 0) | |
2170 | return r; | |
2171 | ||
2172 | r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force); | |
2173 | if (r < 0) | |
2174 | return r; | |
2175 | ||
b3796dd8 JS |
2176 | flags = unit_file_bools_to_flags(runtime, force); |
2177 | ||
d309c1c3 LP |
2178 | if (isempty(mode)) |
2179 | mm = UNIT_FILE_PRESET_FULL; | |
2180 | else { | |
2181 | mm = unit_file_preset_mode_from_string(mode); | |
2182 | if (mm < 0) | |
2183 | return -EINVAL; | |
2184 | } | |
2185 | ||
1d22e906 LP |
2186 | r = bus_verify_manage_unit_files_async(m, message, error); |
2187 | if (r < 0) | |
2188 | return r; | |
2189 | if (r == 0) | |
2190 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2191 | ||
b3796dd8 | 2192 | r = unit_file_preset(m->unit_file_scope, flags, NULL, l, mm, &changes, &n_changes); |
af3d8113 ZJS |
2193 | if (r < 0) |
2194 | return install_error(error, r, changes, n_changes); | |
d309c1c3 | 2195 | |
637d6e5b | 2196 | return reply_unit_file_changes_and_free(m, message, r, changes, n_changes, error); |
d309c1c3 LP |
2197 | } |
2198 | ||
718db961 | 2199 | static int method_disable_unit_files_generic( |
718db961 | 2200 | sd_bus_message *message, |
596fc263 | 2201 | Manager *m, |
da6053d0 | 2202 | int (*call)(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, size_t *n_changes), |
ebcf1f97 | 2203 | sd_bus_error *error) { |
718db961 LP |
2204 | |
2205 | _cleanup_strv_free_ char **l = NULL; | |
2206 | UnitFileChange *changes = NULL; | |
da6053d0 | 2207 | size_t n_changes = 0; |
718db961 LP |
2208 | int r, runtime; |
2209 | ||
718db961 LP |
2210 | assert(message); |
2211 | assert(m); | |
2212 | ||
df823e23 | 2213 | r = sd_bus_message_read_strv(message, &l); |
ebcf1f97 LP |
2214 | if (r < 0) |
2215 | return r; | |
718db961 | 2216 | |
df823e23 | 2217 | r = sd_bus_message_read(message, "b", &runtime); |
718db961 | 2218 | if (r < 0) |
ebcf1f97 | 2219 | return r; |
718db961 | 2220 | |
1d22e906 LP |
2221 | r = bus_verify_manage_unit_files_async(m, message, error); |
2222 | if (r < 0) | |
2223 | return r; | |
2224 | if (r == 0) | |
2225 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2226 | ||
b3796dd8 | 2227 | r = call(m->unit_file_scope, runtime ? UNIT_FILE_RUNTIME : 0, NULL, l, &changes, &n_changes); |
af3d8113 ZJS |
2228 | if (r < 0) |
2229 | return install_error(error, r, changes, n_changes); | |
718db961 | 2230 | |
637d6e5b | 2231 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
718db961 | 2232 | } |
ea430986 | 2233 | |
19070062 | 2234 | static int method_disable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2235 | return method_disable_unit_files_generic(message, userdata, unit_file_disable, error); |
ea430986 LP |
2236 | } |
2237 | ||
19070062 | 2238 | static int method_unmask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2239 | return method_disable_unit_files_generic(message, userdata, unit_file_unmask, error); |
718db961 LP |
2240 | } |
2241 | ||
344ca755 LP |
2242 | static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2243 | _cleanup_strv_free_ char **l = NULL; | |
2244 | UnitFileChange *changes = NULL; | |
da6053d0 | 2245 | size_t n_changes = 0; |
344ca755 LP |
2246 | Manager *m = userdata; |
2247 | int r; | |
2248 | ||
2249 | assert(message); | |
2250 | assert(m); | |
2251 | ||
2252 | r = sd_bus_message_read_strv(message, &l); | |
2253 | if (r < 0) | |
2254 | return r; | |
2255 | ||
2256 | r = bus_verify_manage_unit_files_async(m, message, error); | |
2257 | if (r < 0) | |
2258 | return r; | |
2259 | if (r == 0) | |
2260 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2261 | ||
2262 | r = unit_file_revert(m->unit_file_scope, NULL, l, &changes, &n_changes); | |
af3d8113 ZJS |
2263 | if (r < 0) |
2264 | return install_error(error, r, changes, n_changes); | |
344ca755 | 2265 | |
637d6e5b | 2266 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
344ca755 LP |
2267 | } |
2268 | ||
19070062 | 2269 | static int method_set_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 2270 | UnitFileChange *changes = NULL; |
da6053d0 | 2271 | size_t n_changes = 0; |
718db961 | 2272 | Manager *m = userdata; |
718db961 LP |
2273 | const char *name; |
2274 | int force, r; | |
2275 | ||
718db961 LP |
2276 | assert(message); |
2277 | assert(m); | |
2278 | ||
1d22e906 | 2279 | r = mac_selinux_access_check(message, "enable", error); |
283868e1 SW |
2280 | if (r < 0) |
2281 | return r; | |
283868e1 | 2282 | |
1d22e906 | 2283 | r = sd_bus_message_read(message, "sb", &name, &force); |
ebcf1f97 LP |
2284 | if (r < 0) |
2285 | return r; | |
718db961 | 2286 | |
1d22e906 | 2287 | r = bus_verify_manage_unit_files_async(m, message, error); |
718db961 | 2288 | if (r < 0) |
ebcf1f97 | 2289 | return r; |
1d22e906 LP |
2290 | if (r == 0) |
2291 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
718db961 | 2292 | |
b3796dd8 | 2293 | r = unit_file_set_default(m->unit_file_scope, force ? UNIT_FILE_FORCE : 0, NULL, name, &changes, &n_changes); |
af3d8113 ZJS |
2294 | if (r < 0) |
2295 | return install_error(error, r, changes, n_changes); | |
718db961 | 2296 | |
637d6e5b | 2297 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
718db961 LP |
2298 | } |
2299 | ||
19070062 | 2300 | static int method_preset_all_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
d309c1c3 | 2301 | UnitFileChange *changes = NULL; |
da6053d0 | 2302 | size_t n_changes = 0; |
d309c1c3 LP |
2303 | Manager *m = userdata; |
2304 | UnitFilePresetMode mm; | |
d309c1c3 | 2305 | const char *mode; |
b3796dd8 | 2306 | UnitFileFlags flags; |
d309c1c3 LP |
2307 | int force, runtime, r; |
2308 | ||
d309c1c3 LP |
2309 | assert(message); |
2310 | assert(m); | |
2311 | ||
8a188de9 | 2312 | r = mac_selinux_access_check(message, "enable", error); |
d309c1c3 LP |
2313 | if (r < 0) |
2314 | return r; | |
2315 | ||
2316 | r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force); | |
2317 | if (r < 0) | |
2318 | return r; | |
2319 | ||
b3796dd8 JS |
2320 | flags = unit_file_bools_to_flags(runtime, force); |
2321 | ||
d309c1c3 LP |
2322 | if (isempty(mode)) |
2323 | mm = UNIT_FILE_PRESET_FULL; | |
2324 | else { | |
2325 | mm = unit_file_preset_mode_from_string(mode); | |
2326 | if (mm < 0) | |
2327 | return -EINVAL; | |
2328 | } | |
2329 | ||
1d22e906 LP |
2330 | r = bus_verify_manage_unit_files_async(m, message, error); |
2331 | if (r < 0) | |
2332 | return r; | |
2333 | if (r == 0) | |
2334 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2335 | ||
b3796dd8 | 2336 | r = unit_file_preset_all(m->unit_file_scope, flags, NULL, mm, &changes, &n_changes); |
af3d8113 ZJS |
2337 | if (r < 0) |
2338 | return install_error(error, r, changes, n_changes); | |
d309c1c3 | 2339 | |
637d6e5b | 2340 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
d309c1c3 LP |
2341 | } |
2342 | ||
19070062 | 2343 | static int method_add_dependency_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
e94937df LN |
2344 | _cleanup_strv_free_ char **l = NULL; |
2345 | Manager *m = userdata; | |
2346 | UnitFileChange *changes = NULL; | |
da6053d0 | 2347 | size_t n_changes = 0; |
e94937df | 2348 | int runtime, force, r; |
596fc263 | 2349 | char *target, *type; |
e94937df | 2350 | UnitDependency dep; |
b3796dd8 | 2351 | UnitFileFlags flags; |
e94937df | 2352 | |
e94937df LN |
2353 | assert(message); |
2354 | assert(m); | |
2355 | ||
2356 | r = bus_verify_manage_unit_files_async(m, message, error); | |
2357 | if (r < 0) | |
2358 | return r; | |
2359 | if (r == 0) | |
2360 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2361 | ||
2362 | r = sd_bus_message_read_strv(message, &l); | |
2363 | if (r < 0) | |
2364 | return r; | |
2365 | ||
2366 | r = sd_bus_message_read(message, "ssbb", &target, &type, &runtime, &force); | |
2367 | if (r < 0) | |
2368 | return r; | |
2369 | ||
b3796dd8 JS |
2370 | flags = unit_file_bools_to_flags(runtime, force); |
2371 | ||
e94937df LN |
2372 | dep = unit_dependency_from_string(type); |
2373 | if (dep < 0) | |
2374 | return -EINVAL; | |
2375 | ||
b3796dd8 | 2376 | r = unit_file_add_dependency(m->unit_file_scope, flags, NULL, l, target, dep, &changes, &n_changes); |
af3d8113 ZJS |
2377 | if (r < 0) |
2378 | return install_error(error, r, changes, n_changes); | |
e94937df | 2379 | |
637d6e5b | 2380 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
e94937df LN |
2381 | } |
2382 | ||
3b3557c4 JS |
2383 | static int method_get_unit_file_links(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2384 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
2385 | UnitFileChange *changes = NULL; | |
da6053d0 | 2386 | size_t n_changes = 0, i; |
3b3557c4 JS |
2387 | UnitFileFlags flags; |
2388 | const char *name; | |
2389 | char **p; | |
2390 | int runtime, r; | |
2391 | ||
2392 | r = sd_bus_message_read(message, "sb", &name, &runtime); | |
2393 | if (r < 0) | |
2394 | return r; | |
2395 | ||
2396 | r = sd_bus_message_new_method_return(message, &reply); | |
2397 | if (r < 0) | |
2398 | return r; | |
2399 | ||
2400 | r = sd_bus_message_open_container(reply, SD_BUS_TYPE_ARRAY, "s"); | |
2401 | if (r < 0) | |
2402 | return r; | |
2403 | ||
2404 | p = STRV_MAKE(name); | |
2405 | flags = UNIT_FILE_DRY_RUN | | |
2406 | (runtime ? UNIT_FILE_RUNTIME : 0); | |
2407 | ||
2408 | r = unit_file_disable(UNIT_FILE_SYSTEM, flags, NULL, p, &changes, &n_changes); | |
2409 | if (r < 0) | |
2410 | return log_error_errno(r, "Failed to get file links for %s: %m", name); | |
2411 | ||
2412 | for (i = 0; i < n_changes; i++) | |
2413 | if (changes[i].type == UNIT_FILE_UNLINK) { | |
2414 | r = sd_bus_message_append(reply, "s", changes[i].path); | |
2415 | if (r < 0) | |
2416 | return r; | |
2417 | } | |
2418 | ||
2419 | r = sd_bus_message_close_container(reply); | |
2420 | if (r < 0) | |
2421 | return r; | |
2422 | ||
2423 | return sd_bus_send(NULL, reply, NULL); | |
2424 | } | |
2425 | ||
15ea79f8 LP |
2426 | static int method_get_job_waiting(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2427 | Manager *m = userdata; | |
2428 | uint32_t id; | |
2429 | Job *j; | |
2430 | int r; | |
2431 | ||
2432 | assert(message); | |
2433 | assert(m); | |
2434 | ||
2435 | r = sd_bus_message_read(message, "u", &id); | |
2436 | if (r < 0) | |
2437 | return r; | |
2438 | ||
2439 | j = manager_get_job(m, id); | |
2440 | if (!j) | |
2441 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); | |
2442 | ||
2443 | return bus_job_method_get_waiting_jobs(message, j, error); | |
2444 | } | |
2445 | ||
c20076a8 LP |
2446 | static int method_abandon_scope(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2447 | Manager *m = userdata; | |
2448 | const char *name; | |
2449 | Unit *u; | |
2450 | int r; | |
2451 | ||
2452 | assert(message); | |
2453 | assert(m); | |
2454 | ||
2455 | r = sd_bus_message_read(message, "s", &name); | |
2456 | if (r < 0) | |
2457 | return r; | |
2458 | ||
2459 | r = bus_get_unit_by_name(m, message, name, &u, error); | |
2460 | if (r < 0) | |
2461 | return r; | |
2462 | ||
2463 | if (u->type != UNIT_SCOPE) | |
2464 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit '%s' is not a scope unit, refusing.", name); | |
2465 | ||
2466 | return bus_scope_method_abandon(message, u, error); | |
2467 | } | |
2468 | ||
718db961 LP |
2469 | const sd_bus_vtable bus_manager_vtable[] = { |
2470 | SD_BUS_VTABLE_START(0), | |
2471 | ||
556089dc LP |
2472 | SD_BUS_PROPERTY("Version", "s", property_get_version, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
2473 | SD_BUS_PROPERTY("Features", "s", property_get_features, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
2474 | SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
7452394e | 2475 | SD_BUS_PROPERTY("Architecture", "s", property_get_architecture, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 2476 | SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
9f9f0342 LP |
2477 | BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FIRMWARE]), SD_BUS_VTABLE_PROPERTY_CONST), |
2478 | BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_LOADER]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2479 | BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_KERNEL]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2480 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2481 | BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_USERSPACE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2482 | BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2483 | BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2484 | BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2485 | BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2486 | BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2487 | BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2488 | BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
665a9774 YW |
2489 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDSecurityStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_SECURITY_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
2490 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDSecurityFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_SECURITY_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2491 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_GENERATORS_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2492 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_GENERATORS_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2493 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2494 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
718db961 LP |
2495 | SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level, property_set_log_level, 0, 0), |
2496 | SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target, property_set_log_target, 0, 0), | |
3ff52e8f YW |
2497 | SD_BUS_PROPERTY("NNames", "u", property_get_hashmap_size, offsetof(Manager, units), 0), |
2498 | SD_BUS_PROPERTY("NFailedUnits", "u", property_get_set_size, offsetof(Manager, failed_units), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
2499 | SD_BUS_PROPERTY("NJobs", "u", property_get_hashmap_size, offsetof(Manager, jobs), 0), | |
718db961 LP |
2500 | SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_installed_jobs), 0), |
2501 | SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_failed_jobs), 0), | |
2502 | SD_BUS_PROPERTY("Progress", "d", property_get_progress, 0, 0), | |
1ad6e8b3 | 2503 | SD_BUS_PROPERTY("Environment", "as", property_get_environment, 0, 0), |
556089dc | 2504 | SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool, offsetof(Manager, confirm_spawn), SD_BUS_VTABLE_PROPERTY_CONST), |
52d2566a | 2505 | SD_BUS_PROPERTY("ShowStatus", "b", property_get_show_status, 0, 0), |
a3c4eb07 | 2506 | SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.search_path), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
2507 | SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST), |
2508 | SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST), | |
4c3f1641 LP |
2509 | SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec, property_set_runtime_watchdog, offsetof(Manager, runtime_watchdog), 0), |
2510 | SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec, bus_property_set_usec, offsetof(Manager, shutdown_watchdog), 0), | |
2a12e32e | 2511 | SD_BUS_WRITABLE_PROPERTY("ServiceWatchdogs", "b", bus_property_get_bool, bus_property_set_bool, offsetof(Manager, service_watchdogs), 0), |
b272b74d | 2512 | SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Manager, cgroup_root), 0), |
f755e3b7 | 2513 | SD_BUS_PROPERTY("SystemState", "s", property_get_system_state, 0, 0), |
287419c1 | 2514 | SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned, offsetof(Manager, return_value), 0), |
670a3efe EV |
2515 | SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec, offsetof(Manager, default_timer_accuracy_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
2516 | SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec, offsetof(Manager, default_timeout_start_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
2517 | SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec, offsetof(Manager, default_timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
2518 | SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec, offsetof(Manager, default_restart_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
c075f5fc YW |
2519 | SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST), |
2520 | /* The following two items are obsolete alias */ | |
2521 | SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
2522 | SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
670a3efe EV |
2523 | SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned, offsetof(Manager, default_start_limit_burst), SD_BUS_VTABLE_PROPERTY_CONST), |
2524 | SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool, offsetof(Manager, default_cpu_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2525 | SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool, offsetof(Manager, default_blockio_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2526 | SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, default_memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2527 | SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool, offsetof(Manager, default_tasks_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
97eb4231 | 2528 | SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2529 | SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2530 | SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2531 | SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2532 | SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2533 | SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2534 | SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2535 | SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2536 | SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2537 | SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2538 | SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2539 | SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2540 | SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2541 | SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2542 | SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2543 | SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2544 | SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2545 | SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2546 | SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2547 | SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2548 | SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2549 | SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2550 | SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2551 | SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2552 | SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2553 | SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2554 | SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2555 | SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2556 | SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2557 | SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2558 | SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2559 | SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
0af20ea2 | 2560 | SD_BUS_PROPERTY("DefaultTasksMax", "t", NULL, offsetof(Manager, default_tasks_max), SD_BUS_VTABLE_PROPERTY_CONST), |
eed67a30 | 2561 | SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
718db961 | 2562 | |
adacb957 LP |
2563 | SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
2564 | SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid, SD_BUS_VTABLE_UNPRIVILEGED), | |
4b58153d | 2565 | SD_BUS_METHOD("GetUnitByInvocationID", "ay", "o", method_get_unit_by_invocation_id, SD_BUS_VTABLE_UNPRIVILEGED), |
267dd427 | 2566 | SD_BUS_METHOD("GetUnitByControlGroup", "s", "o", method_get_unit_by_control_group, SD_BUS_VTABLE_UNPRIVILEGED), |
adacb957 | 2567 | SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
283868e1 SW |
2568 | SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
2569 | SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace, SD_BUS_VTABLE_UNPRIVILEGED), | |
2570 | SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2571 | SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2572 | SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2573 | SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2574 | SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2575 | SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
50cbaba4 | 2576 | SD_BUS_METHOD("EnqueueUnitJob", "sss", "uososa(uosos)", method_enqueue_unit_job, SD_BUS_VTABLE_UNPRIVILEGED), |
283868e1 SW |
2577 | SD_BUS_METHOD("KillUnit", "ssi", NULL, method_kill_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
2578 | SD_BUS_METHOD("ResetFailedUnit", "s", NULL, method_reset_failed_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2579 | SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL, method_set_unit_properties, SD_BUS_VTABLE_UNPRIVILEGED), | |
05a98afd LP |
2580 | SD_BUS_METHOD("RefUnit", "s", NULL, method_ref_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
2581 | SD_BUS_METHOD("UnrefUnit", "s", NULL, method_unref_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
283868e1 | 2582 | SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
291d565a | 2583 | SD_BUS_METHOD("GetUnitProcesses", "s", "a(sus)", method_get_unit_processes, SD_BUS_VTABLE_UNPRIVILEGED), |
6592b975 | 2584 | SD_BUS_METHOD("AttachProcessesToUnit", "ssau", NULL, method_attach_processes_to_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
c20076a8 | 2585 | SD_BUS_METHOD("AbandonScope", "s", NULL, method_abandon_scope, SD_BUS_VTABLE_UNPRIVILEGED), |
adacb957 | 2586 | SD_BUS_METHOD("GetJob", "u", "o", method_get_job, SD_BUS_VTABLE_UNPRIVILEGED), |
15ea79f8 LP |
2587 | SD_BUS_METHOD("GetJobAfter", "u", "a(usssoo)", method_get_job_waiting, SD_BUS_VTABLE_UNPRIVILEGED), |
2588 | SD_BUS_METHOD("GetJobBefore", "u", "a(usssoo)", method_get_job_waiting, SD_BUS_VTABLE_UNPRIVILEGED), | |
283868e1 | 2589 | SD_BUS_METHOD("CancelJob", "u", NULL, method_cancel_job, SD_BUS_VTABLE_UNPRIVILEGED), |
1d22e906 LP |
2590 | SD_BUS_METHOD("ClearJobs", NULL, NULL, method_clear_jobs, SD_BUS_VTABLE_UNPRIVILEGED), |
2591 | SD_BUS_METHOD("ResetFailed", NULL, NULL, method_reset_failed, SD_BUS_VTABLE_UNPRIVILEGED), | |
adacb957 | 2592 | SD_BUS_METHOD("ListUnits", NULL, "a(ssssssouso)", method_list_units, SD_BUS_VTABLE_UNPRIVILEGED), |
cdc06ed7 | 2593 | SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered, SD_BUS_VTABLE_UNPRIVILEGED), |
313fe66f | 2594 | SD_BUS_METHOD("ListUnitsByPatterns", "asas", "a(ssssssouso)", method_list_units_by_patterns, SD_BUS_VTABLE_UNPRIVILEGED), |
6900c740 | 2595 | SD_BUS_METHOD("ListUnitsByNames", "as", "a(ssssssouso)", method_list_units_by_names, SD_BUS_VTABLE_UNPRIVILEGED), |
adacb957 LP |
2596 | SD_BUS_METHOD("ListJobs", NULL, "a(usssoo)", method_list_jobs, SD_BUS_VTABLE_UNPRIVILEGED), |
2597 | SD_BUS_METHOD("Subscribe", NULL, NULL, method_subscribe, SD_BUS_VTABLE_UNPRIVILEGED), | |
2598 | SD_BUS_METHOD("Unsubscribe", NULL, NULL, method_unsubscribe, SD_BUS_VTABLE_UNPRIVILEGED), | |
2599 | SD_BUS_METHOD("Dump", NULL, "s", method_dump, SD_BUS_VTABLE_UNPRIVILEGED), | |
c0a1bfac | 2600 | SD_BUS_METHOD("DumpByFileDescriptor", NULL, "h", method_dump_by_fd, SD_BUS_VTABLE_UNPRIVILEGED), |
04b56d9d LP |
2601 | SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_refuse_snapshot, SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), |
2602 | SD_BUS_METHOD("RemoveSnapshot", "s", NULL, method_refuse_snapshot, SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), | |
283868e1 SW |
2603 | SD_BUS_METHOD("Reload", NULL, NULL, method_reload, SD_BUS_VTABLE_UNPRIVILEGED), |
2604 | SD_BUS_METHOD("Reexecute", NULL, NULL, method_reexecute, SD_BUS_VTABLE_UNPRIVILEGED), | |
718db961 | 2605 | SD_BUS_METHOD("Exit", NULL, NULL, method_exit, 0), |
adacb957 LP |
2606 | SD_BUS_METHOD("Reboot", NULL, NULL, method_reboot, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), |
2607 | SD_BUS_METHOD("PowerOff", NULL, NULL, method_poweroff, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2608 | SD_BUS_METHOD("Halt", NULL, NULL, method_halt, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2609 | SD_BUS_METHOD("KExec", NULL, NULL, method_kexec, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2610 | SD_BUS_METHOD("SwitchRoot", "ss", NULL, method_switch_root, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
1d22e906 LP |
2611 | SD_BUS_METHOD("SetEnvironment", "as", NULL, method_set_environment, SD_BUS_VTABLE_UNPRIVILEGED), |
2612 | SD_BUS_METHOD("UnsetEnvironment", "as", NULL, method_unset_environment, SD_BUS_VTABLE_UNPRIVILEGED), | |
2613 | SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL, method_unset_and_set_environment, SD_BUS_VTABLE_UNPRIVILEGED), | |
adacb957 | 2614 | SD_BUS_METHOD("ListUnitFiles", NULL, "a(ss)", method_list_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), |
313fe66f | 2615 | SD_BUS_METHOD("ListUnitFilesByPatterns", "asas", "a(ss)", method_list_unit_files_by_patterns, SD_BUS_VTABLE_UNPRIVILEGED), |
adacb957 | 2616 | SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state, SD_BUS_VTABLE_UNPRIVILEGED), |
283868e1 SW |
2617 | SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), |
2618 | SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), | |
2619 | SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), | |
2620 | SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), | |
2621 | SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), | |
2622 | SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode, SD_BUS_VTABLE_UNPRIVILEGED), | |
2623 | SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), | |
2624 | SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), | |
344ca755 | 2625 | SD_BUS_METHOD("RevertUnitFiles", "as", "a(sss)", method_revert_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), |
283868e1 | 2626 | SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target, SD_BUS_VTABLE_UNPRIVILEGED), |
adacb957 | 2627 | SD_BUS_METHOD("GetDefaultTarget", NULL, "s", method_get_default_target, SD_BUS_VTABLE_UNPRIVILEGED), |
283868e1 | 2628 | SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), |
e94937df | 2629 | SD_BUS_METHOD("AddDependencyUnitFiles", "asssbb", "a(sss)", method_add_dependency_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), |
3b3557c4 | 2630 | SD_BUS_METHOD("GetUnitFileLinks", "sb", "as", method_get_unit_file_links, SD_BUS_VTABLE_UNPRIVILEGED), |
287419c1 | 2631 | SD_BUS_METHOD("SetExitCode", "y", NULL, method_set_exit_code, SD_BUS_VTABLE_UNPRIVILEGED), |
29206d46 LP |
2632 | SD_BUS_METHOD("LookupDynamicUserByName", "s", "u", method_lookup_dynamic_user_by_name, SD_BUS_VTABLE_UNPRIVILEGED), |
2633 | SD_BUS_METHOD("LookupDynamicUserByUID", "u", "s", method_lookup_dynamic_user_by_uid, SD_BUS_VTABLE_UNPRIVILEGED), | |
f9bfa696 | 2634 | SD_BUS_METHOD("GetDynamicUsers", NULL, "a(us)", method_get_dynamic_users, SD_BUS_VTABLE_UNPRIVILEGED), |
718db961 LP |
2635 | |
2636 | SD_BUS_SIGNAL("UnitNew", "so", 0), | |
2637 | SD_BUS_SIGNAL("UnitRemoved", "so", 0), | |
2638 | SD_BUS_SIGNAL("JobNew", "uos", 0), | |
2639 | SD_BUS_SIGNAL("JobRemoved", "uoss", 0), | |
2640 | SD_BUS_SIGNAL("StartupFinished", "tttttt", 0), | |
2641 | SD_BUS_SIGNAL("UnitFilesChanged", NULL, 0), | |
2642 | SD_BUS_SIGNAL("Reloading", "b", 0), | |
2643 | ||
2644 | SD_BUS_VTABLE_END | |
ea430986 | 2645 | }; |
718db961 | 2646 | |
8f8f05a9 | 2647 | static int send_finished(sd_bus *bus, void *userdata) { |
4afd3348 | 2648 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
2649 | usec_t *times = userdata; |
2650 | int r; | |
2651 | ||
2652 | assert(bus); | |
2653 | assert(times); | |
2654 | ||
151b9b96 | 2655 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished"); |
718db961 LP |
2656 | if (r < 0) |
2657 | return r; | |
2658 | ||
2659 | r = sd_bus_message_append(message, "tttttt", times[0], times[1], times[2], times[3], times[4], times[5]); | |
2660 | if (r < 0) | |
2661 | return r; | |
2662 | ||
8f8f05a9 | 2663 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
2664 | } |
2665 | ||
39abcaee | 2666 | void bus_manager_send_finished( |
718db961 LP |
2667 | Manager *m, |
2668 | usec_t firmware_usec, | |
2669 | usec_t loader_usec, | |
2670 | usec_t kernel_usec, | |
2671 | usec_t initrd_usec, | |
2672 | usec_t userspace_usec, | |
2673 | usec_t total_usec) { | |
2674 | ||
39abcaee LP |
2675 | int r; |
2676 | ||
718db961 LP |
2677 | assert(m); |
2678 | ||
8f8f05a9 LP |
2679 | r = bus_foreach_bus( |
2680 | m, | |
2681 | NULL, | |
2682 | send_finished, | |
2683 | (usec_t[6]) { | |
2684 | firmware_usec, | |
2685 | loader_usec, | |
2686 | kernel_usec, | |
2687 | initrd_usec, | |
2688 | userspace_usec, | |
2689 | total_usec | |
2690 | }); | |
39abcaee | 2691 | if (r < 0) |
da927ba9 | 2692 | log_debug_errno(r, "Failed to send finished signal: %m"); |
718db961 LP |
2693 | } |
2694 | ||
8f8f05a9 | 2695 | static int send_reloading(sd_bus *bus, void *userdata) { |
4afd3348 | 2696 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
2697 | int r; |
2698 | ||
2699 | assert(bus); | |
2700 | ||
151b9b96 | 2701 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading"); |
718db961 LP |
2702 | if (r < 0) |
2703 | return r; | |
2704 | ||
2705 | r = sd_bus_message_append(message, "b", PTR_TO_INT(userdata)); | |
2706 | if (r < 0) | |
2707 | return r; | |
2708 | ||
8f8f05a9 | 2709 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
2710 | } |
2711 | ||
39abcaee LP |
2712 | void bus_manager_send_reloading(Manager *m, bool active) { |
2713 | int r; | |
2714 | ||
718db961 LP |
2715 | assert(m); |
2716 | ||
8f8f05a9 | 2717 | r = bus_foreach_bus(m, NULL, send_reloading, INT_TO_PTR(active)); |
39abcaee | 2718 | if (r < 0) |
da927ba9 | 2719 | log_debug_errno(r, "Failed to send reloading signal: %m"); |
03455c28 LDM |
2720 | } |
2721 | ||
2722 | static int send_changed_signal(sd_bus *bus, void *userdata) { | |
2723 | assert(bus); | |
2724 | ||
2725 | return sd_bus_emit_properties_changed_strv(bus, | |
2726 | "/org/freedesktop/systemd1", | |
2727 | "org.freedesktop.systemd1.Manager", | |
2728 | NULL); | |
2729 | } | |
39abcaee | 2730 | |
03455c28 LDM |
2731 | void bus_manager_send_change_signal(Manager *m) { |
2732 | int r; | |
2733 | ||
2734 | assert(m); | |
2735 | ||
2736 | r = bus_foreach_bus(m, NULL, send_changed_signal, NULL); | |
2737 | if (r < 0) | |
2738 | log_debug_errno(r, "Failed to send manager change signal: %m"); | |
718db961 | 2739 | } |