]>
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; | |
718db961 LP |
1061 | Unit *u; |
1062 | int r; | |
c1e1601e | 1063 | |
718db961 LP |
1064 | assert(message); |
1065 | assert(m); | |
b152adec | 1066 | |
283868e1 SW |
1067 | /* Anyone can call this method */ |
1068 | ||
8a188de9 | 1069 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1070 | if (r < 0) |
1071 | return r; | |
cad45ba1 | 1072 | |
df2d202e | 1073 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1074 | if (r < 0) |
ebcf1f97 | 1075 | return r; |
b152adec | 1076 | |
718db961 LP |
1077 | r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)"); |
1078 | if (r < 0) | |
ebcf1f97 | 1079 | return r; |
b152adec | 1080 | |
90e74a66 | 1081 | HASHMAP_FOREACH_KEY(u, k, m->units) { |
718db961 LP |
1082 | if (k != u->id) |
1083 | continue; | |
b152adec | 1084 | |
cdc06ed7 DS |
1085 | if (!strv_isempty(states) && |
1086 | !strv_contains(states, unit_load_state_to_string(u->load_state)) && | |
1087 | !strv_contains(states, unit_active_state_to_string(unit_active_state(u))) && | |
1088 | !strv_contains(states, unit_sub_state_to_string(u))) | |
1089 | continue; | |
1090 | ||
313fe66f | 1091 | if (!strv_isempty(patterns) && |
1092 | !strv_fnmatch_or_empty(patterns, u->id, FNM_NOESCAPE)) | |
1093 | continue; | |
1094 | ||
6900c740 | 1095 | r = reply_unit_info(reply, u); |
718db961 | 1096 | if (r < 0) |
ebcf1f97 | 1097 | return r; |
718db961 | 1098 | } |
4139c1b2 | 1099 | |
718db961 LP |
1100 | r = sd_bus_message_close_container(reply); |
1101 | if (r < 0) | |
ebcf1f97 | 1102 | return r; |
cad45ba1 | 1103 | |
9030ca46 | 1104 | return sd_bus_send(NULL, reply, NULL); |
718db961 | 1105 | } |
4139c1b2 | 1106 | |
19070062 | 1107 | static int method_list_units(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
313fe66f | 1108 | return list_units_filtered(message, userdata, error, NULL, NULL); |
cdc06ed7 DS |
1109 | } |
1110 | ||
19070062 | 1111 | static int method_list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
cdc06ed7 DS |
1112 | _cleanup_strv_free_ char **states = NULL; |
1113 | int r; | |
1114 | ||
1115 | r = sd_bus_message_read_strv(message, &states); | |
1116 | if (r < 0) | |
1117 | return r; | |
1118 | ||
313fe66f | 1119 | return list_units_filtered(message, userdata, error, states, NULL); |
1120 | } | |
1121 | ||
1122 | static int method_list_units_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1123 | _cleanup_strv_free_ char **states = NULL; | |
1124 | _cleanup_strv_free_ char **patterns = NULL; | |
1125 | int r; | |
1126 | ||
1127 | r = sd_bus_message_read_strv(message, &states); | |
1128 | if (r < 0) | |
1129 | return r; | |
1130 | ||
1131 | r = sd_bus_message_read_strv(message, &patterns); | |
1132 | if (r < 0) | |
1133 | return r; | |
1134 | ||
1135 | return list_units_filtered(message, userdata, error, states, patterns); | |
cdc06ed7 DS |
1136 | } |
1137 | ||
19070062 | 1138 | static int method_list_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
4afd3348 | 1139 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
718db961 | 1140 | Manager *m = userdata; |
718db961 LP |
1141 | Job *j; |
1142 | int r; | |
4139c1b2 | 1143 | |
718db961 LP |
1144 | assert(message); |
1145 | assert(m); | |
1146 | ||
283868e1 SW |
1147 | /* Anyone can call this method */ |
1148 | ||
8a188de9 | 1149 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1150 | if (r < 0) |
1151 | return r; | |
718db961 | 1152 | |
df2d202e | 1153 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1154 | if (r < 0) |
ebcf1f97 | 1155 | return r; |
718db961 LP |
1156 | |
1157 | r = sd_bus_message_open_container(reply, 'a', "(usssoo)"); | |
1158 | if (r < 0) | |
ebcf1f97 | 1159 | return r; |
718db961 | 1160 | |
90e74a66 | 1161 | HASHMAP_FOREACH(j, m->jobs) { |
718db961 LP |
1162 | _cleanup_free_ char *unit_path = NULL, *job_path = NULL; |
1163 | ||
1164 | job_path = job_dbus_path(j); | |
1165 | if (!job_path) | |
ebcf1f97 | 1166 | return -ENOMEM; |
718db961 LP |
1167 | |
1168 | unit_path = unit_dbus_path(j->unit); | |
1169 | if (!unit_path) | |
ebcf1f97 | 1170 | return -ENOMEM; |
718db961 LP |
1171 | |
1172 | r = sd_bus_message_append( | |
1173 | reply, "(usssoo)", | |
1174 | j->id, | |
1302759d | 1175 | j->unit->id, |
718db961 | 1176 | job_type_to_string(j->type), |
1302759d | 1177 | job_state_to_string(j->state), |
718db961 LP |
1178 | job_path, |
1179 | unit_path); | |
cad45ba1 | 1180 | if (r < 0) |
ebcf1f97 | 1181 | return r; |
718db961 | 1182 | } |
5dd9014f | 1183 | |
718db961 LP |
1184 | r = sd_bus_message_close_container(reply); |
1185 | if (r < 0) | |
ebcf1f97 | 1186 | return r; |
5dd9014f | 1187 | |
9030ca46 | 1188 | return sd_bus_send(NULL, reply, NULL); |
718db961 | 1189 | } |
5dd9014f | 1190 | |
19070062 | 1191 | static int method_subscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1192 | Manager *m = userdata; |
1193 | int r; | |
5dd9014f | 1194 | |
718db961 LP |
1195 | assert(message); |
1196 | assert(m); | |
ea430986 | 1197 | |
283868e1 SW |
1198 | /* Anyone can call this method */ |
1199 | ||
8a188de9 | 1200 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1201 | if (r < 0) |
1202 | return r; | |
cad45ba1 | 1203 | |
19070062 | 1204 | if (sd_bus_message_get_bus(message) == m->api_bus) { |
8f8f05a9 LP |
1205 | |
1206 | /* Note that direct bus connection subscribe by | |
1207 | * default, we only track peers on the API bus here */ | |
1208 | ||
1209 | if (!m->subscribed) { | |
19070062 | 1210 | r = sd_bus_track_new(sd_bus_message_get_bus(message), &m->subscribed, NULL, NULL); |
8f8f05a9 LP |
1211 | if (r < 0) |
1212 | return r; | |
1213 | } | |
1214 | ||
1215 | r = sd_bus_track_add_sender(m->subscribed, message); | |
1216 | if (r < 0) | |
1217 | return r; | |
1218 | if (r == 0) | |
1219 | return sd_bus_error_setf(error, BUS_ERROR_ALREADY_SUBSCRIBED, "Client is already subscribed."); | |
1220 | } | |
ea430986 | 1221 | |
df2d202e | 1222 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1223 | } |
ea430986 | 1224 | |
19070062 | 1225 | static int method_unsubscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1226 | Manager *m = userdata; |
1227 | int r; | |
ea430986 | 1228 | |
718db961 LP |
1229 | assert(message); |
1230 | assert(m); | |
ea430986 | 1231 | |
283868e1 SW |
1232 | /* Anyone can call this method */ |
1233 | ||
8a188de9 | 1234 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1235 | if (r < 0) |
1236 | return r; | |
ea430986 | 1237 | |
19070062 | 1238 | if (sd_bus_message_get_bus(message) == m->api_bus) { |
8f8f05a9 LP |
1239 | r = sd_bus_track_remove_sender(m->subscribed, message); |
1240 | if (r < 0) | |
1241 | return r; | |
1242 | if (r == 0) | |
1243 | return sd_bus_error_setf(error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed."); | |
1244 | } | |
ea430986 | 1245 | |
df2d202e | 1246 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1247 | } |
ea430986 | 1248 | |
c0a1bfac | 1249 | static int dump_impl(sd_bus_message *message, void *userdata, sd_bus_error *error, int (*reply)(sd_bus_message *, char *)) { |
718db961 | 1250 | _cleanup_free_ char *dump = NULL; |
718db961 | 1251 | Manager *m = userdata; |
ebcf1f97 | 1252 | int r; |
ea430986 | 1253 | |
718db961 LP |
1254 | assert(message); |
1255 | assert(m); | |
ea430986 | 1256 | |
283868e1 SW |
1257 | /* Anyone can call this method */ |
1258 | ||
8a188de9 | 1259 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1260 | if (r < 0) |
1261 | return r; | |
ea430986 | 1262 | |
713f6f90 | 1263 | r = manager_get_dump_string(m, &dump); |
dacd6cee LP |
1264 | if (r < 0) |
1265 | return r; | |
a16e1123 | 1266 | |
c0a1bfac DT |
1267 | return reply(message, dump); |
1268 | } | |
1269 | ||
1270 | static int reply_dump(sd_bus_message *message, char *dump) { | |
df2d202e | 1271 | return sd_bus_reply_method_return(message, "s", dump); |
718db961 | 1272 | } |
cad45ba1 | 1273 | |
c0a1bfac DT |
1274 | static int method_dump(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1275 | return dump_impl(message, userdata, error, reply_dump); | |
1276 | } | |
1277 | ||
1278 | static int reply_dump_by_fd(sd_bus_message *message, char *dump) { | |
1279 | _cleanup_close_ int fd = -1; | |
1280 | ||
1281 | fd = acquire_data_fd(dump, strlen(dump), 0); | |
1282 | if (fd < 0) | |
1283 | return fd; | |
1284 | ||
1285 | return sd_bus_reply_method_return(message, "h", fd); | |
1286 | } | |
1287 | ||
1288 | static int method_dump_by_fd(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1289 | return dump_impl(message, userdata, error, reply_dump_by_fd); | |
1290 | } | |
1291 | ||
36b4a7ba ZJS |
1292 | static int method_refuse_snapshot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1293 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Support for snapshots has been removed."); | |
718db961 | 1294 | } |
cad45ba1 | 1295 | |
ae57dad3 LP |
1296 | static int verify_run_space(const char *message, sd_bus_error *error) { |
1297 | struct statvfs svfs; | |
1298 | uint64_t available; | |
1299 | ||
1300 | if (statvfs("/run/systemd", &svfs) < 0) | |
1301 | return sd_bus_error_set_errnof(error, errno, "Failed to statvfs(/run/systemd): %m"); | |
1302 | ||
1303 | available = (uint64_t) svfs.f_bfree * (uint64_t) svfs.f_bsize; | |
1304 | ||
1305 | if (available < RELOAD_DISK_SPACE_MIN) { | |
1306 | char fb_available[FORMAT_BYTES_MAX], fb_need[FORMAT_BYTES_MAX]; | |
1307 | return sd_bus_error_setf(error, | |
1308 | BUS_ERROR_DISK_FULL, | |
1309 | "%s, not enough space available on /run/systemd. " | |
1310 | "Currently, %s are free, but a safety buffer of %s is enforced.", | |
1311 | message, | |
1312 | format_bytes(fb_available, sizeof(fb_available), available), | |
1313 | format_bytes(fb_need, sizeof(fb_need), RELOAD_DISK_SPACE_MIN)); | |
1314 | } | |
1315 | ||
1316 | return 0; | |
1317 | } | |
1318 | ||
1319 | int verify_run_space_and_log(const char *message) { | |
4dae8ae6 | 1320 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
ae57dad3 LP |
1321 | int r; |
1322 | ||
1323 | r = verify_run_space(message, &error); | |
1324 | if (r < 0) | |
4ae25393 | 1325 | return log_error_errno(r, "%s", bus_error_message(&error, r)); |
ae57dad3 | 1326 | |
4ae25393 | 1327 | return 0; |
ae57dad3 LP |
1328 | } |
1329 | ||
19070062 | 1330 | static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1331 | Manager *m = userdata; |
1332 | int r; | |
6652a2b9 | 1333 | |
718db961 LP |
1334 | assert(message); |
1335 | assert(m); | |
6652a2b9 | 1336 | |
ae57dad3 LP |
1337 | r = verify_run_space("Refusing to reload", error); |
1338 | if (r < 0) | |
1339 | return r; | |
1340 | ||
1d22e906 | 1341 | r = mac_selinux_access_check(message, "reload", error); |
283868e1 SW |
1342 | if (r < 0) |
1343 | return r; | |
283868e1 | 1344 | |
1d22e906 | 1345 | r = bus_verify_reload_daemon_async(m, message, error); |
ebcf1f97 LP |
1346 | if (r < 0) |
1347 | return r; | |
1d22e906 LP |
1348 | if (r == 0) |
1349 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
6652a2b9 | 1350 | |
718db961 LP |
1351 | /* Instead of sending the reply back right away, we just |
1352 | * remember that we need to and then send it after the reload | |
1353 | * is finished. That way the caller knows when the reload | |
1354 | * finished. */ | |
6652a2b9 | 1355 | |
209de525 LP |
1356 | assert(!m->pending_reload_message); |
1357 | r = sd_bus_message_new_method_return(message, &m->pending_reload_message); | |
718db961 | 1358 | if (r < 0) |
ebcf1f97 | 1359 | return r; |
cad45ba1 | 1360 | |
af41e508 | 1361 | m->objective = MANAGER_RELOAD; |
6652a2b9 | 1362 | |
718db961 LP |
1363 | return 1; |
1364 | } | |
6652a2b9 | 1365 | |
19070062 | 1366 | static int method_reexecute(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1367 | Manager *m = userdata; |
ebcf1f97 | 1368 | int r; |
6652a2b9 | 1369 | |
718db961 LP |
1370 | assert(message); |
1371 | assert(m); | |
6652a2b9 | 1372 | |
ae57dad3 LP |
1373 | r = verify_run_space("Refusing to reexecute", error); |
1374 | if (r < 0) | |
1375 | return r; | |
1376 | ||
1d22e906 | 1377 | r = mac_selinux_access_check(message, "reload", error); |
283868e1 SW |
1378 | if (r < 0) |
1379 | return r; | |
283868e1 | 1380 | |
1d22e906 | 1381 | r = bus_verify_reload_daemon_async(m, message, error); |
ebcf1f97 LP |
1382 | if (r < 0) |
1383 | return r; | |
1d22e906 LP |
1384 | if (r == 0) |
1385 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
cad45ba1 | 1386 | |
718db961 LP |
1387 | /* We don't send a reply back here, the client should |
1388 | * just wait for us disconnecting. */ | |
6652a2b9 | 1389 | |
af41e508 | 1390 | m->objective = MANAGER_REEXECUTE; |
718db961 LP |
1391 | return 1; |
1392 | } | |
6652a2b9 | 1393 | |
19070062 | 1394 | static int method_exit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1395 | Manager *m = userdata; |
ebcf1f97 | 1396 | int r; |
6652a2b9 | 1397 | |
718db961 LP |
1398 | assert(message); |
1399 | assert(m); | |
6652a2b9 | 1400 | |
8a188de9 | 1401 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1402 | if (r < 0) |
1403 | return r; | |
cad45ba1 | 1404 | |
287419c1 AC |
1405 | /* Exit() (in contrast to SetExitCode()) is actually allowed even if |
1406 | * we are running on the host. It will fall back on reboot() in | |
1407 | * systemd-shutdown if it cannot do the exit() because it isn't a | |
1408 | * container. */ | |
6652a2b9 | 1409 | |
af41e508 | 1410 | m->objective = MANAGER_EXIT; |
6652a2b9 | 1411 | |
df2d202e | 1412 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1413 | } |
6652a2b9 | 1414 | |
19070062 | 1415 | static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1416 | Manager *m = userdata; |
ebcf1f97 | 1417 | int r; |
664f88a7 | 1418 | |
718db961 LP |
1419 | assert(message); |
1420 | assert(m); | |
cad45ba1 | 1421 | |
8a188de9 | 1422 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1423 | if (r < 0) |
1424 | return r; | |
664f88a7 | 1425 | |
463d0d15 | 1426 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1427 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers."); |
664f88a7 | 1428 | |
af41e508 | 1429 | m->objective = MANAGER_REBOOT; |
664f88a7 | 1430 | |
df2d202e | 1431 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1432 | } |
664f88a7 | 1433 | |
19070062 | 1434 | static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1435 | Manager *m = userdata; |
ebcf1f97 | 1436 | int r; |
50913bc0 | 1437 | |
718db961 LP |
1438 | assert(message); |
1439 | assert(m); | |
1137a57c | 1440 | |
8a188de9 | 1441 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1442 | if (r < 0) |
1443 | return r; | |
1137a57c | 1444 | |
463d0d15 | 1445 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1446 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers."); |
1137a57c | 1447 | |
af41e508 | 1448 | m->objective = MANAGER_POWEROFF; |
1137a57c | 1449 | |
df2d202e | 1450 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1451 | } |
1137a57c | 1452 | |
19070062 | 1453 | static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1454 | Manager *m = userdata; |
ebcf1f97 | 1455 | int r; |
1137a57c | 1456 | |
718db961 LP |
1457 | assert(message); |
1458 | assert(m); | |
8d0e38a2 | 1459 | |
8a188de9 | 1460 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1461 | if (r < 0) |
1462 | return r; | |
cad45ba1 | 1463 | |
463d0d15 | 1464 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1465 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Halt is only supported for system managers."); |
8d0e38a2 | 1466 | |
af41e508 | 1467 | m->objective = MANAGER_HALT; |
8d0e38a2 | 1468 | |
df2d202e | 1469 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1470 | } |
8d0e38a2 | 1471 | |
19070062 | 1472 | static int method_kexec(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1473 | Manager *m = userdata; |
ebcf1f97 | 1474 | int r; |
8d0e38a2 | 1475 | |
718db961 LP |
1476 | assert(message); |
1477 | assert(m); | |
c0576cd6 | 1478 | |
8a188de9 | 1479 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1480 | if (r < 0) |
1481 | return r; | |
cad45ba1 | 1482 | |
463d0d15 | 1483 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1484 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers."); |
c0576cd6 | 1485 | |
af41e508 | 1486 | m->objective = MANAGER_KEXEC; |
c0576cd6 | 1487 | |
df2d202e | 1488 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1489 | } |
c0576cd6 | 1490 | |
19070062 | 1491 | static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
87a19bfe | 1492 | _cleanup_free_ char *ri = NULL, *rt = NULL; |
718db961 LP |
1493 | const char *root, *init; |
1494 | Manager *m = userdata; | |
ae57dad3 LP |
1495 | struct statvfs svfs; |
1496 | uint64_t available; | |
718db961 | 1497 | int r; |
c0576cd6 | 1498 | |
718db961 LP |
1499 | assert(message); |
1500 | assert(m); | |
c0576cd6 | 1501 | |
ae57dad3 LP |
1502 | if (statvfs("/run/systemd", &svfs) < 0) |
1503 | return sd_bus_error_set_errnof(error, errno, "Failed to statvfs(/run/systemd): %m"); | |
1504 | ||
1505 | available = (uint64_t) svfs.f_bfree * (uint64_t) svfs.f_bsize; | |
1506 | ||
1507 | if (available < RELOAD_DISK_SPACE_MIN) { | |
1508 | char fb_available[FORMAT_BYTES_MAX], fb_need[FORMAT_BYTES_MAX]; | |
3fe91079 | 1509 | log_warning("Dangerously low amount of free space on /run/systemd, root switching operation might not complete successfully. " |
ae57dad3 LP |
1510 | "Currently, %s are free, but %s are suggested. Proceeding anyway.", |
1511 | format_bytes(fb_available, sizeof(fb_available), available), | |
1512 | format_bytes(fb_need, sizeof(fb_need), RELOAD_DISK_SPACE_MIN)); | |
1513 | } | |
1514 | ||
8a188de9 | 1515 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1516 | if (r < 0) |
1517 | return r; | |
c0576cd6 | 1518 | |
463d0d15 | 1519 | if (!MANAGER_IS_SYSTEM(m)) |
6ad3b2b6 | 1520 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Root switching is only supported by system manager."); |
c0576cd6 | 1521 | |
718db961 LP |
1522 | r = sd_bus_message_read(message, "ss", &root, &init); |
1523 | if (r < 0) | |
ebcf1f97 | 1524 | return r; |
c0576cd6 | 1525 | |
710028b4 LP |
1526 | if (isempty(root)) |
1527 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "New root directory may not be the empty string."); | |
1528 | if (!path_is_absolute(root)) | |
1529 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "New root path '%s' is not absolute.", root); | |
1530 | if (path_equal(root, "/")) | |
1531 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "New root directory cannot be the old root directory."); | |
c0576cd6 | 1532 | |
718db961 LP |
1533 | /* Safety check */ |
1534 | if (isempty(init)) { | |
710028b4 LP |
1535 | r = path_is_os_tree(root); |
1536 | if (r < 0) | |
1537 | return sd_bus_error_set_errnof(error, r, "Failed to determine whether root path '%s' contains an OS tree: %m", root); | |
1538 | if (r == 0) | |
1539 | 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 | 1540 | } else { |
710028b4 | 1541 | _cleanup_free_ char *chased = NULL; |
c0576cd6 | 1542 | |
718db961 | 1543 | if (!path_is_absolute(init)) |
710028b4 | 1544 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path to init binary '%s' not absolute.", init); |
c0576cd6 | 1545 | |
a5648b80 | 1546 | r = chase_symlinks(init, root, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &chased, NULL); |
710028b4 LP |
1547 | if (r < 0) |
1548 | return sd_bus_error_set_errnof(error, r, "Could not resolve init executable %s: %m", init); | |
1549 | ||
1550 | if (laccess(chased, X_OK) < 0) { | |
1551 | if (errno == EACCES) | |
1552 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Init binary %s is not executable.", init); | |
c0576cd6 | 1553 | |
710028b4 LP |
1554 | return sd_bus_error_set_errnof(error, r, "Could not check whether init binary %s is executable: %m", init); |
1555 | } | |
718db961 LP |
1556 | } |
1557 | ||
1558 | rt = strdup(root); | |
1559 | if (!rt) | |
ebcf1f97 | 1560 | return -ENOMEM; |
718db961 LP |
1561 | |
1562 | if (!isempty(init)) { | |
1563 | ri = strdup(init); | |
87a19bfe | 1564 | if (!ri) |
ebcf1f97 | 1565 | return -ENOMEM; |
718db961 | 1566 | } |
c0576cd6 | 1567 | |
87a19bfe YW |
1568 | free_and_replace(m->switch_root, rt); |
1569 | free_and_replace(m->switch_root_init, ri); | |
c0576cd6 | 1570 | |
af41e508 | 1571 | m->objective = MANAGER_SWITCH_ROOT; |
92b315df | 1572 | |
df2d202e | 1573 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1574 | } |
c0576cd6 | 1575 | |
19070062 | 1576 | static int method_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1577 | _cleanup_strv_free_ char **plus = NULL; |
1578 | Manager *m = userdata; | |
1579 | int r; | |
c0576cd6 | 1580 | |
718db961 LP |
1581 | assert(message); |
1582 | assert(m); | |
cad45ba1 | 1583 | |
8a188de9 | 1584 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1585 | if (r < 0) |
1586 | return r; | |
c0576cd6 | 1587 | |
718db961 LP |
1588 | r = sd_bus_message_read_strv(message, &plus); |
1589 | if (r < 0) | |
ebcf1f97 | 1590 | return r; |
718db961 | 1591 | if (!strv_env_is_valid(plus)) |
ebcf1f97 | 1592 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments"); |
c0576cd6 | 1593 | |
1d22e906 LP |
1594 | r = bus_verify_set_environment_async(m, message, error); |
1595 | if (r < 0) | |
1596 | return r; | |
1597 | if (r == 0) | |
1598 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1599 | ||
1ad6e8b3 | 1600 | r = manager_client_environment_modify(m, NULL, plus); |
718db961 | 1601 | if (r < 0) |
ebcf1f97 | 1602 | return r; |
c0576cd6 | 1603 | |
df2d202e | 1604 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1605 | } |
1606 | ||
19070062 | 1607 | static int method_unset_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1608 | _cleanup_strv_free_ char **minus = NULL; |
1609 | Manager *m = userdata; | |
1610 | int r; | |
1611 | ||
718db961 LP |
1612 | assert(message); |
1613 | assert(m); | |
1614 | ||
8a188de9 | 1615 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1616 | if (r < 0) |
1617 | return r; | |
c0576cd6 | 1618 | |
718db961 LP |
1619 | r = sd_bus_message_read_strv(message, &minus); |
1620 | if (r < 0) | |
ebcf1f97 | 1621 | return r; |
718db961 LP |
1622 | |
1623 | if (!strv_env_name_or_assignment_is_valid(minus)) | |
ebcf1f97 | 1624 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments"); |
718db961 | 1625 | |
1d22e906 LP |
1626 | r = bus_verify_set_environment_async(m, message, error); |
1627 | if (r < 0) | |
1628 | return r; | |
1629 | if (r == 0) | |
1630 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1631 | ||
1ad6e8b3 | 1632 | r = manager_client_environment_modify(m, minus, NULL); |
718db961 | 1633 | if (r < 0) |
ebcf1f97 | 1634 | return r; |
718db961 | 1635 | |
df2d202e | 1636 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1637 | } |
1638 | ||
19070062 | 1639 | static int method_unset_and_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1640 | _cleanup_strv_free_ char **minus = NULL, **plus = NULL; |
1641 | Manager *m = userdata; | |
1642 | int r; | |
1643 | ||
718db961 LP |
1644 | assert(message); |
1645 | assert(m); | |
1646 | ||
8a188de9 | 1647 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1648 | if (r < 0) |
1649 | return r; | |
718db961 | 1650 | |
eb6c7d20 | 1651 | r = sd_bus_message_read_strv(message, &minus); |
718db961 | 1652 | if (r < 0) |
ebcf1f97 | 1653 | return r; |
718db961 | 1654 | |
eb6c7d20 | 1655 | r = sd_bus_message_read_strv(message, &plus); |
718db961 | 1656 | if (r < 0) |
ebcf1f97 | 1657 | return r; |
718db961 | 1658 | |
718db961 | 1659 | if (!strv_env_name_or_assignment_is_valid(minus)) |
ebcf1f97 | 1660 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments"); |
eb6c7d20 ZJS |
1661 | if (!strv_env_is_valid(plus)) |
1662 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments"); | |
718db961 | 1663 | |
1d22e906 LP |
1664 | r = bus_verify_set_environment_async(m, message, error); |
1665 | if (r < 0) | |
1666 | return r; | |
1667 | if (r == 0) | |
1668 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1669 | ||
1ad6e8b3 | 1670 | r = manager_client_environment_modify(m, minus, plus); |
718db961 | 1671 | if (r < 0) |
ebcf1f97 | 1672 | return r; |
718db961 | 1673 | |
df2d202e | 1674 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1675 | } |
1676 | ||
287419c1 | 1677 | static int method_set_exit_code(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
287419c1 | 1678 | Manager *m = userdata; |
29206d46 | 1679 | uint8_t code; |
287419c1 AC |
1680 | int r; |
1681 | ||
1682 | assert(message); | |
1683 | assert(m); | |
1684 | ||
1685 | r = mac_selinux_access_check(message, "exit", error); | |
1686 | if (r < 0) | |
1687 | return r; | |
1688 | ||
1689 | r = sd_bus_message_read_basic(message, 'y', &code); | |
1690 | if (r < 0) | |
1691 | return r; | |
1692 | ||
463d0d15 | 1693 | if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0) |
287419c1 AC |
1694 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "ExitCode can only be set for user service managers or in containers."); |
1695 | ||
1696 | m->return_value = code; | |
1697 | ||
1698 | return sd_bus_reply_method_return(message, NULL); | |
1699 | } | |
1700 | ||
29206d46 LP |
1701 | static int method_lookup_dynamic_user_by_name(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1702 | Manager *m = userdata; | |
1703 | const char *name; | |
1704 | uid_t uid; | |
1705 | int r; | |
1706 | ||
1707 | assert(message); | |
1708 | assert(m); | |
1709 | ||
1710 | r = sd_bus_message_read_basic(message, 's', &name); | |
1711 | if (r < 0) | |
1712 | return r; | |
1713 | ||
1714 | if (!MANAGER_IS_SYSTEM(m)) | |
1715 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Dynamic users are only supported in the system instance."); | |
7a8867ab | 1716 | if (!valid_user_group_name(name, VALID_USER_RELAX)) |
29206d46 LP |
1717 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "User name invalid: %s", name); |
1718 | ||
1719 | r = dynamic_user_lookup_name(m, name, &uid); | |
1720 | if (r == -ESRCH) | |
1721 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, "Dynamic user %s does not exist.", name); | |
1722 | if (r < 0) | |
1723 | return r; | |
1724 | ||
1725 | return sd_bus_reply_method_return(message, "u", (uint32_t) uid); | |
1726 | } | |
1727 | ||
1728 | static int method_lookup_dynamic_user_by_uid(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1729 | _cleanup_free_ char *name = NULL; | |
1730 | Manager *m = userdata; | |
1731 | uid_t uid; | |
1732 | int r; | |
1733 | ||
1734 | assert(message); | |
1735 | assert(m); | |
1736 | ||
60d0a509 | 1737 | assert_cc(sizeof(uid_t) == sizeof(uint32_t)); |
29206d46 LP |
1738 | r = sd_bus_message_read_basic(message, 'u', &uid); |
1739 | if (r < 0) | |
1740 | return r; | |
1741 | ||
1742 | if (!MANAGER_IS_SYSTEM(m)) | |
1743 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Dynamic users are only supported in the system instance."); | |
1744 | if (!uid_is_valid(uid)) | |
1745 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "User ID invalid: " UID_FMT, uid); | |
1746 | ||
1747 | r = dynamic_user_lookup_uid(m, uid, &name); | |
1748 | if (r == -ESRCH) | |
1749 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, "Dynamic user ID " UID_FMT " does not exist.", uid); | |
1750 | if (r < 0) | |
1751 | return r; | |
1752 | ||
1753 | return sd_bus_reply_method_return(message, "s", name); | |
1754 | } | |
1755 | ||
f9bfa696 YW |
1756 | static int method_get_dynamic_users(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1757 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
1758 | Manager *m = userdata; | |
1759 | DynamicUser *d; | |
f9bfa696 YW |
1760 | int r; |
1761 | ||
1762 | assert(message); | |
1763 | assert(m); | |
1764 | ||
1765 | assert_cc(sizeof(uid_t) == sizeof(uint32_t)); | |
1766 | ||
1767 | if (!MANAGER_IS_SYSTEM(m)) | |
1768 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Dynamic users are only supported in the system instance."); | |
1769 | ||
1770 | r = sd_bus_message_new_method_return(message, &reply); | |
1771 | if (r < 0) | |
1772 | return r; | |
1773 | ||
1774 | r = sd_bus_message_open_container(reply, 'a', "(us)"); | |
1775 | if (r < 0) | |
1776 | return r; | |
1777 | ||
90e74a66 | 1778 | HASHMAP_FOREACH(d, m->dynamic_users) { |
f9bfa696 YW |
1779 | uid_t uid; |
1780 | ||
1781 | r = dynamic_user_current(d, &uid); | |
1782 | if (r == -EAGAIN) /* not realized yet? */ | |
1783 | continue; | |
1784 | if (r < 0) | |
105a1a36 | 1785 | return sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "Failed to look up a dynamic user."); |
f9bfa696 YW |
1786 | |
1787 | r = sd_bus_message_append(reply, "(us)", uid, d->name); | |
1788 | if (r < 0) | |
1789 | return r; | |
1790 | } | |
1791 | ||
1792 | r = sd_bus_message_close_container(reply); | |
1793 | if (r < 0) | |
1794 | return r; | |
1795 | ||
1796 | return sd_bus_send(NULL, reply, NULL); | |
1797 | } | |
1798 | ||
313fe66f | 1799 | static int list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error, char **states, char **patterns) { |
4afd3348 | 1800 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
718db961 LP |
1801 | Manager *m = userdata; |
1802 | UnitFileList *item; | |
1803 | Hashmap *h; | |
718db961 LP |
1804 | int r; |
1805 | ||
718db961 LP |
1806 | assert(message); |
1807 | assert(m); | |
1808 | ||
283868e1 SW |
1809 | /* Anyone can call this method */ |
1810 | ||
8a188de9 | 1811 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1812 | if (r < 0) |
1813 | return r; | |
718db961 | 1814 | |
df2d202e | 1815 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1816 | if (r < 0) |
ebcf1f97 | 1817 | return r; |
c0576cd6 | 1818 | |
d5099efc | 1819 | h = hashmap_new(&string_hash_ops); |
718db961 | 1820 | if (!h) |
ebcf1f97 | 1821 | return -ENOMEM; |
c0576cd6 | 1822 | |
313fe66f | 1823 | r = unit_file_get_list(m->unit_file_scope, NULL, h, states, patterns); |
ebcf1f97 | 1824 | if (r < 0) |
718db961 | 1825 | goto fail; |
718db961 LP |
1826 | |
1827 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); | |
ebcf1f97 | 1828 | if (r < 0) |
718db961 | 1829 | goto fail; |
718db961 | 1830 | |
90e74a66 | 1831 | HASHMAP_FOREACH(item, h) { |
718db961 LP |
1832 | |
1833 | r = sd_bus_message_append(reply, "(ss)", item->path, unit_file_state_to_string(item->state)); | |
ebcf1f97 | 1834 | if (r < 0) |
718db961 | 1835 | goto fail; |
718db961 | 1836 | } |
c0576cd6 | 1837 | |
718db961 | 1838 | unit_file_list_free(h); |
c0576cd6 | 1839 | |
718db961 LP |
1840 | r = sd_bus_message_close_container(reply); |
1841 | if (r < 0) | |
ebcf1f97 | 1842 | return r; |
8d0e38a2 | 1843 | |
9030ca46 | 1844 | return sd_bus_send(NULL, reply, NULL); |
99504dd4 | 1845 | |
718db961 LP |
1846 | fail: |
1847 | unit_file_list_free(h); | |
1848 | return r; | |
1849 | } | |
99504dd4 | 1850 | |
313fe66f | 1851 | static int method_list_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1852 | return list_unit_files_by_patterns(message, userdata, error, NULL, NULL); | |
1853 | } | |
1854 | ||
1855 | static int method_list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1856 | _cleanup_strv_free_ char **states = NULL; | |
1857 | _cleanup_strv_free_ char **patterns = NULL; | |
1858 | int r; | |
1859 | ||
1860 | r = sd_bus_message_read_strv(message, &states); | |
1861 | if (r < 0) | |
1862 | return r; | |
1863 | ||
1864 | r = sd_bus_message_read_strv(message, &patterns); | |
1865 | if (r < 0) | |
1866 | return r; | |
1867 | ||
1868 | return list_unit_files_by_patterns(message, userdata, error, states, patterns); | |
1869 | } | |
1870 | ||
19070062 | 1871 | static int method_get_unit_file_state(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1872 | Manager *m = userdata; |
1873 | const char *name; | |
1874 | UnitFileState state; | |
718db961 | 1875 | int r; |
99504dd4 | 1876 | |
718db961 LP |
1877 | assert(message); |
1878 | assert(m); | |
8e2af478 | 1879 | |
283868e1 SW |
1880 | /* Anyone can call this method */ |
1881 | ||
8a188de9 | 1882 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1883 | if (r < 0) |
1884 | return r; | |
8e2af478 | 1885 | |
718db961 LP |
1886 | r = sd_bus_message_read(message, "s", &name); |
1887 | if (r < 0) | |
ebcf1f97 | 1888 | return r; |
8e2af478 | 1889 | |
463d0d15 | 1890 | r = unit_file_get_state(m->unit_file_scope, NULL, name, &state); |
0ec0deaa LP |
1891 | if (r < 0) |
1892 | return r; | |
8e2af478 | 1893 | |
df2d202e | 1894 | return sd_bus_reply_method_return(message, "s", unit_file_state_to_string(state)); |
718db961 | 1895 | } |
8e2af478 | 1896 | |
19070062 | 1897 | static int method_get_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1898 | _cleanup_free_ char *default_target = NULL; |
1899 | Manager *m = userdata; | |
718db961 | 1900 | int r; |
c2756a68 | 1901 | |
718db961 LP |
1902 | assert(message); |
1903 | assert(m); | |
c2756a68 | 1904 | |
283868e1 SW |
1905 | /* Anyone can call this method */ |
1906 | ||
8a188de9 | 1907 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1908 | if (r < 0) |
1909 | return r; | |
c2756a68 | 1910 | |
463d0d15 | 1911 | r = unit_file_get_default(m->unit_file_scope, NULL, &default_target); |
718db961 | 1912 | if (r < 0) |
ebcf1f97 | 1913 | return r; |
c2756a68 | 1914 | |
df2d202e | 1915 | return sd_bus_reply_method_return(message, "s", default_target); |
718db961 | 1916 | } |
c2756a68 | 1917 | |
8f8f05a9 | 1918 | static int send_unit_files_changed(sd_bus *bus, void *userdata) { |
4afd3348 | 1919 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
1920 | int r; |
1921 | ||
1922 | assert(bus); | |
1923 | ||
151b9b96 | 1924 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged"); |
718db961 LP |
1925 | if (r < 0) |
1926 | return r; | |
1927 | ||
8f8f05a9 | 1928 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
1929 | } |
1930 | ||
af3d8113 ZJS |
1931 | /* Create an error reply, using the error information from changes[] |
1932 | * if possible, and fall back to generating an error from error code c. | |
1933 | * The error message only describes the first error. | |
1934 | * | |
1935 | * Coordinate with unit_file_dump_changes() in install.c. | |
1936 | */ | |
1937 | static int install_error( | |
1938 | sd_bus_error *error, | |
1939 | int c, | |
1940 | UnitFileChange *changes, | |
da6053d0 LP |
1941 | size_t n_changes) { |
1942 | ||
1943 | size_t i; | |
af3d8113 | 1944 | int r; |
8e20adca | 1945 | |
af3d8113 | 1946 | for (i = 0; i < n_changes; i++) |
637d6e5b | 1947 | |
af3d8113 | 1948 | switch(changes[i].type) { |
637d6e5b | 1949 | |
af3d8113 ZJS |
1950 | case 0 ... INT_MAX: |
1951 | continue; | |
637d6e5b | 1952 | |
af3d8113 ZJS |
1953 | case -EEXIST: |
1954 | if (changes[i].source) | |
1955 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, | |
1956 | "File %s already exists and is a symlink to %s.", | |
1957 | changes[i].path, changes[i].source); | |
1958 | else | |
1959 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, | |
1960 | "File %s already exists.", | |
1961 | changes[i].path); | |
1962 | goto found; | |
637d6e5b | 1963 | |
af3d8113 ZJS |
1964 | case -ERFKILL: |
1965 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, | |
1966 | "Unit file %s is masked.", changes[i].path); | |
1967 | goto found; | |
637d6e5b | 1968 | |
af3d8113 ZJS |
1969 | case -EADDRNOTAVAIL: |
1970 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_GENERATED, | |
1971 | "Unit %s is transient or generated.", changes[i].path); | |
1972 | goto found; | |
637d6e5b | 1973 | |
d7ceaf72 ZJS |
1974 | case -EUCLEAN: |
1975 | r = sd_bus_error_setf(error, BUS_ERROR_BAD_UNIT_SETTING, | |
1976 | "\"%s\" is not a valid unit name.", | |
1977 | changes[i].path); | |
1978 | goto found; | |
1979 | ||
af3d8113 ZJS |
1980 | case -ELOOP: |
1981 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_LINKED, | |
22683674 FB |
1982 | "Refusing to operate on alias name or linked unit file: %s", |
1983 | changes[i].path); | |
af3d8113 | 1984 | goto found; |
637d6e5b LP |
1985 | |
1986 | case -ENOENT: | |
22683674 FB |
1987 | r = sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, |
1988 | "Unit file %s does not exist.", changes[i].path); | |
637d6e5b LP |
1989 | goto found; |
1990 | ||
af3d8113 ZJS |
1991 | default: |
1992 | r = sd_bus_error_set_errnof(error, changes[i].type, "File %s: %m", changes[i].path); | |
1993 | goto found; | |
1994 | } | |
8e20adca | 1995 | |
637d6e5b LP |
1996 | r = c < 0 ? c : -EINVAL; |
1997 | ||
af3d8113 ZJS |
1998 | found: |
1999 | unit_file_changes_free(changes, n_changes); | |
2000 | return r; | |
8e20adca LP |
2001 | } |
2002 | ||
637d6e5b LP |
2003 | static int reply_unit_file_changes_and_free( |
2004 | Manager *m, | |
2005 | sd_bus_message *message, | |
2006 | int carries_install_info, | |
2007 | UnitFileChange *changes, | |
da6053d0 | 2008 | size_t n_changes, |
637d6e5b LP |
2009 | sd_bus_error *error) { |
2010 | ||
2011 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
2012 | bool bad = false, good = false; | |
da6053d0 | 2013 | size_t i; |
637d6e5b LP |
2014 | int r; |
2015 | ||
2016 | if (unit_file_changes_have_modification(changes, n_changes)) { | |
2017 | r = bus_foreach_bus(m, NULL, send_unit_files_changed, NULL); | |
2018 | if (r < 0) | |
2019 | log_debug_errno(r, "Failed to send UnitFilesChanged signal: %m"); | |
2020 | } | |
2021 | ||
2022 | r = sd_bus_message_new_method_return(message, &reply); | |
2023 | if (r < 0) | |
2024 | goto fail; | |
2025 | ||
2026 | if (carries_install_info >= 0) { | |
2027 | r = sd_bus_message_append(reply, "b", carries_install_info); | |
2028 | if (r < 0) | |
2029 | goto fail; | |
2030 | } | |
2031 | ||
2032 | r = sd_bus_message_open_container(reply, 'a', "(sss)"); | |
2033 | if (r < 0) | |
2034 | goto fail; | |
2035 | ||
2036 | for (i = 0; i < n_changes; i++) { | |
2037 | ||
2038 | if (changes[i].type < 0) { | |
2039 | bad = true; | |
2040 | continue; | |
2041 | } | |
2042 | ||
2043 | r = sd_bus_message_append( | |
2044 | reply, "(sss)", | |
2045 | unit_file_change_type_to_string(changes[i].type), | |
2046 | changes[i].path, | |
2047 | changes[i].source); | |
2048 | if (r < 0) | |
2049 | goto fail; | |
2050 | ||
2051 | good = true; | |
2052 | } | |
2053 | ||
2054 | /* If there was a failed change, and no successful change, then return the first failure as proper method call | |
2055 | * error. */ | |
2056 | if (bad && !good) | |
2057 | return install_error(error, 0, changes, n_changes); | |
2058 | ||
2059 | r = sd_bus_message_close_container(reply); | |
2060 | if (r < 0) | |
2061 | goto fail; | |
2062 | ||
2063 | unit_file_changes_free(changes, n_changes); | |
2064 | return sd_bus_send(NULL, reply, NULL); | |
2065 | ||
2066 | fail: | |
2067 | unit_file_changes_free(changes, n_changes); | |
2068 | return r; | |
2069 | } | |
2070 | ||
718db961 | 2071 | static int method_enable_unit_files_generic( |
718db961 | 2072 | sd_bus_message *message, |
d309c1c3 | 2073 | Manager *m, |
da6053d0 | 2074 | int (*call)(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, size_t *n_changes), |
ebcf1f97 LP |
2075 | bool carries_install_info, |
2076 | sd_bus_error *error) { | |
718db961 LP |
2077 | |
2078 | _cleanup_strv_free_ char **l = NULL; | |
2079 | UnitFileChange *changes = NULL; | |
da6053d0 | 2080 | size_t n_changes = 0; |
b3796dd8 | 2081 | UnitFileFlags flags; |
83654007 | 2082 | int r; |
718db961 | 2083 | |
718db961 LP |
2084 | assert(message); |
2085 | assert(m); | |
cad45ba1 | 2086 | |
718db961 LP |
2087 | r = sd_bus_message_read_strv(message, &l); |
2088 | if (r < 0) | |
ebcf1f97 | 2089 | return r; |
90bb85e1 | 2090 | |
83654007 LB |
2091 | if (sd_bus_message_is_method_call(message, NULL, "EnableUnitFilesWithFlags")) { |
2092 | uint64_t raw_flags; | |
d309c1c3 | 2093 | |
83654007 LB |
2094 | r = sd_bus_message_read(message, "t", &raw_flags); |
2095 | if (r < 0) | |
2096 | return r; | |
2097 | if ((raw_flags & ~_UNIT_FILE_FLAGS_MASK_PUBLIC) != 0) | |
2098 | return -EINVAL; | |
2099 | flags = raw_flags; | |
2100 | } else { | |
2101 | int runtime, force; | |
2102 | ||
2103 | r = sd_bus_message_read(message, "bb", &runtime, &force); | |
2104 | if (r < 0) | |
2105 | return r; | |
2106 | flags = unit_file_bools_to_flags(runtime, force); | |
2107 | } | |
b3796dd8 | 2108 | |
1d22e906 LP |
2109 | r = bus_verify_manage_unit_files_async(m, message, error); |
2110 | if (r < 0) | |
2111 | return r; | |
2112 | if (r == 0) | |
2113 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2114 | ||
b3796dd8 | 2115 | r = call(m->unit_file_scope, flags, NULL, l, &changes, &n_changes); |
af3d8113 ZJS |
2116 | if (r < 0) |
2117 | return install_error(error, r, changes, n_changes); | |
718db961 | 2118 | |
637d6e5b | 2119 | return reply_unit_file_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes, error); |
718db961 | 2120 | } |
c87eba54 | 2121 | |
83654007 LB |
2122 | static int method_enable_unit_files_with_flags(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2123 | return method_enable_unit_files_generic(message, userdata, unit_file_enable, true, error); | |
2124 | } | |
2125 | ||
19070062 | 2126 | static int method_enable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2127 | return method_enable_unit_files_generic(message, userdata, unit_file_enable, true, error); |
718db961 | 2128 | } |
ea430986 | 2129 | |
19070062 | 2130 | static int method_reenable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2131 | return method_enable_unit_files_generic(message, userdata, unit_file_reenable, true, error); |
718db961 LP |
2132 | } |
2133 | ||
19070062 | 2134 | static int method_link_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2135 | return method_enable_unit_files_generic(message, userdata, unit_file_link, false, error); |
718db961 LP |
2136 | } |
2137 | ||
da6053d0 | 2138 | static int unit_file_preset_without_mode(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char **files, UnitFileChange **changes, size_t *n_changes) { |
b3796dd8 | 2139 | return unit_file_preset(scope, flags, root_dir, files, UNIT_FILE_PRESET_FULL, changes, n_changes); |
d309c1c3 LP |
2140 | } |
2141 | ||
19070062 | 2142 | static int method_preset_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2143 | return method_enable_unit_files_generic(message, userdata, unit_file_preset_without_mode, true, error); |
718db961 LP |
2144 | } |
2145 | ||
19070062 | 2146 | static int method_mask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2147 | return method_enable_unit_files_generic(message, userdata, unit_file_mask, false, error); |
718db961 | 2148 | } |
ea430986 | 2149 | |
19070062 | 2150 | static int method_preset_unit_files_with_mode(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
d309c1c3 LP |
2151 | |
2152 | _cleanup_strv_free_ char **l = NULL; | |
d309c1c3 | 2153 | UnitFileChange *changes = NULL; |
da6053d0 | 2154 | size_t n_changes = 0; |
d309c1c3 LP |
2155 | Manager *m = userdata; |
2156 | UnitFilePresetMode mm; | |
d309c1c3 | 2157 | int runtime, force, r; |
b3796dd8 | 2158 | UnitFileFlags flags; |
d309c1c3 LP |
2159 | const char *mode; |
2160 | ||
d309c1c3 LP |
2161 | assert(message); |
2162 | assert(m); | |
2163 | ||
2164 | r = sd_bus_message_read_strv(message, &l); | |
2165 | if (r < 0) | |
2166 | return r; | |
2167 | ||
2168 | r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force); | |
2169 | if (r < 0) | |
2170 | return r; | |
2171 | ||
b3796dd8 JS |
2172 | flags = unit_file_bools_to_flags(runtime, force); |
2173 | ||
d309c1c3 LP |
2174 | if (isempty(mode)) |
2175 | mm = UNIT_FILE_PRESET_FULL; | |
2176 | else { | |
2177 | mm = unit_file_preset_mode_from_string(mode); | |
2178 | if (mm < 0) | |
2179 | return -EINVAL; | |
2180 | } | |
2181 | ||
1d22e906 LP |
2182 | r = bus_verify_manage_unit_files_async(m, message, error); |
2183 | if (r < 0) | |
2184 | return r; | |
2185 | if (r == 0) | |
2186 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2187 | ||
b3796dd8 | 2188 | r = unit_file_preset(m->unit_file_scope, flags, NULL, l, mm, &changes, &n_changes); |
af3d8113 ZJS |
2189 | if (r < 0) |
2190 | return install_error(error, r, changes, n_changes); | |
d309c1c3 | 2191 | |
637d6e5b | 2192 | return reply_unit_file_changes_and_free(m, message, r, changes, n_changes, error); |
d309c1c3 LP |
2193 | } |
2194 | ||
718db961 | 2195 | static int method_disable_unit_files_generic( |
718db961 | 2196 | sd_bus_message *message, |
596fc263 | 2197 | Manager *m, |
da6053d0 | 2198 | int (*call)(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, size_t *n_changes), |
ebcf1f97 | 2199 | sd_bus_error *error) { |
718db961 LP |
2200 | |
2201 | _cleanup_strv_free_ char **l = NULL; | |
2202 | UnitFileChange *changes = NULL; | |
83654007 | 2203 | UnitFileFlags flags; |
da6053d0 | 2204 | size_t n_changes = 0; |
83654007 | 2205 | int r; |
718db961 | 2206 | |
718db961 LP |
2207 | assert(message); |
2208 | assert(m); | |
2209 | ||
df823e23 | 2210 | r = sd_bus_message_read_strv(message, &l); |
ebcf1f97 LP |
2211 | if (r < 0) |
2212 | return r; | |
718db961 | 2213 | |
83654007 LB |
2214 | if (sd_bus_message_is_method_call(message, NULL, "DisableUnitFilesWithFlags")) { |
2215 | uint64_t raw_flags; | |
2216 | ||
2217 | r = sd_bus_message_read(message, "t", &raw_flags); | |
2218 | if (r < 0) | |
2219 | return r; | |
2220 | if ((raw_flags & ~_UNIT_FILE_FLAGS_MASK_PUBLIC) != 0 || | |
2221 | FLAGS_SET(raw_flags, UNIT_FILE_FORCE)) | |
2222 | return -EINVAL; | |
2223 | flags = raw_flags; | |
2224 | } else { | |
2225 | int runtime; | |
2226 | ||
2227 | r = sd_bus_message_read(message, "b", &runtime); | |
2228 | if (r < 0) | |
2229 | return r; | |
2230 | flags = unit_file_bools_to_flags(runtime, false); | |
2231 | } | |
718db961 | 2232 | |
1d22e906 LP |
2233 | r = bus_verify_manage_unit_files_async(m, message, error); |
2234 | if (r < 0) | |
2235 | return r; | |
2236 | if (r == 0) | |
2237 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2238 | ||
83654007 | 2239 | r = call(m->unit_file_scope, flags, NULL, l, &changes, &n_changes); |
af3d8113 ZJS |
2240 | if (r < 0) |
2241 | return install_error(error, r, changes, n_changes); | |
718db961 | 2242 | |
637d6e5b | 2243 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
718db961 | 2244 | } |
ea430986 | 2245 | |
83654007 LB |
2246 | static int method_disable_unit_files_with_flags(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2247 | return method_disable_unit_files_generic(message, userdata, unit_file_disable, error); | |
2248 | } | |
2249 | ||
19070062 | 2250 | static int method_disable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2251 | return method_disable_unit_files_generic(message, userdata, unit_file_disable, error); |
ea430986 LP |
2252 | } |
2253 | ||
19070062 | 2254 | static int method_unmask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2255 | return method_disable_unit_files_generic(message, userdata, unit_file_unmask, error); |
718db961 LP |
2256 | } |
2257 | ||
344ca755 LP |
2258 | static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2259 | _cleanup_strv_free_ char **l = NULL; | |
2260 | UnitFileChange *changes = NULL; | |
da6053d0 | 2261 | size_t n_changes = 0; |
344ca755 LP |
2262 | Manager *m = userdata; |
2263 | int r; | |
2264 | ||
2265 | assert(message); | |
2266 | assert(m); | |
2267 | ||
2268 | r = sd_bus_message_read_strv(message, &l); | |
2269 | if (r < 0) | |
2270 | return r; | |
2271 | ||
2272 | r = bus_verify_manage_unit_files_async(m, message, error); | |
2273 | if (r < 0) | |
2274 | return r; | |
2275 | if (r == 0) | |
2276 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2277 | ||
2278 | r = unit_file_revert(m->unit_file_scope, NULL, l, &changes, &n_changes); | |
af3d8113 ZJS |
2279 | if (r < 0) |
2280 | return install_error(error, r, changes, n_changes); | |
344ca755 | 2281 | |
637d6e5b | 2282 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
344ca755 LP |
2283 | } |
2284 | ||
19070062 | 2285 | static int method_set_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 2286 | UnitFileChange *changes = NULL; |
da6053d0 | 2287 | size_t n_changes = 0; |
718db961 | 2288 | Manager *m = userdata; |
718db961 LP |
2289 | const char *name; |
2290 | int force, r; | |
2291 | ||
718db961 LP |
2292 | assert(message); |
2293 | assert(m); | |
2294 | ||
1d22e906 | 2295 | r = mac_selinux_access_check(message, "enable", error); |
283868e1 SW |
2296 | if (r < 0) |
2297 | return r; | |
283868e1 | 2298 | |
1d22e906 | 2299 | r = sd_bus_message_read(message, "sb", &name, &force); |
ebcf1f97 LP |
2300 | if (r < 0) |
2301 | return r; | |
718db961 | 2302 | |
1d22e906 | 2303 | r = bus_verify_manage_unit_files_async(m, message, error); |
718db961 | 2304 | if (r < 0) |
ebcf1f97 | 2305 | return r; |
1d22e906 LP |
2306 | if (r == 0) |
2307 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
718db961 | 2308 | |
b3796dd8 | 2309 | r = unit_file_set_default(m->unit_file_scope, force ? UNIT_FILE_FORCE : 0, NULL, name, &changes, &n_changes); |
af3d8113 ZJS |
2310 | if (r < 0) |
2311 | return install_error(error, r, changes, n_changes); | |
718db961 | 2312 | |
637d6e5b | 2313 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
718db961 LP |
2314 | } |
2315 | ||
19070062 | 2316 | static int method_preset_all_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
d309c1c3 | 2317 | UnitFileChange *changes = NULL; |
da6053d0 | 2318 | size_t n_changes = 0; |
d309c1c3 LP |
2319 | Manager *m = userdata; |
2320 | UnitFilePresetMode mm; | |
d309c1c3 | 2321 | const char *mode; |
b3796dd8 | 2322 | UnitFileFlags flags; |
d309c1c3 LP |
2323 | int force, runtime, r; |
2324 | ||
d309c1c3 LP |
2325 | assert(message); |
2326 | assert(m); | |
2327 | ||
8a188de9 | 2328 | r = mac_selinux_access_check(message, "enable", error); |
d309c1c3 LP |
2329 | if (r < 0) |
2330 | return r; | |
2331 | ||
2332 | r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force); | |
2333 | if (r < 0) | |
2334 | return r; | |
2335 | ||
b3796dd8 JS |
2336 | flags = unit_file_bools_to_flags(runtime, force); |
2337 | ||
d309c1c3 LP |
2338 | if (isempty(mode)) |
2339 | mm = UNIT_FILE_PRESET_FULL; | |
2340 | else { | |
2341 | mm = unit_file_preset_mode_from_string(mode); | |
2342 | if (mm < 0) | |
2343 | return -EINVAL; | |
2344 | } | |
2345 | ||
1d22e906 LP |
2346 | r = bus_verify_manage_unit_files_async(m, message, error); |
2347 | if (r < 0) | |
2348 | return r; | |
2349 | if (r == 0) | |
2350 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2351 | ||
b3796dd8 | 2352 | r = unit_file_preset_all(m->unit_file_scope, flags, NULL, mm, &changes, &n_changes); |
af3d8113 ZJS |
2353 | if (r < 0) |
2354 | return install_error(error, r, changes, n_changes); | |
d309c1c3 | 2355 | |
637d6e5b | 2356 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
d309c1c3 LP |
2357 | } |
2358 | ||
19070062 | 2359 | static int method_add_dependency_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
e94937df LN |
2360 | _cleanup_strv_free_ char **l = NULL; |
2361 | Manager *m = userdata; | |
2362 | UnitFileChange *changes = NULL; | |
da6053d0 | 2363 | size_t n_changes = 0; |
e94937df | 2364 | int runtime, force, r; |
596fc263 | 2365 | char *target, *type; |
e94937df | 2366 | UnitDependency dep; |
b3796dd8 | 2367 | UnitFileFlags flags; |
e94937df | 2368 | |
e94937df LN |
2369 | assert(message); |
2370 | assert(m); | |
2371 | ||
2372 | r = bus_verify_manage_unit_files_async(m, message, error); | |
2373 | if (r < 0) | |
2374 | return r; | |
2375 | if (r == 0) | |
2376 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2377 | ||
2378 | r = sd_bus_message_read_strv(message, &l); | |
2379 | if (r < 0) | |
2380 | return r; | |
2381 | ||
2382 | r = sd_bus_message_read(message, "ssbb", &target, &type, &runtime, &force); | |
2383 | if (r < 0) | |
2384 | return r; | |
2385 | ||
b3796dd8 JS |
2386 | flags = unit_file_bools_to_flags(runtime, force); |
2387 | ||
e94937df LN |
2388 | dep = unit_dependency_from_string(type); |
2389 | if (dep < 0) | |
2390 | return -EINVAL; | |
2391 | ||
b3796dd8 | 2392 | r = unit_file_add_dependency(m->unit_file_scope, flags, NULL, l, target, dep, &changes, &n_changes); |
af3d8113 ZJS |
2393 | if (r < 0) |
2394 | return install_error(error, r, changes, n_changes); | |
e94937df | 2395 | |
637d6e5b | 2396 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
e94937df LN |
2397 | } |
2398 | ||
3b3557c4 JS |
2399 | static int method_get_unit_file_links(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2400 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
2401 | UnitFileChange *changes = NULL; | |
da6053d0 | 2402 | size_t n_changes = 0, i; |
3b3557c4 JS |
2403 | UnitFileFlags flags; |
2404 | const char *name; | |
2405 | char **p; | |
2406 | int runtime, r; | |
2407 | ||
2408 | r = sd_bus_message_read(message, "sb", &name, &runtime); | |
2409 | if (r < 0) | |
2410 | return r; | |
2411 | ||
2412 | r = sd_bus_message_new_method_return(message, &reply); | |
2413 | if (r < 0) | |
2414 | return r; | |
2415 | ||
2416 | r = sd_bus_message_open_container(reply, SD_BUS_TYPE_ARRAY, "s"); | |
2417 | if (r < 0) | |
2418 | return r; | |
2419 | ||
2420 | p = STRV_MAKE(name); | |
2421 | flags = UNIT_FILE_DRY_RUN | | |
2422 | (runtime ? UNIT_FILE_RUNTIME : 0); | |
2423 | ||
2424 | r = unit_file_disable(UNIT_FILE_SYSTEM, flags, NULL, p, &changes, &n_changes); | |
2425 | if (r < 0) | |
2426 | return log_error_errno(r, "Failed to get file links for %s: %m", name); | |
2427 | ||
2428 | for (i = 0; i < n_changes; i++) | |
2429 | if (changes[i].type == UNIT_FILE_UNLINK) { | |
2430 | r = sd_bus_message_append(reply, "s", changes[i].path); | |
2431 | if (r < 0) | |
2432 | return r; | |
2433 | } | |
2434 | ||
2435 | r = sd_bus_message_close_container(reply); | |
2436 | if (r < 0) | |
2437 | return r; | |
2438 | ||
2439 | return sd_bus_send(NULL, reply, NULL); | |
2440 | } | |
2441 | ||
15ea79f8 LP |
2442 | static int method_get_job_waiting(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2443 | Manager *m = userdata; | |
2444 | uint32_t id; | |
2445 | Job *j; | |
2446 | int r; | |
2447 | ||
2448 | assert(message); | |
2449 | assert(m); | |
2450 | ||
2451 | r = sd_bus_message_read(message, "u", &id); | |
2452 | if (r < 0) | |
2453 | return r; | |
2454 | ||
2455 | j = manager_get_job(m, id); | |
2456 | if (!j) | |
2457 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); | |
2458 | ||
2459 | return bus_job_method_get_waiting_jobs(message, j, error); | |
2460 | } | |
2461 | ||
c20076a8 LP |
2462 | static int method_abandon_scope(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2463 | Manager *m = userdata; | |
2464 | const char *name; | |
2465 | Unit *u; | |
2466 | int r; | |
2467 | ||
2468 | assert(message); | |
2469 | assert(m); | |
2470 | ||
2471 | r = sd_bus_message_read(message, "s", &name); | |
2472 | if (r < 0) | |
2473 | return r; | |
2474 | ||
2475 | r = bus_get_unit_by_name(m, message, name, &u, error); | |
2476 | if (r < 0) | |
2477 | return r; | |
2478 | ||
2479 | if (u->type != UNIT_SCOPE) | |
2480 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit '%s' is not a scope unit, refusing.", name); | |
2481 | ||
2482 | return bus_scope_method_abandon(message, u, error); | |
2483 | } | |
2484 | ||
0bb007f7 FB |
2485 | static int method_set_show_status(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2486 | Manager *m = userdata; | |
2487 | ShowStatus mode = _SHOW_STATUS_INVALID; | |
2488 | const char *t; | |
2489 | int r; | |
2490 | ||
2491 | assert(m); | |
2492 | assert(message); | |
2493 | ||
2494 | r = sd_bus_message_read(message, "s", &t); | |
2495 | if (r < 0) | |
2496 | return r; | |
2497 | ||
2498 | if (!isempty(t)) { | |
2499 | mode = show_status_from_string(t); | |
2500 | if (mode < 0) | |
2501 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid show status '%s'", t); | |
2502 | } | |
2503 | ||
43bba15a | 2504 | manager_override_show_status(m, mode, "bus"); |
0bb007f7 FB |
2505 | |
2506 | return sd_bus_reply_method_return(message, NULL); | |
2507 | } | |
2508 | ||
718db961 LP |
2509 | const sd_bus_vtable bus_manager_vtable[] = { |
2510 | SD_BUS_VTABLE_START(0), | |
2511 | ||
556089dc LP |
2512 | SD_BUS_PROPERTY("Version", "s", property_get_version, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
2513 | SD_BUS_PROPERTY("Features", "s", property_get_features, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
2514 | SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
7452394e | 2515 | SD_BUS_PROPERTY("Architecture", "s", property_get_architecture, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 2516 | SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
9f9f0342 LP |
2517 | BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FIRMWARE]), SD_BUS_VTABLE_PROPERTY_CONST), |
2518 | BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_LOADER]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2519 | BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_KERNEL]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2520 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2521 | BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_USERSPACE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2522 | BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2523 | BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2524 | BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2525 | BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2526 | BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2527 | BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2528 | BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
665a9774 YW |
2529 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDSecurityStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_SECURITY_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
2530 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDSecurityFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_SECURITY_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2531 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_GENERATORS_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2532 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_GENERATORS_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2533 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2534 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
25141692 LP |
2535 | SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level, property_set_log_level, 0, 0), |
2536 | SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target, property_set_log_target, 0, 0), | |
3ff52e8f YW |
2537 | SD_BUS_PROPERTY("NNames", "u", property_get_hashmap_size, offsetof(Manager, units), 0), |
2538 | SD_BUS_PROPERTY("NFailedUnits", "u", property_get_set_size, offsetof(Manager, failed_units), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
2539 | SD_BUS_PROPERTY("NJobs", "u", property_get_hashmap_size, offsetof(Manager, jobs), 0), | |
718db961 LP |
2540 | SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_installed_jobs), 0), |
2541 | SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_failed_jobs), 0), | |
2542 | SD_BUS_PROPERTY("Progress", "d", property_get_progress, 0, 0), | |
1ad6e8b3 | 2543 | SD_BUS_PROPERTY("Environment", "as", property_get_environment, 0, 0), |
556089dc | 2544 | SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool, offsetof(Manager, confirm_spawn), SD_BUS_VTABLE_PROPERTY_CONST), |
52d2566a | 2545 | SD_BUS_PROPERTY("ShowStatus", "b", property_get_show_status, 0, 0), |
a3c4eb07 | 2546 | SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.search_path), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
2547 | SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST), |
2548 | SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST), | |
986935cf FB |
2549 | SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", property_get_runtime_watchdog, property_set_runtime_watchdog, 0, 0), |
2550 | SD_BUS_WRITABLE_PROPERTY("RebootWatchdogUSec", "t", property_get_reboot_watchdog, property_set_reboot_watchdog, 0, 0), | |
65224c1d | 2551 | /* The following item is an obsolete alias */ |
986935cf FB |
2552 | SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", property_get_reboot_watchdog, property_set_reboot_watchdog, 0, SD_BUS_VTABLE_HIDDEN), |
2553 | SD_BUS_WRITABLE_PROPERTY("KExecWatchdogUSec", "t", property_get_kexec_watchdog, property_set_kexec_watchdog, 0, 0), | |
2a12e32e | 2554 | SD_BUS_WRITABLE_PROPERTY("ServiceWatchdogs", "b", bus_property_get_bool, bus_property_set_bool, offsetof(Manager, service_watchdogs), 0), |
b272b74d | 2555 | SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Manager, cgroup_root), 0), |
f755e3b7 | 2556 | SD_BUS_PROPERTY("SystemState", "s", property_get_system_state, 0, 0), |
287419c1 | 2557 | SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned, offsetof(Manager, return_value), 0), |
670a3efe EV |
2558 | SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec, offsetof(Manager, default_timer_accuracy_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
2559 | SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec, offsetof(Manager, default_timeout_start_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
2560 | SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec, offsetof(Manager, default_timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
dc653bf4 | 2561 | SD_BUS_PROPERTY("DefaultTimeoutAbortUSec", "t", property_get_default_timeout_abort_usec, 0, 0), |
670a3efe | 2562 | SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec, offsetof(Manager, default_restart_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
c075f5fc YW |
2563 | SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST), |
2564 | /* The following two items are obsolete alias */ | |
2565 | SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
2566 | 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 |
2567 | SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned, offsetof(Manager, default_start_limit_burst), SD_BUS_VTABLE_PROPERTY_CONST), |
2568 | SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool, offsetof(Manager, default_cpu_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2569 | SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool, offsetof(Manager, default_blockio_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2570 | SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, default_memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2571 | SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool, offsetof(Manager, default_tasks_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
97eb4231 | 2572 | SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2573 | SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2574 | SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2575 | SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2576 | SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2577 | SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2578 | SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2579 | SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2580 | SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2581 | SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2582 | SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2583 | SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2584 | SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2585 | SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2586 | SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2587 | SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2588 | SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2589 | SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2590 | SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2591 | SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2592 | SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2593 | SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2594 | SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2595 | SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2596 | SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2597 | SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2598 | SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2599 | SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2600 | SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2601 | SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2602 | SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2603 | SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
3a0f06c4 | 2604 | SD_BUS_PROPERTY("DefaultTasksMax", "t", bus_property_get_tasks_max, offsetof(Manager, default_tasks_max), 0), |
eed67a30 | 2605 | SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
afcfaa69 | 2606 | SD_BUS_PROPERTY("DefaultOOMPolicy", "s", bus_property_get_oom_policy, offsetof(Manager, default_oom_policy), SD_BUS_VTABLE_PROPERTY_CONST), |
718db961 | 2607 | |
dad97f04 ZJS |
2608 | SD_BUS_METHOD_WITH_NAMES("GetUnit", |
2609 | "s", | |
2610 | SD_BUS_PARAM(name), | |
2611 | "o", | |
2612 | SD_BUS_PARAM(unit), | |
2613 | method_get_unit, | |
2614 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2615 | SD_BUS_METHOD_WITH_NAMES("GetUnitByPID", | |
2616 | "u", | |
2617 | SD_BUS_PARAM(pid), | |
2618 | "o", | |
2619 | SD_BUS_PARAM(unit), | |
2620 | method_get_unit_by_pid, | |
2621 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2622 | SD_BUS_METHOD_WITH_NAMES("GetUnitByInvocationID", | |
2623 | "ay", | |
2624 | SD_BUS_PARAM(invocation_id), | |
2625 | "o", | |
2626 | SD_BUS_PARAM(unit), | |
2627 | method_get_unit_by_invocation_id, | |
2628 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2629 | SD_BUS_METHOD_WITH_NAMES("GetUnitByControlGroup", | |
2630 | "s", | |
2631 | SD_BUS_PARAM(cgroup), | |
2632 | "o", | |
2633 | SD_BUS_PARAM(unit), | |
2634 | method_get_unit_by_control_group, | |
2635 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2636 | SD_BUS_METHOD_WITH_NAMES("LoadUnit", | |
2637 | "s", | |
2638 | SD_BUS_PARAM(name), | |
2639 | "o", | |
2640 | SD_BUS_PARAM(unit), | |
2641 | method_load_unit, | |
2642 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2643 | SD_BUS_METHOD_WITH_NAMES("StartUnit", | |
2644 | "ss", | |
2645 | SD_BUS_PARAM(name) | |
2646 | SD_BUS_PARAM(mode), | |
2647 | "o", | |
2648 | SD_BUS_PARAM(job), | |
2649 | method_start_unit, | |
2650 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2651 | SD_BUS_METHOD_WITH_NAMES("StartUnitReplace", | |
2652 | "sss", | |
2653 | SD_BUS_PARAM(old_unit) | |
2654 | SD_BUS_PARAM(new_unit) | |
2655 | SD_BUS_PARAM(mode), | |
2656 | "o", | |
2657 | SD_BUS_PARAM(job), | |
2658 | method_start_unit_replace, | |
2659 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2660 | SD_BUS_METHOD_WITH_NAMES("StopUnit", | |
2661 | "ss", | |
2662 | SD_BUS_PARAM(name) | |
2663 | SD_BUS_PARAM(mode), | |
2664 | "o", | |
2665 | SD_BUS_PARAM(job), | |
2666 | method_stop_unit, | |
2667 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2668 | SD_BUS_METHOD_WITH_NAMES("ReloadUnit", | |
2669 | "ss", | |
2670 | SD_BUS_PARAM(name) | |
2671 | SD_BUS_PARAM(mode), | |
2672 | "o", | |
2673 | SD_BUS_PARAM(job), | |
2674 | method_reload_unit, | |
2675 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2676 | SD_BUS_METHOD_WITH_NAMES("RestartUnit", | |
2677 | "ss", | |
2678 | SD_BUS_PARAM(name) | |
2679 | SD_BUS_PARAM(mode), | |
2680 | "o", | |
2681 | SD_BUS_PARAM(job), | |
2682 | method_restart_unit, | |
2683 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2684 | SD_BUS_METHOD_WITH_NAMES("TryRestartUnit", | |
2685 | "ss", | |
2686 | SD_BUS_PARAM(name) | |
2687 | SD_BUS_PARAM(mode), | |
2688 | "o", | |
2689 | SD_BUS_PARAM(job), | |
2690 | method_try_restart_unit, | |
2691 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2692 | SD_BUS_METHOD_WITH_NAMES("ReloadOrRestartUnit", | |
2693 | "ss", | |
2694 | SD_BUS_PARAM(name) | |
2695 | SD_BUS_PARAM(mode), | |
2696 | "o", | |
2697 | SD_BUS_PARAM(job), | |
2698 | method_reload_or_restart_unit, | |
2699 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2700 | SD_BUS_METHOD_WITH_NAMES("ReloadOrTryRestartUnit", | |
2701 | "ss", | |
2702 | SD_BUS_PARAM(name) | |
2703 | SD_BUS_PARAM(mode), | |
2704 | "o", | |
2705 | SD_BUS_PARAM(job), | |
2706 | method_reload_or_try_restart_unit, | |
2707 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2708 | SD_BUS_METHOD_WITH_NAMES("EnqueueUnitJob", | |
2709 | "sss", | |
2710 | SD_BUS_PARAM(name) | |
2711 | SD_BUS_PARAM(job_type) | |
2712 | SD_BUS_PARAM(job_mode), | |
2713 | "uososa(uosos)", | |
2714 | SD_BUS_PARAM(job_id) | |
2715 | SD_BUS_PARAM(job_path) | |
2716 | SD_BUS_PARAM(unit_id) | |
2717 | SD_BUS_PARAM(unit_path) | |
2718 | SD_BUS_PARAM(job_type) | |
2719 | SD_BUS_PARAM(affected_jobs), | |
2720 | method_enqueue_unit_job, | |
2721 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2722 | SD_BUS_METHOD_WITH_NAMES("KillUnit", | |
2723 | "ssi", | |
2724 | SD_BUS_PARAM(name) | |
2725 | SD_BUS_PARAM(whom) | |
2726 | SD_BUS_PARAM(signal), | |
2727 | NULL,, | |
2728 | method_kill_unit, | |
2729 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2730 | SD_BUS_METHOD_WITH_NAMES("CleanUnit", | |
2731 | "sas", | |
2732 | SD_BUS_PARAM(name) | |
2733 | SD_BUS_PARAM(mask), | |
2734 | NULL,, | |
2735 | method_clean_unit, | |
2736 | SD_BUS_VTABLE_UNPRIVILEGED), | |
d9e45bc3 MS |
2737 | SD_BUS_METHOD_WITH_NAMES("FreezeUnit", |
2738 | "s", | |
2739 | SD_BUS_PARAM(name), | |
2740 | NULL,, | |
2741 | method_freeze_unit, | |
2742 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2743 | SD_BUS_METHOD_WITH_NAMES("ThawUnit", | |
2744 | "s", | |
2745 | SD_BUS_PARAM(name), | |
2746 | NULL,, | |
2747 | method_thaw_unit, | |
2748 | SD_BUS_VTABLE_UNPRIVILEGED), | |
dad97f04 ZJS |
2749 | SD_BUS_METHOD_WITH_NAMES("ResetFailedUnit", |
2750 | "s", | |
2751 | SD_BUS_PARAM(name), | |
2752 | NULL,, | |
2753 | method_reset_failed_unit, | |
2754 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2755 | SD_BUS_METHOD_WITH_NAMES("SetUnitProperties", | |
2756 | "sba(sv)", | |
2757 | SD_BUS_PARAM(name) | |
2758 | SD_BUS_PARAM(runtime) | |
2759 | SD_BUS_PARAM(properties), | |
2760 | NULL,, | |
2761 | method_set_unit_properties, | |
2762 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2763 | SD_BUS_METHOD_WITH_NAMES("RefUnit", | |
2764 | "s", | |
2765 | SD_BUS_PARAM(name), | |
2766 | NULL,, | |
2767 | method_ref_unit, | |
2768 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2769 | SD_BUS_METHOD_WITH_NAMES("UnrefUnit", | |
2770 | "s", | |
2771 | SD_BUS_PARAM(name), | |
2772 | NULL,, | |
2773 | method_unref_unit, | |
2774 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2775 | SD_BUS_METHOD_WITH_NAMES("StartTransientUnit", | |
2776 | "ssa(sv)a(sa(sv))", | |
2777 | SD_BUS_PARAM(name) | |
2778 | SD_BUS_PARAM(mode) | |
2779 | SD_BUS_PARAM(properties) | |
2780 | SD_BUS_PARAM(aux), | |
2781 | "o", | |
2782 | SD_BUS_PARAM(job), | |
2783 | method_start_transient_unit, | |
2784 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2785 | SD_BUS_METHOD_WITH_NAMES("GetUnitProcesses", | |
2786 | "s", | |
2787 | SD_BUS_PARAM(name), | |
2788 | "a(sus)", | |
2789 | SD_BUS_PARAM(processes), | |
2790 | method_get_unit_processes, | |
2791 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2792 | SD_BUS_METHOD_WITH_NAMES("AttachProcessesToUnit", | |
2793 | "ssau", | |
2794 | SD_BUS_PARAM(unit_name) | |
2795 | SD_BUS_PARAM(subcgroup) | |
2796 | SD_BUS_PARAM(pids), | |
2797 | NULL,, | |
2798 | method_attach_processes_to_unit, | |
2799 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2800 | SD_BUS_METHOD_WITH_NAMES("AbandonScope", | |
2801 | "s", | |
2802 | SD_BUS_PARAM(name), | |
2803 | NULL,, | |
2804 | method_abandon_scope, | |
2805 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2806 | SD_BUS_METHOD_WITH_NAMES("GetJob", | |
2807 | "u", | |
2808 | SD_BUS_PARAM(id), | |
2809 | "o", | |
2810 | SD_BUS_PARAM(job), | |
2811 | method_get_job, | |
2812 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2813 | SD_BUS_METHOD_WITH_NAMES("GetJobAfter", | |
2814 | "u", | |
2815 | SD_BUS_PARAM(id), | |
2816 | "a(usssoo)", | |
2817 | SD_BUS_PARAM(jobs), | |
2818 | method_get_job_waiting, | |
2819 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2820 | SD_BUS_METHOD_WITH_NAMES("GetJobBefore", | |
2821 | "u", | |
2822 | SD_BUS_PARAM(id), | |
2823 | "a(usssoo)", | |
2824 | SD_BUS_PARAM(jobs), | |
2825 | method_get_job_waiting, | |
2826 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2827 | SD_BUS_METHOD_WITH_NAMES("CancelJob", | |
2828 | "u", | |
2829 | SD_BUS_PARAM(id), | |
2830 | NULL,, | |
2831 | method_cancel_job, | |
2832 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2833 | SD_BUS_METHOD("ClearJobs", | |
2834 | NULL, | |
2835 | NULL, | |
2836 | method_clear_jobs, | |
2837 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2838 | SD_BUS_METHOD("ResetFailed", | |
2839 | NULL, | |
2840 | NULL, | |
2841 | method_reset_failed, | |
2842 | SD_BUS_VTABLE_UNPRIVILEGED), | |
0bb007f7 FB |
2843 | SD_BUS_METHOD_WITH_NAMES("SetShowStatus", |
2844 | "s", | |
2845 | SD_BUS_PARAM(mode), | |
2846 | NULL,, | |
2847 | method_set_show_status, | |
2848 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_ADMIN)), | |
dad97f04 ZJS |
2849 | SD_BUS_METHOD_WITH_NAMES("ListUnits", |
2850 | NULL,, | |
2851 | "a(ssssssouso)", | |
2852 | SD_BUS_PARAM(units), | |
2853 | method_list_units, | |
2854 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2855 | SD_BUS_METHOD_WITH_NAMES("ListUnitsFiltered", | |
2856 | "as", | |
2857 | SD_BUS_PARAM(states), | |
2858 | "a(ssssssouso)", | |
2859 | SD_BUS_PARAM(units), | |
2860 | method_list_units_filtered, | |
2861 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2862 | SD_BUS_METHOD_WITH_NAMES("ListUnitsByPatterns", | |
2863 | "asas", | |
2864 | SD_BUS_PARAM(states) | |
2865 | SD_BUS_PARAM(patterns), | |
2866 | "a(ssssssouso)", | |
2867 | SD_BUS_PARAM(units), | |
2868 | method_list_units_by_patterns, | |
2869 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2870 | SD_BUS_METHOD_WITH_NAMES("ListUnitsByNames", | |
2871 | "as", | |
2872 | SD_BUS_PARAM(names), | |
2873 | "a(ssssssouso)", | |
2874 | SD_BUS_PARAM(units), | |
2875 | method_list_units_by_names, | |
2876 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2877 | SD_BUS_METHOD_WITH_NAMES("ListJobs", | |
2878 | NULL,, | |
2879 | "a(usssoo)", | |
2880 | SD_BUS_PARAM(jobs), | |
2881 | method_list_jobs, | |
2882 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2883 | SD_BUS_METHOD("Subscribe", | |
2884 | NULL, | |
2885 | NULL, | |
2886 | method_subscribe, | |
2887 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2888 | SD_BUS_METHOD("Unsubscribe", | |
2889 | NULL, | |
2890 | NULL, | |
2891 | method_unsubscribe, | |
2892 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2893 | SD_BUS_METHOD_WITH_NAMES("Dump", | |
2894 | NULL,, | |
2895 | "s", | |
2896 | SD_BUS_PARAM(output), | |
2897 | method_dump, | |
2898 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2899 | SD_BUS_METHOD_WITH_NAMES("DumpByFileDescriptor", | |
2900 | NULL,, | |
2901 | "h", | |
2902 | SD_BUS_PARAM(fd), | |
2903 | method_dump_by_fd, | |
2904 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2905 | SD_BUS_METHOD_WITH_NAMES("CreateSnapshot", | |
2906 | "sb", | |
2907 | SD_BUS_PARAM(name) | |
2908 | SD_BUS_PARAM(cleanup), | |
2909 | "o", | |
2910 | SD_BUS_PARAM(unit), | |
2911 | method_refuse_snapshot, | |
2912 | SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), | |
2913 | SD_BUS_METHOD_WITH_NAMES("RemoveSnapshot", | |
2914 | "s", | |
2915 | SD_BUS_PARAM(name), | |
2916 | NULL,, | |
2917 | method_refuse_snapshot, | |
2918 | SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), | |
2919 | SD_BUS_METHOD("Reload", | |
2920 | NULL, | |
2921 | NULL, | |
2922 | method_reload, | |
2923 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2924 | SD_BUS_METHOD("Reexecute", | |
2925 | NULL, | |
2926 | NULL, | |
2927 | method_reexecute, | |
2928 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2929 | SD_BUS_METHOD("Exit", | |
2930 | NULL, | |
2931 | NULL, | |
2932 | method_exit, | |
2933 | 0), | |
2934 | SD_BUS_METHOD("Reboot", | |
2935 | NULL, | |
2936 | NULL, | |
2937 | method_reboot, | |
2938 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2939 | SD_BUS_METHOD("PowerOff", | |
2940 | NULL, | |
2941 | NULL, | |
2942 | method_poweroff, | |
2943 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2944 | SD_BUS_METHOD("Halt", | |
2945 | NULL, | |
2946 | NULL, | |
2947 | method_halt, | |
2948 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2949 | SD_BUS_METHOD("KExec", | |
2950 | NULL, | |
2951 | NULL, | |
2952 | method_kexec, | |
2953 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2954 | SD_BUS_METHOD_WITH_NAMES("SwitchRoot", | |
2955 | "ss", | |
2956 | SD_BUS_PARAM(new_root) | |
2957 | SD_BUS_PARAM(init), | |
2958 | NULL,, | |
2959 | method_switch_root, | |
2960 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2961 | SD_BUS_METHOD_WITH_NAMES("SetEnvironment", | |
2962 | "as", | |
2963 | SD_BUS_PARAM(assignments), | |
2964 | NULL,, | |
2965 | method_set_environment, | |
2966 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2967 | SD_BUS_METHOD_WITH_NAMES("UnsetEnvironment", | |
2968 | "as", | |
2969 | SD_BUS_PARAM(names), | |
2970 | NULL,, | |
2971 | method_unset_environment, | |
2972 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2973 | SD_BUS_METHOD_WITH_NAMES("UnsetAndSetEnvironment", | |
2974 | "asas", | |
2975 | SD_BUS_PARAM(names) | |
2976 | SD_BUS_PARAM(assignments), | |
2977 | NULL,, | |
2978 | method_unset_and_set_environment, | |
2979 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2980 | SD_BUS_METHOD_WITH_NAMES("ListUnitFiles", | |
2981 | NULL,, | |
2982 | "a(ss)", | |
2983 | SD_BUS_PARAM(unit_files), | |
2984 | method_list_unit_files, | |
2985 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2986 | SD_BUS_METHOD_WITH_NAMES("ListUnitFilesByPatterns", | |
2987 | "asas", | |
2988 | SD_BUS_PARAM(states) | |
2989 | SD_BUS_PARAM(patterns), | |
2990 | "a(ss)", | |
2991 | SD_BUS_PARAM(unit_files), | |
2992 | method_list_unit_files_by_patterns, | |
2993 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2994 | SD_BUS_METHOD_WITH_NAMES("GetUnitFileState", | |
2995 | "s", | |
2996 | SD_BUS_PARAM(file), | |
2997 | "s", | |
2998 | SD_BUS_PARAM(state), | |
2999 | method_get_unit_file_state, | |
3000 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3001 | SD_BUS_METHOD_WITH_NAMES("EnableUnitFiles", | |
3002 | "asbb", | |
3003 | SD_BUS_PARAM(files) | |
3004 | SD_BUS_PARAM(runtime) | |
3005 | SD_BUS_PARAM(force), | |
3006 | "ba(sss)", | |
3007 | SD_BUS_PARAM(carries_install_info) | |
3008 | SD_BUS_PARAM(changes), | |
3009 | method_enable_unit_files, | |
3010 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3011 | SD_BUS_METHOD_WITH_NAMES("DisableUnitFiles", | |
3012 | "asb", | |
3013 | SD_BUS_PARAM(files) | |
3014 | SD_BUS_PARAM(runtime), | |
3015 | "a(sss)", | |
3016 | SD_BUS_PARAM(changes), | |
3017 | method_disable_unit_files, | |
3018 | SD_BUS_VTABLE_UNPRIVILEGED), | |
83654007 LB |
3019 | SD_BUS_METHOD_WITH_NAMES("EnableUnitFilesWithFlags", |
3020 | "ast", | |
3021 | SD_BUS_PARAM(files) | |
3022 | SD_BUS_PARAM(flags), | |
3023 | "ba(sss)", | |
3024 | SD_BUS_PARAM(carries_install_info) | |
3025 | SD_BUS_PARAM(changes), | |
3026 | method_enable_unit_files_with_flags, | |
3027 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3028 | SD_BUS_METHOD_WITH_NAMES("DisableUnitFilesWithFlags", | |
3029 | "ast", | |
3030 | SD_BUS_PARAM(files) | |
3031 | SD_BUS_PARAM(flags), | |
3032 | "a(sss)", | |
3033 | SD_BUS_PARAM(changes), | |
3034 | method_disable_unit_files_with_flags, | |
3035 | SD_BUS_VTABLE_UNPRIVILEGED), | |
dad97f04 ZJS |
3036 | SD_BUS_METHOD_WITH_NAMES("ReenableUnitFiles", |
3037 | "asbb", | |
3038 | SD_BUS_PARAM(files) | |
3039 | SD_BUS_PARAM(runtime) | |
3040 | SD_BUS_PARAM(force), | |
3041 | "ba(sss)", | |
3042 | SD_BUS_PARAM(carries_install_info) | |
3043 | SD_BUS_PARAM(changes), | |
3044 | method_reenable_unit_files, | |
3045 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3046 | SD_BUS_METHOD_WITH_NAMES("LinkUnitFiles", | |
3047 | "asbb", | |
3048 | SD_BUS_PARAM(files) | |
3049 | SD_BUS_PARAM(runtime) | |
3050 | SD_BUS_PARAM(force), | |
3051 | "a(sss)", | |
3052 | SD_BUS_PARAM(changes), | |
3053 | method_link_unit_files, | |
3054 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3055 | SD_BUS_METHOD_WITH_NAMES("PresetUnitFiles", | |
3056 | "asbb", | |
3057 | SD_BUS_PARAM(files) | |
3058 | SD_BUS_PARAM(runtime) | |
3059 | SD_BUS_PARAM(force), | |
3060 | "ba(sss)", | |
3061 | SD_BUS_PARAM(carries_install_info) | |
3062 | SD_BUS_PARAM(changes), | |
3063 | method_preset_unit_files, | |
3064 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3065 | SD_BUS_METHOD_WITH_NAMES("PresetUnitFilesWithMode", | |
3066 | "assbb", | |
3067 | SD_BUS_PARAM(files) | |
3068 | SD_BUS_PARAM(mode) | |
3069 | SD_BUS_PARAM(runtime) | |
3070 | SD_BUS_PARAM(force), | |
3071 | "ba(sss)", | |
3072 | SD_BUS_PARAM(carries_install_info) | |
3073 | SD_BUS_PARAM(changes), | |
3074 | method_preset_unit_files_with_mode, | |
3075 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3076 | SD_BUS_METHOD_WITH_NAMES("MaskUnitFiles", | |
3077 | "asbb", | |
3078 | SD_BUS_PARAM(files) | |
3079 | SD_BUS_PARAM(runtime) | |
3080 | SD_BUS_PARAM(force), | |
3081 | "a(sss)", | |
3082 | SD_BUS_PARAM(changes), | |
3083 | method_mask_unit_files, | |
3084 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3085 | SD_BUS_METHOD_WITH_NAMES("UnmaskUnitFiles", | |
3086 | "asb", | |
3087 | SD_BUS_PARAM(files) | |
3088 | SD_BUS_PARAM(runtime), | |
3089 | "a(sss)", | |
3090 | SD_BUS_PARAM(changes), | |
3091 | method_unmask_unit_files, | |
3092 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3093 | SD_BUS_METHOD_WITH_NAMES("RevertUnitFiles", | |
3094 | "as", | |
3095 | SD_BUS_PARAM(files), | |
3096 | "a(sss)", | |
3097 | SD_BUS_PARAM(changes), | |
3098 | method_revert_unit_files, | |
3099 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3100 | SD_BUS_METHOD_WITH_NAMES("SetDefaultTarget", | |
3101 | "sb", | |
3102 | SD_BUS_PARAM(name) | |
3103 | SD_BUS_PARAM(force), | |
3104 | "a(sss)", | |
3105 | SD_BUS_PARAM(changes), | |
3106 | method_set_default_target, | |
3107 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3108 | SD_BUS_METHOD_WITH_NAMES("GetDefaultTarget", | |
3109 | NULL,, | |
3110 | "s", | |
3111 | SD_BUS_PARAM(name), | |
3112 | method_get_default_target, | |
3113 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3114 | SD_BUS_METHOD_WITH_NAMES("PresetAllUnitFiles", | |
3115 | "sbb", | |
3116 | SD_BUS_PARAM(mode) | |
3117 | SD_BUS_PARAM(runtime) | |
3118 | SD_BUS_PARAM(force), | |
3119 | "a(sss)", | |
3120 | SD_BUS_PARAM(changes), | |
3121 | method_preset_all_unit_files, | |
3122 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3123 | SD_BUS_METHOD_WITH_NAMES("AddDependencyUnitFiles", | |
3124 | "asssbb", | |
3125 | SD_BUS_PARAM(files) | |
3126 | SD_BUS_PARAM(target) | |
3127 | SD_BUS_PARAM(type) | |
3128 | SD_BUS_PARAM(runtime) | |
3129 | SD_BUS_PARAM(force), | |
3130 | "a(sss)", | |
3131 | SD_BUS_PARAM(changes), | |
3132 | method_add_dependency_unit_files, | |
3133 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3134 | SD_BUS_METHOD_WITH_NAMES("GetUnitFileLinks", | |
3135 | "sb", | |
3136 | SD_BUS_PARAM(name) | |
3137 | SD_BUS_PARAM(runtime), | |
3138 | "as", | |
3139 | SD_BUS_PARAM(links), | |
3140 | method_get_unit_file_links, | |
3141 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3142 | SD_BUS_METHOD_WITH_NAMES("SetExitCode", | |
3143 | "y", | |
3144 | SD_BUS_PARAM(number), | |
3145 | NULL,, | |
3146 | method_set_exit_code, | |
3147 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3148 | SD_BUS_METHOD_WITH_NAMES("LookupDynamicUserByName", | |
3149 | "s", | |
3150 | SD_BUS_PARAM(name), | |
3151 | "u", | |
3152 | SD_BUS_PARAM(uid), | |
3153 | method_lookup_dynamic_user_by_name, | |
3154 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3155 | SD_BUS_METHOD_WITH_NAMES("LookupDynamicUserByUID", | |
3156 | "u", | |
3157 | SD_BUS_PARAM(uid), | |
3158 | "s", | |
3159 | SD_BUS_PARAM(name), | |
3160 | method_lookup_dynamic_user_by_uid, | |
3161 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3162 | SD_BUS_METHOD_WITH_NAMES("GetDynamicUsers", | |
3163 | NULL,, | |
3164 | "a(us)", | |
3165 | SD_BUS_PARAM(users), | |
3166 | method_get_dynamic_users, | |
3167 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3168 | ||
3169 | SD_BUS_SIGNAL_WITH_NAMES("UnitNew", | |
3170 | "so", | |
3171 | SD_BUS_PARAM(id) | |
3172 | SD_BUS_PARAM(unit), | |
3173 | 0), | |
3174 | SD_BUS_SIGNAL_WITH_NAMES("UnitRemoved", | |
3175 | "so", | |
3176 | SD_BUS_PARAM(id) | |
3177 | SD_BUS_PARAM(unit), | |
3178 | 0), | |
3179 | SD_BUS_SIGNAL_WITH_NAMES("JobNew", | |
3180 | "uos", | |
3181 | SD_BUS_PARAM(id) | |
3182 | SD_BUS_PARAM(job) | |
3183 | SD_BUS_PARAM(unit), | |
3184 | 0), | |
3185 | SD_BUS_SIGNAL_WITH_NAMES("JobRemoved", | |
3186 | "uoss", | |
3187 | SD_BUS_PARAM(id) | |
3188 | SD_BUS_PARAM(job) | |
3189 | SD_BUS_PARAM(unit) | |
3190 | SD_BUS_PARAM(result), | |
3191 | 0), | |
3192 | SD_BUS_SIGNAL_WITH_NAMES("StartupFinished", | |
3193 | "tttttt", | |
3194 | SD_BUS_PARAM(firmware) | |
3195 | SD_BUS_PARAM(loader) | |
3196 | SD_BUS_PARAM(kernel) | |
3197 | SD_BUS_PARAM(initrd) | |
3198 | SD_BUS_PARAM(userspace) | |
3199 | SD_BUS_PARAM(total), | |
3200 | 0), | |
718db961 | 3201 | SD_BUS_SIGNAL("UnitFilesChanged", NULL, 0), |
dad97f04 ZJS |
3202 | SD_BUS_SIGNAL_WITH_NAMES("Reloading", |
3203 | "b", | |
3204 | SD_BUS_PARAM(active), | |
3205 | 0), | |
718db961 LP |
3206 | |
3207 | SD_BUS_VTABLE_END | |
ea430986 | 3208 | }; |
718db961 | 3209 | |
893f801d LP |
3210 | const sd_bus_vtable bus_manager_log_control_vtable[] = { |
3211 | SD_BUS_VTABLE_START(0), | |
3212 | ||
3213 | /* We define a private version of this interface here, since we want slightly different | |
3214 | * implementations for the setters. We'll still use the generic getters however, and we share the | |
3215 | * setters with the implementations for the Manager interface above (which pre-dates the generic | |
3216 | * service API interface). */ | |
3217 | ||
3218 | SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level, property_set_log_level, 0, 0), | |
3219 | SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target, property_set_log_target, 0, 0), | |
3220 | SD_BUS_PROPERTY("SyslogIdentifier", "s", bus_property_get_syslog_identifier, 0, 0), | |
3221 | ||
3222 | SD_BUS_VTABLE_END, | |
3223 | }; | |
3224 | ||
8f8f05a9 | 3225 | static int send_finished(sd_bus *bus, void *userdata) { |
4afd3348 | 3226 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
3227 | usec_t *times = userdata; |
3228 | int r; | |
3229 | ||
3230 | assert(bus); | |
3231 | assert(times); | |
3232 | ||
151b9b96 | 3233 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished"); |
718db961 LP |
3234 | if (r < 0) |
3235 | return r; | |
3236 | ||
3237 | r = sd_bus_message_append(message, "tttttt", times[0], times[1], times[2], times[3], times[4], times[5]); | |
3238 | if (r < 0) | |
3239 | return r; | |
3240 | ||
8f8f05a9 | 3241 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
3242 | } |
3243 | ||
39abcaee | 3244 | void bus_manager_send_finished( |
718db961 LP |
3245 | Manager *m, |
3246 | usec_t firmware_usec, | |
3247 | usec_t loader_usec, | |
3248 | usec_t kernel_usec, | |
3249 | usec_t initrd_usec, | |
3250 | usec_t userspace_usec, | |
3251 | usec_t total_usec) { | |
3252 | ||
39abcaee LP |
3253 | int r; |
3254 | ||
718db961 LP |
3255 | assert(m); |
3256 | ||
8f8f05a9 LP |
3257 | r = bus_foreach_bus( |
3258 | m, | |
3259 | NULL, | |
3260 | send_finished, | |
3261 | (usec_t[6]) { | |
3262 | firmware_usec, | |
3263 | loader_usec, | |
3264 | kernel_usec, | |
3265 | initrd_usec, | |
3266 | userspace_usec, | |
3267 | total_usec | |
3268 | }); | |
39abcaee | 3269 | if (r < 0) |
da927ba9 | 3270 | log_debug_errno(r, "Failed to send finished signal: %m"); |
718db961 LP |
3271 | } |
3272 | ||
8f8f05a9 | 3273 | static int send_reloading(sd_bus *bus, void *userdata) { |
4afd3348 | 3274 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
3275 | int r; |
3276 | ||
3277 | assert(bus); | |
3278 | ||
151b9b96 | 3279 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading"); |
718db961 LP |
3280 | if (r < 0) |
3281 | return r; | |
3282 | ||
3283 | r = sd_bus_message_append(message, "b", PTR_TO_INT(userdata)); | |
3284 | if (r < 0) | |
3285 | return r; | |
3286 | ||
8f8f05a9 | 3287 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
3288 | } |
3289 | ||
39abcaee LP |
3290 | void bus_manager_send_reloading(Manager *m, bool active) { |
3291 | int r; | |
3292 | ||
718db961 LP |
3293 | assert(m); |
3294 | ||
8f8f05a9 | 3295 | r = bus_foreach_bus(m, NULL, send_reloading, INT_TO_PTR(active)); |
39abcaee | 3296 | if (r < 0) |
da927ba9 | 3297 | log_debug_errno(r, "Failed to send reloading signal: %m"); |
03455c28 LDM |
3298 | } |
3299 | ||
3300 | static int send_changed_signal(sd_bus *bus, void *userdata) { | |
3301 | assert(bus); | |
3302 | ||
3303 | return sd_bus_emit_properties_changed_strv(bus, | |
3304 | "/org/freedesktop/systemd1", | |
3305 | "org.freedesktop.systemd1.Manager", | |
3306 | NULL); | |
3307 | } | |
39abcaee | 3308 | |
03455c28 LDM |
3309 | void bus_manager_send_change_signal(Manager *m) { |
3310 | int r; | |
3311 | ||
3312 | assert(m); | |
3313 | ||
3314 | r = bus_foreach_bus(m, NULL, send_changed_signal, NULL); | |
3315 | if (r < 0) | |
3316 | log_debug_errno(r, "Failed to send manager change signal: %m"); | |
718db961 | 3317 | } |