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