]>
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" |
40af3d02 | 12 | #include "bus-get-properties.h" |
25141692 | 13 | #include "bus-log-control-api.h" |
3a0f06c4 | 14 | #include "dbus-cgroup.h" |
07630cea | 15 | #include "dbus-execute.h" |
2ea31e5b | 16 | #include "dbus-job.h" |
3ffd4af2 | 17 | #include "dbus-manager.h" |
c20076a8 | 18 | #include "dbus-scope.h" |
07630cea LP |
19 | #include "dbus-unit.h" |
20 | #include "dbus.h" | |
21 | #include "env-util.h" | |
3ffd4af2 | 22 | #include "fd-util.h" |
0d39fa9c | 23 | #include "fileio.h" |
f97b34a6 | 24 | #include "format-util.h" |
710028b4 | 25 | #include "fs-util.h" |
07630cea LP |
26 | #include "install.h" |
27 | #include "log.h" | |
d58ad743 | 28 | #include "os-util.h" |
ae57dad3 | 29 | #include "parse-util.h" |
07630cea LP |
30 | #include "path-util.h" |
31 | #include "selinux-access.h" | |
8fcde012 | 32 | #include "stat-util.h" |
07630cea LP |
33 | #include "string-util.h" |
34 | #include "strv.h" | |
7ccbd1ae | 35 | #include "syslog-util.h" |
29206d46 | 36 | #include "user-util.h" |
07630cea LP |
37 | #include "virt.h" |
38 | #include "watchdog.h" | |
ea430986 | 39 | |
ae57dad3 LP |
40 | /* Require 16MiB free in /run/systemd for reloading/reexecing. After all we need to serialize our state there, and if |
41 | * we can't we'll fail badly. */ | |
42 | #define RELOAD_DISK_SPACE_MIN (UINT64_C(16) * UINT64_C(1024) * UINT64_C(1024)) | |
43 | ||
b3796dd8 JS |
44 | static UnitFileFlags unit_file_bools_to_flags(bool runtime, bool force) { |
45 | return (runtime ? UNIT_FILE_RUNTIME : 0) | | |
46 | (force ? UNIT_FILE_FORCE : 0); | |
47 | } | |
48 | ||
afcfaa69 LP |
49 | BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_oom_policy, oom_policy, OOMPolicy); |
50 | ||
681bd2c5 | 51 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_version, "s", GIT_VERSION); |
23c9a63a YW |
52 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_features, "s", SYSTEMD_FEATURES); |
53 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_architecture, "s", architecture_to_string(uname_architecture())); | |
23c9a63a YW |
54 | static BUS_DEFINE_PROPERTY_GET2(property_get_system_state, "s", Manager, manager_state, manager_state_to_string); |
55 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_timer_slack_nsec, "t", (uint64_t) prctl(PR_GET_TIMERSLACK)); | |
92c23c5a YW |
56 | static BUS_DEFINE_PROPERTY_GET_REF(property_get_hashmap_size, "u", Hashmap *, hashmap_size); |
57 | static BUS_DEFINE_PROPERTY_GET_REF(property_get_set_size, "u", Set *, set_size); | |
3bf0cb65 | 58 | static BUS_DEFINE_PROPERTY_GET(property_get_default_timeout_abort_usec, "t", Manager, manager_default_timeout_abort_usec); |
718db961 LP |
59 | |
60 | static int property_get_virtualization( | |
61 | sd_bus *bus, | |
62 | const char *path, | |
63 | const char *interface, | |
64 | const char *property, | |
65 | sd_bus_message *reply, | |
ebcf1f97 LP |
66 | void *userdata, |
67 | sd_bus_error *error) { | |
718db961 | 68 | |
5c22925a LP |
69 | int v; |
70 | ||
718db961 LP |
71 | assert(bus); |
72 | assert(reply); | |
73 | ||
5c22925a LP |
74 | v = detect_virtualization(); |
75 | ||
76 | /* Make sure to return the empty string when we detect no virtualization, as that is the API. | |
77 | * | |
78 | * https://github.com/systemd/systemd/issues/1423 | |
79 | */ | |
80 | ||
81 | return sd_bus_message_append( | |
82 | reply, "s", | |
79a60375 | 83 | v == VIRTUALIZATION_NONE ? NULL : virtualization_to_string(v)); |
718db961 LP |
84 | } |
85 | ||
86 | static int property_get_tainted( | |
87 | sd_bus *bus, | |
88 | const char *path, | |
89 | const char *interface, | |
90 | const char *property, | |
91 | sd_bus_message *reply, | |
ebcf1f97 LP |
92 | void *userdata, |
93 | sd_bus_error *error) { | |
718db961 | 94 | |
af6b0ecc | 95 | _cleanup_free_ char *s = NULL; |
718db961 LP |
96 | Manager *m = userdata; |
97 | ||
98 | assert(bus); | |
99 | assert(reply); | |
bfebab7f | 100 | assert(m); |
c5d34390 | 101 | |
af6b0ecc LP |
102 | s = manager_taint_string(m); |
103 | if (!s) | |
104 | return log_oom(); | |
c5d34390 | 105 | |
af6b0ecc | 106 | return sd_bus_message_append(reply, "s", s); |
c5d34390 LP |
107 | } |
108 | ||
718db961 LP |
109 | static int property_set_log_target( |
110 | sd_bus *bus, | |
111 | const char *path, | |
112 | const char *interface, | |
113 | const char *property, | |
114 | sd_bus_message *value, | |
ebcf1f97 LP |
115 | void *userdata, |
116 | sd_bus_error *error) { | |
718db961 | 117 | |
bda7d78b | 118 | Manager *m = userdata; |
c826cda4 | 119 | const char *t; |
718db961 | 120 | int r; |
c826cda4 | 121 | |
718db961 LP |
122 | assert(bus); |
123 | assert(value); | |
c826cda4 | 124 | |
718db961 LP |
125 | r = sd_bus_message_read(value, "s", &t); |
126 | if (r < 0) | |
127 | return r; | |
c826cda4 | 128 | |
bda7d78b FB |
129 | if (isempty(t)) |
130 | manager_restore_original_log_target(m); | |
131 | else { | |
132 | LogTarget target; | |
133 | ||
134 | target = log_target_from_string(t); | |
135 | if (target < 0) | |
136 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid log target '%s'", t); | |
137 | ||
138 | manager_override_log_target(m, target); | |
139 | } | |
140 | ||
141 | return 0; | |
c826cda4 AB |
142 | } |
143 | ||
718db961 LP |
144 | static int property_set_log_level( |
145 | sd_bus *bus, | |
146 | const char *path, | |
147 | const char *interface, | |
148 | const char *property, | |
149 | sd_bus_message *value, | |
ebcf1f97 LP |
150 | void *userdata, |
151 | sd_bus_error *error) { | |
718db961 | 152 | |
a6ecbf83 | 153 | Manager *m = userdata; |
c826cda4 | 154 | const char *t; |
718db961 | 155 | int r; |
c826cda4 | 156 | |
718db961 LP |
157 | assert(bus); |
158 | assert(value); | |
c826cda4 | 159 | |
718db961 LP |
160 | r = sd_bus_message_read(value, "s", &t); |
161 | if (r < 0) | |
162 | return r; | |
c826cda4 | 163 | |
a6ecbf83 FB |
164 | if (isempty(t)) |
165 | manager_restore_original_log_level(m); | |
166 | else { | |
167 | int level; | |
168 | ||
169 | level = log_level_from_string(t); | |
170 | if (level < 0) | |
171 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid log level '%s'", t); | |
172 | ||
173 | manager_override_log_level(m, level); | |
174 | } | |
175 | ||
176 | return 0; | |
c826cda4 AB |
177 | } |
178 | ||
718db961 LP |
179 | static int property_get_progress( |
180 | sd_bus *bus, | |
181 | const char *path, | |
182 | const char *interface, | |
183 | const char *property, | |
184 | sd_bus_message *reply, | |
ebcf1f97 LP |
185 | void *userdata, |
186 | sd_bus_error *error) { | |
718db961 LP |
187 | |
188 | Manager *m = userdata; | |
05d6a3b6 LP |
189 | double d; |
190 | ||
718db961 LP |
191 | assert(bus); |
192 | assert(reply); | |
bfebab7f | 193 | assert(m); |
05d6a3b6 | 194 | |
49d5666c | 195 | if (MANAGER_IS_FINISHED(m)) |
05d6a3b6 LP |
196 | d = 1.0; |
197 | else | |
198 | d = 1.0 - ((double) hashmap_size(m->jobs) / (double) m->n_installed_jobs); | |
199 | ||
718db961 LP |
200 | return sd_bus_message_append(reply, "d", d); |
201 | } | |
202 | ||
1ad6e8b3 LP |
203 | static int property_get_environment( |
204 | sd_bus *bus, | |
205 | const char *path, | |
206 | const char *interface, | |
207 | const char *property, | |
208 | sd_bus_message *reply, | |
209 | void *userdata, | |
210 | sd_bus_error *error) { | |
211 | ||
212 | _cleanup_strv_free_ char **l = NULL; | |
213 | Manager *m = userdata; | |
214 | int r; | |
215 | ||
216 | assert(bus); | |
217 | assert(reply); | |
218 | assert(m); | |
219 | ||
220 | r = manager_get_effective_environment(m, &l); | |
221 | if (r < 0) | |
222 | return r; | |
223 | ||
224 | return sd_bus_message_append_strv(reply, l); | |
225 | } | |
226 | ||
52d2566a ZJS |
227 | static int property_get_show_status( |
228 | sd_bus *bus, | |
229 | const char *path, | |
230 | const char *interface, | |
231 | const char *property, | |
232 | sd_bus_message *reply, | |
233 | void *userdata, | |
234 | sd_bus_error *error) { | |
235 | ||
236 | Manager *m = userdata; | |
52d2566a | 237 | |
44a41954 | 238 | assert(m); |
52d2566a ZJS |
239 | assert(bus); |
240 | assert(reply); | |
52d2566a | 241 | |
44a41954 | 242 | return sd_bus_message_append(reply, "b", manager_get_show_status_on(m)); |
52d2566a ZJS |
243 | } |
244 | ||
986935cf | 245 | static int property_get_runtime_watchdog( |
718db961 LP |
246 | sd_bus *bus, |
247 | const char *path, | |
248 | const char *interface, | |
249 | const char *property, | |
986935cf | 250 | sd_bus_message *reply, |
ebcf1f97 LP |
251 | void *userdata, |
252 | sd_bus_error *error) { | |
05d6a3b6 | 253 | |
986935cf | 254 | Manager *m = userdata; |
718db961 | 255 | |
986935cf | 256 | assert(m); |
718db961 | 257 | assert(bus); |
986935cf FB |
258 | assert(reply); |
259 | ||
260 | return sd_bus_message_append(reply, "t", manager_get_watchdog(m, WATCHDOG_RUNTIME)); | |
261 | } | |
262 | ||
263 | static int property_get_reboot_watchdog( | |
264 | sd_bus *bus, | |
265 | const char *path, | |
266 | const char *interface, | |
267 | const char *property, | |
268 | sd_bus_message *reply, | |
269 | void *userdata, | |
270 | sd_bus_error *error) { | |
271 | ||
272 | Manager *m = userdata; | |
273 | ||
274 | assert(m); | |
275 | assert(bus); | |
276 | assert(reply); | |
277 | ||
278 | return sd_bus_message_append(reply, "t", manager_get_watchdog(m, WATCHDOG_REBOOT)); | |
279 | } | |
280 | ||
281 | static int property_get_kexec_watchdog( | |
282 | sd_bus *bus, | |
283 | const char *path, | |
284 | const char *interface, | |
285 | const char *property, | |
286 | sd_bus_message *reply, | |
287 | void *userdata, | |
288 | sd_bus_error *error) { | |
289 | ||
290 | Manager *m = userdata; | |
291 | ||
292 | assert(m); | |
293 | assert(bus); | |
294 | assert(reply); | |
295 | ||
296 | return sd_bus_message_append(reply, "t", manager_get_watchdog(m, WATCHDOG_KEXEC)); | |
297 | } | |
298 | ||
299 | static int property_set_watchdog(Manager *m, WatchdogType type, sd_bus_message *value) { | |
300 | usec_t timeout; | |
301 | int r; | |
302 | ||
303 | assert(m); | |
718db961 LP |
304 | assert(value); |
305 | ||
306 | assert_cc(sizeof(usec_t) == sizeof(uint64_t)); | |
307 | ||
986935cf | 308 | r = sd_bus_message_read(value, "t", &timeout); |
718db961 LP |
309 | if (r < 0) |
310 | return r; | |
311 | ||
43bba15a | 312 | return manager_override_watchdog(m, type, timeout); |
986935cf FB |
313 | } |
314 | ||
315 | static int property_set_runtime_watchdog( | |
316 | sd_bus *bus, | |
317 | const char *path, | |
318 | const char *interface, | |
319 | const char *property, | |
320 | sd_bus_message *value, | |
321 | void *userdata, | |
322 | sd_bus_error *error) { | |
323 | ||
324 | return property_set_watchdog(userdata, WATCHDOG_RUNTIME, value); | |
325 | } | |
326 | ||
327 | static int property_set_reboot_watchdog( | |
328 | sd_bus *bus, | |
329 | const char *path, | |
330 | const char *interface, | |
331 | const char *property, | |
332 | sd_bus_message *value, | |
333 | void *userdata, | |
334 | sd_bus_error *error) { | |
335 | ||
336 | return property_set_watchdog(userdata, WATCHDOG_REBOOT, value); | |
337 | } | |
338 | ||
339 | static int property_set_kexec_watchdog( | |
340 | sd_bus *bus, | |
341 | const char *path, | |
342 | const char *interface, | |
343 | const char *property, | |
344 | sd_bus_message *value, | |
345 | void *userdata, | |
346 | sd_bus_error *error) { | |
347 | ||
dfa64b64 | 348 | _unused_ Manager *m = userdata; |
986935cf FB |
349 | |
350 | assert(m); | |
351 | assert(bus); | |
352 | assert(value); | |
353 | ||
354 | return property_set_watchdog(userdata, WATCHDOG_KEXEC, value); | |
05d6a3b6 LP |
355 | } |
356 | ||
96cc4453 | 357 | 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 |
358 | Unit *u; |
359 | int r; | |
dfae3488 | 360 | |
dfae3488 | 361 | assert(m); |
96cc4453 LP |
362 | assert(message); |
363 | assert(ret_unit); | |
dfae3488 | 364 | |
96cc4453 LP |
365 | /* More or less a wrapper around manager_get_unit() that generates nice errors and has one trick up its sleeve: |
366 | * if the name is specified empty we use the client's unit. */ | |
dfae3488 | 367 | |
1d22e906 | 368 | if (isempty(name)) { |
4afd3348 | 369 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; |
1d22e906 LP |
370 | pid_t pid; |
371 | ||
372 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); | |
373 | if (r < 0) | |
374 | return r; | |
375 | ||
376 | r = sd_bus_creds_get_pid(creds, &pid); | |
377 | if (r < 0) | |
378 | return r; | |
379 | ||
380 | u = manager_get_unit_by_pid(m, pid); | |
381 | if (!u) | |
382 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Client not member of any unit."); | |
383 | } else { | |
384 | u = manager_get_unit(m, name); | |
385 | if (!u) | |
386 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", name); | |
387 | } | |
dfae3488 | 388 | |
96cc4453 LP |
389 | *ret_unit = u; |
390 | return 0; | |
391 | } | |
392 | ||
393 | static int bus_load_unit_by_name(Manager *m, sd_bus_message *message, const char *name, Unit **ret_unit, sd_bus_error *error) { | |
394 | assert(m); | |
395 | assert(message); | |
396 | assert(ret_unit); | |
397 | ||
398 | /* Pretty much the same as bus_get_unit_by_name(), but we also load the unit if necessary. */ | |
399 | ||
400 | if (isempty(name)) | |
401 | return bus_get_unit_by_name(m, message, name, ret_unit, error); | |
402 | ||
403 | return manager_load_unit(m, name, NULL, error, ret_unit); | |
404 | } | |
405 | ||
4659bf6f | 406 | static int reply_unit_path(Unit *u, sd_bus_message *message, sd_bus_error *error) { |
96cc4453 | 407 | _cleanup_free_ char *path = NULL; |
4659bf6f LP |
408 | int r; |
409 | ||
410 | assert(u); | |
411 | assert(message); | |
412 | ||
413 | r = mac_selinux_unit_access_check(u, message, "status", error); | |
414 | if (r < 0) | |
415 | return r; | |
416 | ||
417 | path = unit_dbus_path(u); | |
418 | if (!path) | |
419 | return log_oom(); | |
420 | ||
421 | return sd_bus_reply_method_return(message, "o", path); | |
422 | } | |
423 | ||
424 | static int method_get_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
96cc4453 LP |
425 | Manager *m = userdata; |
426 | const char *name; | |
427 | Unit *u; | |
428 | int r; | |
429 | ||
430 | assert(message); | |
431 | assert(m); | |
432 | ||
433 | /* Anyone can call this method */ | |
434 | ||
435 | r = sd_bus_message_read(message, "s", &name); | |
436 | if (r < 0) | |
437 | return r; | |
438 | ||
439 | r = bus_get_unit_by_name(m, message, name, &u, error); | |
440 | if (r < 0) | |
441 | return r; | |
442 | ||
4659bf6f | 443 | return reply_unit_path(u, message, error); |
718db961 | 444 | } |
c0576cd6 | 445 | |
19070062 | 446 | static int method_get_unit_by_pid(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
447 | Manager *m = userdata; |
448 | pid_t pid; | |
449 | Unit *u; | |
450 | int r; | |
c0576cd6 | 451 | |
718db961 LP |
452 | assert(message); |
453 | assert(m); | |
c0576cd6 | 454 | |
718db961 | 455 | assert_cc(sizeof(pid_t) == sizeof(uint32_t)); |
729e3769 | 456 | |
283868e1 SW |
457 | /* Anyone can call this method */ |
458 | ||
718db961 LP |
459 | r = sd_bus_message_read(message, "u", &pid); |
460 | if (r < 0) | |
ebcf1f97 | 461 | return r; |
07b38ba5 | 462 | if (pid < 0) |
1d22e906 | 463 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PID " PID_FMT, pid); |
718db961 LP |
464 | |
465 | if (pid == 0) { | |
4afd3348 | 466 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; |
5b12334d LP |
467 | |
468 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); | |
469 | if (r < 0) | |
470 | return r; | |
471 | ||
472 | r = sd_bus_creds_get_pid(creds, &pid); | |
718db961 | 473 | if (r < 0) |
ebcf1f97 | 474 | return r; |
729e3769 LP |
475 | } |
476 | ||
718db961 LP |
477 | u = manager_get_unit_by_pid(m, pid); |
478 | if (!u) | |
1fa2f38f | 479 | return sd_bus_error_setf(error, BUS_ERROR_NO_UNIT_FOR_PID, "PID "PID_FMT" does not belong to any loaded unit.", pid); |
c0576cd6 | 480 | |
4659bf6f | 481 | return reply_unit_path(u, message, error); |
718db961 LP |
482 | } |
483 | ||
4b58153d LP |
484 | static int method_get_unit_by_invocation_id(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
485 | _cleanup_free_ char *path = NULL; | |
486 | Manager *m = userdata; | |
487 | sd_id128_t id; | |
488 | const void *a; | |
489 | Unit *u; | |
490 | size_t sz; | |
491 | int r; | |
492 | ||
493 | assert(message); | |
494 | assert(m); | |
495 | ||
496 | /* Anyone can call this method */ | |
497 | ||
498 | r = sd_bus_message_read_array(message, 'y', &a, &sz); | |
499 | if (r < 0) | |
500 | return r; | |
501 | if (sz == 0) | |
502 | id = SD_ID128_NULL; | |
503 | else if (sz == 16) | |
504 | memcpy(&id, a, sz); | |
505 | else | |
506 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid invocation ID"); | |
507 | ||
508 | if (sd_id128_is_null(id)) { | |
509 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; | |
510 | pid_t pid; | |
511 | ||
512 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); | |
513 | if (r < 0) | |
514 | return r; | |
515 | ||
516 | r = sd_bus_creds_get_pid(creds, &pid); | |
517 | if (r < 0) | |
518 | return r; | |
519 | ||
520 | u = manager_get_unit_by_pid(m, pid); | |
521 | if (!u) | |
522 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Client " PID_FMT " not member of any unit.", pid); | |
523 | } else { | |
524 | u = hashmap_get(m->units_by_invocation_id, &id); | |
525 | if (!u) | |
526 | 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)); | |
527 | } | |
528 | ||
529 | r = mac_selinux_unit_access_check(u, message, "status", error); | |
530 | if (r < 0) | |
531 | return r; | |
532 | ||
533 | /* So here's a special trick: the bus path we return actually references the unit by its invocation ID instead | |
534 | * of the unit name. This means it stays valid only as long as the invocation ID stays the same. */ | |
535 | path = unit_dbus_path_invocation_id(u); | |
536 | if (!path) | |
537 | return -ENOMEM; | |
538 | ||
539 | return sd_bus_reply_method_return(message, "o", path); | |
540 | } | |
541 | ||
267dd427 | 542 | static int method_get_unit_by_control_group(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
267dd427 LP |
543 | Manager *m = userdata; |
544 | const char *cgroup; | |
545 | Unit *u; | |
546 | int r; | |
547 | ||
548 | r = sd_bus_message_read(message, "s", &cgroup); | |
549 | if (r < 0) | |
550 | return r; | |
551 | ||
552 | u = manager_get_unit_by_cgroup(m, cgroup); | |
553 | if (!u) | |
554 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Control group '%s' is not valid or not managed by this instance", cgroup); | |
555 | ||
4659bf6f | 556 | return reply_unit_path(u, message, error); |
267dd427 LP |
557 | } |
558 | ||
19070062 | 559 | static int method_load_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
560 | Manager *m = userdata; |
561 | const char *name; | |
562 | Unit *u; | |
563 | int r; | |
c0576cd6 | 564 | |
718db961 LP |
565 | assert(message); |
566 | assert(m); | |
567 | ||
283868e1 SW |
568 | /* Anyone can call this method */ |
569 | ||
718db961 LP |
570 | r = sd_bus_message_read(message, "s", &name); |
571 | if (r < 0) | |
ebcf1f97 | 572 | return r; |
c0576cd6 | 573 | |
96cc4453 LP |
574 | r = bus_load_unit_by_name(m, message, name, &u, error); |
575 | if (r < 0) | |
576 | return r; | |
718db961 | 577 | |
4659bf6f | 578 | return reply_unit_path(u, message, error); |
c0576cd6 LP |
579 | } |
580 | ||
19070062 | 581 | 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 |
582 | const char *name; |
583 | Unit *u; | |
c0576cd6 LP |
584 | int r; |
585 | ||
718db961 LP |
586 | assert(message); |
587 | assert(m); | |
c0576cd6 | 588 | |
718db961 LP |
589 | r = sd_bus_message_read(message, "s", &name); |
590 | if (r < 0) | |
ebcf1f97 | 591 | return r; |
c0576cd6 | 592 | |
ebcf1f97 | 593 | r = manager_load_unit(m, name, NULL, error, &u); |
718db961 | 594 | if (r < 0) |
ebcf1f97 | 595 | return r; |
718db961 | 596 | |
19070062 | 597 | return bus_unit_method_start_generic(message, u, job_type, reload_if_possible, error); |
c0576cd6 LP |
598 | } |
599 | ||
19070062 LP |
600 | static int method_start_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
601 | return method_start_unit_generic(message, userdata, JOB_START, false, error); | |
718db961 | 602 | } |
c757a65b | 603 | |
19070062 LP |
604 | static int method_stop_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
605 | return method_start_unit_generic(message, userdata, JOB_STOP, false, error); | |
718db961 | 606 | } |
c757a65b | 607 | |
19070062 LP |
608 | static int method_reload_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
609 | return method_start_unit_generic(message, userdata, JOB_RELOAD, false, error); | |
718db961 | 610 | } |
c757a65b | 611 | |
19070062 LP |
612 | static int method_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
613 | return method_start_unit_generic(message, userdata, JOB_RESTART, false, error); | |
c757a65b LP |
614 | } |
615 | ||
19070062 LP |
616 | static int method_try_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
617 | return method_start_unit_generic(message, userdata, JOB_TRY_RESTART, false, error); | |
718db961 | 618 | } |
d200735e | 619 | |
19070062 LP |
620 | static int method_reload_or_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
621 | return method_start_unit_generic(message, userdata, JOB_RESTART, true, error); | |
718db961 | 622 | } |
d200735e | 623 | |
19070062 LP |
624 | static int method_reload_or_try_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
625 | return method_start_unit_generic(message, userdata, JOB_TRY_RESTART, true, error); | |
718db961 | 626 | } |
d200735e | 627 | |
42561fc9 LP |
628 | typedef enum GenericUnitOperationFlags { |
629 | GENERIC_UNIT_LOAD = 1 << 0, /* Load if the unit is not loaded yet */ | |
630 | GENERIC_UNIT_VALIDATE_LOADED = 1 << 1, /* Verify unit is properly loaded before forwarding call */ | |
631 | } GenericUnitOperationFlags; | |
632 | ||
633 | static int method_generic_unit_operation( | |
634 | sd_bus_message *message, | |
635 | Manager *m, | |
636 | sd_bus_error *error, | |
637 | sd_bus_message_handler_t handler, | |
638 | GenericUnitOperationFlags flags) { | |
639 | ||
50cbaba4 LP |
640 | const char *name; |
641 | Unit *u; | |
642 | int r; | |
643 | ||
644 | assert(message); | |
645 | assert(m); | |
646 | ||
42561fc9 LP |
647 | /* Read the first argument from the command and pass the operation to the specified per-unit |
648 | * method. */ | |
649 | ||
50cbaba4 LP |
650 | r = sd_bus_message_read(message, "s", &name); |
651 | if (r < 0) | |
652 | return r; | |
653 | ||
42561fc9 LP |
654 | if (!isempty(name) && FLAGS_SET(flags, GENERIC_UNIT_LOAD)) |
655 | r = manager_load_unit(m, name, NULL, error, &u); | |
656 | else | |
657 | r = bus_get_unit_by_name(m, message, name, &u, error); | |
50cbaba4 LP |
658 | if (r < 0) |
659 | return r; | |
660 | ||
42561fc9 LP |
661 | if (FLAGS_SET(flags, GENERIC_UNIT_VALIDATE_LOADED)) { |
662 | r = bus_unit_validate_load_state(u, error); | |
663 | if (r < 0) | |
664 | return r; | |
665 | } | |
666 | ||
667 | return handler(message, u, error); | |
668 | } | |
669 | ||
670 | static int method_enqueue_unit_job(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
671 | /* We don't bother with GENERIC_UNIT_VALIDATE_LOADED here, as the job logic validates that anyway */ | |
672 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_enqueue_job, GENERIC_UNIT_LOAD); | |
50cbaba4 LP |
673 | } |
674 | ||
19070062 | 675 | static int method_start_unit_replace(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
676 | Manager *m = userdata; |
677 | const char *old_name; | |
678 | Unit *u; | |
1adf1049 | 679 | int r; |
ea430986 | 680 | |
ea430986 LP |
681 | assert(message); |
682 | assert(m); | |
683 | ||
718db961 LP |
684 | r = sd_bus_message_read(message, "s", &old_name); |
685 | if (r < 0) | |
ebcf1f97 | 686 | return r; |
ea430986 | 687 | |
96cc4453 LP |
688 | r = bus_get_unit_by_name(m, message, old_name, &u, error); |
689 | if (r < 0) | |
690 | return r; | |
691 | if (!u->job || u->job->type != JOB_START) | |
ebcf1f97 | 692 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name); |
c0576cd6 | 693 | |
19070062 | 694 | return method_start_unit_generic(message, m, JOB_START, false, error); |
718db961 | 695 | } |
ea430986 | 696 | |
19070062 | 697 | static int method_kill_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
698 | /* We don't bother with GENERIC_UNIT_LOAD nor GENERIC_UNIT_VALIDATE_LOADED here, as it shouldn't |
699 | * matter whether a unit is loaded for killing any processes possibly in the unit's cgroup. */ | |
700 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_kill, 0); | |
718db961 | 701 | } |
8a0867d6 | 702 | |
4d3bac56 LP |
703 | static int method_clean_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
704 | /* Load the unit if necessary, in order to load it, and insist on the unit being loaded to be | |
705 | * cleaned */ | |
706 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_clean, GENERIC_UNIT_LOAD|GENERIC_UNIT_VALIDATE_LOADED); | |
707 | } | |
708 | ||
d9e45bc3 MS |
709 | static int method_freeze_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
710 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_freeze, 0); | |
711 | } | |
712 | ||
713 | static int method_thaw_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
714 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_thaw, 0); | |
715 | } | |
716 | ||
19070062 | 717 | static int method_reset_failed_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
718 | /* Don't load the unit (because unloaded units can't be in failed state), and don't insist on the |
719 | * unit to be loaded properly (since a failed unit might have its unit file disappeared) */ | |
720 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_reset_failed, 0); | |
718db961 | 721 | } |
5dd9014f | 722 | |
19070062 | 723 | static int method_set_unit_properties(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
724 | /* Only change properties on fully loaded units, and load them in order to set properties */ |
725 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_set_properties, GENERIC_UNIT_LOAD|GENERIC_UNIT_VALIDATE_LOADED); | |
718db961 LP |
726 | } |
727 | ||
05a98afd | 728 | static int method_ref_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
729 | /* Only allow reffing of fully loaded units, and make sure reffing a unit loads it. */ |
730 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_ref, GENERIC_UNIT_LOAD|GENERIC_UNIT_VALIDATE_LOADED); | |
05a98afd LP |
731 | } |
732 | ||
733 | static int method_unref_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
42561fc9 LP |
734 | /* Dropping a ref OTOH should not require the unit to still be loaded. And since a reffed unit is a |
735 | * loaded unit there's no need to load the unit for unreffing it. */ | |
736 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_unref, 0); | |
05a98afd LP |
737 | } |
738 | ||
6900c740 | 739 | static int reply_unit_info(sd_bus_message *reply, Unit *u) { |
740 | _cleanup_free_ char *unit_path = NULL, *job_path = NULL; | |
741 | Unit *following; | |
742 | ||
743 | following = unit_following(u); | |
744 | ||
745 | unit_path = unit_dbus_path(u); | |
746 | if (!unit_path) | |
747 | return -ENOMEM; | |
748 | ||
749 | if (u->job) { | |
750 | job_path = job_dbus_path(u->job); | |
751 | if (!job_path) | |
752 | return -ENOMEM; | |
753 | } | |
754 | ||
755 | return sd_bus_message_append( | |
756 | reply, "(ssssssouso)", | |
757 | u->id, | |
758 | unit_description(u), | |
759 | unit_load_state_to_string(u->load_state), | |
760 | unit_active_state_to_string(unit_active_state(u)), | |
761 | unit_sub_state_to_string(u), | |
762 | following ? following->id : "", | |
763 | unit_path, | |
764 | u->job ? u->job->id : 0, | |
765 | u->job ? job_type_to_string(u->job->type) : "", | |
c1d95b71 | 766 | empty_to_root(job_path)); |
6900c740 | 767 | } |
768 | ||
769 | static int method_list_units_by_names(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
770 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
771 | Manager *m = userdata; | |
772 | int r; | |
773 | char **unit; | |
774 | _cleanup_strv_free_ char **units = NULL; | |
775 | ||
776 | assert(message); | |
777 | assert(m); | |
778 | ||
779 | r = sd_bus_message_read_strv(message, &units); | |
780 | if (r < 0) | |
781 | return r; | |
782 | ||
783 | r = sd_bus_message_new_method_return(message, &reply); | |
784 | if (r < 0) | |
785 | return r; | |
786 | ||
787 | r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)"); | |
788 | if (r < 0) | |
789 | return r; | |
790 | ||
791 | STRV_FOREACH(unit, units) { | |
792 | Unit *u; | |
793 | ||
794 | if (!unit_name_is_valid(*unit, UNIT_NAME_ANY)) | |
795 | continue; | |
796 | ||
96cc4453 | 797 | r = bus_load_unit_by_name(m, message, *unit, &u, error); |
6900c740 | 798 | if (r < 0) |
799 | return r; | |
800 | ||
801 | r = reply_unit_info(reply, u); | |
802 | if (r < 0) | |
803 | return r; | |
804 | } | |
805 | ||
806 | r = sd_bus_message_close_container(reply); | |
807 | if (r < 0) | |
808 | return r; | |
809 | ||
810 | return sd_bus_send(NULL, reply, NULL); | |
811 | } | |
812 | ||
291d565a | 813 | static int method_get_unit_processes(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
814 | /* Don't load a unit (since it won't have any processes if it's not loaded), but don't insist on the |
815 | * unit being loaded (because even improperly loaded units might still have processes around */ | |
816 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_get_processes, 0); | |
291d565a LP |
817 | } |
818 | ||
6592b975 | 819 | static int method_attach_processes_to_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
820 | /* Don't allow attaching new processes to units that aren't loaded. Don't bother with loading a unit |
821 | * for this purpose though, as an unloaded unit is a stopped unit, and we don't allow attaching | |
822 | * processes to stopped units anyway. */ | |
823 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_attach_processes, GENERIC_UNIT_VALIDATE_LOADED); | |
6592b975 LP |
824 | } |
825 | ||
ab31f6b8 WC |
826 | static int transient_unit_from_message( |
827 | Manager *m, | |
828 | sd_bus_message *message, | |
829 | const char *name, | |
830 | Unit **unit, | |
831 | sd_bus_error *error) { | |
832 | ||
06cc6afa | 833 | UnitType t; |
ab31f6b8 WC |
834 | Unit *u; |
835 | int r; | |
836 | ||
837 | assert(m); | |
838 | assert(message); | |
839 | assert(name); | |
840 | ||
06cc6afa LP |
841 | t = unit_name_to_type(name); |
842 | if (t < 0) | |
843 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit name or type."); | |
844 | ||
845 | if (!unit_vtable[t]->can_transient) | |
846 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit type %s does not support transient units.", unit_type_to_string(t)); | |
847 | ||
ab31f6b8 WC |
848 | r = manager_load_unit(m, name, NULL, error, &u); |
849 | if (r < 0) | |
850 | return r; | |
851 | ||
0f13f3bd | 852 | if (!unit_is_pristine(u)) |
ab31f6b8 WC |
853 | return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name); |
854 | ||
855 | /* OK, the unit failed to load and is unreferenced, now let's | |
856 | * fill in the transient data instead */ | |
857 | r = unit_make_transient(u); | |
858 | if (r < 0) | |
859 | return r; | |
860 | ||
861 | /* Set our properties */ | |
862 | r = bus_unit_set_properties(u, message, UNIT_RUNTIME, false, error); | |
863 | if (r < 0) | |
864 | return r; | |
865 | ||
05a98afd LP |
866 | /* If the client asked for it, automatically add a reference to this unit. */ |
867 | if (u->bus_track_add) { | |
868 | r = bus_unit_track_add_sender(u, message); | |
869 | if (r < 0) | |
870 | return log_error_errno(r, "Failed to watch sender: %m"); | |
871 | } | |
872 | ||
97329d20 | 873 | /* Now load the missing bits of the unit we just created */ |
4f952a3f | 874 | unit_add_to_load_queue(u); |
97329d20 LP |
875 | manager_dispatch_load_queue(m); |
876 | ||
ab31f6b8 WC |
877 | *unit = u; |
878 | ||
879 | return 0; | |
880 | } | |
881 | ||
882 | static int transient_aux_units_from_message( | |
883 | Manager *m, | |
884 | sd_bus_message *message, | |
885 | sd_bus_error *error) { | |
886 | ||
ab31f6b8 WC |
887 | int r; |
888 | ||
889 | assert(m); | |
890 | assert(message); | |
891 | ||
892 | r = sd_bus_message_enter_container(message, 'a', "(sa(sv))"); | |
893 | if (r < 0) | |
894 | return r; | |
895 | ||
896 | while ((r = sd_bus_message_enter_container(message, 'r', "sa(sv)")) > 0) { | |
97329d20 LP |
897 | const char *name = NULL; |
898 | Unit *u; | |
899 | ||
ab31f6b8 WC |
900 | r = sd_bus_message_read(message, "s", &name); |
901 | if (r < 0) | |
902 | return r; | |
903 | ||
904 | r = transient_unit_from_message(m, message, name, &u, error); | |
97329d20 | 905 | if (r < 0) |
ab31f6b8 WC |
906 | return r; |
907 | ||
ab31f6b8 WC |
908 | r = sd_bus_message_exit_container(message); |
909 | if (r < 0) | |
910 | return r; | |
911 | } | |
912 | if (r < 0) | |
913 | return r; | |
914 | ||
915 | r = sd_bus_message_exit_container(message); | |
916 | if (r < 0) | |
917 | return r; | |
918 | ||
919 | return 0; | |
920 | } | |
921 | ||
19070062 | 922 | static int method_start_transient_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
923 | const char *name, *smode; |
924 | Manager *m = userdata; | |
925 | JobMode mode; | |
718db961 LP |
926 | Unit *u; |
927 | int r; | |
ea430986 | 928 | |
718db961 LP |
929 | assert(message); |
930 | assert(m); | |
ea430986 | 931 | |
1d22e906 | 932 | r = mac_selinux_access_check(message, "start", error); |
283868e1 SW |
933 | if (r < 0) |
934 | return r; | |
283868e1 | 935 | |
718db961 LP |
936 | r = sd_bus_message_read(message, "ss", &name, &smode); |
937 | if (r < 0) | |
ebcf1f97 | 938 | return r; |
5632e374 | 939 | |
718db961 LP |
940 | mode = job_mode_from_string(smode); |
941 | if (mode < 0) | |
ebcf1f97 | 942 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s is invalid.", smode); |
5632e374 | 943 | |
1d22e906 | 944 | r = bus_verify_manage_units_async(m, message, error); |
718db961 | 945 | if (r < 0) |
ebcf1f97 | 946 | return r; |
1d22e906 LP |
947 | if (r == 0) |
948 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
5632e374 | 949 | |
ab31f6b8 | 950 | r = transient_unit_from_message(m, message, name, &u, error); |
ebcf1f97 LP |
951 | if (r < 0) |
952 | return r; | |
5632e374 | 953 | |
ab31f6b8 | 954 | r = transient_aux_units_from_message(m, message, error); |
718db961 | 955 | if (r < 0) |
ebcf1f97 | 956 | return r; |
ea430986 | 957 | |
718db961 | 958 | /* Finally, start it */ |
50cbaba4 | 959 | return bus_unit_queue_job(message, u, JOB_START, mode, 0, error); |
718db961 | 960 | } |
ea430986 | 961 | |
19070062 | 962 | static int method_get_job(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
963 | _cleanup_free_ char *path = NULL; |
964 | Manager *m = userdata; | |
965 | uint32_t id; | |
966 | Job *j; | |
967 | int r; | |
ea430986 | 968 | |
718db961 LP |
969 | assert(message); |
970 | assert(m); | |
ea430986 | 971 | |
283868e1 SW |
972 | /* Anyone can call this method */ |
973 | ||
718db961 LP |
974 | r = sd_bus_message_read(message, "u", &id); |
975 | if (r < 0) | |
ebcf1f97 | 976 | return r; |
ea430986 | 977 | |
718db961 LP |
978 | j = manager_get_job(m, id); |
979 | if (!j) | |
ebcf1f97 | 980 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); |
ea430986 | 981 | |
8a188de9 | 982 | r = mac_selinux_unit_access_check(j->unit, message, "status", error); |
ebcf1f97 LP |
983 | if (r < 0) |
984 | return r; | |
ea430986 | 985 | |
718db961 LP |
986 | path = job_dbus_path(j); |
987 | if (!path) | |
ebcf1f97 | 988 | return -ENOMEM; |
ea430986 | 989 | |
df2d202e | 990 | return sd_bus_reply_method_return(message, "o", path); |
718db961 | 991 | } |
ea430986 | 992 | |
19070062 | 993 | static int method_cancel_job(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
994 | Manager *m = userdata; |
995 | uint32_t id; | |
996 | Job *j; | |
997 | int r; | |
ea430986 | 998 | |
718db961 LP |
999 | assert(message); |
1000 | assert(m); | |
ea430986 | 1001 | |
718db961 LP |
1002 | r = sd_bus_message_read(message, "u", &id); |
1003 | if (r < 0) | |
ebcf1f97 | 1004 | return r; |
ea430986 | 1005 | |
718db961 LP |
1006 | j = manager_get_job(m, id); |
1007 | if (!j) | |
ebcf1f97 | 1008 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); |
ea430986 | 1009 | |
19070062 | 1010 | return bus_job_method_cancel(message, j, error); |
718db961 | 1011 | } |
c1e1601e | 1012 | |
19070062 | 1013 | static int method_clear_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1014 | Manager *m = userdata; |
ebcf1f97 | 1015 | int r; |
c1e1601e | 1016 | |
718db961 LP |
1017 | assert(message); |
1018 | assert(m); | |
c1e1601e | 1019 | |
1d22e906 | 1020 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1021 | if (r < 0) |
1022 | return r; | |
1023 | ||
1d22e906 LP |
1024 | r = bus_verify_manage_units_async(m, message, error); |
1025 | if (r < 0) | |
1026 | return r; | |
1027 | if (r == 0) | |
1028 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1029 | ||
718db961 | 1030 | manager_clear_jobs(m); |
c1e1601e | 1031 | |
df2d202e | 1032 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1033 | } |
c1e1601e | 1034 | |
19070062 | 1035 | static int method_reset_failed(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1036 | Manager *m = userdata; |
ebcf1f97 | 1037 | int r; |
cad45ba1 | 1038 | |
718db961 LP |
1039 | assert(message); |
1040 | assert(m); | |
1041 | ||
8a188de9 | 1042 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1043 | if (r < 0) |
1044 | return r; | |
1045 | ||
1d22e906 LP |
1046 | r = bus_verify_manage_units_async(m, message, error); |
1047 | if (r < 0) | |
1048 | return r; | |
1049 | if (r == 0) | |
1050 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1051 | ||
718db961 | 1052 | manager_reset_failed(m); |
c1e1601e | 1053 | |
df2d202e | 1054 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1055 | } |
c1e1601e | 1056 | |
313fe66f | 1057 | static int list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *error, char **states, char **patterns) { |
4afd3348 | 1058 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
718db961 LP |
1059 | Manager *m = userdata; |
1060 | const char *k; | |
1061 | Iterator i; | |
1062 | Unit *u; | |
1063 | int r; | |
c1e1601e | 1064 | |
718db961 LP |
1065 | assert(message); |
1066 | assert(m); | |
b152adec | 1067 | |
283868e1 SW |
1068 | /* Anyone can call this method */ |
1069 | ||
8a188de9 | 1070 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1071 | if (r < 0) |
1072 | return r; | |
cad45ba1 | 1073 | |
df2d202e | 1074 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1075 | if (r < 0) |
ebcf1f97 | 1076 | return r; |
b152adec | 1077 | |
718db961 LP |
1078 | r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)"); |
1079 | if (r < 0) | |
ebcf1f97 | 1080 | return r; |
b152adec | 1081 | |
718db961 | 1082 | HASHMAP_FOREACH_KEY(u, k, m->units, i) { |
718db961 LP |
1083 | if (k != u->id) |
1084 | continue; | |
b152adec | 1085 | |
cdc06ed7 DS |
1086 | if (!strv_isempty(states) && |
1087 | !strv_contains(states, unit_load_state_to_string(u->load_state)) && | |
1088 | !strv_contains(states, unit_active_state_to_string(unit_active_state(u))) && | |
1089 | !strv_contains(states, unit_sub_state_to_string(u))) | |
1090 | continue; | |
1091 | ||
313fe66f | 1092 | if (!strv_isempty(patterns) && |
1093 | !strv_fnmatch_or_empty(patterns, u->id, FNM_NOESCAPE)) | |
1094 | continue; | |
1095 | ||
6900c740 | 1096 | r = reply_unit_info(reply, u); |
718db961 | 1097 | if (r < 0) |
ebcf1f97 | 1098 | return r; |
718db961 | 1099 | } |
4139c1b2 | 1100 | |
718db961 LP |
1101 | r = sd_bus_message_close_container(reply); |
1102 | if (r < 0) | |
ebcf1f97 | 1103 | return r; |
cad45ba1 | 1104 | |
9030ca46 | 1105 | return sd_bus_send(NULL, reply, NULL); |
718db961 | 1106 | } |
4139c1b2 | 1107 | |
19070062 | 1108 | static int method_list_units(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
313fe66f | 1109 | return list_units_filtered(message, userdata, error, NULL, NULL); |
cdc06ed7 DS |
1110 | } |
1111 | ||
19070062 | 1112 | static int method_list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
cdc06ed7 DS |
1113 | _cleanup_strv_free_ char **states = NULL; |
1114 | int r; | |
1115 | ||
1116 | r = sd_bus_message_read_strv(message, &states); | |
1117 | if (r < 0) | |
1118 | return r; | |
1119 | ||
313fe66f | 1120 | return list_units_filtered(message, userdata, error, states, NULL); |
1121 | } | |
1122 | ||
1123 | static int method_list_units_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1124 | _cleanup_strv_free_ char **states = NULL; | |
1125 | _cleanup_strv_free_ char **patterns = NULL; | |
1126 | int r; | |
1127 | ||
1128 | r = sd_bus_message_read_strv(message, &states); | |
1129 | if (r < 0) | |
1130 | return r; | |
1131 | ||
1132 | r = sd_bus_message_read_strv(message, &patterns); | |
1133 | if (r < 0) | |
1134 | return r; | |
1135 | ||
1136 | return list_units_filtered(message, userdata, error, states, patterns); | |
cdc06ed7 DS |
1137 | } |
1138 | ||
19070062 | 1139 | static int method_list_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
4afd3348 | 1140 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
718db961 LP |
1141 | Manager *m = userdata; |
1142 | Iterator i; | |
1143 | Job *j; | |
1144 | int r; | |
4139c1b2 | 1145 | |
718db961 LP |
1146 | assert(message); |
1147 | assert(m); | |
1148 | ||
283868e1 SW |
1149 | /* Anyone can call this method */ |
1150 | ||
8a188de9 | 1151 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1152 | if (r < 0) |
1153 | return r; | |
718db961 | 1154 | |
df2d202e | 1155 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1156 | if (r < 0) |
ebcf1f97 | 1157 | return r; |
718db961 LP |
1158 | |
1159 | r = sd_bus_message_open_container(reply, 'a', "(usssoo)"); | |
1160 | if (r < 0) | |
ebcf1f97 | 1161 | return r; |
718db961 LP |
1162 | |
1163 | HASHMAP_FOREACH(j, m->jobs, i) { | |
1164 | _cleanup_free_ char *unit_path = NULL, *job_path = NULL; | |
1165 | ||
1166 | job_path = job_dbus_path(j); | |
1167 | if (!job_path) | |
ebcf1f97 | 1168 | return -ENOMEM; |
718db961 LP |
1169 | |
1170 | unit_path = unit_dbus_path(j->unit); | |
1171 | if (!unit_path) | |
ebcf1f97 | 1172 | return -ENOMEM; |
718db961 LP |
1173 | |
1174 | r = sd_bus_message_append( | |
1175 | reply, "(usssoo)", | |
1176 | j->id, | |
1302759d | 1177 | j->unit->id, |
718db961 | 1178 | job_type_to_string(j->type), |
1302759d | 1179 | job_state_to_string(j->state), |
718db961 LP |
1180 | job_path, |
1181 | unit_path); | |
cad45ba1 | 1182 | if (r < 0) |
ebcf1f97 | 1183 | return r; |
718db961 | 1184 | } |
5dd9014f | 1185 | |
718db961 LP |
1186 | r = sd_bus_message_close_container(reply); |
1187 | if (r < 0) | |
ebcf1f97 | 1188 | return r; |
5dd9014f | 1189 | |
9030ca46 | 1190 | return sd_bus_send(NULL, reply, NULL); |
718db961 | 1191 | } |
5dd9014f | 1192 | |
19070062 | 1193 | static int method_subscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1194 | Manager *m = userdata; |
1195 | int r; | |
5dd9014f | 1196 | |
718db961 LP |
1197 | assert(message); |
1198 | assert(m); | |
ea430986 | 1199 | |
283868e1 SW |
1200 | /* Anyone can call this method */ |
1201 | ||
8a188de9 | 1202 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1203 | if (r < 0) |
1204 | return r; | |
cad45ba1 | 1205 | |
19070062 | 1206 | if (sd_bus_message_get_bus(message) == m->api_bus) { |
8f8f05a9 LP |
1207 | |
1208 | /* Note that direct bus connection subscribe by | |
1209 | * default, we only track peers on the API bus here */ | |
1210 | ||
1211 | if (!m->subscribed) { | |
19070062 | 1212 | r = sd_bus_track_new(sd_bus_message_get_bus(message), &m->subscribed, NULL, NULL); |
8f8f05a9 LP |
1213 | if (r < 0) |
1214 | return r; | |
1215 | } | |
1216 | ||
1217 | r = sd_bus_track_add_sender(m->subscribed, message); | |
1218 | if (r < 0) | |
1219 | return r; | |
1220 | if (r == 0) | |
1221 | return sd_bus_error_setf(error, BUS_ERROR_ALREADY_SUBSCRIBED, "Client is already subscribed."); | |
1222 | } | |
ea430986 | 1223 | |
df2d202e | 1224 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1225 | } |
ea430986 | 1226 | |
19070062 | 1227 | static int method_unsubscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1228 | Manager *m = userdata; |
1229 | int r; | |
ea430986 | 1230 | |
718db961 LP |
1231 | assert(message); |
1232 | assert(m); | |
ea430986 | 1233 | |
283868e1 SW |
1234 | /* Anyone can call this method */ |
1235 | ||
8a188de9 | 1236 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1237 | if (r < 0) |
1238 | return r; | |
ea430986 | 1239 | |
19070062 | 1240 | if (sd_bus_message_get_bus(message) == m->api_bus) { |
8f8f05a9 LP |
1241 | r = sd_bus_track_remove_sender(m->subscribed, message); |
1242 | if (r < 0) | |
1243 | return r; | |
1244 | if (r == 0) | |
1245 | return sd_bus_error_setf(error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed."); | |
1246 | } | |
ea430986 | 1247 | |
df2d202e | 1248 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1249 | } |
ea430986 | 1250 | |
c0a1bfac | 1251 | static int dump_impl(sd_bus_message *message, void *userdata, sd_bus_error *error, int (*reply)(sd_bus_message *, char *)) { |
718db961 | 1252 | _cleanup_free_ char *dump = NULL; |
718db961 | 1253 | Manager *m = userdata; |
ebcf1f97 | 1254 | int r; |
ea430986 | 1255 | |
718db961 LP |
1256 | assert(message); |
1257 | assert(m); | |
ea430986 | 1258 | |
283868e1 SW |
1259 | /* Anyone can call this method */ |
1260 | ||
8a188de9 | 1261 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1262 | if (r < 0) |
1263 | return r; | |
ea430986 | 1264 | |
713f6f90 | 1265 | r = manager_get_dump_string(m, &dump); |
dacd6cee LP |
1266 | if (r < 0) |
1267 | return r; | |
a16e1123 | 1268 | |
c0a1bfac DT |
1269 | return reply(message, dump); |
1270 | } | |
1271 | ||
1272 | static int reply_dump(sd_bus_message *message, char *dump) { | |
df2d202e | 1273 | return sd_bus_reply_method_return(message, "s", dump); |
718db961 | 1274 | } |
cad45ba1 | 1275 | |
c0a1bfac DT |
1276 | static int method_dump(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1277 | return dump_impl(message, userdata, error, reply_dump); | |
1278 | } | |
1279 | ||
1280 | static int reply_dump_by_fd(sd_bus_message *message, char *dump) { | |
1281 | _cleanup_close_ int fd = -1; | |
1282 | ||
1283 | fd = acquire_data_fd(dump, strlen(dump), 0); | |
1284 | if (fd < 0) | |
1285 | return fd; | |
1286 | ||
1287 | return sd_bus_reply_method_return(message, "h", fd); | |
1288 | } | |
1289 | ||
1290 | static int method_dump_by_fd(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1291 | return dump_impl(message, userdata, error, reply_dump_by_fd); | |
1292 | } | |
1293 | ||
36b4a7ba ZJS |
1294 | static int method_refuse_snapshot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1295 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Support for snapshots has been removed."); | |
718db961 | 1296 | } |
cad45ba1 | 1297 | |
ae57dad3 LP |
1298 | static int verify_run_space(const char *message, sd_bus_error *error) { |
1299 | struct statvfs svfs; | |
1300 | uint64_t available; | |
1301 | ||
1302 | if (statvfs("/run/systemd", &svfs) < 0) | |
1303 | return sd_bus_error_set_errnof(error, errno, "Failed to statvfs(/run/systemd): %m"); | |
1304 | ||
1305 | available = (uint64_t) svfs.f_bfree * (uint64_t) svfs.f_bsize; | |
1306 | ||
1307 | if (available < RELOAD_DISK_SPACE_MIN) { | |
1308 | char fb_available[FORMAT_BYTES_MAX], fb_need[FORMAT_BYTES_MAX]; | |
1309 | return sd_bus_error_setf(error, | |
1310 | BUS_ERROR_DISK_FULL, | |
1311 | "%s, not enough space available on /run/systemd. " | |
1312 | "Currently, %s are free, but a safety buffer of %s is enforced.", | |
1313 | message, | |
1314 | format_bytes(fb_available, sizeof(fb_available), available), | |
1315 | format_bytes(fb_need, sizeof(fb_need), RELOAD_DISK_SPACE_MIN)); | |
1316 | } | |
1317 | ||
1318 | return 0; | |
1319 | } | |
1320 | ||
1321 | int verify_run_space_and_log(const char *message) { | |
4dae8ae6 | 1322 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
ae57dad3 LP |
1323 | int r; |
1324 | ||
1325 | r = verify_run_space(message, &error); | |
1326 | if (r < 0) | |
4ae25393 | 1327 | return log_error_errno(r, "%s", bus_error_message(&error, r)); |
ae57dad3 | 1328 | |
4ae25393 | 1329 | return 0; |
ae57dad3 LP |
1330 | } |
1331 | ||
19070062 | 1332 | static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1333 | Manager *m = userdata; |
1334 | int r; | |
6652a2b9 | 1335 | |
718db961 LP |
1336 | assert(message); |
1337 | assert(m); | |
6652a2b9 | 1338 | |
ae57dad3 LP |
1339 | r = verify_run_space("Refusing to reload", error); |
1340 | if (r < 0) | |
1341 | return r; | |
1342 | ||
1d22e906 | 1343 | r = mac_selinux_access_check(message, "reload", error); |
283868e1 SW |
1344 | if (r < 0) |
1345 | return r; | |
283868e1 | 1346 | |
1d22e906 | 1347 | r = bus_verify_reload_daemon_async(m, message, error); |
ebcf1f97 LP |
1348 | if (r < 0) |
1349 | return r; | |
1d22e906 LP |
1350 | if (r == 0) |
1351 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
6652a2b9 | 1352 | |
718db961 LP |
1353 | /* Instead of sending the reply back right away, we just |
1354 | * remember that we need to and then send it after the reload | |
1355 | * is finished. That way the caller knows when the reload | |
1356 | * finished. */ | |
6652a2b9 | 1357 | |
209de525 LP |
1358 | assert(!m->pending_reload_message); |
1359 | r = sd_bus_message_new_method_return(message, &m->pending_reload_message); | |
718db961 | 1360 | if (r < 0) |
ebcf1f97 | 1361 | return r; |
cad45ba1 | 1362 | |
af41e508 | 1363 | m->objective = MANAGER_RELOAD; |
6652a2b9 | 1364 | |
718db961 LP |
1365 | return 1; |
1366 | } | |
6652a2b9 | 1367 | |
19070062 | 1368 | static int method_reexecute(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1369 | Manager *m = userdata; |
ebcf1f97 | 1370 | int r; |
6652a2b9 | 1371 | |
718db961 LP |
1372 | assert(message); |
1373 | assert(m); | |
6652a2b9 | 1374 | |
ae57dad3 LP |
1375 | r = verify_run_space("Refusing to reexecute", error); |
1376 | if (r < 0) | |
1377 | return r; | |
1378 | ||
1d22e906 | 1379 | r = mac_selinux_access_check(message, "reload", error); |
283868e1 SW |
1380 | if (r < 0) |
1381 | return r; | |
283868e1 | 1382 | |
1d22e906 | 1383 | r = bus_verify_reload_daemon_async(m, message, error); |
ebcf1f97 LP |
1384 | if (r < 0) |
1385 | return r; | |
1d22e906 LP |
1386 | if (r == 0) |
1387 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
cad45ba1 | 1388 | |
718db961 LP |
1389 | /* We don't send a reply back here, the client should |
1390 | * just wait for us disconnecting. */ | |
6652a2b9 | 1391 | |
af41e508 | 1392 | m->objective = MANAGER_REEXECUTE; |
718db961 LP |
1393 | return 1; |
1394 | } | |
6652a2b9 | 1395 | |
19070062 | 1396 | static int method_exit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1397 | Manager *m = userdata; |
ebcf1f97 | 1398 | int r; |
6652a2b9 | 1399 | |
718db961 LP |
1400 | assert(message); |
1401 | assert(m); | |
6652a2b9 | 1402 | |
8a188de9 | 1403 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1404 | if (r < 0) |
1405 | return r; | |
cad45ba1 | 1406 | |
287419c1 AC |
1407 | /* Exit() (in contrast to SetExitCode()) is actually allowed even if |
1408 | * we are running on the host. It will fall back on reboot() in | |
1409 | * systemd-shutdown if it cannot do the exit() because it isn't a | |
1410 | * container. */ | |
6652a2b9 | 1411 | |
af41e508 | 1412 | m->objective = MANAGER_EXIT; |
6652a2b9 | 1413 | |
df2d202e | 1414 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1415 | } |
6652a2b9 | 1416 | |
19070062 | 1417 | static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1418 | Manager *m = userdata; |
ebcf1f97 | 1419 | int r; |
664f88a7 | 1420 | |
718db961 LP |
1421 | assert(message); |
1422 | assert(m); | |
cad45ba1 | 1423 | |
8a188de9 | 1424 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1425 | if (r < 0) |
1426 | return r; | |
664f88a7 | 1427 | |
463d0d15 | 1428 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1429 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers."); |
664f88a7 | 1430 | |
af41e508 | 1431 | m->objective = MANAGER_REBOOT; |
664f88a7 | 1432 | |
df2d202e | 1433 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1434 | } |
664f88a7 | 1435 | |
19070062 | 1436 | static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1437 | Manager *m = userdata; |
ebcf1f97 | 1438 | int r; |
50913bc0 | 1439 | |
718db961 LP |
1440 | assert(message); |
1441 | assert(m); | |
1137a57c | 1442 | |
8a188de9 | 1443 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1444 | if (r < 0) |
1445 | return r; | |
1137a57c | 1446 | |
463d0d15 | 1447 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1448 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers."); |
1137a57c | 1449 | |
af41e508 | 1450 | m->objective = MANAGER_POWEROFF; |
1137a57c | 1451 | |
df2d202e | 1452 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1453 | } |
1137a57c | 1454 | |
19070062 | 1455 | static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1456 | Manager *m = userdata; |
ebcf1f97 | 1457 | int r; |
1137a57c | 1458 | |
718db961 LP |
1459 | assert(message); |
1460 | assert(m); | |
8d0e38a2 | 1461 | |
8a188de9 | 1462 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1463 | if (r < 0) |
1464 | return r; | |
cad45ba1 | 1465 | |
463d0d15 | 1466 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1467 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Halt is only supported for system managers."); |
8d0e38a2 | 1468 | |
af41e508 | 1469 | m->objective = MANAGER_HALT; |
8d0e38a2 | 1470 | |
df2d202e | 1471 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1472 | } |
8d0e38a2 | 1473 | |
19070062 | 1474 | static int method_kexec(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1475 | Manager *m = userdata; |
ebcf1f97 | 1476 | int r; |
8d0e38a2 | 1477 | |
718db961 LP |
1478 | assert(message); |
1479 | assert(m); | |
c0576cd6 | 1480 | |
8a188de9 | 1481 | r = mac_selinux_access_check(message, "reboot", 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, "KExec is only supported for system managers."); |
c0576cd6 | 1487 | |
af41e508 | 1488 | m->objective = MANAGER_KEXEC; |
c0576cd6 | 1489 | |
df2d202e | 1490 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1491 | } |
c0576cd6 | 1492 | |
19070062 | 1493 | static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
87a19bfe | 1494 | _cleanup_free_ char *ri = NULL, *rt = NULL; |
718db961 LP |
1495 | const char *root, *init; |
1496 | Manager *m = userdata; | |
ae57dad3 LP |
1497 | struct statvfs svfs; |
1498 | uint64_t available; | |
718db961 | 1499 | int r; |
c0576cd6 | 1500 | |
718db961 LP |
1501 | assert(message); |
1502 | assert(m); | |
c0576cd6 | 1503 | |
ae57dad3 LP |
1504 | if (statvfs("/run/systemd", &svfs) < 0) |
1505 | return sd_bus_error_set_errnof(error, errno, "Failed to statvfs(/run/systemd): %m"); | |
1506 | ||
1507 | available = (uint64_t) svfs.f_bfree * (uint64_t) svfs.f_bsize; | |
1508 | ||
1509 | if (available < RELOAD_DISK_SPACE_MIN) { | |
1510 | char fb_available[FORMAT_BYTES_MAX], fb_need[FORMAT_BYTES_MAX]; | |
3fe91079 | 1511 | log_warning("Dangerously low amount of free space on /run/systemd, root switching operation might not complete successfully. " |
ae57dad3 LP |
1512 | "Currently, %s are free, but %s are suggested. Proceeding anyway.", |
1513 | format_bytes(fb_available, sizeof(fb_available), available), | |
1514 | format_bytes(fb_need, sizeof(fb_need), RELOAD_DISK_SPACE_MIN)); | |
1515 | } | |
1516 | ||
8a188de9 | 1517 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1518 | if (r < 0) |
1519 | return r; | |
c0576cd6 | 1520 | |
463d0d15 | 1521 | if (!MANAGER_IS_SYSTEM(m)) |
6ad3b2b6 | 1522 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Root switching is only supported by system manager."); |
c0576cd6 | 1523 | |
718db961 LP |
1524 | r = sd_bus_message_read(message, "ss", &root, &init); |
1525 | if (r < 0) | |
ebcf1f97 | 1526 | return r; |
c0576cd6 | 1527 | |
710028b4 LP |
1528 | if (isempty(root)) |
1529 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "New root directory may not be the empty string."); | |
1530 | if (!path_is_absolute(root)) | |
1531 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "New root path '%s' is not absolute.", root); | |
1532 | if (path_equal(root, "/")) | |
1533 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "New root directory cannot be the old root directory."); | |
c0576cd6 | 1534 | |
718db961 LP |
1535 | /* Safety check */ |
1536 | if (isempty(init)) { | |
710028b4 LP |
1537 | r = path_is_os_tree(root); |
1538 | if (r < 0) | |
1539 | return sd_bus_error_set_errnof(error, r, "Failed to determine whether root path '%s' contains an OS tree: %m", root); | |
1540 | if (r == 0) | |
1541 | 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 | 1542 | } else { |
710028b4 | 1543 | _cleanup_free_ char *chased = NULL; |
c0576cd6 | 1544 | |
718db961 | 1545 | if (!path_is_absolute(init)) |
710028b4 | 1546 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path to init binary '%s' not absolute.", init); |
c0576cd6 | 1547 | |
a5648b80 | 1548 | r = chase_symlinks(init, root, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &chased, NULL); |
710028b4 LP |
1549 | if (r < 0) |
1550 | return sd_bus_error_set_errnof(error, r, "Could not resolve init executable %s: %m", init); | |
1551 | ||
1552 | if (laccess(chased, X_OK) < 0) { | |
1553 | if (errno == EACCES) | |
1554 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Init binary %s is not executable.", init); | |
c0576cd6 | 1555 | |
710028b4 LP |
1556 | return sd_bus_error_set_errnof(error, r, "Could not check whether init binary %s is executable: %m", init); |
1557 | } | |
718db961 LP |
1558 | } |
1559 | ||
1560 | rt = strdup(root); | |
1561 | if (!rt) | |
ebcf1f97 | 1562 | return -ENOMEM; |
718db961 LP |
1563 | |
1564 | if (!isempty(init)) { | |
1565 | ri = strdup(init); | |
87a19bfe | 1566 | if (!ri) |
ebcf1f97 | 1567 | return -ENOMEM; |
718db961 | 1568 | } |
c0576cd6 | 1569 | |
87a19bfe YW |
1570 | free_and_replace(m->switch_root, rt); |
1571 | free_and_replace(m->switch_root_init, ri); | |
c0576cd6 | 1572 | |
af41e508 | 1573 | m->objective = MANAGER_SWITCH_ROOT; |
92b315df | 1574 | |
df2d202e | 1575 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1576 | } |
c0576cd6 | 1577 | |
19070062 | 1578 | static int method_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1579 | _cleanup_strv_free_ char **plus = NULL; |
1580 | Manager *m = userdata; | |
1581 | int r; | |
c0576cd6 | 1582 | |
718db961 LP |
1583 | assert(message); |
1584 | assert(m); | |
cad45ba1 | 1585 | |
8a188de9 | 1586 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1587 | if (r < 0) |
1588 | return r; | |
c0576cd6 | 1589 | |
718db961 LP |
1590 | r = sd_bus_message_read_strv(message, &plus); |
1591 | if (r < 0) | |
ebcf1f97 | 1592 | return r; |
718db961 | 1593 | if (!strv_env_is_valid(plus)) |
ebcf1f97 | 1594 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments"); |
c0576cd6 | 1595 | |
1d22e906 LP |
1596 | r = bus_verify_set_environment_async(m, message, error); |
1597 | if (r < 0) | |
1598 | return r; | |
1599 | if (r == 0) | |
1600 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1601 | ||
1ad6e8b3 | 1602 | r = manager_client_environment_modify(m, NULL, plus); |
718db961 | 1603 | if (r < 0) |
ebcf1f97 | 1604 | return r; |
c0576cd6 | 1605 | |
df2d202e | 1606 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1607 | } |
1608 | ||
19070062 | 1609 | static int method_unset_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1610 | _cleanup_strv_free_ char **minus = NULL; |
1611 | Manager *m = userdata; | |
1612 | int r; | |
1613 | ||
718db961 LP |
1614 | assert(message); |
1615 | assert(m); | |
1616 | ||
8a188de9 | 1617 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1618 | if (r < 0) |
1619 | return r; | |
c0576cd6 | 1620 | |
718db961 LP |
1621 | r = sd_bus_message_read_strv(message, &minus); |
1622 | if (r < 0) | |
ebcf1f97 | 1623 | return r; |
718db961 LP |
1624 | |
1625 | if (!strv_env_name_or_assignment_is_valid(minus)) | |
ebcf1f97 | 1626 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments"); |
718db961 | 1627 | |
1d22e906 LP |
1628 | r = bus_verify_set_environment_async(m, message, error); |
1629 | if (r < 0) | |
1630 | return r; | |
1631 | if (r == 0) | |
1632 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1633 | ||
1ad6e8b3 | 1634 | r = manager_client_environment_modify(m, minus, NULL); |
718db961 | 1635 | if (r < 0) |
ebcf1f97 | 1636 | return r; |
718db961 | 1637 | |
df2d202e | 1638 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1639 | } |
1640 | ||
19070062 | 1641 | static int method_unset_and_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1642 | _cleanup_strv_free_ char **minus = NULL, **plus = NULL; |
1643 | Manager *m = userdata; | |
1644 | int r; | |
1645 | ||
718db961 LP |
1646 | assert(message); |
1647 | assert(m); | |
1648 | ||
8a188de9 | 1649 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1650 | if (r < 0) |
1651 | return r; | |
718db961 | 1652 | |
eb6c7d20 | 1653 | r = sd_bus_message_read_strv(message, &minus); |
718db961 | 1654 | if (r < 0) |
ebcf1f97 | 1655 | return r; |
718db961 | 1656 | |
eb6c7d20 | 1657 | r = sd_bus_message_read_strv(message, &plus); |
718db961 | 1658 | if (r < 0) |
ebcf1f97 | 1659 | return r; |
718db961 | 1660 | |
718db961 | 1661 | if (!strv_env_name_or_assignment_is_valid(minus)) |
ebcf1f97 | 1662 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments"); |
eb6c7d20 ZJS |
1663 | if (!strv_env_is_valid(plus)) |
1664 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments"); | |
718db961 | 1665 | |
1d22e906 LP |
1666 | r = bus_verify_set_environment_async(m, message, error); |
1667 | if (r < 0) | |
1668 | return r; | |
1669 | if (r == 0) | |
1670 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1671 | ||
1ad6e8b3 | 1672 | r = manager_client_environment_modify(m, minus, plus); |
718db961 | 1673 | if (r < 0) |
ebcf1f97 | 1674 | return r; |
718db961 | 1675 | |
df2d202e | 1676 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1677 | } |
1678 | ||
287419c1 | 1679 | static int method_set_exit_code(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
287419c1 | 1680 | Manager *m = userdata; |
29206d46 | 1681 | uint8_t code; |
287419c1 AC |
1682 | int r; |
1683 | ||
1684 | assert(message); | |
1685 | assert(m); | |
1686 | ||
1687 | r = mac_selinux_access_check(message, "exit", error); | |
1688 | if (r < 0) | |
1689 | return r; | |
1690 | ||
1691 | r = sd_bus_message_read_basic(message, 'y', &code); | |
1692 | if (r < 0) | |
1693 | return r; | |
1694 | ||
463d0d15 | 1695 | if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0) |
287419c1 AC |
1696 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "ExitCode can only be set for user service managers or in containers."); |
1697 | ||
1698 | m->return_value = code; | |
1699 | ||
1700 | return sd_bus_reply_method_return(message, NULL); | |
1701 | } | |
1702 | ||
29206d46 LP |
1703 | static int method_lookup_dynamic_user_by_name(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1704 | Manager *m = userdata; | |
1705 | const char *name; | |
1706 | uid_t uid; | |
1707 | int r; | |
1708 | ||
1709 | assert(message); | |
1710 | assert(m); | |
1711 | ||
1712 | r = sd_bus_message_read_basic(message, 's', &name); | |
1713 | if (r < 0) | |
1714 | return r; | |
1715 | ||
1716 | if (!MANAGER_IS_SYSTEM(m)) | |
1717 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Dynamic users are only supported in the system instance."); | |
7a8867ab | 1718 | if (!valid_user_group_name(name, VALID_USER_RELAX)) |
29206d46 LP |
1719 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "User name invalid: %s", name); |
1720 | ||
1721 | r = dynamic_user_lookup_name(m, name, &uid); | |
1722 | if (r == -ESRCH) | |
1723 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, "Dynamic user %s does not exist.", name); | |
1724 | if (r < 0) | |
1725 | return r; | |
1726 | ||
1727 | return sd_bus_reply_method_return(message, "u", (uint32_t) uid); | |
1728 | } | |
1729 | ||
1730 | static int method_lookup_dynamic_user_by_uid(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1731 | _cleanup_free_ char *name = NULL; | |
1732 | Manager *m = userdata; | |
1733 | uid_t uid; | |
1734 | int r; | |
1735 | ||
1736 | assert(message); | |
1737 | assert(m); | |
1738 | ||
60d0a509 | 1739 | assert_cc(sizeof(uid_t) == sizeof(uint32_t)); |
29206d46 LP |
1740 | r = sd_bus_message_read_basic(message, 'u', &uid); |
1741 | if (r < 0) | |
1742 | return r; | |
1743 | ||
1744 | if (!MANAGER_IS_SYSTEM(m)) | |
1745 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Dynamic users are only supported in the system instance."); | |
1746 | if (!uid_is_valid(uid)) | |
1747 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "User ID invalid: " UID_FMT, uid); | |
1748 | ||
1749 | r = dynamic_user_lookup_uid(m, uid, &name); | |
1750 | if (r == -ESRCH) | |
1751 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, "Dynamic user ID " UID_FMT " does not exist.", uid); | |
1752 | if (r < 0) | |
1753 | return r; | |
1754 | ||
1755 | return sd_bus_reply_method_return(message, "s", name); | |
1756 | } | |
1757 | ||
f9bfa696 YW |
1758 | static int method_get_dynamic_users(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1759 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
1760 | Manager *m = userdata; | |
1761 | DynamicUser *d; | |
1762 | Iterator i; | |
1763 | int r; | |
1764 | ||
1765 | assert(message); | |
1766 | assert(m); | |
1767 | ||
1768 | assert_cc(sizeof(uid_t) == sizeof(uint32_t)); | |
1769 | ||
1770 | if (!MANAGER_IS_SYSTEM(m)) | |
1771 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Dynamic users are only supported in the system instance."); | |
1772 | ||
1773 | r = sd_bus_message_new_method_return(message, &reply); | |
1774 | if (r < 0) | |
1775 | return r; | |
1776 | ||
1777 | r = sd_bus_message_open_container(reply, 'a', "(us)"); | |
1778 | if (r < 0) | |
1779 | return r; | |
1780 | ||
1781 | HASHMAP_FOREACH(d, m->dynamic_users, i) { | |
1782 | uid_t uid; | |
1783 | ||
1784 | r = dynamic_user_current(d, &uid); | |
1785 | if (r == -EAGAIN) /* not realized yet? */ | |
1786 | continue; | |
1787 | if (r < 0) | |
105a1a36 | 1788 | return sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "Failed to look up a dynamic user."); |
f9bfa696 YW |
1789 | |
1790 | r = sd_bus_message_append(reply, "(us)", uid, d->name); | |
1791 | if (r < 0) | |
1792 | return r; | |
1793 | } | |
1794 | ||
1795 | r = sd_bus_message_close_container(reply); | |
1796 | if (r < 0) | |
1797 | return r; | |
1798 | ||
1799 | return sd_bus_send(NULL, reply, NULL); | |
1800 | } | |
1801 | ||
313fe66f | 1802 | static int list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error, char **states, char **patterns) { |
4afd3348 | 1803 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
718db961 LP |
1804 | Manager *m = userdata; |
1805 | UnitFileList *item; | |
1806 | Hashmap *h; | |
1807 | Iterator i; | |
1808 | int r; | |
1809 | ||
718db961 LP |
1810 | assert(message); |
1811 | assert(m); | |
1812 | ||
283868e1 SW |
1813 | /* Anyone can call this method */ |
1814 | ||
8a188de9 | 1815 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1816 | if (r < 0) |
1817 | return r; | |
718db961 | 1818 | |
df2d202e | 1819 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1820 | if (r < 0) |
ebcf1f97 | 1821 | return r; |
c0576cd6 | 1822 | |
d5099efc | 1823 | h = hashmap_new(&string_hash_ops); |
718db961 | 1824 | if (!h) |
ebcf1f97 | 1825 | return -ENOMEM; |
c0576cd6 | 1826 | |
313fe66f | 1827 | r = unit_file_get_list(m->unit_file_scope, NULL, h, states, patterns); |
ebcf1f97 | 1828 | if (r < 0) |
718db961 | 1829 | goto fail; |
718db961 LP |
1830 | |
1831 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); | |
ebcf1f97 | 1832 | if (r < 0) |
718db961 | 1833 | goto fail; |
718db961 LP |
1834 | |
1835 | HASHMAP_FOREACH(item, h, i) { | |
1836 | ||
1837 | r = sd_bus_message_append(reply, "(ss)", item->path, unit_file_state_to_string(item->state)); | |
ebcf1f97 | 1838 | if (r < 0) |
718db961 | 1839 | goto fail; |
718db961 | 1840 | } |
c0576cd6 | 1841 | |
718db961 | 1842 | unit_file_list_free(h); |
c0576cd6 | 1843 | |
718db961 LP |
1844 | r = sd_bus_message_close_container(reply); |
1845 | if (r < 0) | |
ebcf1f97 | 1846 | return r; |
8d0e38a2 | 1847 | |
9030ca46 | 1848 | return sd_bus_send(NULL, reply, NULL); |
99504dd4 | 1849 | |
718db961 LP |
1850 | fail: |
1851 | unit_file_list_free(h); | |
1852 | return r; | |
1853 | } | |
99504dd4 | 1854 | |
313fe66f | 1855 | static int method_list_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1856 | return list_unit_files_by_patterns(message, userdata, error, NULL, NULL); | |
1857 | } | |
1858 | ||
1859 | static int method_list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1860 | _cleanup_strv_free_ char **states = NULL; | |
1861 | _cleanup_strv_free_ char **patterns = NULL; | |
1862 | int r; | |
1863 | ||
1864 | r = sd_bus_message_read_strv(message, &states); | |
1865 | if (r < 0) | |
1866 | return r; | |
1867 | ||
1868 | r = sd_bus_message_read_strv(message, &patterns); | |
1869 | if (r < 0) | |
1870 | return r; | |
1871 | ||
1872 | return list_unit_files_by_patterns(message, userdata, error, states, patterns); | |
1873 | } | |
1874 | ||
19070062 | 1875 | static int method_get_unit_file_state(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1876 | Manager *m = userdata; |
1877 | const char *name; | |
1878 | UnitFileState state; | |
718db961 | 1879 | int r; |
99504dd4 | 1880 | |
718db961 LP |
1881 | assert(message); |
1882 | assert(m); | |
8e2af478 | 1883 | |
283868e1 SW |
1884 | /* Anyone can call this method */ |
1885 | ||
8a188de9 | 1886 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1887 | if (r < 0) |
1888 | return r; | |
8e2af478 | 1889 | |
718db961 LP |
1890 | r = sd_bus_message_read(message, "s", &name); |
1891 | if (r < 0) | |
ebcf1f97 | 1892 | return r; |
8e2af478 | 1893 | |
463d0d15 | 1894 | r = unit_file_get_state(m->unit_file_scope, NULL, name, &state); |
0ec0deaa LP |
1895 | if (r < 0) |
1896 | return r; | |
8e2af478 | 1897 | |
df2d202e | 1898 | return sd_bus_reply_method_return(message, "s", unit_file_state_to_string(state)); |
718db961 | 1899 | } |
8e2af478 | 1900 | |
19070062 | 1901 | static int method_get_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1902 | _cleanup_free_ char *default_target = NULL; |
1903 | Manager *m = userdata; | |
718db961 | 1904 | int r; |
c2756a68 | 1905 | |
718db961 LP |
1906 | assert(message); |
1907 | assert(m); | |
c2756a68 | 1908 | |
283868e1 SW |
1909 | /* Anyone can call this method */ |
1910 | ||
8a188de9 | 1911 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1912 | if (r < 0) |
1913 | return r; | |
c2756a68 | 1914 | |
463d0d15 | 1915 | r = unit_file_get_default(m->unit_file_scope, NULL, &default_target); |
718db961 | 1916 | if (r < 0) |
ebcf1f97 | 1917 | return r; |
c2756a68 | 1918 | |
df2d202e | 1919 | return sd_bus_reply_method_return(message, "s", default_target); |
718db961 | 1920 | } |
c2756a68 | 1921 | |
8f8f05a9 | 1922 | static int send_unit_files_changed(sd_bus *bus, void *userdata) { |
4afd3348 | 1923 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
1924 | int r; |
1925 | ||
1926 | assert(bus); | |
1927 | ||
151b9b96 | 1928 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged"); |
718db961 LP |
1929 | if (r < 0) |
1930 | return r; | |
1931 | ||
8f8f05a9 | 1932 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
1933 | } |
1934 | ||
af3d8113 ZJS |
1935 | /* Create an error reply, using the error information from changes[] |
1936 | * if possible, and fall back to generating an error from error code c. | |
1937 | * The error message only describes the first error. | |
1938 | * | |
1939 | * Coordinate with unit_file_dump_changes() in install.c. | |
1940 | */ | |
1941 | static int install_error( | |
1942 | sd_bus_error *error, | |
1943 | int c, | |
1944 | UnitFileChange *changes, | |
da6053d0 LP |
1945 | size_t n_changes) { |
1946 | ||
1947 | size_t i; | |
af3d8113 | 1948 | int r; |
8e20adca | 1949 | |
af3d8113 | 1950 | for (i = 0; i < n_changes; i++) |
637d6e5b | 1951 | |
af3d8113 | 1952 | switch(changes[i].type) { |
637d6e5b | 1953 | |
af3d8113 ZJS |
1954 | case 0 ... INT_MAX: |
1955 | continue; | |
637d6e5b | 1956 | |
af3d8113 ZJS |
1957 | case -EEXIST: |
1958 | if (changes[i].source) | |
1959 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, | |
1960 | "File %s already exists and is a symlink to %s.", | |
1961 | changes[i].path, changes[i].source); | |
1962 | else | |
1963 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, | |
1964 | "File %s already exists.", | |
1965 | changes[i].path); | |
1966 | goto found; | |
637d6e5b | 1967 | |
af3d8113 ZJS |
1968 | case -ERFKILL: |
1969 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, | |
1970 | "Unit file %s is masked.", changes[i].path); | |
1971 | goto found; | |
637d6e5b | 1972 | |
af3d8113 ZJS |
1973 | case -EADDRNOTAVAIL: |
1974 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_GENERATED, | |
1975 | "Unit %s is transient or generated.", changes[i].path); | |
1976 | goto found; | |
637d6e5b | 1977 | |
d7ceaf72 ZJS |
1978 | case -EUCLEAN: |
1979 | r = sd_bus_error_setf(error, BUS_ERROR_BAD_UNIT_SETTING, | |
1980 | "\"%s\" is not a valid unit name.", | |
1981 | changes[i].path); | |
1982 | goto found; | |
1983 | ||
af3d8113 ZJS |
1984 | case -ELOOP: |
1985 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_LINKED, | |
22683674 FB |
1986 | "Refusing to operate on alias name or linked unit file: %s", |
1987 | changes[i].path); | |
af3d8113 | 1988 | goto found; |
637d6e5b LP |
1989 | |
1990 | case -ENOENT: | |
22683674 FB |
1991 | r = sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, |
1992 | "Unit file %s does not exist.", changes[i].path); | |
637d6e5b LP |
1993 | goto found; |
1994 | ||
af3d8113 ZJS |
1995 | default: |
1996 | r = sd_bus_error_set_errnof(error, changes[i].type, "File %s: %m", changes[i].path); | |
1997 | goto found; | |
1998 | } | |
8e20adca | 1999 | |
637d6e5b LP |
2000 | r = c < 0 ? c : -EINVAL; |
2001 | ||
af3d8113 ZJS |
2002 | found: |
2003 | unit_file_changes_free(changes, n_changes); | |
2004 | return r; | |
8e20adca LP |
2005 | } |
2006 | ||
637d6e5b LP |
2007 | static int reply_unit_file_changes_and_free( |
2008 | Manager *m, | |
2009 | sd_bus_message *message, | |
2010 | int carries_install_info, | |
2011 | UnitFileChange *changes, | |
da6053d0 | 2012 | size_t n_changes, |
637d6e5b LP |
2013 | sd_bus_error *error) { |
2014 | ||
2015 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
2016 | bool bad = false, good = false; | |
da6053d0 | 2017 | size_t i; |
637d6e5b LP |
2018 | int r; |
2019 | ||
2020 | if (unit_file_changes_have_modification(changes, n_changes)) { | |
2021 | r = bus_foreach_bus(m, NULL, send_unit_files_changed, NULL); | |
2022 | if (r < 0) | |
2023 | log_debug_errno(r, "Failed to send UnitFilesChanged signal: %m"); | |
2024 | } | |
2025 | ||
2026 | r = sd_bus_message_new_method_return(message, &reply); | |
2027 | if (r < 0) | |
2028 | goto fail; | |
2029 | ||
2030 | if (carries_install_info >= 0) { | |
2031 | r = sd_bus_message_append(reply, "b", carries_install_info); | |
2032 | if (r < 0) | |
2033 | goto fail; | |
2034 | } | |
2035 | ||
2036 | r = sd_bus_message_open_container(reply, 'a', "(sss)"); | |
2037 | if (r < 0) | |
2038 | goto fail; | |
2039 | ||
2040 | for (i = 0; i < n_changes; i++) { | |
2041 | ||
2042 | if (changes[i].type < 0) { | |
2043 | bad = true; | |
2044 | continue; | |
2045 | } | |
2046 | ||
2047 | r = sd_bus_message_append( | |
2048 | reply, "(sss)", | |
2049 | unit_file_change_type_to_string(changes[i].type), | |
2050 | changes[i].path, | |
2051 | changes[i].source); | |
2052 | if (r < 0) | |
2053 | goto fail; | |
2054 | ||
2055 | good = true; | |
2056 | } | |
2057 | ||
2058 | /* If there was a failed change, and no successful change, then return the first failure as proper method call | |
2059 | * error. */ | |
2060 | if (bad && !good) | |
2061 | return install_error(error, 0, changes, n_changes); | |
2062 | ||
2063 | r = sd_bus_message_close_container(reply); | |
2064 | if (r < 0) | |
2065 | goto fail; | |
2066 | ||
2067 | unit_file_changes_free(changes, n_changes); | |
2068 | return sd_bus_send(NULL, reply, NULL); | |
2069 | ||
2070 | fail: | |
2071 | unit_file_changes_free(changes, n_changes); | |
2072 | return r; | |
2073 | } | |
2074 | ||
718db961 | 2075 | static int method_enable_unit_files_generic( |
718db961 | 2076 | sd_bus_message *message, |
d309c1c3 | 2077 | Manager *m, |
da6053d0 | 2078 | int (*call)(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, size_t *n_changes), |
ebcf1f97 LP |
2079 | bool carries_install_info, |
2080 | sd_bus_error *error) { | |
718db961 LP |
2081 | |
2082 | _cleanup_strv_free_ char **l = NULL; | |
2083 | UnitFileChange *changes = NULL; | |
da6053d0 | 2084 | size_t n_changes = 0; |
b3796dd8 | 2085 | UnitFileFlags flags; |
83654007 | 2086 | int r; |
718db961 | 2087 | |
718db961 LP |
2088 | assert(message); |
2089 | assert(m); | |
cad45ba1 | 2090 | |
718db961 LP |
2091 | r = sd_bus_message_read_strv(message, &l); |
2092 | if (r < 0) | |
ebcf1f97 | 2093 | return r; |
90bb85e1 | 2094 | |
83654007 LB |
2095 | if (sd_bus_message_is_method_call(message, NULL, "EnableUnitFilesWithFlags")) { |
2096 | uint64_t raw_flags; | |
d309c1c3 | 2097 | |
83654007 LB |
2098 | r = sd_bus_message_read(message, "t", &raw_flags); |
2099 | if (r < 0) | |
2100 | return r; | |
2101 | if ((raw_flags & ~_UNIT_FILE_FLAGS_MASK_PUBLIC) != 0) | |
2102 | return -EINVAL; | |
2103 | flags = raw_flags; | |
2104 | } else { | |
2105 | int runtime, force; | |
2106 | ||
2107 | r = sd_bus_message_read(message, "bb", &runtime, &force); | |
2108 | if (r < 0) | |
2109 | return r; | |
2110 | flags = unit_file_bools_to_flags(runtime, force); | |
2111 | } | |
b3796dd8 | 2112 | |
1d22e906 LP |
2113 | r = bus_verify_manage_unit_files_async(m, message, error); |
2114 | if (r < 0) | |
2115 | return r; | |
2116 | if (r == 0) | |
2117 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2118 | ||
b3796dd8 | 2119 | r = call(m->unit_file_scope, flags, NULL, l, &changes, &n_changes); |
af3d8113 ZJS |
2120 | if (r < 0) |
2121 | return install_error(error, r, changes, n_changes); | |
718db961 | 2122 | |
637d6e5b | 2123 | return reply_unit_file_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes, error); |
718db961 | 2124 | } |
c87eba54 | 2125 | |
83654007 LB |
2126 | static int method_enable_unit_files_with_flags(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2127 | return method_enable_unit_files_generic(message, userdata, unit_file_enable, true, error); | |
2128 | } | |
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; | |
83654007 | 2207 | UnitFileFlags flags; |
da6053d0 | 2208 | size_t n_changes = 0; |
83654007 | 2209 | int r; |
718db961 | 2210 | |
718db961 LP |
2211 | assert(message); |
2212 | assert(m); | |
2213 | ||
df823e23 | 2214 | r = sd_bus_message_read_strv(message, &l); |
ebcf1f97 LP |
2215 | if (r < 0) |
2216 | return r; | |
718db961 | 2217 | |
83654007 LB |
2218 | if (sd_bus_message_is_method_call(message, NULL, "DisableUnitFilesWithFlags")) { |
2219 | uint64_t raw_flags; | |
2220 | ||
2221 | r = sd_bus_message_read(message, "t", &raw_flags); | |
2222 | if (r < 0) | |
2223 | return r; | |
2224 | if ((raw_flags & ~_UNIT_FILE_FLAGS_MASK_PUBLIC) != 0 || | |
2225 | FLAGS_SET(raw_flags, UNIT_FILE_FORCE)) | |
2226 | return -EINVAL; | |
2227 | flags = raw_flags; | |
2228 | } else { | |
2229 | int runtime; | |
2230 | ||
2231 | r = sd_bus_message_read(message, "b", &runtime); | |
2232 | if (r < 0) | |
2233 | return r; | |
2234 | flags = unit_file_bools_to_flags(runtime, false); | |
2235 | } | |
718db961 | 2236 | |
1d22e906 LP |
2237 | r = bus_verify_manage_unit_files_async(m, message, error); |
2238 | if (r < 0) | |
2239 | return r; | |
2240 | if (r == 0) | |
2241 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2242 | ||
83654007 | 2243 | r = call(m->unit_file_scope, flags, NULL, l, &changes, &n_changes); |
af3d8113 ZJS |
2244 | if (r < 0) |
2245 | return install_error(error, r, changes, n_changes); | |
718db961 | 2246 | |
637d6e5b | 2247 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
718db961 | 2248 | } |
ea430986 | 2249 | |
83654007 LB |
2250 | static int method_disable_unit_files_with_flags(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2251 | return method_disable_unit_files_generic(message, userdata, unit_file_disable, error); | |
2252 | } | |
2253 | ||
19070062 | 2254 | static int method_disable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2255 | return method_disable_unit_files_generic(message, userdata, unit_file_disable, error); |
ea430986 LP |
2256 | } |
2257 | ||
19070062 | 2258 | static int method_unmask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2259 | return method_disable_unit_files_generic(message, userdata, unit_file_unmask, error); |
718db961 LP |
2260 | } |
2261 | ||
344ca755 LP |
2262 | static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2263 | _cleanup_strv_free_ char **l = NULL; | |
2264 | UnitFileChange *changes = NULL; | |
da6053d0 | 2265 | size_t n_changes = 0; |
344ca755 LP |
2266 | Manager *m = userdata; |
2267 | int r; | |
2268 | ||
2269 | assert(message); | |
2270 | assert(m); | |
2271 | ||
2272 | r = sd_bus_message_read_strv(message, &l); | |
2273 | if (r < 0) | |
2274 | return r; | |
2275 | ||
2276 | r = bus_verify_manage_unit_files_async(m, message, error); | |
2277 | if (r < 0) | |
2278 | return r; | |
2279 | if (r == 0) | |
2280 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2281 | ||
2282 | r = unit_file_revert(m->unit_file_scope, NULL, l, &changes, &n_changes); | |
af3d8113 ZJS |
2283 | if (r < 0) |
2284 | return install_error(error, r, changes, n_changes); | |
344ca755 | 2285 | |
637d6e5b | 2286 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
344ca755 LP |
2287 | } |
2288 | ||
19070062 | 2289 | static int method_set_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 2290 | UnitFileChange *changes = NULL; |
da6053d0 | 2291 | size_t n_changes = 0; |
718db961 | 2292 | Manager *m = userdata; |
718db961 LP |
2293 | const char *name; |
2294 | int force, r; | |
2295 | ||
718db961 LP |
2296 | assert(message); |
2297 | assert(m); | |
2298 | ||
1d22e906 | 2299 | r = mac_selinux_access_check(message, "enable", error); |
283868e1 SW |
2300 | if (r < 0) |
2301 | return r; | |
283868e1 | 2302 | |
1d22e906 | 2303 | r = sd_bus_message_read(message, "sb", &name, &force); |
ebcf1f97 LP |
2304 | if (r < 0) |
2305 | return r; | |
718db961 | 2306 | |
1d22e906 | 2307 | r = bus_verify_manage_unit_files_async(m, message, error); |
718db961 | 2308 | if (r < 0) |
ebcf1f97 | 2309 | return r; |
1d22e906 LP |
2310 | if (r == 0) |
2311 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
718db961 | 2312 | |
b3796dd8 | 2313 | r = unit_file_set_default(m->unit_file_scope, force ? UNIT_FILE_FORCE : 0, NULL, name, &changes, &n_changes); |
af3d8113 ZJS |
2314 | if (r < 0) |
2315 | return install_error(error, r, changes, n_changes); | |
718db961 | 2316 | |
637d6e5b | 2317 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
718db961 LP |
2318 | } |
2319 | ||
19070062 | 2320 | static int method_preset_all_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
d309c1c3 | 2321 | UnitFileChange *changes = NULL; |
da6053d0 | 2322 | size_t n_changes = 0; |
d309c1c3 LP |
2323 | Manager *m = userdata; |
2324 | UnitFilePresetMode mm; | |
d309c1c3 | 2325 | const char *mode; |
b3796dd8 | 2326 | UnitFileFlags flags; |
d309c1c3 LP |
2327 | int force, runtime, r; |
2328 | ||
d309c1c3 LP |
2329 | assert(message); |
2330 | assert(m); | |
2331 | ||
8a188de9 | 2332 | r = mac_selinux_access_check(message, "enable", error); |
d309c1c3 LP |
2333 | if (r < 0) |
2334 | return r; | |
2335 | ||
2336 | r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force); | |
2337 | if (r < 0) | |
2338 | return r; | |
2339 | ||
b3796dd8 JS |
2340 | flags = unit_file_bools_to_flags(runtime, force); |
2341 | ||
d309c1c3 LP |
2342 | if (isempty(mode)) |
2343 | mm = UNIT_FILE_PRESET_FULL; | |
2344 | else { | |
2345 | mm = unit_file_preset_mode_from_string(mode); | |
2346 | if (mm < 0) | |
2347 | return -EINVAL; | |
2348 | } | |
2349 | ||
1d22e906 LP |
2350 | r = bus_verify_manage_unit_files_async(m, message, error); |
2351 | if (r < 0) | |
2352 | return r; | |
2353 | if (r == 0) | |
2354 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2355 | ||
b3796dd8 | 2356 | r = unit_file_preset_all(m->unit_file_scope, flags, NULL, mm, &changes, &n_changes); |
af3d8113 ZJS |
2357 | if (r < 0) |
2358 | return install_error(error, r, changes, n_changes); | |
d309c1c3 | 2359 | |
637d6e5b | 2360 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
d309c1c3 LP |
2361 | } |
2362 | ||
19070062 | 2363 | static int method_add_dependency_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
e94937df LN |
2364 | _cleanup_strv_free_ char **l = NULL; |
2365 | Manager *m = userdata; | |
2366 | UnitFileChange *changes = NULL; | |
da6053d0 | 2367 | size_t n_changes = 0; |
e94937df | 2368 | int runtime, force, r; |
596fc263 | 2369 | char *target, *type; |
e94937df | 2370 | UnitDependency dep; |
b3796dd8 | 2371 | UnitFileFlags flags; |
e94937df | 2372 | |
e94937df LN |
2373 | assert(message); |
2374 | assert(m); | |
2375 | ||
2376 | r = bus_verify_manage_unit_files_async(m, message, error); | |
2377 | if (r < 0) | |
2378 | return r; | |
2379 | if (r == 0) | |
2380 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2381 | ||
2382 | r = sd_bus_message_read_strv(message, &l); | |
2383 | if (r < 0) | |
2384 | return r; | |
2385 | ||
2386 | r = sd_bus_message_read(message, "ssbb", &target, &type, &runtime, &force); | |
2387 | if (r < 0) | |
2388 | return r; | |
2389 | ||
b3796dd8 JS |
2390 | flags = unit_file_bools_to_flags(runtime, force); |
2391 | ||
e94937df LN |
2392 | dep = unit_dependency_from_string(type); |
2393 | if (dep < 0) | |
2394 | return -EINVAL; | |
2395 | ||
b3796dd8 | 2396 | r = unit_file_add_dependency(m->unit_file_scope, flags, NULL, l, target, dep, &changes, &n_changes); |
af3d8113 ZJS |
2397 | if (r < 0) |
2398 | return install_error(error, r, changes, n_changes); | |
e94937df | 2399 | |
637d6e5b | 2400 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
e94937df LN |
2401 | } |
2402 | ||
3b3557c4 JS |
2403 | static int method_get_unit_file_links(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2404 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
2405 | UnitFileChange *changes = NULL; | |
da6053d0 | 2406 | size_t n_changes = 0, i; |
3b3557c4 JS |
2407 | UnitFileFlags flags; |
2408 | const char *name; | |
2409 | char **p; | |
2410 | int runtime, r; | |
2411 | ||
2412 | r = sd_bus_message_read(message, "sb", &name, &runtime); | |
2413 | if (r < 0) | |
2414 | return r; | |
2415 | ||
2416 | r = sd_bus_message_new_method_return(message, &reply); | |
2417 | if (r < 0) | |
2418 | return r; | |
2419 | ||
2420 | r = sd_bus_message_open_container(reply, SD_BUS_TYPE_ARRAY, "s"); | |
2421 | if (r < 0) | |
2422 | return r; | |
2423 | ||
2424 | p = STRV_MAKE(name); | |
2425 | flags = UNIT_FILE_DRY_RUN | | |
2426 | (runtime ? UNIT_FILE_RUNTIME : 0); | |
2427 | ||
2428 | r = unit_file_disable(UNIT_FILE_SYSTEM, flags, NULL, p, &changes, &n_changes); | |
2429 | if (r < 0) | |
2430 | return log_error_errno(r, "Failed to get file links for %s: %m", name); | |
2431 | ||
2432 | for (i = 0; i < n_changes; i++) | |
2433 | if (changes[i].type == UNIT_FILE_UNLINK) { | |
2434 | r = sd_bus_message_append(reply, "s", changes[i].path); | |
2435 | if (r < 0) | |
2436 | return r; | |
2437 | } | |
2438 | ||
2439 | r = sd_bus_message_close_container(reply); | |
2440 | if (r < 0) | |
2441 | return r; | |
2442 | ||
2443 | return sd_bus_send(NULL, reply, NULL); | |
2444 | } | |
2445 | ||
15ea79f8 LP |
2446 | static int method_get_job_waiting(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2447 | Manager *m = userdata; | |
2448 | uint32_t id; | |
2449 | Job *j; | |
2450 | int r; | |
2451 | ||
2452 | assert(message); | |
2453 | assert(m); | |
2454 | ||
2455 | r = sd_bus_message_read(message, "u", &id); | |
2456 | if (r < 0) | |
2457 | return r; | |
2458 | ||
2459 | j = manager_get_job(m, id); | |
2460 | if (!j) | |
2461 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); | |
2462 | ||
2463 | return bus_job_method_get_waiting_jobs(message, j, error); | |
2464 | } | |
2465 | ||
c20076a8 LP |
2466 | static int method_abandon_scope(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2467 | Manager *m = userdata; | |
2468 | const char *name; | |
2469 | Unit *u; | |
2470 | int r; | |
2471 | ||
2472 | assert(message); | |
2473 | assert(m); | |
2474 | ||
2475 | r = sd_bus_message_read(message, "s", &name); | |
2476 | if (r < 0) | |
2477 | return r; | |
2478 | ||
2479 | r = bus_get_unit_by_name(m, message, name, &u, error); | |
2480 | if (r < 0) | |
2481 | return r; | |
2482 | ||
2483 | if (u->type != UNIT_SCOPE) | |
2484 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit '%s' is not a scope unit, refusing.", name); | |
2485 | ||
2486 | return bus_scope_method_abandon(message, u, error); | |
2487 | } | |
2488 | ||
0bb007f7 FB |
2489 | static int method_set_show_status(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2490 | Manager *m = userdata; | |
2491 | ShowStatus mode = _SHOW_STATUS_INVALID; | |
2492 | const char *t; | |
2493 | int r; | |
2494 | ||
2495 | assert(m); | |
2496 | assert(message); | |
2497 | ||
2498 | r = sd_bus_message_read(message, "s", &t); | |
2499 | if (r < 0) | |
2500 | return r; | |
2501 | ||
2502 | if (!isempty(t)) { | |
2503 | mode = show_status_from_string(t); | |
2504 | if (mode < 0) | |
2505 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid show status '%s'", t); | |
2506 | } | |
2507 | ||
43bba15a | 2508 | manager_override_show_status(m, mode, "bus"); |
0bb007f7 FB |
2509 | |
2510 | return sd_bus_reply_method_return(message, NULL); | |
2511 | } | |
2512 | ||
718db961 LP |
2513 | const sd_bus_vtable bus_manager_vtable[] = { |
2514 | SD_BUS_VTABLE_START(0), | |
2515 | ||
556089dc LP |
2516 | SD_BUS_PROPERTY("Version", "s", property_get_version, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
2517 | SD_BUS_PROPERTY("Features", "s", property_get_features, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
2518 | SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
7452394e | 2519 | SD_BUS_PROPERTY("Architecture", "s", property_get_architecture, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 2520 | SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
9f9f0342 LP |
2521 | BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FIRMWARE]), SD_BUS_VTABLE_PROPERTY_CONST), |
2522 | BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_LOADER]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2523 | BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_KERNEL]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2524 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2525 | BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_USERSPACE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2526 | BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2527 | BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2528 | BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2529 | BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2530 | BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2531 | BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2532 | BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
665a9774 YW |
2533 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDSecurityStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_SECURITY_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
2534 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDSecurityFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_SECURITY_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2535 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_GENERATORS_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2536 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_GENERATORS_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2537 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2538 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
25141692 LP |
2539 | SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level, property_set_log_level, 0, 0), |
2540 | SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target, property_set_log_target, 0, 0), | |
3ff52e8f YW |
2541 | SD_BUS_PROPERTY("NNames", "u", property_get_hashmap_size, offsetof(Manager, units), 0), |
2542 | SD_BUS_PROPERTY("NFailedUnits", "u", property_get_set_size, offsetof(Manager, failed_units), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
2543 | SD_BUS_PROPERTY("NJobs", "u", property_get_hashmap_size, offsetof(Manager, jobs), 0), | |
718db961 LP |
2544 | SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_installed_jobs), 0), |
2545 | SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_failed_jobs), 0), | |
2546 | SD_BUS_PROPERTY("Progress", "d", property_get_progress, 0, 0), | |
1ad6e8b3 | 2547 | SD_BUS_PROPERTY("Environment", "as", property_get_environment, 0, 0), |
556089dc | 2548 | SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool, offsetof(Manager, confirm_spawn), SD_BUS_VTABLE_PROPERTY_CONST), |
52d2566a | 2549 | SD_BUS_PROPERTY("ShowStatus", "b", property_get_show_status, 0, 0), |
a3c4eb07 | 2550 | SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.search_path), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
2551 | SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST), |
2552 | SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST), | |
986935cf FB |
2553 | SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", property_get_runtime_watchdog, property_set_runtime_watchdog, 0, 0), |
2554 | SD_BUS_WRITABLE_PROPERTY("RebootWatchdogUSec", "t", property_get_reboot_watchdog, property_set_reboot_watchdog, 0, 0), | |
65224c1d | 2555 | /* The following item is an obsolete alias */ |
986935cf FB |
2556 | SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", property_get_reboot_watchdog, property_set_reboot_watchdog, 0, SD_BUS_VTABLE_HIDDEN), |
2557 | SD_BUS_WRITABLE_PROPERTY("KExecWatchdogUSec", "t", property_get_kexec_watchdog, property_set_kexec_watchdog, 0, 0), | |
2a12e32e | 2558 | SD_BUS_WRITABLE_PROPERTY("ServiceWatchdogs", "b", bus_property_get_bool, bus_property_set_bool, offsetof(Manager, service_watchdogs), 0), |
b272b74d | 2559 | SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Manager, cgroup_root), 0), |
f755e3b7 | 2560 | SD_BUS_PROPERTY("SystemState", "s", property_get_system_state, 0, 0), |
287419c1 | 2561 | SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned, offsetof(Manager, return_value), 0), |
670a3efe EV |
2562 | SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec, offsetof(Manager, default_timer_accuracy_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
2563 | SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec, offsetof(Manager, default_timeout_start_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
2564 | SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec, offsetof(Manager, default_timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
dc653bf4 | 2565 | SD_BUS_PROPERTY("DefaultTimeoutAbortUSec", "t", property_get_default_timeout_abort_usec, 0, 0), |
670a3efe | 2566 | SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec, offsetof(Manager, default_restart_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
c075f5fc YW |
2567 | SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST), |
2568 | /* The following two items are obsolete alias */ | |
2569 | SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
2570 | 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 |
2571 | SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned, offsetof(Manager, default_start_limit_burst), SD_BUS_VTABLE_PROPERTY_CONST), |
2572 | SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool, offsetof(Manager, default_cpu_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2573 | SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool, offsetof(Manager, default_blockio_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2574 | SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, default_memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2575 | SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool, offsetof(Manager, default_tasks_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
97eb4231 | 2576 | SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2577 | SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2578 | SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2579 | SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2580 | SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2581 | SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2582 | SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2583 | SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2584 | SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2585 | SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2586 | SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2587 | SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2588 | SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2589 | SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2590 | SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2591 | SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2592 | SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2593 | SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2594 | SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2595 | SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2596 | SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2597 | SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2598 | SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2599 | SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2600 | SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2601 | SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2602 | SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2603 | SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2604 | SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2605 | SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2606 | SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2607 | SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
3a0f06c4 | 2608 | SD_BUS_PROPERTY("DefaultTasksMax", "t", bus_property_get_tasks_max, offsetof(Manager, default_tasks_max), 0), |
eed67a30 | 2609 | SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
afcfaa69 | 2610 | SD_BUS_PROPERTY("DefaultOOMPolicy", "s", bus_property_get_oom_policy, offsetof(Manager, default_oom_policy), SD_BUS_VTABLE_PROPERTY_CONST), |
718db961 | 2611 | |
dad97f04 ZJS |
2612 | SD_BUS_METHOD_WITH_NAMES("GetUnit", |
2613 | "s", | |
2614 | SD_BUS_PARAM(name), | |
2615 | "o", | |
2616 | SD_BUS_PARAM(unit), | |
2617 | method_get_unit, | |
2618 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2619 | SD_BUS_METHOD_WITH_NAMES("GetUnitByPID", | |
2620 | "u", | |
2621 | SD_BUS_PARAM(pid), | |
2622 | "o", | |
2623 | SD_BUS_PARAM(unit), | |
2624 | method_get_unit_by_pid, | |
2625 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2626 | SD_BUS_METHOD_WITH_NAMES("GetUnitByInvocationID", | |
2627 | "ay", | |
2628 | SD_BUS_PARAM(invocation_id), | |
2629 | "o", | |
2630 | SD_BUS_PARAM(unit), | |
2631 | method_get_unit_by_invocation_id, | |
2632 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2633 | SD_BUS_METHOD_WITH_NAMES("GetUnitByControlGroup", | |
2634 | "s", | |
2635 | SD_BUS_PARAM(cgroup), | |
2636 | "o", | |
2637 | SD_BUS_PARAM(unit), | |
2638 | method_get_unit_by_control_group, | |
2639 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2640 | SD_BUS_METHOD_WITH_NAMES("LoadUnit", | |
2641 | "s", | |
2642 | SD_BUS_PARAM(name), | |
2643 | "o", | |
2644 | SD_BUS_PARAM(unit), | |
2645 | method_load_unit, | |
2646 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2647 | SD_BUS_METHOD_WITH_NAMES("StartUnit", | |
2648 | "ss", | |
2649 | SD_BUS_PARAM(name) | |
2650 | SD_BUS_PARAM(mode), | |
2651 | "o", | |
2652 | SD_BUS_PARAM(job), | |
2653 | method_start_unit, | |
2654 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2655 | SD_BUS_METHOD_WITH_NAMES("StartUnitReplace", | |
2656 | "sss", | |
2657 | SD_BUS_PARAM(old_unit) | |
2658 | SD_BUS_PARAM(new_unit) | |
2659 | SD_BUS_PARAM(mode), | |
2660 | "o", | |
2661 | SD_BUS_PARAM(job), | |
2662 | method_start_unit_replace, | |
2663 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2664 | SD_BUS_METHOD_WITH_NAMES("StopUnit", | |
2665 | "ss", | |
2666 | SD_BUS_PARAM(name) | |
2667 | SD_BUS_PARAM(mode), | |
2668 | "o", | |
2669 | SD_BUS_PARAM(job), | |
2670 | method_stop_unit, | |
2671 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2672 | SD_BUS_METHOD_WITH_NAMES("ReloadUnit", | |
2673 | "ss", | |
2674 | SD_BUS_PARAM(name) | |
2675 | SD_BUS_PARAM(mode), | |
2676 | "o", | |
2677 | SD_BUS_PARAM(job), | |
2678 | method_reload_unit, | |
2679 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2680 | SD_BUS_METHOD_WITH_NAMES("RestartUnit", | |
2681 | "ss", | |
2682 | SD_BUS_PARAM(name) | |
2683 | SD_BUS_PARAM(mode), | |
2684 | "o", | |
2685 | SD_BUS_PARAM(job), | |
2686 | method_restart_unit, | |
2687 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2688 | SD_BUS_METHOD_WITH_NAMES("TryRestartUnit", | |
2689 | "ss", | |
2690 | SD_BUS_PARAM(name) | |
2691 | SD_BUS_PARAM(mode), | |
2692 | "o", | |
2693 | SD_BUS_PARAM(job), | |
2694 | method_try_restart_unit, | |
2695 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2696 | SD_BUS_METHOD_WITH_NAMES("ReloadOrRestartUnit", | |
2697 | "ss", | |
2698 | SD_BUS_PARAM(name) | |
2699 | SD_BUS_PARAM(mode), | |
2700 | "o", | |
2701 | SD_BUS_PARAM(job), | |
2702 | method_reload_or_restart_unit, | |
2703 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2704 | SD_BUS_METHOD_WITH_NAMES("ReloadOrTryRestartUnit", | |
2705 | "ss", | |
2706 | SD_BUS_PARAM(name) | |
2707 | SD_BUS_PARAM(mode), | |
2708 | "o", | |
2709 | SD_BUS_PARAM(job), | |
2710 | method_reload_or_try_restart_unit, | |
2711 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2712 | SD_BUS_METHOD_WITH_NAMES("EnqueueUnitJob", | |
2713 | "sss", | |
2714 | SD_BUS_PARAM(name) | |
2715 | SD_BUS_PARAM(job_type) | |
2716 | SD_BUS_PARAM(job_mode), | |
2717 | "uososa(uosos)", | |
2718 | SD_BUS_PARAM(job_id) | |
2719 | SD_BUS_PARAM(job_path) | |
2720 | SD_BUS_PARAM(unit_id) | |
2721 | SD_BUS_PARAM(unit_path) | |
2722 | SD_BUS_PARAM(job_type) | |
2723 | SD_BUS_PARAM(affected_jobs), | |
2724 | method_enqueue_unit_job, | |
2725 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2726 | SD_BUS_METHOD_WITH_NAMES("KillUnit", | |
2727 | "ssi", | |
2728 | SD_BUS_PARAM(name) | |
2729 | SD_BUS_PARAM(whom) | |
2730 | SD_BUS_PARAM(signal), | |
2731 | NULL,, | |
2732 | method_kill_unit, | |
2733 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2734 | SD_BUS_METHOD_WITH_NAMES("CleanUnit", | |
2735 | "sas", | |
2736 | SD_BUS_PARAM(name) | |
2737 | SD_BUS_PARAM(mask), | |
2738 | NULL,, | |
2739 | method_clean_unit, | |
2740 | SD_BUS_VTABLE_UNPRIVILEGED), | |
d9e45bc3 MS |
2741 | SD_BUS_METHOD_WITH_NAMES("FreezeUnit", |
2742 | "s", | |
2743 | SD_BUS_PARAM(name), | |
2744 | NULL,, | |
2745 | method_freeze_unit, | |
2746 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2747 | SD_BUS_METHOD_WITH_NAMES("ThawUnit", | |
2748 | "s", | |
2749 | SD_BUS_PARAM(name), | |
2750 | NULL,, | |
2751 | method_thaw_unit, | |
2752 | SD_BUS_VTABLE_UNPRIVILEGED), | |
dad97f04 ZJS |
2753 | SD_BUS_METHOD_WITH_NAMES("ResetFailedUnit", |
2754 | "s", | |
2755 | SD_BUS_PARAM(name), | |
2756 | NULL,, | |
2757 | method_reset_failed_unit, | |
2758 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2759 | SD_BUS_METHOD_WITH_NAMES("SetUnitProperties", | |
2760 | "sba(sv)", | |
2761 | SD_BUS_PARAM(name) | |
2762 | SD_BUS_PARAM(runtime) | |
2763 | SD_BUS_PARAM(properties), | |
2764 | NULL,, | |
2765 | method_set_unit_properties, | |
2766 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2767 | SD_BUS_METHOD_WITH_NAMES("RefUnit", | |
2768 | "s", | |
2769 | SD_BUS_PARAM(name), | |
2770 | NULL,, | |
2771 | method_ref_unit, | |
2772 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2773 | SD_BUS_METHOD_WITH_NAMES("UnrefUnit", | |
2774 | "s", | |
2775 | SD_BUS_PARAM(name), | |
2776 | NULL,, | |
2777 | method_unref_unit, | |
2778 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2779 | SD_BUS_METHOD_WITH_NAMES("StartTransientUnit", | |
2780 | "ssa(sv)a(sa(sv))", | |
2781 | SD_BUS_PARAM(name) | |
2782 | SD_BUS_PARAM(mode) | |
2783 | SD_BUS_PARAM(properties) | |
2784 | SD_BUS_PARAM(aux), | |
2785 | "o", | |
2786 | SD_BUS_PARAM(job), | |
2787 | method_start_transient_unit, | |
2788 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2789 | SD_BUS_METHOD_WITH_NAMES("GetUnitProcesses", | |
2790 | "s", | |
2791 | SD_BUS_PARAM(name), | |
2792 | "a(sus)", | |
2793 | SD_BUS_PARAM(processes), | |
2794 | method_get_unit_processes, | |
2795 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2796 | SD_BUS_METHOD_WITH_NAMES("AttachProcessesToUnit", | |
2797 | "ssau", | |
2798 | SD_BUS_PARAM(unit_name) | |
2799 | SD_BUS_PARAM(subcgroup) | |
2800 | SD_BUS_PARAM(pids), | |
2801 | NULL,, | |
2802 | method_attach_processes_to_unit, | |
2803 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2804 | SD_BUS_METHOD_WITH_NAMES("AbandonScope", | |
2805 | "s", | |
2806 | SD_BUS_PARAM(name), | |
2807 | NULL,, | |
2808 | method_abandon_scope, | |
2809 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2810 | SD_BUS_METHOD_WITH_NAMES("GetJob", | |
2811 | "u", | |
2812 | SD_BUS_PARAM(id), | |
2813 | "o", | |
2814 | SD_BUS_PARAM(job), | |
2815 | method_get_job, | |
2816 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2817 | SD_BUS_METHOD_WITH_NAMES("GetJobAfter", | |
2818 | "u", | |
2819 | SD_BUS_PARAM(id), | |
2820 | "a(usssoo)", | |
2821 | SD_BUS_PARAM(jobs), | |
2822 | method_get_job_waiting, | |
2823 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2824 | SD_BUS_METHOD_WITH_NAMES("GetJobBefore", | |
2825 | "u", | |
2826 | SD_BUS_PARAM(id), | |
2827 | "a(usssoo)", | |
2828 | SD_BUS_PARAM(jobs), | |
2829 | method_get_job_waiting, | |
2830 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2831 | SD_BUS_METHOD_WITH_NAMES("CancelJob", | |
2832 | "u", | |
2833 | SD_BUS_PARAM(id), | |
2834 | NULL,, | |
2835 | method_cancel_job, | |
2836 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2837 | SD_BUS_METHOD("ClearJobs", | |
2838 | NULL, | |
2839 | NULL, | |
2840 | method_clear_jobs, | |
2841 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2842 | SD_BUS_METHOD("ResetFailed", | |
2843 | NULL, | |
2844 | NULL, | |
2845 | method_reset_failed, | |
2846 | SD_BUS_VTABLE_UNPRIVILEGED), | |
0bb007f7 FB |
2847 | SD_BUS_METHOD_WITH_NAMES("SetShowStatus", |
2848 | "s", | |
2849 | SD_BUS_PARAM(mode), | |
2850 | NULL,, | |
2851 | method_set_show_status, | |
2852 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_ADMIN)), | |
dad97f04 ZJS |
2853 | SD_BUS_METHOD_WITH_NAMES("ListUnits", |
2854 | NULL,, | |
2855 | "a(ssssssouso)", | |
2856 | SD_BUS_PARAM(units), | |
2857 | method_list_units, | |
2858 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2859 | SD_BUS_METHOD_WITH_NAMES("ListUnitsFiltered", | |
2860 | "as", | |
2861 | SD_BUS_PARAM(states), | |
2862 | "a(ssssssouso)", | |
2863 | SD_BUS_PARAM(units), | |
2864 | method_list_units_filtered, | |
2865 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2866 | SD_BUS_METHOD_WITH_NAMES("ListUnitsByPatterns", | |
2867 | "asas", | |
2868 | SD_BUS_PARAM(states) | |
2869 | SD_BUS_PARAM(patterns), | |
2870 | "a(ssssssouso)", | |
2871 | SD_BUS_PARAM(units), | |
2872 | method_list_units_by_patterns, | |
2873 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2874 | SD_BUS_METHOD_WITH_NAMES("ListUnitsByNames", | |
2875 | "as", | |
2876 | SD_BUS_PARAM(names), | |
2877 | "a(ssssssouso)", | |
2878 | SD_BUS_PARAM(units), | |
2879 | method_list_units_by_names, | |
2880 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2881 | SD_BUS_METHOD_WITH_NAMES("ListJobs", | |
2882 | NULL,, | |
2883 | "a(usssoo)", | |
2884 | SD_BUS_PARAM(jobs), | |
2885 | method_list_jobs, | |
2886 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2887 | SD_BUS_METHOD("Subscribe", | |
2888 | NULL, | |
2889 | NULL, | |
2890 | method_subscribe, | |
2891 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2892 | SD_BUS_METHOD("Unsubscribe", | |
2893 | NULL, | |
2894 | NULL, | |
2895 | method_unsubscribe, | |
2896 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2897 | SD_BUS_METHOD_WITH_NAMES("Dump", | |
2898 | NULL,, | |
2899 | "s", | |
2900 | SD_BUS_PARAM(output), | |
2901 | method_dump, | |
2902 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2903 | SD_BUS_METHOD_WITH_NAMES("DumpByFileDescriptor", | |
2904 | NULL,, | |
2905 | "h", | |
2906 | SD_BUS_PARAM(fd), | |
2907 | method_dump_by_fd, | |
2908 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2909 | SD_BUS_METHOD_WITH_NAMES("CreateSnapshot", | |
2910 | "sb", | |
2911 | SD_BUS_PARAM(name) | |
2912 | SD_BUS_PARAM(cleanup), | |
2913 | "o", | |
2914 | SD_BUS_PARAM(unit), | |
2915 | method_refuse_snapshot, | |
2916 | SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), | |
2917 | SD_BUS_METHOD_WITH_NAMES("RemoveSnapshot", | |
2918 | "s", | |
2919 | SD_BUS_PARAM(name), | |
2920 | NULL,, | |
2921 | method_refuse_snapshot, | |
2922 | SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), | |
2923 | SD_BUS_METHOD("Reload", | |
2924 | NULL, | |
2925 | NULL, | |
2926 | method_reload, | |
2927 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2928 | SD_BUS_METHOD("Reexecute", | |
2929 | NULL, | |
2930 | NULL, | |
2931 | method_reexecute, | |
2932 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2933 | SD_BUS_METHOD("Exit", | |
2934 | NULL, | |
2935 | NULL, | |
2936 | method_exit, | |
2937 | 0), | |
2938 | SD_BUS_METHOD("Reboot", | |
2939 | NULL, | |
2940 | NULL, | |
2941 | method_reboot, | |
2942 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2943 | SD_BUS_METHOD("PowerOff", | |
2944 | NULL, | |
2945 | NULL, | |
2946 | method_poweroff, | |
2947 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2948 | SD_BUS_METHOD("Halt", | |
2949 | NULL, | |
2950 | NULL, | |
2951 | method_halt, | |
2952 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2953 | SD_BUS_METHOD("KExec", | |
2954 | NULL, | |
2955 | NULL, | |
2956 | method_kexec, | |
2957 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2958 | SD_BUS_METHOD_WITH_NAMES("SwitchRoot", | |
2959 | "ss", | |
2960 | SD_BUS_PARAM(new_root) | |
2961 | SD_BUS_PARAM(init), | |
2962 | NULL,, | |
2963 | method_switch_root, | |
2964 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2965 | SD_BUS_METHOD_WITH_NAMES("SetEnvironment", | |
2966 | "as", | |
2967 | SD_BUS_PARAM(assignments), | |
2968 | NULL,, | |
2969 | method_set_environment, | |
2970 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2971 | SD_BUS_METHOD_WITH_NAMES("UnsetEnvironment", | |
2972 | "as", | |
2973 | SD_BUS_PARAM(names), | |
2974 | NULL,, | |
2975 | method_unset_environment, | |
2976 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2977 | SD_BUS_METHOD_WITH_NAMES("UnsetAndSetEnvironment", | |
2978 | "asas", | |
2979 | SD_BUS_PARAM(names) | |
2980 | SD_BUS_PARAM(assignments), | |
2981 | NULL,, | |
2982 | method_unset_and_set_environment, | |
2983 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2984 | SD_BUS_METHOD_WITH_NAMES("ListUnitFiles", | |
2985 | NULL,, | |
2986 | "a(ss)", | |
2987 | SD_BUS_PARAM(unit_files), | |
2988 | method_list_unit_files, | |
2989 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2990 | SD_BUS_METHOD_WITH_NAMES("ListUnitFilesByPatterns", | |
2991 | "asas", | |
2992 | SD_BUS_PARAM(states) | |
2993 | SD_BUS_PARAM(patterns), | |
2994 | "a(ss)", | |
2995 | SD_BUS_PARAM(unit_files), | |
2996 | method_list_unit_files_by_patterns, | |
2997 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2998 | SD_BUS_METHOD_WITH_NAMES("GetUnitFileState", | |
2999 | "s", | |
3000 | SD_BUS_PARAM(file), | |
3001 | "s", | |
3002 | SD_BUS_PARAM(state), | |
3003 | method_get_unit_file_state, | |
3004 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3005 | SD_BUS_METHOD_WITH_NAMES("EnableUnitFiles", | |
3006 | "asbb", | |
3007 | SD_BUS_PARAM(files) | |
3008 | SD_BUS_PARAM(runtime) | |
3009 | SD_BUS_PARAM(force), | |
3010 | "ba(sss)", | |
3011 | SD_BUS_PARAM(carries_install_info) | |
3012 | SD_BUS_PARAM(changes), | |
3013 | method_enable_unit_files, | |
3014 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3015 | SD_BUS_METHOD_WITH_NAMES("DisableUnitFiles", | |
3016 | "asb", | |
3017 | SD_BUS_PARAM(files) | |
3018 | SD_BUS_PARAM(runtime), | |
3019 | "a(sss)", | |
3020 | SD_BUS_PARAM(changes), | |
3021 | method_disable_unit_files, | |
3022 | SD_BUS_VTABLE_UNPRIVILEGED), | |
83654007 LB |
3023 | SD_BUS_METHOD_WITH_NAMES("EnableUnitFilesWithFlags", |
3024 | "ast", | |
3025 | SD_BUS_PARAM(files) | |
3026 | SD_BUS_PARAM(flags), | |
3027 | "ba(sss)", | |
3028 | SD_BUS_PARAM(carries_install_info) | |
3029 | SD_BUS_PARAM(changes), | |
3030 | method_enable_unit_files_with_flags, | |
3031 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3032 | SD_BUS_METHOD_WITH_NAMES("DisableUnitFilesWithFlags", | |
3033 | "ast", | |
3034 | SD_BUS_PARAM(files) | |
3035 | SD_BUS_PARAM(flags), | |
3036 | "a(sss)", | |
3037 | SD_BUS_PARAM(changes), | |
3038 | method_disable_unit_files_with_flags, | |
3039 | SD_BUS_VTABLE_UNPRIVILEGED), | |
dad97f04 ZJS |
3040 | SD_BUS_METHOD_WITH_NAMES("ReenableUnitFiles", |
3041 | "asbb", | |
3042 | SD_BUS_PARAM(files) | |
3043 | SD_BUS_PARAM(runtime) | |
3044 | SD_BUS_PARAM(force), | |
3045 | "ba(sss)", | |
3046 | SD_BUS_PARAM(carries_install_info) | |
3047 | SD_BUS_PARAM(changes), | |
3048 | method_reenable_unit_files, | |
3049 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3050 | SD_BUS_METHOD_WITH_NAMES("LinkUnitFiles", | |
3051 | "asbb", | |
3052 | SD_BUS_PARAM(files) | |
3053 | SD_BUS_PARAM(runtime) | |
3054 | SD_BUS_PARAM(force), | |
3055 | "a(sss)", | |
3056 | SD_BUS_PARAM(changes), | |
3057 | method_link_unit_files, | |
3058 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3059 | SD_BUS_METHOD_WITH_NAMES("PresetUnitFiles", | |
3060 | "asbb", | |
3061 | SD_BUS_PARAM(files) | |
3062 | SD_BUS_PARAM(runtime) | |
3063 | SD_BUS_PARAM(force), | |
3064 | "ba(sss)", | |
3065 | SD_BUS_PARAM(carries_install_info) | |
3066 | SD_BUS_PARAM(changes), | |
3067 | method_preset_unit_files, | |
3068 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3069 | SD_BUS_METHOD_WITH_NAMES("PresetUnitFilesWithMode", | |
3070 | "assbb", | |
3071 | SD_BUS_PARAM(files) | |
3072 | SD_BUS_PARAM(mode) | |
3073 | SD_BUS_PARAM(runtime) | |
3074 | SD_BUS_PARAM(force), | |
3075 | "ba(sss)", | |
3076 | SD_BUS_PARAM(carries_install_info) | |
3077 | SD_BUS_PARAM(changes), | |
3078 | method_preset_unit_files_with_mode, | |
3079 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3080 | SD_BUS_METHOD_WITH_NAMES("MaskUnitFiles", | |
3081 | "asbb", | |
3082 | SD_BUS_PARAM(files) | |
3083 | SD_BUS_PARAM(runtime) | |
3084 | SD_BUS_PARAM(force), | |
3085 | "a(sss)", | |
3086 | SD_BUS_PARAM(changes), | |
3087 | method_mask_unit_files, | |
3088 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3089 | SD_BUS_METHOD_WITH_NAMES("UnmaskUnitFiles", | |
3090 | "asb", | |
3091 | SD_BUS_PARAM(files) | |
3092 | SD_BUS_PARAM(runtime), | |
3093 | "a(sss)", | |
3094 | SD_BUS_PARAM(changes), | |
3095 | method_unmask_unit_files, | |
3096 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3097 | SD_BUS_METHOD_WITH_NAMES("RevertUnitFiles", | |
3098 | "as", | |
3099 | SD_BUS_PARAM(files), | |
3100 | "a(sss)", | |
3101 | SD_BUS_PARAM(changes), | |
3102 | method_revert_unit_files, | |
3103 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3104 | SD_BUS_METHOD_WITH_NAMES("SetDefaultTarget", | |
3105 | "sb", | |
3106 | SD_BUS_PARAM(name) | |
3107 | SD_BUS_PARAM(force), | |
3108 | "a(sss)", | |
3109 | SD_BUS_PARAM(changes), | |
3110 | method_set_default_target, | |
3111 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3112 | SD_BUS_METHOD_WITH_NAMES("GetDefaultTarget", | |
3113 | NULL,, | |
3114 | "s", | |
3115 | SD_BUS_PARAM(name), | |
3116 | method_get_default_target, | |
3117 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3118 | SD_BUS_METHOD_WITH_NAMES("PresetAllUnitFiles", | |
3119 | "sbb", | |
3120 | SD_BUS_PARAM(mode) | |
3121 | SD_BUS_PARAM(runtime) | |
3122 | SD_BUS_PARAM(force), | |
3123 | "a(sss)", | |
3124 | SD_BUS_PARAM(changes), | |
3125 | method_preset_all_unit_files, | |
3126 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3127 | SD_BUS_METHOD_WITH_NAMES("AddDependencyUnitFiles", | |
3128 | "asssbb", | |
3129 | SD_BUS_PARAM(files) | |
3130 | SD_BUS_PARAM(target) | |
3131 | SD_BUS_PARAM(type) | |
3132 | SD_BUS_PARAM(runtime) | |
3133 | SD_BUS_PARAM(force), | |
3134 | "a(sss)", | |
3135 | SD_BUS_PARAM(changes), | |
3136 | method_add_dependency_unit_files, | |
3137 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3138 | SD_BUS_METHOD_WITH_NAMES("GetUnitFileLinks", | |
3139 | "sb", | |
3140 | SD_BUS_PARAM(name) | |
3141 | SD_BUS_PARAM(runtime), | |
3142 | "as", | |
3143 | SD_BUS_PARAM(links), | |
3144 | method_get_unit_file_links, | |
3145 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3146 | SD_BUS_METHOD_WITH_NAMES("SetExitCode", | |
3147 | "y", | |
3148 | SD_BUS_PARAM(number), | |
3149 | NULL,, | |
3150 | method_set_exit_code, | |
3151 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3152 | SD_BUS_METHOD_WITH_NAMES("LookupDynamicUserByName", | |
3153 | "s", | |
3154 | SD_BUS_PARAM(name), | |
3155 | "u", | |
3156 | SD_BUS_PARAM(uid), | |
3157 | method_lookup_dynamic_user_by_name, | |
3158 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3159 | SD_BUS_METHOD_WITH_NAMES("LookupDynamicUserByUID", | |
3160 | "u", | |
3161 | SD_BUS_PARAM(uid), | |
3162 | "s", | |
3163 | SD_BUS_PARAM(name), | |
3164 | method_lookup_dynamic_user_by_uid, | |
3165 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3166 | SD_BUS_METHOD_WITH_NAMES("GetDynamicUsers", | |
3167 | NULL,, | |
3168 | "a(us)", | |
3169 | SD_BUS_PARAM(users), | |
3170 | method_get_dynamic_users, | |
3171 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3172 | ||
3173 | SD_BUS_SIGNAL_WITH_NAMES("UnitNew", | |
3174 | "so", | |
3175 | SD_BUS_PARAM(id) | |
3176 | SD_BUS_PARAM(unit), | |
3177 | 0), | |
3178 | SD_BUS_SIGNAL_WITH_NAMES("UnitRemoved", | |
3179 | "so", | |
3180 | SD_BUS_PARAM(id) | |
3181 | SD_BUS_PARAM(unit), | |
3182 | 0), | |
3183 | SD_BUS_SIGNAL_WITH_NAMES("JobNew", | |
3184 | "uos", | |
3185 | SD_BUS_PARAM(id) | |
3186 | SD_BUS_PARAM(job) | |
3187 | SD_BUS_PARAM(unit), | |
3188 | 0), | |
3189 | SD_BUS_SIGNAL_WITH_NAMES("JobRemoved", | |
3190 | "uoss", | |
3191 | SD_BUS_PARAM(id) | |
3192 | SD_BUS_PARAM(job) | |
3193 | SD_BUS_PARAM(unit) | |
3194 | SD_BUS_PARAM(result), | |
3195 | 0), | |
3196 | SD_BUS_SIGNAL_WITH_NAMES("StartupFinished", | |
3197 | "tttttt", | |
3198 | SD_BUS_PARAM(firmware) | |
3199 | SD_BUS_PARAM(loader) | |
3200 | SD_BUS_PARAM(kernel) | |
3201 | SD_BUS_PARAM(initrd) | |
3202 | SD_BUS_PARAM(userspace) | |
3203 | SD_BUS_PARAM(total), | |
3204 | 0), | |
718db961 | 3205 | SD_BUS_SIGNAL("UnitFilesChanged", NULL, 0), |
dad97f04 ZJS |
3206 | SD_BUS_SIGNAL_WITH_NAMES("Reloading", |
3207 | "b", | |
3208 | SD_BUS_PARAM(active), | |
3209 | 0), | |
718db961 LP |
3210 | |
3211 | SD_BUS_VTABLE_END | |
ea430986 | 3212 | }; |
718db961 | 3213 | |
893f801d LP |
3214 | const sd_bus_vtable bus_manager_log_control_vtable[] = { |
3215 | SD_BUS_VTABLE_START(0), | |
3216 | ||
3217 | /* We define a private version of this interface here, since we want slightly different | |
3218 | * implementations for the setters. We'll still use the generic getters however, and we share the | |
3219 | * setters with the implementations for the Manager interface above (which pre-dates the generic | |
3220 | * service API interface). */ | |
3221 | ||
3222 | SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level, property_set_log_level, 0, 0), | |
3223 | SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target, property_set_log_target, 0, 0), | |
3224 | SD_BUS_PROPERTY("SyslogIdentifier", "s", bus_property_get_syslog_identifier, 0, 0), | |
3225 | ||
3226 | SD_BUS_VTABLE_END, | |
3227 | }; | |
3228 | ||
8f8f05a9 | 3229 | static int send_finished(sd_bus *bus, void *userdata) { |
4afd3348 | 3230 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
3231 | usec_t *times = userdata; |
3232 | int r; | |
3233 | ||
3234 | assert(bus); | |
3235 | assert(times); | |
3236 | ||
151b9b96 | 3237 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished"); |
718db961 LP |
3238 | if (r < 0) |
3239 | return r; | |
3240 | ||
3241 | r = sd_bus_message_append(message, "tttttt", times[0], times[1], times[2], times[3], times[4], times[5]); | |
3242 | if (r < 0) | |
3243 | return r; | |
3244 | ||
8f8f05a9 | 3245 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
3246 | } |
3247 | ||
39abcaee | 3248 | void bus_manager_send_finished( |
718db961 LP |
3249 | Manager *m, |
3250 | usec_t firmware_usec, | |
3251 | usec_t loader_usec, | |
3252 | usec_t kernel_usec, | |
3253 | usec_t initrd_usec, | |
3254 | usec_t userspace_usec, | |
3255 | usec_t total_usec) { | |
3256 | ||
39abcaee LP |
3257 | int r; |
3258 | ||
718db961 LP |
3259 | assert(m); |
3260 | ||
8f8f05a9 LP |
3261 | r = bus_foreach_bus( |
3262 | m, | |
3263 | NULL, | |
3264 | send_finished, | |
3265 | (usec_t[6]) { | |
3266 | firmware_usec, | |
3267 | loader_usec, | |
3268 | kernel_usec, | |
3269 | initrd_usec, | |
3270 | userspace_usec, | |
3271 | total_usec | |
3272 | }); | |
39abcaee | 3273 | if (r < 0) |
da927ba9 | 3274 | log_debug_errno(r, "Failed to send finished signal: %m"); |
718db961 LP |
3275 | } |
3276 | ||
8f8f05a9 | 3277 | static int send_reloading(sd_bus *bus, void *userdata) { |
4afd3348 | 3278 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
3279 | int r; |
3280 | ||
3281 | assert(bus); | |
3282 | ||
151b9b96 | 3283 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading"); |
718db961 LP |
3284 | if (r < 0) |
3285 | return r; | |
3286 | ||
3287 | r = sd_bus_message_append(message, "b", PTR_TO_INT(userdata)); | |
3288 | if (r < 0) | |
3289 | return r; | |
3290 | ||
8f8f05a9 | 3291 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
3292 | } |
3293 | ||
39abcaee LP |
3294 | void bus_manager_send_reloading(Manager *m, bool active) { |
3295 | int r; | |
3296 | ||
718db961 LP |
3297 | assert(m); |
3298 | ||
8f8f05a9 | 3299 | r = bus_foreach_bus(m, NULL, send_reloading, INT_TO_PTR(active)); |
39abcaee | 3300 | if (r < 0) |
da927ba9 | 3301 | log_debug_errno(r, "Failed to send reloading signal: %m"); |
03455c28 LDM |
3302 | } |
3303 | ||
3304 | static int send_changed_signal(sd_bus *bus, void *userdata) { | |
3305 | assert(bus); | |
3306 | ||
3307 | return sd_bus_emit_properties_changed_strv(bus, | |
3308 | "/org/freedesktop/systemd1", | |
3309 | "org.freedesktop.systemd1.Manager", | |
3310 | NULL); | |
3311 | } | |
39abcaee | 3312 | |
03455c28 LDM |
3313 | void bus_manager_send_change_signal(Manager *m) { |
3314 | int r; | |
3315 | ||
3316 | assert(m); | |
3317 | ||
3318 | r = bus_foreach_bus(m, NULL, send_changed_signal, NULL); | |
3319 | if (r < 0) | |
3320 | log_debug_errno(r, "Failed to send manager change signal: %m"); | |
718db961 | 3321 | } |