]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
a7334b09 | 2 | |
836e4e7e | 3 | #include <linux/capability.h> |
eed67a30 | 4 | #include <sys/prctl.h> |
871c44a7 | 5 | #include <unistd.h> |
ea430986 | 6 | |
b5efdb8a | 7 | #include "alloc-util.h" |
07630cea | 8 | #include "architecture.h" |
1e4e5572 | 9 | #include "bitfield.h" |
09bde77f | 10 | #include "build.h" |
07630cea | 11 | #include "bus-common-errors.h" |
40af3d02 | 12 | #include "bus-get-properties.h" |
25141692 | 13 | #include "bus-log-control-api.h" |
ab33edb0 | 14 | #include "bus-message-util.h" |
4ac08d8a | 15 | #include "bus-util.h" |
f461a28d | 16 | #include "chase.h" |
1257274a | 17 | #include "confidential-virt.h" |
3a0f06c4 | 18 | #include "dbus-cgroup.h" |
07630cea | 19 | #include "dbus-execute.h" |
836e4e7e | 20 | #include "dbus.h" |
2ea31e5b | 21 | #include "dbus-job.h" |
3ffd4af2 | 22 | #include "dbus-manager.h" |
c20076a8 | 23 | #include "dbus-scope.h" |
5e8deb94 | 24 | #include "dbus-service.h" |
07630cea | 25 | #include "dbus-unit.h" |
d0309467 | 26 | #include "dbus-util.h" |
4ea4abb6 | 27 | #include "dynamic-user.h" |
07630cea | 28 | #include "env-util.h" |
836e4e7e | 29 | #include "errno-util.h" |
3ffd4af2 | 30 | #include "fd-util.h" |
f97b34a6 | 31 | #include "format-util.h" |
836e4e7e DDM |
32 | #include "glyph-util.h" |
33 | #include "hashmap.h" | |
4da159bc | 34 | #include "initrd-util.h" |
07630cea | 35 | #include "install.h" |
3a437f52 | 36 | #include "locale-util.h" |
07630cea | 37 | #include "log.h" |
2a341bb9 | 38 | #include "manager-dump.h" |
836e4e7e | 39 | #include "manager.h" |
a87a9625 | 40 | #include "memfd-util.h" |
d58ad743 | 41 | #include "os-util.h" |
07630cea | 42 | #include "path-util.h" |
836e4e7e | 43 | #include "pidref.h" |
d4a402e4 | 44 | #include "process-util.h" |
07630cea | 45 | #include "selinux-access.h" |
836e4e7e | 46 | #include "set.h" |
07630cea LP |
47 | #include "string-util.h" |
48 | #include "strv.h" | |
7ccbd1ae | 49 | #include "syslog-util.h" |
d851637c | 50 | #include "taint.h" |
836e4e7e | 51 | #include "unit-name.h" |
29206d46 | 52 | #include "user-util.h" |
bdb577f5 | 53 | #include "version.h" |
07630cea LP |
54 | #include "virt.h" |
55 | #include "watchdog.h" | |
ea430986 | 56 | |
b3796dd8 JS |
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 | ||
afcfaa69 | 62 | BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_oom_policy, oom_policy, OOMPolicy); |
c44a285c | 63 | BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_emergency_action, emergency_action, EmergencyAction); |
afcfaa69 | 64 | |
681bd2c5 | 65 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_version, "s", GIT_VERSION); |
91b79ba8 | 66 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_features, "s", systemd_features); |
23c9a63a | 67 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_architecture, "s", architecture_to_string(uname_architecture())); |
23c9a63a YW |
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)); | |
92c23c5a YW |
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); | |
3bf0cb65 | 72 | static BUS_DEFINE_PROPERTY_GET(property_get_default_timeout_abort_usec, "t", Manager, manager_default_timeout_abort_usec); |
10f3f4ed | 73 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_watchdog_device, "s", watchdog_get_device()); |
10f3f4ed YW |
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)); | |
cc156539 | 76 | static BUS_DEFINE_PROPERTY_GET(property_get_progress, "d", Manager, manager_get_progress); |
718db961 LP |
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, | |
ebcf1f97 LP |
84 | void *userdata, |
85 | sd_bus_error *error) { | |
718db961 | 86 | |
1b86c7c5 | 87 | Virtualization v; |
5c22925a | 88 | |
718db961 LP |
89 | assert(bus); |
90 | assert(reply); | |
91 | ||
5c22925a LP |
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", | |
79a60375 | 101 | v == VIRTUALIZATION_NONE ? NULL : virtualization_to_string(v)); |
718db961 LP |
102 | } |
103 | ||
1257274a DB |
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 | ||
718db961 LP |
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, | |
ebcf1f97 LP |
131 | void *userdata, |
132 | sd_bus_error *error) { | |
718db961 | 133 | |
718db961 LP |
134 | assert(bus); |
135 | assert(reply); | |
c5d34390 | 136 | |
d851637c | 137 | _cleanup_free_ char *s = taint_string(); |
af6b0ecc LP |
138 | if (!s) |
139 | return log_oom(); | |
c5d34390 | 140 | |
af6b0ecc | 141 | return sd_bus_message_append(reply, "s", s); |
c5d34390 LP |
142 | } |
143 | ||
718db961 LP |
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, | |
ebcf1f97 LP |
150 | void *userdata, |
151 | sd_bus_error *error) { | |
718db961 | 152 | |
bda7d78b | 153 | Manager *m = userdata; |
c826cda4 | 154 | const char *t; |
718db961 | 155 | int r; |
c826cda4 | 156 | |
718db961 LP |
157 | assert(bus); |
158 | assert(value); | |
c826cda4 | 159 | |
718db961 LP |
160 | r = sd_bus_message_read(value, "s", &t); |
161 | if (r < 0) | |
162 | return r; | |
c826cda4 | 163 | |
bda7d78b FB |
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; | |
c826cda4 AB |
177 | } |
178 | ||
718db961 LP |
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, | |
ebcf1f97 LP |
185 | void *userdata, |
186 | sd_bus_error *error) { | |
718db961 | 187 | |
a6ecbf83 | 188 | Manager *m = userdata; |
c826cda4 | 189 | const char *t; |
718db961 | 190 | int r; |
c826cda4 | 191 | |
718db961 LP |
192 | assert(bus); |
193 | assert(value); | |
c826cda4 | 194 | |
718db961 LP |
195 | r = sd_bus_message_read(value, "s", &t); |
196 | if (r < 0) | |
197 | return r; | |
c826cda4 | 198 | |
a6ecbf83 FB |
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; | |
c826cda4 AB |
212 | } |
213 | ||
1ad6e8b3 LP |
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; | |
99534007 | 224 | Manager *m = ASSERT_PTR(userdata); |
1ad6e8b3 LP |
225 | int r; |
226 | ||
227 | assert(bus); | |
228 | assert(reply); | |
1ad6e8b3 LP |
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 | ||
52d2566a ZJS |
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 | ||
99534007 | 246 | Manager *m = ASSERT_PTR(userdata); |
52d2566a ZJS |
247 | |
248 | assert(bus); | |
249 | assert(reply); | |
52d2566a | 250 | |
44a41954 | 251 | return sd_bus_message_append(reply, "b", manager_get_show_status_on(m)); |
52d2566a ZJS |
252 | } |
253 | ||
986935cf | 254 | static int property_get_runtime_watchdog( |
718db961 LP |
255 | sd_bus *bus, |
256 | const char *path, | |
257 | const char *interface, | |
258 | const char *property, | |
986935cf | 259 | sd_bus_message *reply, |
ebcf1f97 LP |
260 | void *userdata, |
261 | sd_bus_error *error) { | |
05d6a3b6 | 262 | |
99534007 | 263 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
264 | |
265 | assert(bus); | |
986935cf FB |
266 | assert(reply); |
267 | ||
268 | return sd_bus_message_append(reply, "t", manager_get_watchdog(m, WATCHDOG_RUNTIME)); | |
269 | } | |
270 | ||
5717062e CK |
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 | ||
99534007 | 280 | Manager *m = ASSERT_PTR(userdata); |
5717062e | 281 | |
5717062e CK |
282 | assert(bus); |
283 | assert(reply); | |
284 | ||
285 | return sd_bus_message_append(reply, "t", manager_get_watchdog(m, WATCHDOG_PRETIMEOUT)); | |
286 | } | |
287 | ||
aff3a9e1 LB |
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 | ||
99534007 | 297 | Manager *m = ASSERT_PTR(userdata); |
aff3a9e1 | 298 | |
aff3a9e1 LB |
299 | assert(bus); |
300 | assert(reply); | |
301 | ||
302 | return sd_bus_message_append(reply, "s", m->watchdog_pretimeout_governor); | |
303 | } | |
304 | ||
986935cf FB |
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 | ||
99534007 | 314 | Manager *m = ASSERT_PTR(userdata); |
986935cf | 315 | |
986935cf FB |
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 | ||
99534007 | 331 | Manager *m = ASSERT_PTR(userdata); |
986935cf | 332 | |
986935cf FB |
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); | |
718db961 LP |
344 | assert(value); |
345 | ||
346 | assert_cc(sizeof(usec_t) == sizeof(uint64_t)); | |
347 | ||
986935cf | 348 | r = sd_bus_message_read(value, "t", &timeout); |
718db961 LP |
349 | if (r < 0) |
350 | return r; | |
351 | ||
aac47032 YW |
352 | manager_override_watchdog(m, type, timeout); |
353 | return 0; | |
986935cf FB |
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 | ||
5717062e CK |
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 | ||
aff3a9e1 LB |
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 | ||
99534007 | 389 | Manager *m = ASSERT_PTR(userdata); |
aff3a9e1 LB |
390 | char *governor; |
391 | int r; | |
392 | ||
aff3a9e1 LB |
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 | ||
986935cf FB |
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 | ||
99534007 | 423 | _unused_ Manager *m = ASSERT_PTR(userdata); |
986935cf | 424 | |
986935cf FB |
425 | assert(bus); |
426 | assert(value); | |
427 | ||
428 | return property_set_watchdog(userdata, WATCHDOG_KEXEC, value); | |
05d6a3b6 LP |
429 | } |
430 | ||
d4a402e4 LP |
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 | ||
99534007 | 440 | Manager *m = ASSERT_PTR(userdata); |
d4a402e4 LP |
441 | int r, n; |
442 | ||
d4a402e4 LP |
443 | assert(bus); |
444 | assert(reply); | |
445 | ||
c9e120e0 LP |
446 | if (m->defaults.oom_score_adjust_set) |
447 | n = m->defaults.oom_score_adjust; | |
d4a402e4 LP |
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 | ||
96cc4453 | 458 | static int bus_get_unit_by_name(Manager *m, sd_bus_message *message, const char *name, Unit **ret_unit, sd_bus_error *error) { |
718db961 LP |
459 | Unit *u; |
460 | int r; | |
dfae3488 | 461 | |
dfae3488 | 462 | assert(m); |
96cc4453 LP |
463 | assert(message); |
464 | assert(ret_unit); | |
dfae3488 | 465 | |
cb31470f ZJS |
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. */ | |
dfae3488 | 468 | |
1d22e906 | 469 | if (isempty(name)) { |
4ac08d8a | 470 | _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; |
1d22e906 | 471 | |
4ac08d8a | 472 | r = bus_query_sender_pidref(message, &pidref); |
1d22e906 LP |
473 | if (r < 0) |
474 | return r; | |
475 | ||
4ac08d8a | 476 | u = manager_get_unit_by_pidref(m, &pidref); |
1d22e906 | 477 | if (!u) |
1b09b81c | 478 | return sd_bus_error_set(error, BUS_ERROR_NO_SUCH_UNIT, "Client not member of any unit."); |
1d22e906 LP |
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 | } | |
dfae3488 | 484 | |
96cc4453 LP |
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 | ||
4659bf6f | 502 | static int reply_unit_path(Unit *u, sd_bus_message *message, sd_bus_error *error) { |
96cc4453 | 503 | _cleanup_free_ char *path = NULL; |
4659bf6f LP |
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) { | |
99534007 | 521 | Manager *m = ASSERT_PTR(userdata); |
96cc4453 LP |
522 | const char *name; |
523 | Unit *u; | |
524 | int r; | |
525 | ||
526 | assert(message); | |
96cc4453 LP |
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 | ||
4659bf6f | 538 | return reply_unit_path(u, message, error); |
718db961 | 539 | } |
c0576cd6 | 540 | |
19070062 | 541 | static int method_get_unit_by_pid(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 542 | Manager *m = ASSERT_PTR(userdata); |
4ac08d8a | 543 | _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; |
718db961 LP |
544 | Unit *u; |
545 | int r; | |
c0576cd6 | 546 | |
718db961 | 547 | assert(message); |
c0576cd6 | 548 | |
718db961 | 549 | assert_cc(sizeof(pid_t) == sizeof(uint32_t)); |
729e3769 | 550 | |
283868e1 SW |
551 | /* Anyone can call this method */ |
552 | ||
4ac08d8a | 553 | r = sd_bus_message_read(message, "u", &pidref.pid); |
718db961 | 554 | if (r < 0) |
ebcf1f97 | 555 | return r; |
4ac08d8a LP |
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); | |
718db961 | 560 | if (r < 0) |
ebcf1f97 | 561 | return r; |
729e3769 LP |
562 | } |
563 | ||
4ac08d8a | 564 | u = manager_get_unit_by_pidref(m, &pidref); |
718db961 | 565 | if (!u) |
4ac08d8a | 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); |
c0576cd6 | 567 | |
4659bf6f | 568 | return reply_unit_path(u, message, error); |
718db961 LP |
569 | } |
570 | ||
4b58153d LP |
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; | |
99534007 | 573 | Manager *m = ASSERT_PTR(userdata); |
4b58153d | 574 | sd_id128_t id; |
4b58153d | 575 | Unit *u; |
4b58153d LP |
576 | int r; |
577 | ||
578 | assert(message); | |
4b58153d LP |
579 | |
580 | /* Anyone can call this method */ | |
581 | ||
8157cc0e | 582 | if (bus_message_read_id128(message, &id) < 0) |
1b09b81c | 583 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid invocation ID"); |
4b58153d LP |
584 | |
585 | if (sd_id128_is_null(id)) { | |
4ac08d8a | 586 | _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; |
4b58153d | 587 | |
4ac08d8a | 588 | r = bus_query_sender_pidref(message, &pidref); |
4b58153d LP |
589 | if (r < 0) |
590 | return r; | |
591 | ||
4ac08d8a | 592 | u = manager_get_unit_by_pidref(m, &pidref); |
4b58153d | 593 | if (!u) |
cb31470f | 594 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, |
4ac08d8a | 595 | "Client " PID_FMT " not member of any unit.", pidref.pid); |
4b58153d LP |
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 | ||
cb31470f ZJS |
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. */ | |
4b58153d LP |
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 | ||
267dd427 | 616 | static int method_get_unit_by_control_group(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
267dd427 LP |
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) | |
cb31470f ZJS |
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); | |
267dd427 | 631 | |
4659bf6f | 632 | return reply_unit_path(u, message, error); |
267dd427 LP |
633 | } |
634 | ||
e0e7bc82 LB |
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; | |
495e75ed | 637 | _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; |
e0e7bc82 LB |
638 | Manager *m = ASSERT_PTR(userdata); |
639 | _cleanup_free_ char *path = NULL; | |
640 | int r, pidfd; | |
e0e7bc82 LB |
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 | ||
495e75ed | 649 | r = pidref_set_pidfd(&pidref, pidfd); |
e0e7bc82 LB |
650 | if (r < 0) |
651 | return sd_bus_error_set_errnof(error, r, "Failed to get PID from PIDFD: %m"); | |
652 | ||
495e75ed | 653 | u = manager_get_unit_by_pidref(m, &pidref); |
e0e7bc82 | 654 | if (!u) |
495e75ed | 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); |
e0e7bc82 LB |
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. */ | |
495e75ed | 679 | r = pidref_verify(&pidref); |
f840c7d5 | 680 | if (r == -ESRCH) |
e0e7bc82 LB |
681 | return sd_bus_error_setf(error, |
682 | BUS_ERROR_NO_SUCH_PROCESS, | |
f840c7d5 | 683 | "The PIDFD's PID "PID_FMT" changed during the lookup operation.", |
495e75ed | 684 | pidref.pid); |
f840c7d5 LB |
685 | if (r < 0) |
686 | return sd_bus_error_set_errnof(error, r, "Failed to get PID from PIDFD: %m"); | |
e0e7bc82 | 687 | |
51cc3825 | 688 | return sd_bus_message_send(reply); |
e0e7bc82 LB |
689 | } |
690 | ||
19070062 | 691 | static int method_load_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 692 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
693 | const char *name; |
694 | Unit *u; | |
695 | int r; | |
c0576cd6 | 696 | |
718db961 | 697 | assert(message); |
718db961 | 698 | |
283868e1 SW |
699 | /* Anyone can call this method */ |
700 | ||
718db961 LP |
701 | r = sd_bus_message_read(message, "s", &name); |
702 | if (r < 0) | |
ebcf1f97 | 703 | return r; |
c0576cd6 | 704 | |
96cc4453 LP |
705 | r = bus_load_unit_by_name(m, message, name, &u, error); |
706 | if (r < 0) | |
707 | return r; | |
718db961 | 708 | |
4659bf6f | 709 | return reply_unit_path(u, message, error); |
c0576cd6 LP |
710 | } |
711 | ||
19070062 | 712 | static int method_start_unit_generic(sd_bus_message *message, Manager *m, JobType job_type, bool reload_if_possible, sd_bus_error *error) { |
718db961 LP |
713 | const char *name; |
714 | Unit *u; | |
c0576cd6 LP |
715 | int r; |
716 | ||
718db961 LP |
717 | assert(message); |
718 | assert(m); | |
c0576cd6 | 719 | |
718db961 LP |
720 | r = sd_bus_message_read(message, "s", &name); |
721 | if (r < 0) | |
ebcf1f97 | 722 | return r; |
c0576cd6 | 723 | |
ebcf1f97 | 724 | r = manager_load_unit(m, name, NULL, error, &u); |
718db961 | 725 | if (r < 0) |
ebcf1f97 | 726 | return r; |
718db961 | 727 | |
19070062 | 728 | return bus_unit_method_start_generic(message, u, job_type, reload_if_possible, error); |
c0576cd6 LP |
729 | } |
730 | ||
19070062 | 731 | static int method_start_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 732 | return method_start_unit_generic(message, userdata, JOB_START, /* reload_if_possible = */ false, error); |
718db961 | 733 | } |
c757a65b | 734 | |
19070062 | 735 | static int method_stop_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 736 | return method_start_unit_generic(message, userdata, JOB_STOP, /* reload_if_possible = */ false, error); |
718db961 | 737 | } |
c757a65b | 738 | |
19070062 | 739 | static int method_reload_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 740 | return method_start_unit_generic(message, userdata, JOB_RELOAD, /* reload_if_possible = */ false, error); |
718db961 | 741 | } |
c757a65b | 742 | |
19070062 | 743 | static int method_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 744 | return method_start_unit_generic(message, userdata, JOB_RESTART, /* reload_if_possible = */ false, error); |
c757a65b LP |
745 | } |
746 | ||
19070062 | 747 | static int method_try_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 748 | return method_start_unit_generic(message, userdata, JOB_TRY_RESTART, /* reload_if_possible = */ false, error); |
718db961 | 749 | } |
d200735e | 750 | |
19070062 | 751 | static int method_reload_or_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 752 | return method_start_unit_generic(message, userdata, JOB_RESTART, /* reload_if_possible = */ true, error); |
718db961 | 753 | } |
d200735e | 754 | |
19070062 | 755 | static int method_reload_or_try_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 756 | return method_start_unit_generic(message, userdata, JOB_TRY_RESTART, /* reload_if_possible = */ true, error); |
718db961 | 757 | } |
d200735e | 758 | |
42561fc9 LP |
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 | ||
50cbaba4 LP |
771 | const char *name; |
772 | Unit *u; | |
773 | int r; | |
774 | ||
775 | assert(message); | |
776 | assert(m); | |
8a70edc1 | 777 | assert(handler); |
50cbaba4 | 778 | |
42561fc9 LP |
779 | /* Read the first argument from the command and pass the operation to the specified per-unit |
780 | * method. */ | |
781 | ||
50cbaba4 LP |
782 | r = sd_bus_message_read(message, "s", &name); |
783 | if (r < 0) | |
784 | return r; | |
785 | ||
42561fc9 LP |
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); | |
50cbaba4 LP |
790 | if (r < 0) |
791 | return r; | |
792 | ||
42561fc9 LP |
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); | |
50cbaba4 LP |
805 | } |
806 | ||
19070062 | 807 | static int method_start_unit_replace(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 808 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
809 | const char *old_name; |
810 | Unit *u; | |
1adf1049 | 811 | int r; |
ea430986 | 812 | |
ea430986 | 813 | assert(message); |
ea430986 | 814 | |
718db961 LP |
815 | r = sd_bus_message_read(message, "s", &old_name); |
816 | if (r < 0) | |
ebcf1f97 | 817 | return r; |
ea430986 | 818 | |
96cc4453 LP |
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) | |
ebcf1f97 | 823 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name); |
c0576cd6 | 824 | |
2d8cc7a7 | 825 | return method_start_unit_generic(message, m, JOB_START, /* reload_if_possible = */ false, error); |
718db961 | 826 | } |
ea430986 | 827 | |
19070062 | 828 | static int method_kill_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
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); | |
718db961 | 832 | } |
8a0867d6 | 833 | |
4d3bac56 LP |
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 | ||
d9e45bc3 | 840 | static int method_freeze_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
47266ea2 MY |
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); | |
d9e45bc3 MS |
843 | } |
844 | ||
845 | static int method_thaw_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
47266ea2 MY |
846 | /* Same as freeze above */ |
847 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_thaw, GENERIC_UNIT_VALIDATE_LOADED); | |
d9e45bc3 MS |
848 | } |
849 | ||
19070062 | 850 | static int method_reset_failed_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
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); | |
718db961 | 854 | } |
5dd9014f | 855 | |
19070062 | 856 | static int method_set_unit_properties(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
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); | |
718db961 LP |
859 | } |
860 | ||
5e8deb94 LB |
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 | ||
af477139 LB |
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 | ||
05a98afd | 871 | static int method_ref_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
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); | |
05a98afd LP |
874 | } |
875 | ||
876 | static int method_unref_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
42561fc9 LP |
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); | |
05a98afd LP |
880 | } |
881 | ||
6900c740 | 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) : "", | |
c1d95b71 | 909 | empty_to_root(job_path)); |
6900c740 | 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; | |
99534007 | 914 | Manager *m = ASSERT_PTR(userdata); |
6900c740 | 915 | int r; |
6900c740 | 916 | _cleanup_strv_free_ char **units = NULL; |
917 | ||
918 | assert(message); | |
6900c740 | 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 | ||
96cc4453 | 938 | r = bus_load_unit_by_name(m, message, *unit, &u, error); |
6900c740 | 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 | ||
51cc3825 | 951 | return sd_bus_message_send(reply); |
6900c740 | 952 | } |
953 | ||
291d565a | 954 | static int method_get_unit_processes(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
ad68a4e5 MY |
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); | |
291d565a LP |
959 | } |
960 | ||
6592b975 | 961 | static int method_attach_processes_to_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
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); | |
6592b975 LP |
966 | } |
967 | ||
94634b4b LP |
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 | ||
ab31f6b8 WC |
974 | static int transient_unit_from_message( |
975 | Manager *m, | |
976 | sd_bus_message *message, | |
977 | const char *name, | |
9fdb1c63 | 978 | Unit **ret_unit, |
ab31f6b8 WC |
979 | sd_bus_error *error) { |
980 | ||
06cc6afa | 981 | UnitType t; |
ab31f6b8 WC |
982 | Unit *u; |
983 | int r; | |
984 | ||
985 | assert(m); | |
986 | assert(message); | |
987 | assert(name); | |
988 | ||
06cc6afa LP |
989 | t = unit_name_to_type(name); |
990 | if (t < 0) | |
cb31470f ZJS |
991 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
992 | "Invalid unit name or type."); | |
06cc6afa LP |
993 | |
994 | if (!unit_vtable[t]->can_transient) | |
cb31470f ZJS |
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)); | |
06cc6afa | 998 | |
ab31f6b8 WC |
999 | r = manager_load_unit(m, name, NULL, error, &u); |
1000 | if (r < 0) | |
1001 | return r; | |
1002 | ||
0f13f3bd | 1003 | if (!unit_is_pristine(u)) |
cb31470f | 1004 | return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, |
1f832446 | 1005 | "Unit %s was already loaded or has a fragment file.", name); |
ab31f6b8 WC |
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 | ||
05a98afd LP |
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 | ||
97329d20 | 1025 | /* Now load the missing bits of the unit we just created */ |
4f952a3f | 1026 | unit_add_to_load_queue(u); |
97329d20 LP |
1027 | manager_dispatch_load_queue(m); |
1028 | ||
9fdb1c63 YW |
1029 | if (ret_unit) |
1030 | *ret_unit = u; | |
ab31f6b8 WC |
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 | ||
ab31f6b8 WC |
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) { | |
9fdb1c63 | 1050 | const char *name; |
97329d20 | 1051 | |
ab31f6b8 WC |
1052 | r = sd_bus_message_read(message, "s", &name); |
1053 | if (r < 0) | |
1054 | return r; | |
1055 | ||
26208dd4 | 1056 | r = transient_unit_from_message(m, message, name, /* ret_unit = */ NULL, error); |
97329d20 | 1057 | if (r < 0) |
ab31f6b8 WC |
1058 | return r; |
1059 | ||
ab31f6b8 WC |
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 | ||
19070062 | 1074 | static int method_start_transient_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1075 | const char *name, *smode; |
99534007 | 1076 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 1077 | JobMode mode; |
718db961 LP |
1078 | Unit *u; |
1079 | int r; | |
ea430986 | 1080 | |
718db961 | 1081 | assert(message); |
ea430986 | 1082 | |
1d22e906 | 1083 | r = mac_selinux_access_check(message, "start", error); |
283868e1 SW |
1084 | if (r < 0) |
1085 | return r; | |
283868e1 | 1086 | |
718db961 LP |
1087 | r = sd_bus_message_read(message, "ss", &name, &smode); |
1088 | if (r < 0) | |
ebcf1f97 | 1089 | return r; |
5632e374 | 1090 | |
718db961 LP |
1091 | mode = job_mode_from_string(smode); |
1092 | if (mode < 0) | |
ebcf1f97 | 1093 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s is invalid.", smode); |
5632e374 | 1094 | |
3a437f52 RRZ |
1095 | r = bus_verify_manage_units_async_impl( |
1096 | m, | |
1097 | name, | |
1098 | "start", | |
4e0bdf95 | 1099 | N_("Authentication is required to start transient unit '$(unit)'."), |
3a437f52 RRZ |
1100 | message, |
1101 | error); | |
718db961 | 1102 | if (r < 0) |
ebcf1f97 | 1103 | return r; |
1d22e906 LP |
1104 | if (r == 0) |
1105 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
5632e374 | 1106 | |
ab31f6b8 | 1107 | r = transient_unit_from_message(m, message, name, &u, error); |
ebcf1f97 LP |
1108 | if (r < 0) |
1109 | return r; | |
5632e374 | 1110 | |
ab31f6b8 | 1111 | r = transient_aux_units_from_message(m, message, error); |
718db961 | 1112 | if (r < 0) |
ebcf1f97 | 1113 | return r; |
ea430986 | 1114 | |
718db961 | 1115 | /* Finally, start it */ |
50cbaba4 | 1116 | return bus_unit_queue_job(message, u, JOB_START, mode, 0, error); |
718db961 | 1117 | } |
ea430986 | 1118 | |
19070062 | 1119 | static int method_get_job(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1120 | _cleanup_free_ char *path = NULL; |
99534007 | 1121 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
1122 | uint32_t id; |
1123 | Job *j; | |
1124 | int r; | |
ea430986 | 1125 | |
718db961 | 1126 | assert(message); |
ea430986 | 1127 | |
283868e1 SW |
1128 | /* Anyone can call this method */ |
1129 | ||
718db961 LP |
1130 | r = sd_bus_message_read(message, "u", &id); |
1131 | if (r < 0) | |
ebcf1f97 | 1132 | return r; |
ea430986 | 1133 | |
718db961 LP |
1134 | j = manager_get_job(m, id); |
1135 | if (!j) | |
ebcf1f97 | 1136 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); |
ea430986 | 1137 | |
8a188de9 | 1138 | r = mac_selinux_unit_access_check(j->unit, message, "status", error); |
ebcf1f97 LP |
1139 | if (r < 0) |
1140 | return r; | |
ea430986 | 1141 | |
718db961 LP |
1142 | path = job_dbus_path(j); |
1143 | if (!path) | |
ebcf1f97 | 1144 | return -ENOMEM; |
ea430986 | 1145 | |
df2d202e | 1146 | return sd_bus_reply_method_return(message, "o", path); |
718db961 | 1147 | } |
ea430986 | 1148 | |
19070062 | 1149 | static int method_cancel_job(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1150 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
1151 | uint32_t id; |
1152 | Job *j; | |
1153 | int r; | |
ea430986 | 1154 | |
718db961 | 1155 | assert(message); |
ea430986 | 1156 | |
718db961 LP |
1157 | r = sd_bus_message_read(message, "u", &id); |
1158 | if (r < 0) | |
ebcf1f97 | 1159 | return r; |
ea430986 | 1160 | |
718db961 LP |
1161 | j = manager_get_job(m, id); |
1162 | if (!j) | |
ebcf1f97 | 1163 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); |
ea430986 | 1164 | |
19070062 | 1165 | return bus_job_method_cancel(message, j, error); |
718db961 | 1166 | } |
c1e1601e | 1167 | |
19070062 | 1168 | static int method_clear_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1169 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1170 | int r; |
c1e1601e | 1171 | |
718db961 | 1172 | assert(message); |
c1e1601e | 1173 | |
1d22e906 | 1174 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1175 | if (r < 0) |
1176 | return r; | |
1177 | ||
1d22e906 LP |
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 | ||
718db961 | 1184 | manager_clear_jobs(m); |
c1e1601e | 1185 | |
df2d202e | 1186 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1187 | } |
c1e1601e | 1188 | |
19070062 | 1189 | static int method_reset_failed(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1190 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1191 | int r; |
cad45ba1 | 1192 | |
718db961 | 1193 | assert(message); |
718db961 | 1194 | |
8a188de9 | 1195 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1196 | if (r < 0) |
1197 | return r; | |
1198 | ||
1d22e906 LP |
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 | ||
718db961 | 1205 | manager_reset_failed(m); |
c1e1601e | 1206 | |
df2d202e | 1207 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1208 | } |
c1e1601e | 1209 | |
313fe66f | 1210 | static int list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *error, char **states, char **patterns) { |
4afd3348 | 1211 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
99534007 | 1212 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 1213 | const char *k; |
718db961 LP |
1214 | Unit *u; |
1215 | int r; | |
c1e1601e | 1216 | |
718db961 | 1217 | assert(message); |
b152adec | 1218 | |
283868e1 SW |
1219 | /* Anyone can call this method */ |
1220 | ||
8a188de9 | 1221 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1222 | if (r < 0) |
1223 | return r; | |
cad45ba1 | 1224 | |
df2d202e | 1225 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1226 | if (r < 0) |
ebcf1f97 | 1227 | return r; |
b152adec | 1228 | |
718db961 LP |
1229 | r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)"); |
1230 | if (r < 0) | |
ebcf1f97 | 1231 | return r; |
b152adec | 1232 | |
90e74a66 | 1233 | HASHMAP_FOREACH_KEY(u, k, m->units) { |
718db961 LP |
1234 | if (k != u->id) |
1235 | continue; | |
b152adec | 1236 | |
6e0f9593 | 1237 | if (!unit_passes_filter(u, states, patterns)) |
313fe66f | 1238 | continue; |
1239 | ||
6900c740 | 1240 | r = reply_unit_info(reply, u); |
718db961 | 1241 | if (r < 0) |
ebcf1f97 | 1242 | return r; |
718db961 | 1243 | } |
4139c1b2 | 1244 | |
718db961 LP |
1245 | r = sd_bus_message_close_container(reply); |
1246 | if (r < 0) | |
ebcf1f97 | 1247 | return r; |
cad45ba1 | 1248 | |
51cc3825 | 1249 | return sd_bus_message_send(reply); |
718db961 | 1250 | } |
4139c1b2 | 1251 | |
19070062 | 1252 | static int method_list_units(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
313fe66f | 1253 | return list_units_filtered(message, userdata, error, NULL, NULL); |
cdc06ed7 DS |
1254 | } |
1255 | ||
19070062 | 1256 | static int method_list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
cdc06ed7 DS |
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 | ||
313fe66f | 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); | |
cdc06ed7 DS |
1281 | } |
1282 | ||
19070062 | 1283 | static int method_list_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
4afd3348 | 1284 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
99534007 | 1285 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
1286 | Job *j; |
1287 | int r; | |
4139c1b2 | 1288 | |
718db961 | 1289 | assert(message); |
718db961 | 1290 | |
283868e1 SW |
1291 | /* Anyone can call this method */ |
1292 | ||
8a188de9 | 1293 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1294 | if (r < 0) |
1295 | return r; | |
718db961 | 1296 | |
df2d202e | 1297 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1298 | if (r < 0) |
ebcf1f97 | 1299 | return r; |
718db961 LP |
1300 | |
1301 | r = sd_bus_message_open_container(reply, 'a', "(usssoo)"); | |
1302 | if (r < 0) | |
ebcf1f97 | 1303 | return r; |
718db961 | 1304 | |
90e74a66 | 1305 | HASHMAP_FOREACH(j, m->jobs) { |
718db961 LP |
1306 | _cleanup_free_ char *unit_path = NULL, *job_path = NULL; |
1307 | ||
1308 | job_path = job_dbus_path(j); | |
1309 | if (!job_path) | |
ebcf1f97 | 1310 | return -ENOMEM; |
718db961 LP |
1311 | |
1312 | unit_path = unit_dbus_path(j->unit); | |
1313 | if (!unit_path) | |
ebcf1f97 | 1314 | return -ENOMEM; |
718db961 LP |
1315 | |
1316 | r = sd_bus_message_append( | |
1317 | reply, "(usssoo)", | |
1318 | j->id, | |
1302759d | 1319 | j->unit->id, |
718db961 | 1320 | job_type_to_string(j->type), |
1302759d | 1321 | job_state_to_string(j->state), |
718db961 LP |
1322 | job_path, |
1323 | unit_path); | |
cad45ba1 | 1324 | if (r < 0) |
ebcf1f97 | 1325 | return r; |
718db961 | 1326 | } |
5dd9014f | 1327 | |
718db961 LP |
1328 | r = sd_bus_message_close_container(reply); |
1329 | if (r < 0) | |
ebcf1f97 | 1330 | return r; |
5dd9014f | 1331 | |
51cc3825 | 1332 | return sd_bus_message_send(reply); |
718db961 | 1333 | } |
5dd9014f | 1334 | |
19070062 | 1335 | static int method_subscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1336 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 1337 | int r; |
5dd9014f | 1338 | |
718db961 | 1339 | assert(message); |
ea430986 | 1340 | |
283868e1 SW |
1341 | /* Anyone can call this method */ |
1342 | ||
8a188de9 | 1343 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1344 | if (r < 0) |
1345 | return r; | |
cad45ba1 | 1346 | |
19070062 | 1347 | if (sd_bus_message_get_bus(message) == m->api_bus) { |
8f8f05a9 LP |
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) { | |
19070062 | 1353 | r = sd_bus_track_new(sd_bus_message_get_bus(message), &m->subscribed, NULL, NULL); |
8f8f05a9 LP |
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) | |
1b09b81c | 1362 | return sd_bus_error_set(error, BUS_ERROR_ALREADY_SUBSCRIBED, "Client is already subscribed."); |
8f8f05a9 | 1363 | } |
ea430986 | 1364 | |
df2d202e | 1365 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1366 | } |
ea430986 | 1367 | |
19070062 | 1368 | static int method_unsubscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1369 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 1370 | int r; |
ea430986 | 1371 | |
718db961 | 1372 | assert(message); |
ea430986 | 1373 | |
283868e1 SW |
1374 | /* Anyone can call this method */ |
1375 | ||
8a188de9 | 1376 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1377 | if (r < 0) |
1378 | return r; | |
ea430986 | 1379 | |
19070062 | 1380 | if (sd_bus_message_get_bus(message) == m->api_bus) { |
8f8f05a9 LP |
1381 | r = sd_bus_track_remove_sender(m->subscribed, message); |
1382 | if (r < 0) | |
1383 | return r; | |
1384 | if (r == 0) | |
1b09b81c | 1385 | return sd_bus_error_set(error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed."); |
8f8f05a9 | 1386 | } |
ea430986 | 1387 | |
df2d202e | 1388 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1389 | } |
ea430986 | 1390 | |
d1d8786c FB |
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 | ||
718db961 | 1398 | _cleanup_free_ char *dump = NULL; |
99534007 | 1399 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1400 | int r; |
ea430986 | 1401 | |
718db961 | 1402 | assert(message); |
ea430986 | 1403 | |
d9365956 LB |
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. */ | |
8a188de9 | 1406 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1407 | if (r < 0) |
1408 | return r; | |
ea430986 | 1409 | |
d9365956 LB |
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. */ | |
ba4c69a0 | 1419 | r = mac_selinux_access_check(message, "reload", /* error = */ NULL); |
d9365956 LB |
1420 | if (r < 0) |
1421 | goto ratelimited; | |
1422 | ||
ba4c69a0 | 1423 | r = bus_verify_bypass_dump_ratelimit_async(m, message, /* error = */ NULL); |
d9365956 LB |
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 | ||
d1d8786c | 1432 | r = manager_get_dump_string(m, patterns, &dump); |
dacd6cee LP |
1433 | if (r < 0) |
1434 | return r; | |
a16e1123 | 1435 | |
c0a1bfac | 1436 | return reply(message, dump); |
d9365956 LB |
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)); | |
c0a1bfac DT |
1445 | } |
1446 | ||
1447 | static int reply_dump(sd_bus_message *message, char *dump) { | |
df2d202e | 1448 | return sd_bus_reply_method_return(message, "s", dump); |
718db961 | 1449 | } |
cad45ba1 | 1450 | |
c0a1bfac | 1451 | static int method_dump(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
d1d8786c | 1452 | return dump_impl(message, userdata, error, NULL, reply_dump); |
c0a1bfac DT |
1453 | } |
1454 | ||
1455 | static int reply_dump_by_fd(sd_bus_message *message, char *dump) { | |
254d1313 | 1456 | _cleanup_close_ int fd = -EBADF; |
c0a1bfac | 1457 | |
a87a9625 | 1458 | fd = memfd_new_and_seal_string("dump", dump); |
c0a1bfac DT |
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) { | |
d1d8786c FB |
1466 | return dump_impl(message, userdata, error, NULL, reply_dump_by_fd); |
1467 | } | |
1468 | ||
f6cce15b ZJS |
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 *)) { | |
d1d8786c FB |
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 | ||
f6cce15b ZJS |
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); | |
c0a1bfac DT |
1490 | } |
1491 | ||
36b4a7ba | 1492 | static int method_refuse_snapshot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1b09b81c | 1493 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, "Support for snapshots has been removed."); |
718db961 | 1494 | } |
cad45ba1 | 1495 | |
4895bacc | 1496 | static void log_caller(sd_bus_message *message, Manager *manager, const char *method) { |
9524c2fd | 1497 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; |
ff21827f | 1498 | _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; |
9524c2fd LB |
1499 | |
1500 | assert(message); | |
1501 | assert(manager); | |
4895bacc | 1502 | assert(method); |
9524c2fd | 1503 | |
ff21827f | 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) |
9524c2fd LB |
1505 | return; |
1506 | ||
ff21827f MY |
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) | |
9524c2fd LB |
1509 | return; |
1510 | ||
ff21827f MY |
1511 | const char *comm = NULL; |
1512 | Unit *caller; | |
1513 | ||
9524c2fd | 1514 | (void) sd_bus_creds_get_comm(creds, &comm); |
ff21827f | 1515 | caller = manager_get_unit_by_pidref(manager, &pidref); |
9524c2fd | 1516 | |
4ee41be8 DDM |
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 ? ")" : ""); | |
9524c2fd LB |
1521 | } |
1522 | ||
19070062 | 1523 | static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1524 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 1525 | int r; |
6652a2b9 | 1526 | |
718db961 | 1527 | assert(message); |
6652a2b9 | 1528 | |
1d22e906 | 1529 | r = mac_selinux_access_check(message, "reload", error); |
283868e1 SW |
1530 | if (r < 0) |
1531 | return r; | |
283868e1 | 1532 | |
1d22e906 | 1533 | r = bus_verify_reload_daemon_async(m, message, error); |
ebcf1f97 LP |
1534 | if (r < 0) |
1535 | return r; | |
1d22e906 LP |
1536 | if (r == 0) |
1537 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
6652a2b9 | 1538 | |
9524c2fd | 1539 | /* Write a log message noting the unit or process who requested the Reload() */ |
71322b95 | 1540 | log_caller(message, m, "Reload"); |
9524c2fd | 1541 | |
856bfaeb | 1542 | /* Check the rate limit after the authorization succeeds, to avoid denial-of-service issues. */ |
8312b17a | 1543 | if (!ratelimit_below(&m->reload_reexec_ratelimit)) { |
856bfaeb LB |
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 | ||
718db961 LP |
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. */ | |
6652a2b9 | 1554 | |
209de525 LP |
1555 | assert(!m->pending_reload_message); |
1556 | r = sd_bus_message_new_method_return(message, &m->pending_reload_message); | |
718db961 | 1557 | if (r < 0) |
ebcf1f97 | 1558 | return r; |
cad45ba1 | 1559 | |
af41e508 | 1560 | m->objective = MANAGER_RELOAD; |
6652a2b9 | 1561 | |
718db961 LP |
1562 | return 1; |
1563 | } | |
6652a2b9 | 1564 | |
19070062 | 1565 | static int method_reexecute(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1566 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1567 | int r; |
6652a2b9 | 1568 | |
718db961 | 1569 | assert(message); |
6652a2b9 | 1570 | |
1d22e906 | 1571 | r = mac_selinux_access_check(message, "reload", error); |
283868e1 SW |
1572 | if (r < 0) |
1573 | return r; | |
283868e1 | 1574 | |
1d22e906 | 1575 | r = bus_verify_reload_daemon_async(m, message, error); |
ebcf1f97 LP |
1576 | if (r < 0) |
1577 | return r; | |
1d22e906 LP |
1578 | if (r == 0) |
1579 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
cad45ba1 | 1580 | |
4895bacc | 1581 | /* Write a log message noting the unit or process who requested the Reexecute() */ |
71322b95 | 1582 | log_caller(message, m, "Reexecution"); |
4895bacc | 1583 | |
8312b17a LB |
1584 | /* Check the rate limit after the authorization succeeds, to avoid denial-of-service issues. */ |
1585 | if (!ratelimit_below(&m->reload_reexec_ratelimit)) { | |
71322b95 | 1586 | log_warning("Reexecution request rejected due to rate limit."); |
8312b17a LB |
1587 | return sd_bus_error_setf(error, |
1588 | SD_BUS_ERROR_LIMITS_EXCEEDED, | |
1589 | "Reexecute() request rejected due to rate limit."); | |
1590 | } | |
1591 | ||
718db961 LP |
1592 | /* We don't send a reply back here, the client should |
1593 | * just wait for us disconnecting. */ | |
6652a2b9 | 1594 | |
af41e508 | 1595 | m->objective = MANAGER_REEXECUTE; |
718db961 LP |
1596 | return 1; |
1597 | } | |
6652a2b9 | 1598 | |
19070062 | 1599 | static int method_exit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1600 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1601 | int r; |
6652a2b9 | 1602 | |
718db961 | 1603 | assert(message); |
6652a2b9 | 1604 | |
8a188de9 | 1605 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1606 | if (r < 0) |
1607 | return r; | |
cad45ba1 | 1608 | |
acb0f501 DDM |
1609 | log_caller(message, m, "Exit"); |
1610 | ||
287419c1 AC |
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. */ | |
6652a2b9 | 1615 | |
af41e508 | 1616 | m->objective = MANAGER_EXIT; |
6652a2b9 | 1617 | |
df2d202e | 1618 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1619 | } |
6652a2b9 | 1620 | |
19070062 | 1621 | static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1622 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1623 | int r; |
664f88a7 | 1624 | |
718db961 | 1625 | assert(message); |
cad45ba1 | 1626 | |
463d0d15 | 1627 | if (!MANAGER_IS_SYSTEM(m)) |
a85fe612 MY |
1628 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, |
1629 | "Reboot is only supported by system manager."); | |
664f88a7 | 1630 | |
541aadff MY |
1631 | r = mac_selinux_access_check(message, "reboot", error); |
1632 | if (r < 0) | |
1633 | return r; | |
1634 | ||
acb0f501 DDM |
1635 | log_caller(message, m, "Reboot"); |
1636 | ||
af41e508 | 1637 | m->objective = MANAGER_REBOOT; |
664f88a7 | 1638 | |
df2d202e | 1639 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1640 | } |
664f88a7 | 1641 | |
13ffc607 | 1642 | static int method_soft_reboot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
13ffc607 | 1643 | Manager *m = ASSERT_PTR(userdata); |
b80ae4bc | 1644 | _cleanup_free_ char *rt = NULL; |
13ffc607 LP |
1645 | const char *root; |
1646 | int r; | |
1647 | ||
1648 | assert(message); | |
1649 | ||
236cd485 MY |
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 | ||
13ffc607 LP |
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 | ||
b80ae4bc MY |
1670 | r = path_simplify_alloc(root, &rt); |
1671 | if (r < 0) | |
1672 | return r; | |
13ffc607 LP |
1673 | } |
1674 | ||
acb0f501 DDM |
1675 | log_caller(message, m, "Soft reboot"); |
1676 | ||
13ffc607 LP |
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 | ||
19070062 | 1683 | static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1684 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1685 | int r; |
50913bc0 | 1686 | |
718db961 | 1687 | assert(message); |
1137a57c | 1688 | |
463d0d15 | 1689 | if (!MANAGER_IS_SYSTEM(m)) |
a85fe612 MY |
1690 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, |
1691 | "Powering off is only supported by system manager."); | |
1137a57c | 1692 | |
541aadff MY |
1693 | r = mac_selinux_access_check(message, "halt", error); |
1694 | if (r < 0) | |
1695 | return r; | |
1696 | ||
acb0f501 DDM |
1697 | log_caller(message, m, "Poweroff"); |
1698 | ||
af41e508 | 1699 | m->objective = MANAGER_POWEROFF; |
1137a57c | 1700 | |
df2d202e | 1701 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1702 | } |
1137a57c | 1703 | |
19070062 | 1704 | static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1705 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1706 | int r; |
1137a57c | 1707 | |
718db961 | 1708 | assert(message); |
8d0e38a2 | 1709 | |
463d0d15 | 1710 | if (!MANAGER_IS_SYSTEM(m)) |
a85fe612 MY |
1711 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, |
1712 | "Halt is only supported by system manager."); | |
8d0e38a2 | 1713 | |
541aadff MY |
1714 | r = mac_selinux_access_check(message, "halt", error); |
1715 | if (r < 0) | |
1716 | return r; | |
1717 | ||
acb0f501 DDM |
1718 | log_caller(message, m, "Halt"); |
1719 | ||
af41e508 | 1720 | m->objective = MANAGER_HALT; |
8d0e38a2 | 1721 | |
df2d202e | 1722 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1723 | } |
8d0e38a2 | 1724 | |
19070062 | 1725 | static int method_kexec(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1726 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1727 | int r; |
8d0e38a2 | 1728 | |
718db961 | 1729 | assert(message); |
c0576cd6 | 1730 | |
463d0d15 | 1731 | if (!MANAGER_IS_SYSTEM(m)) |
a85fe612 MY |
1732 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, |
1733 | "KExec is only supported by system manager."); | |
c0576cd6 | 1734 | |
541aadff MY |
1735 | r = mac_selinux_access_check(message, "reboot", error); |
1736 | if (r < 0) | |
1737 | return r; | |
1738 | ||
acb0f501 DDM |
1739 | log_caller(message, m, "Kexec"); |
1740 | ||
af41e508 | 1741 | m->objective = MANAGER_KEXEC; |
c0576cd6 | 1742 | |
df2d202e | 1743 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1744 | } |
c0576cd6 | 1745 | |
19070062 | 1746 | static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1747 | Manager *m = ASSERT_PTR(userdata); |
b80ae4bc | 1748 | _cleanup_free_ char *ri = NULL, *rt = NULL; |
13ffc607 | 1749 | const char *root, *init; |
718db961 | 1750 | int r; |
c0576cd6 | 1751 | |
718db961 | 1752 | assert(message); |
c0576cd6 | 1753 | |
541aadff MY |
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 | ||
8a188de9 | 1758 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1759 | if (r < 0) |
1760 | return r; | |
c0576cd6 | 1761 | |
718db961 LP |
1762 | r = sd_bus_message_read(message, "ss", &root, &init); |
1763 | if (r < 0) | |
ebcf1f97 | 1764 | return r; |
c0576cd6 | 1765 | |
5ae89ef3 LP |
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)) | |
a85fe612 MY |
1772 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, |
1773 | "New root directory must be a valid path."); | |
b0c5f0e1 | 1774 | |
5ae89ef3 LP |
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); | |
b0c5f0e1 MY |
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) | |
a85fe612 MY |
1785 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, |
1786 | "New root directory cannot be the old root directory."); | |
5ae89ef3 | 1787 | } |
c0576cd6 | 1788 | |
718db961 | 1789 | /* Safety check */ |
4da159bc | 1790 | if (!in_initrd()) |
a85fe612 MY |
1791 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, |
1792 | "Not in initrd, refusing switch-root operation."); | |
4da159bc MY |
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)) { | |
5f4c9c27 LP |
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 | ||
718db961 | 1809 | if (!path_is_absolute(init)) |
cb31470f ZJS |
1810 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
1811 | "Path to init binary '%s' not absolute.", init); | |
c0576cd6 | 1812 | |
f461a28d | 1813 | r = chase_and_access(init, root, CHASE_PREFIX_ROOT, X_OK, NULL); |
e10086ac LP |
1814 | if (r == -EACCES) |
1815 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, | |
1816 | "Init binary %s is not executable.", init); | |
710028b4 | 1817 | if (r < 0) |
cb31470f ZJS |
1818 | return sd_bus_error_set_errnof(error, r, |
1819 | "Could not resolve init executable %s: %m", init); | |
718db961 LP |
1820 | } |
1821 | ||
b80ae4bc MY |
1822 | r = path_simplify_alloc(root, &rt); |
1823 | if (r < 0) | |
1824 | return r; | |
718db961 LP |
1825 | |
1826 | if (!isempty(init)) { | |
b80ae4bc MY |
1827 | r = path_simplify_alloc(init, &ri); |
1828 | if (r < 0) | |
1829 | return r; | |
718db961 | 1830 | } |
c0576cd6 | 1831 | |
87a19bfe YW |
1832 | free_and_replace(m->switch_root, rt); |
1833 | free_and_replace(m->switch_root_init, ri); | |
c0576cd6 | 1834 | |
af41e508 | 1835 | m->objective = MANAGER_SWITCH_ROOT; |
92b315df | 1836 | |
df2d202e | 1837 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1838 | } |
c0576cd6 | 1839 | |
19070062 | 1840 | static int method_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1841 | _cleanup_strv_free_ char **plus = NULL; |
99534007 | 1842 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 1843 | int r; |
c0576cd6 | 1844 | |
718db961 | 1845 | assert(message); |
cad45ba1 | 1846 | |
8a188de9 | 1847 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1848 | if (r < 0) |
1849 | return r; | |
c0576cd6 | 1850 | |
718db961 LP |
1851 | r = sd_bus_message_read_strv(message, &plus); |
1852 | if (r < 0) | |
ebcf1f97 | 1853 | return r; |
718db961 | 1854 | if (!strv_env_is_valid(plus)) |
1b09b81c | 1855 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments"); |
c0576cd6 | 1856 | |
1d22e906 LP |
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 | ||
1ad6e8b3 | 1863 | r = manager_client_environment_modify(m, NULL, plus); |
718db961 | 1864 | if (r < 0) |
ebcf1f97 | 1865 | return r; |
c0576cd6 | 1866 | |
df2d202e | 1867 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1868 | } |
1869 | ||
19070062 | 1870 | static int method_unset_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1871 | _cleanup_strv_free_ char **minus = NULL; |
99534007 | 1872 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
1873 | int r; |
1874 | ||
718db961 | 1875 | assert(message); |
718db961 | 1876 | |
8a188de9 | 1877 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1878 | if (r < 0) |
1879 | return r; | |
c0576cd6 | 1880 | |
718db961 LP |
1881 | r = sd_bus_message_read_strv(message, &minus); |
1882 | if (r < 0) | |
ebcf1f97 | 1883 | return r; |
718db961 LP |
1884 | |
1885 | if (!strv_env_name_or_assignment_is_valid(minus)) | |
cb31470f ZJS |
1886 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
1887 | "Invalid environment variable names or assignments"); | |
718db961 | 1888 | |
1d22e906 LP |
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 | ||
1ad6e8b3 | 1895 | r = manager_client_environment_modify(m, minus, NULL); |
718db961 | 1896 | if (r < 0) |
ebcf1f97 | 1897 | return r; |
718db961 | 1898 | |
df2d202e | 1899 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1900 | } |
1901 | ||
19070062 | 1902 | static int method_unset_and_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1903 | _cleanup_strv_free_ char **minus = NULL, **plus = NULL; |
99534007 | 1904 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
1905 | int r; |
1906 | ||
718db961 | 1907 | assert(message); |
718db961 | 1908 | |
8a188de9 | 1909 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1910 | if (r < 0) |
1911 | return r; | |
718db961 | 1912 | |
eb6c7d20 | 1913 | r = sd_bus_message_read_strv(message, &minus); |
718db961 | 1914 | if (r < 0) |
ebcf1f97 | 1915 | return r; |
718db961 | 1916 | |
eb6c7d20 | 1917 | r = sd_bus_message_read_strv(message, &plus); |
718db961 | 1918 | if (r < 0) |
ebcf1f97 | 1919 | return r; |
718db961 | 1920 | |
718db961 | 1921 | if (!strv_env_name_or_assignment_is_valid(minus)) |
cb31470f ZJS |
1922 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
1923 | "Invalid environment variable names or assignments"); | |
eb6c7d20 | 1924 | if (!strv_env_is_valid(plus)) |
cb31470f ZJS |
1925 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
1926 | "Invalid environment assignments"); | |
718db961 | 1927 | |
1d22e906 LP |
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 | ||
1ad6e8b3 | 1934 | r = manager_client_environment_modify(m, minus, plus); |
718db961 | 1935 | if (r < 0) |
ebcf1f97 | 1936 | return r; |
718db961 | 1937 | |
df2d202e | 1938 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1939 | } |
1940 | ||
287419c1 | 1941 | static int method_set_exit_code(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1942 | Manager *m = ASSERT_PTR(userdata); |
29206d46 | 1943 | uint8_t code; |
287419c1 AC |
1944 | int r; |
1945 | ||
1946 | assert(message); | |
287419c1 AC |
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 | ||
287419c1 AC |
1956 | m->return_value = code; |
1957 | ||
1958 | return sd_bus_reply_method_return(message, NULL); | |
1959 | } | |
1960 | ||
29206d46 | 1961 | static int method_lookup_dynamic_user_by_name(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1962 | Manager *m = ASSERT_PTR(userdata); |
29206d46 LP |
1963 | const char *name; |
1964 | uid_t uid; | |
1965 | int r; | |
1966 | ||
1967 | assert(message); | |
29206d46 LP |
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)) | |
cb31470f ZJS |
1974 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, |
1975 | "Dynamic users are only supported in the system instance."); | |
7a8867ab | 1976 | if (!valid_user_group_name(name, VALID_USER_RELAX)) |
cb31470f ZJS |
1977 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
1978 | "User name invalid: %s", name); | |
29206d46 LP |
1979 | |
1980 | r = dynamic_user_lookup_name(m, name, &uid); | |
1981 | if (r == -ESRCH) | |
cb31470f ZJS |
1982 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, |
1983 | "Dynamic user %s does not exist.", name); | |
29206d46 LP |
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; | |
99534007 | 1992 | Manager *m = ASSERT_PTR(userdata); |
29206d46 LP |
1993 | uid_t uid; |
1994 | int r; | |
1995 | ||
1996 | assert(message); | |
29206d46 | 1997 | |
60d0a509 | 1998 | assert_cc(sizeof(uid_t) == sizeof(uint32_t)); |
29206d46 LP |
1999 | r = sd_bus_message_read_basic(message, 'u', &uid); |
2000 | if (r < 0) | |
2001 | return r; | |
2002 | ||
2003 | if (!MANAGER_IS_SYSTEM(m)) | |
cb31470f ZJS |
2004 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, |
2005 | "Dynamic users are only supported in the system instance."); | |
29206d46 | 2006 | if (!uid_is_valid(uid)) |
cb31470f ZJS |
2007 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
2008 | "User ID invalid: " UID_FMT, uid); | |
29206d46 LP |
2009 | |
2010 | r = dynamic_user_lookup_uid(m, uid, &name); | |
2011 | if (r == -ESRCH) | |
cb31470f ZJS |
2012 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, |
2013 | "Dynamic user ID " UID_FMT " does not exist.", uid); | |
29206d46 LP |
2014 | if (r < 0) |
2015 | return r; | |
2016 | ||
2017 | return sd_bus_reply_method_return(message, "s", name); | |
2018 | } | |
2019 | ||
f9bfa696 YW |
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; | |
99534007 | 2022 | Manager *m = ASSERT_PTR(userdata); |
f9bfa696 | 2023 | DynamicUser *d; |
f9bfa696 YW |
2024 | int r; |
2025 | ||
2026 | assert(message); | |
f9bfa696 YW |
2027 | |
2028 | assert_cc(sizeof(uid_t) == sizeof(uint32_t)); | |
2029 | ||
2030 | if (!MANAGER_IS_SYSTEM(m)) | |
cb31470f ZJS |
2031 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, |
2032 | "Dynamic users are only supported in the system instance."); | |
f9bfa696 YW |
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 | ||
90e74a66 | 2042 | HASHMAP_FOREACH(d, m->dynamic_users) { |
f9bfa696 YW |
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) | |
cb31470f ZJS |
2049 | return sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, |
2050 | "Failed to look up a dynamic user."); | |
f9bfa696 YW |
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 | ||
51cc3825 | 2061 | return sd_bus_message_send(reply); |
f9bfa696 YW |
2062 | } |
2063 | ||
70666e28 | 2064 | static int method_enqueue_marked_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 2065 | Manager *m = ASSERT_PTR(userdata); |
70666e28 ZJS |
2066 | int r; |
2067 | ||
2068 | assert(message); | |
70666e28 ZJS |
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 | ||
1ae9b0cf | 2080 | log_info("Queuing reload/restart jobs for marked units%s", glyph(GLYPH_ELLIPSIS)); |
70666e28 ZJS |
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; | |
1e4e5572 | 2100 | if (BIT_SET(u->markers, UNIT_MARKER_NEEDS_RESTART)) |
70666e28 | 2101 | flags = 0; |
1e4e5572 | 2102 | else if (BIT_SET(u->markers, UNIT_MARKER_NEEDS_RELOAD)) |
70666e28 ZJS |
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); | |
bb44fd07 ZJS |
2112 | if (ERRNO_IS_NEG_RESOURCE(r)) |
2113 | return r; | |
70666e28 | 2114 | if (r < 0) { |
70666e28 ZJS |
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 | ||
51cc3825 | 2129 | return sd_bus_message_send(reply); |
70666e28 ZJS |
2130 | } |
2131 | ||
313fe66f | 2132 | static int list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error, char **states, char **patterns) { |
99534007 | 2133 | Manager *m = ASSERT_PTR(userdata); |
ca3c95c1 | 2134 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
5d2a48da | 2135 | _cleanup_hashmap_free_ Hashmap *h = NULL; |
718db961 LP |
2136 | int r; |
2137 | ||
718db961 | 2138 | assert(message); |
718db961 | 2139 | |
283868e1 SW |
2140 | /* Anyone can call this method */ |
2141 | ||
8a188de9 | 2142 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
2143 | if (r < 0) |
2144 | return r; | |
718db961 | 2145 | |
df2d202e | 2146 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 2147 | if (r < 0) |
ebcf1f97 | 2148 | return r; |
c0576cd6 | 2149 | |
ca3c95c1 | 2150 | r = unit_file_get_list(m->runtime_scope, /* root_dir = */ NULL, states, patterns, &h); |
ebcf1f97 | 2151 | if (r < 0) |
066ba68e | 2152 | return r; |
718db961 LP |
2153 | |
2154 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); | |
ebcf1f97 | 2155 | if (r < 0) |
066ba68e | 2156 | return r; |
718db961 | 2157 | |
ca3c95c1 | 2158 | UnitFileList *item; |
90e74a66 | 2159 | HASHMAP_FOREACH(item, h) { |
718db961 | 2160 | r = sd_bus_message_append(reply, "(ss)", item->path, unit_file_state_to_string(item->state)); |
ebcf1f97 | 2161 | if (r < 0) |
066ba68e | 2162 | return r; |
718db961 | 2163 | } |
c0576cd6 | 2164 | |
718db961 LP |
2165 | r = sd_bus_message_close_container(reply); |
2166 | if (r < 0) | |
ebcf1f97 | 2167 | return r; |
8d0e38a2 | 2168 | |
51cc3825 | 2169 | return sd_bus_message_send(reply); |
718db961 | 2170 | } |
99504dd4 | 2171 | |
313fe66f | 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 | ||
19070062 | 2192 | static int method_get_unit_file_state(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 2193 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
2194 | const char *name; |
2195 | UnitFileState state; | |
718db961 | 2196 | int r; |
99504dd4 | 2197 | |
718db961 | 2198 | assert(message); |
8e2af478 | 2199 | |
283868e1 SW |
2200 | /* Anyone can call this method */ |
2201 | ||
8a188de9 | 2202 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
2203 | if (r < 0) |
2204 | return r; | |
8e2af478 | 2205 | |
718db961 LP |
2206 | r = sd_bus_message_read(message, "s", &name); |
2207 | if (r < 0) | |
ebcf1f97 | 2208 | return r; |
8e2af478 | 2209 | |
4870133b | 2210 | r = unit_file_get_state(m->runtime_scope, NULL, name, &state); |
0ec0deaa LP |
2211 | if (r < 0) |
2212 | return r; | |
8e2af478 | 2213 | |
df2d202e | 2214 | return sd_bus_reply_method_return(message, "s", unit_file_state_to_string(state)); |
718db961 | 2215 | } |
8e2af478 | 2216 | |
19070062 | 2217 | static int method_get_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 2218 | _cleanup_free_ char *default_target = NULL; |
99534007 | 2219 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 2220 | int r; |
c2756a68 | 2221 | |
718db961 | 2222 | assert(message); |
c2756a68 | 2223 | |
283868e1 SW |
2224 | /* Anyone can call this method */ |
2225 | ||
8a188de9 | 2226 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
2227 | if (r < 0) |
2228 | return r; | |
c2756a68 | 2229 | |
4870133b | 2230 | r = unit_file_get_default(m->runtime_scope, NULL, &default_target); |
7c78a193 DT |
2231 | if (r == -ERFKILL) |
2232 | sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit file is masked."); | |
718db961 | 2233 | if (r < 0) |
ebcf1f97 | 2234 | return r; |
c2756a68 | 2235 | |
df2d202e | 2236 | return sd_bus_reply_method_return(message, "s", default_target); |
718db961 | 2237 | } |
c2756a68 | 2238 | |
8f8f05a9 | 2239 | static int send_unit_files_changed(sd_bus *bus, void *userdata) { |
4afd3348 | 2240 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
2241 | int r; |
2242 | ||
2243 | assert(bus); | |
2244 | ||
cb31470f ZJS |
2245 | r = sd_bus_message_new_signal(bus, &message, |
2246 | "/org/freedesktop/systemd1", | |
2247 | "org.freedesktop.systemd1.Manager", | |
2248 | "UnitFilesChanged"); | |
718db961 LP |
2249 | if (r < 0) |
2250 | return r; | |
2251 | ||
8f8f05a9 | 2252 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
2253 | } |
2254 | ||
d69cba3b MY |
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 | ||
af3d8113 ZJS |
2272 | static int install_error( |
2273 | sd_bus_error *error, | |
2274 | int c, | |
cd44ec5a | 2275 | InstallChange *changes, |
da6053d0 LP |
2276 | size_t n_changes) { |
2277 | ||
d41f08bd MY |
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 | ||
f8888b9a | 2285 | CLEANUP_ARRAY(changes, n_changes, install_changes_free); |
8e20adca | 2286 | |
d41f08bd MY |
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; | |
637d6e5b | 2293 | |
d41f08bd MY |
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); | |
c89d0c3b | 2299 | |
d41f08bd MY |
2300 | return sd_bus_error_set(error, bus_error, err_message); |
2301 | } | |
8e20adca | 2302 | |
f8888b9a | 2303 | return c < 0 ? c : -EINVAL; |
8e20adca LP |
2304 | } |
2305 | ||
cd44ec5a | 2306 | static int reply_install_changes_and_free( |
637d6e5b LP |
2307 | Manager *m, |
2308 | sd_bus_message *message, | |
2309 | int carries_install_info, | |
cd44ec5a | 2310 | InstallChange *changes, |
da6053d0 | 2311 | size_t n_changes, |
637d6e5b LP |
2312 | sd_bus_error *error) { |
2313 | ||
2314 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
2315 | bool bad = false, good = false; | |
637d6e5b LP |
2316 | int r; |
2317 | ||
8c2d0d3a LP |
2318 | CLEANUP_ARRAY(changes, n_changes, install_changes_free); |
2319 | ||
637d6e5b LP |
2320 | r = sd_bus_message_new_method_return(message, &reply); |
2321 | if (r < 0) | |
8c2d0d3a | 2322 | return r; |
637d6e5b LP |
2323 | |
2324 | if (carries_install_info >= 0) { | |
2325 | r = sd_bus_message_append(reply, "b", carries_install_info); | |
2326 | if (r < 0) | |
8c2d0d3a | 2327 | return r; |
637d6e5b LP |
2328 | } |
2329 | ||
2330 | r = sd_bus_message_open_container(reply, 'a', "(sss)"); | |
2331 | if (r < 0) | |
8c2d0d3a | 2332 | return r; |
637d6e5b | 2333 | |
d41f08bd MY |
2334 | FOREACH_ARRAY(i, changes, n_changes) { |
2335 | if (i->type < 0) { | |
637d6e5b LP |
2336 | bad = true; |
2337 | continue; | |
2338 | } | |
2339 | ||
2340 | r = sd_bus_message_append( | |
2341 | reply, "(sss)", | |
d41f08bd MY |
2342 | install_change_type_to_string(i->type), |
2343 | i->path, | |
2344 | i->source); | |
637d6e5b | 2345 | if (r < 0) |
8c2d0d3a | 2346 | return r; |
637d6e5b LP |
2347 | |
2348 | good = true; | |
2349 | } | |
2350 | ||
cb31470f ZJS |
2351 | /* If there was a failed change, and no successful change, then return the first failure as proper |
2352 | * method call error. */ | |
637d6e5b | 2353 | if (bad && !good) |
8c2d0d3a | 2354 | return install_error(error, 0, TAKE_PTR(changes), n_changes); |
637d6e5b LP |
2355 | |
2356 | r = sd_bus_message_close_container(reply); | |
2357 | if (r < 0) | |
8c2d0d3a | 2358 | return r; |
637d6e5b | 2359 | |
51cc3825 | 2360 | return sd_bus_message_send(reply); |
637d6e5b LP |
2361 | } |
2362 | ||
718db961 | 2363 | static int method_enable_unit_files_generic( |
718db961 | 2364 | sd_bus_message *message, |
d309c1c3 | 2365 | Manager *m, |
e9e77e44 | 2366 | int (*call)(RuntimeScope scope, UnitFileFlags flags, const char *root_dir, char * const *files, InstallChange **changes, size_t *n_changes), |
ebcf1f97 LP |
2367 | bool carries_install_info, |
2368 | sd_bus_error *error) { | |
718db961 LP |
2369 | |
2370 | _cleanup_strv_free_ char **l = NULL; | |
cd44ec5a | 2371 | InstallChange *changes = NULL; |
da6053d0 | 2372 | size_t n_changes = 0; |
b3796dd8 | 2373 | UnitFileFlags flags; |
83654007 | 2374 | int r; |
718db961 | 2375 | |
718db961 LP |
2376 | assert(message); |
2377 | assert(m); | |
cad45ba1 | 2378 | |
718db961 LP |
2379 | r = sd_bus_message_read_strv(message, &l); |
2380 | if (r < 0) | |
ebcf1f97 | 2381 | return r; |
90bb85e1 | 2382 | |
83654007 LB |
2383 | if (sd_bus_message_is_method_call(message, NULL, "EnableUnitFilesWithFlags")) { |
2384 | uint64_t raw_flags; | |
d309c1c3 | 2385 | |
83654007 LB |
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 | } | |
b3796dd8 | 2400 | |
1d22e906 LP |
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 | ||
4870133b | 2407 | r = call(m->runtime_scope, flags, NULL, l, &changes, &n_changes); |
d69cba3b | 2408 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2409 | if (r < 0) |
2410 | return install_error(error, r, changes, n_changes); | |
718db961 | 2411 | |
cd44ec5a | 2412 | return reply_install_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes, error); |
718db961 | 2413 | } |
c87eba54 | 2414 | |
83654007 | 2415 | static int method_enable_unit_files_with_flags(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 2416 | return method_enable_unit_files_generic(message, userdata, unit_file_enable, /* carries_install_info = */ true, error); |
83654007 LB |
2417 | } |
2418 | ||
19070062 | 2419 | static int method_enable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 2420 | return method_enable_unit_files_generic(message, userdata, unit_file_enable, /* carries_install_info = */ true, error); |
718db961 | 2421 | } |
ea430986 | 2422 | |
19070062 | 2423 | static int method_reenable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 2424 | return method_enable_unit_files_generic(message, userdata, unit_file_reenable, /* carries_install_info = */ true, error); |
718db961 LP |
2425 | } |
2426 | ||
19070062 | 2427 | static int method_link_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 2428 | return method_enable_unit_files_generic(message, userdata, unit_file_link, /* carries_install_info = */ false, error); |
718db961 LP |
2429 | } |
2430 | ||
e9e77e44 | 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) { |
b3796dd8 | 2432 | return unit_file_preset(scope, flags, root_dir, files, UNIT_FILE_PRESET_FULL, changes, n_changes); |
d309c1c3 LP |
2433 | } |
2434 | ||
19070062 | 2435 | static int method_preset_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 2436 | return method_enable_unit_files_generic(message, userdata, unit_file_preset_without_mode, /* carries_install_info = */ true, error); |
718db961 LP |
2437 | } |
2438 | ||
19070062 | 2439 | static int method_mask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 2440 | return method_enable_unit_files_generic(message, userdata, unit_file_mask, /* carries_install_info = */ false, error); |
718db961 | 2441 | } |
ea430986 | 2442 | |
19070062 | 2443 | static int method_preset_unit_files_with_mode(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
d309c1c3 LP |
2444 | |
2445 | _cleanup_strv_free_ char **l = NULL; | |
cd44ec5a | 2446 | InstallChange *changes = NULL; |
da6053d0 | 2447 | size_t n_changes = 0; |
99534007 | 2448 | Manager *m = ASSERT_PTR(userdata); |
8331b221 | 2449 | UnitFilePresetMode preset_mode; |
d309c1c3 | 2450 | int runtime, force, r; |
b3796dd8 | 2451 | UnitFileFlags flags; |
d309c1c3 LP |
2452 | const char *mode; |
2453 | ||
d309c1c3 | 2454 | assert(message); |
d309c1c3 LP |
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 | ||
b3796dd8 JS |
2464 | flags = unit_file_bools_to_flags(runtime, force); |
2465 | ||
d309c1c3 | 2466 | if (isempty(mode)) |
8331b221 | 2467 | preset_mode = UNIT_FILE_PRESET_FULL; |
d309c1c3 | 2468 | else { |
8331b221 ZJS |
2469 | preset_mode = unit_file_preset_mode_from_string(mode); |
2470 | if (preset_mode < 0) | |
d309c1c3 LP |
2471 | return -EINVAL; |
2472 | } | |
2473 | ||
1d22e906 LP |
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 | ||
4870133b | 2480 | r = unit_file_preset(m->runtime_scope, flags, NULL, l, preset_mode, &changes, &n_changes); |
d69cba3b | 2481 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2482 | if (r < 0) |
2483 | return install_error(error, r, changes, n_changes); | |
d309c1c3 | 2484 | |
cd44ec5a | 2485 | return reply_install_changes_and_free(m, message, r, changes, n_changes, error); |
d309c1c3 LP |
2486 | } |
2487 | ||
718db961 | 2488 | static int method_disable_unit_files_generic( |
718db961 | 2489 | sd_bus_message *message, |
596fc263 | 2490 | Manager *m, |
e9e77e44 | 2491 | int (*call)(RuntimeScope scope, UnitFileFlags flags, const char *root_dir, char * const *files, InstallChange **changes, size_t *n_changes), |
bf1bea43 | 2492 | bool carries_install_info, |
ebcf1f97 | 2493 | sd_bus_error *error) { |
718db961 LP |
2494 | |
2495 | _cleanup_strv_free_ char **l = NULL; | |
cd44ec5a | 2496 | InstallChange *changes = NULL; |
83654007 | 2497 | UnitFileFlags flags; |
da6053d0 | 2498 | size_t n_changes = 0; |
83654007 | 2499 | int r; |
718db961 | 2500 | |
718db961 LP |
2501 | assert(message); |
2502 | assert(m); | |
2503 | ||
df823e23 | 2504 | r = sd_bus_message_read_strv(message, &l); |
ebcf1f97 LP |
2505 | if (r < 0) |
2506 | return r; | |
718db961 | 2507 | |
bf1bea43 MY |
2508 | if (sd_bus_message_is_method_call(message, NULL, "DisableUnitFilesWithFlags") || |
2509 | sd_bus_message_is_method_call(message, NULL, "DisableUnitFilesWithFlagsAndInstallInfo")) { | |
83654007 LB |
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 | } | |
718db961 | 2527 | |
1d22e906 LP |
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 | ||
4870133b | 2534 | r = call(m->runtime_scope, flags, NULL, l, &changes, &n_changes); |
d69cba3b | 2535 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2536 | if (r < 0) |
2537 | return install_error(error, r, changes, n_changes); | |
718db961 | 2538 | |
bf1bea43 | 2539 | return reply_install_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes, error); |
718db961 | 2540 | } |
ea430986 | 2541 | |
83654007 | 2542 | static int method_disable_unit_files_with_flags(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
bf1bea43 MY |
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); | |
83654007 LB |
2548 | } |
2549 | ||
19070062 | 2550 | static int method_disable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
bf1bea43 | 2551 | return method_disable_unit_files_generic(message, userdata, unit_file_disable, /* carries_install_info = */ false, error); |
ea430986 LP |
2552 | } |
2553 | ||
19070062 | 2554 | static int method_unmask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
bf1bea43 | 2555 | return method_disable_unit_files_generic(message, userdata, unit_file_unmask, /* carries_install_info = */ false, error); |
718db961 LP |
2556 | } |
2557 | ||
344ca755 LP |
2558 | static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2559 | _cleanup_strv_free_ char **l = NULL; | |
cd44ec5a | 2560 | InstallChange *changes = NULL; |
da6053d0 | 2561 | size_t n_changes = 0; |
99534007 | 2562 | Manager *m = ASSERT_PTR(userdata); |
344ca755 LP |
2563 | int r; |
2564 | ||
2565 | assert(message); | |
344ca755 LP |
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 | ||
4870133b | 2577 | r = unit_file_revert(m->runtime_scope, NULL, l, &changes, &n_changes); |
d69cba3b | 2578 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2579 | if (r < 0) |
2580 | return install_error(error, r, changes, n_changes); | |
344ca755 | 2581 | |
cd44ec5a | 2582 | return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); |
344ca755 LP |
2583 | } |
2584 | ||
19070062 | 2585 | static int method_set_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
cd44ec5a | 2586 | InstallChange *changes = NULL; |
da6053d0 | 2587 | size_t n_changes = 0; |
99534007 | 2588 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
2589 | const char *name; |
2590 | int force, r; | |
2591 | ||
718db961 | 2592 | assert(message); |
718db961 | 2593 | |
1d22e906 | 2594 | r = mac_selinux_access_check(message, "enable", error); |
283868e1 SW |
2595 | if (r < 0) |
2596 | return r; | |
283868e1 | 2597 | |
1d22e906 | 2598 | r = sd_bus_message_read(message, "sb", &name, &force); |
ebcf1f97 LP |
2599 | if (r < 0) |
2600 | return r; | |
718db961 | 2601 | |
1d22e906 | 2602 | r = bus_verify_manage_unit_files_async(m, message, error); |
718db961 | 2603 | if (r < 0) |
ebcf1f97 | 2604 | return r; |
1d22e906 LP |
2605 | if (r == 0) |
2606 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
718db961 | 2607 | |
4870133b | 2608 | r = unit_file_set_default(m->runtime_scope, force ? UNIT_FILE_FORCE : 0, NULL, name, &changes, &n_changes); |
d69cba3b | 2609 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2610 | if (r < 0) |
2611 | return install_error(error, r, changes, n_changes); | |
718db961 | 2612 | |
cd44ec5a | 2613 | return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); |
718db961 LP |
2614 | } |
2615 | ||
19070062 | 2616 | static int method_preset_all_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
cd44ec5a | 2617 | InstallChange *changes = NULL; |
da6053d0 | 2618 | size_t n_changes = 0; |
99534007 | 2619 | Manager *m = ASSERT_PTR(userdata); |
8331b221 | 2620 | UnitFilePresetMode preset_mode; |
d309c1c3 | 2621 | const char *mode; |
b3796dd8 | 2622 | UnitFileFlags flags; |
d309c1c3 LP |
2623 | int force, runtime, r; |
2624 | ||
d309c1c3 | 2625 | assert(message); |
d309c1c3 | 2626 | |
8a188de9 | 2627 | r = mac_selinux_access_check(message, "enable", error); |
d309c1c3 LP |
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 | ||
b3796dd8 JS |
2635 | flags = unit_file_bools_to_flags(runtime, force); |
2636 | ||
d309c1c3 | 2637 | if (isempty(mode)) |
8331b221 | 2638 | preset_mode = UNIT_FILE_PRESET_FULL; |
d309c1c3 | 2639 | else { |
8331b221 ZJS |
2640 | preset_mode = unit_file_preset_mode_from_string(mode); |
2641 | if (preset_mode < 0) | |
d309c1c3 LP |
2642 | return -EINVAL; |
2643 | } | |
2644 | ||
1d22e906 LP |
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 | ||
4870133b | 2651 | r = unit_file_preset_all(m->runtime_scope, flags, NULL, preset_mode, &changes, &n_changes); |
d69cba3b | 2652 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2653 | if (r < 0) |
2654 | return install_error(error, r, changes, n_changes); | |
d309c1c3 | 2655 | |
cd44ec5a | 2656 | return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); |
d309c1c3 LP |
2657 | } |
2658 | ||
19070062 | 2659 | static int method_add_dependency_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
e94937df | 2660 | _cleanup_strv_free_ char **l = NULL; |
99534007 | 2661 | Manager *m = ASSERT_PTR(userdata); |
cd44ec5a | 2662 | InstallChange *changes = NULL; |
da6053d0 | 2663 | size_t n_changes = 0; |
e94937df | 2664 | int runtime, force, r; |
596fc263 | 2665 | char *target, *type; |
e94937df | 2666 | UnitDependency dep; |
b3796dd8 | 2667 | UnitFileFlags flags; |
e94937df | 2668 | |
e94937df | 2669 | assert(message); |
e94937df LN |
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 | ||
b3796dd8 JS |
2685 | flags = unit_file_bools_to_flags(runtime, force); |
2686 | ||
e94937df | 2687 | dep = unit_dependency_from_string(type); |
d87dc74e | 2688 | if (dep < 0 || !IN_SET(dep, UNIT_WANTS, UNIT_REQUIRES)) |
e94937df LN |
2689 | return -EINVAL; |
2690 | ||
4870133b | 2691 | r = unit_file_add_dependency(m->runtime_scope, flags, NULL, l, target, dep, &changes, &n_changes); |
d69cba3b | 2692 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2693 | if (r < 0) |
2694 | return install_error(error, r, changes, n_changes); | |
e94937df | 2695 | |
cd44ec5a | 2696 | return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); |
e94937df LN |
2697 | } |
2698 | ||
3b3557c4 JS |
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; | |
47c57b48 | 2701 | Manager *m = ASSERT_PTR(userdata); |
cd44ec5a | 2702 | InstallChange *changes = NULL; |
da6053d0 | 2703 | size_t n_changes = 0, i; |
3b3557c4 | 2704 | const char *name; |
3b3557c4 JS |
2705 | int runtime, r; |
2706 | ||
2a711edd DT |
2707 | CLEANUP_ARRAY(changes, n_changes, install_changes_free); |
2708 | ||
3b3557c4 JS |
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 | ||
4870133b | 2721 | r = unit_file_disable(m->runtime_scope, |
47c57b48 YW |
2722 | UNIT_FILE_DRY_RUN | (runtime ? UNIT_FILE_RUNTIME : 0), |
2723 | NULL, STRV_MAKE(name), &changes, &n_changes); | |
2a711edd DT |
2724 | if (r < 0) |
2725 | return log_error_errno(r, "Failed to get file links for %s: %m", name); | |
3b3557c4 JS |
2726 | |
2727 | for (i = 0; i < n_changes; i++) | |
f8662fee | 2728 | if (changes[i].type == INSTALL_CHANGE_UNLINK) { |
3b3557c4 JS |
2729 | r = sd_bus_message_append(reply, "s", changes[i].path); |
2730 | if (r < 0) | |
2a711edd | 2731 | return r; |
3b3557c4 JS |
2732 | } |
2733 | ||
2734 | r = sd_bus_message_close_container(reply); | |
2735 | if (r < 0) | |
2a711edd | 2736 | return r; |
a12ba535 | 2737 | |
51cc3825 | 2738 | return sd_bus_message_send(reply); |
3b3557c4 JS |
2739 | } |
2740 | ||
15ea79f8 | 2741 | static int method_get_job_waiting(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 2742 | Manager *m = ASSERT_PTR(userdata); |
15ea79f8 LP |
2743 | uint32_t id; |
2744 | Job *j; | |
2745 | int r; | |
2746 | ||
2747 | assert(message); | |
15ea79f8 LP |
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 | ||
c20076a8 | 2760 | static int method_abandon_scope(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 2761 | Manager *m = ASSERT_PTR(userdata); |
c20076a8 LP |
2762 | const char *name; |
2763 | Unit *u; | |
2764 | int r; | |
2765 | ||
2766 | assert(message); | |
c20076a8 LP |
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) | |
cb31470f ZJS |
2777 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
2778 | "Unit '%s' is not a scope unit, refusing.", name); | |
c20076a8 LP |
2779 | |
2780 | return bus_scope_method_abandon(message, u, error); | |
2781 | } | |
2782 | ||
0bb007f7 | 2783 | static int method_set_show_status(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 2784 | Manager *m = ASSERT_PTR(userdata); |
0bb007f7 FB |
2785 | ShowStatus mode = _SHOW_STATUS_INVALID; |
2786 | const char *t; | |
2787 | int r; | |
2788 | ||
0bb007f7 FB |
2789 | assert(message); |
2790 | ||
4db62561 ZJS |
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 | ||
0bb007f7 FB |
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) | |
cb31470f ZJS |
2808 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
2809 | "Invalid show status '%s'", t); | |
0bb007f7 FB |
2810 | } |
2811 | ||
43bba15a | 2812 | manager_override_show_status(m, mode, "bus"); |
0bb007f7 FB |
2813 | |
2814 | return sd_bus_reply_method_return(message, NULL); | |
2815 | } | |
2816 | ||
2ea24611 LP |
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 | ||
84c01612 | 2821 | static int method_start_aux_scope(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
8c35e8a9 | 2822 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, "StartAuxiliaryScope() method has been removed."); |
84c01612 MS |
2823 | } |
2824 | ||
718db961 LP |
2825 | const sd_bus_vtable bus_manager_vtable[] = { |
2826 | SD_BUS_VTABLE_START(0), | |
2827 | ||
556089dc LP |
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), | |
1257274a | 2831 | SD_BUS_PROPERTY("ConfidentialVirtualization", "s", property_get_confidential_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
7452394e | 2832 | SD_BUS_PROPERTY("Architecture", "s", property_get_architecture, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 2833 | SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
9f9f0342 LP |
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), | |
b3f54861 | 2840 | BUS_PROPERTY_DUAL_TIMESTAMP("ShutdownStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SHUTDOWN_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
9f9f0342 LP |
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), | |
49fbe940 | 2847 | BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD]), SD_BUS_VTABLE_PROPERTY_CONST), |
665a9774 YW |
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), | |
25141692 LP |
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), | |
3ff52e8f YW |
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), | |
718db961 LP |
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), | |
1ad6e8b3 | 2862 | SD_BUS_PROPERTY("Environment", "as", property_get_environment, 0, 0), |
556089dc | 2863 | SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool, offsetof(Manager, confirm_spawn), SD_BUS_VTABLE_PROPERTY_CONST), |
52d2566a | 2864 | SD_BUS_PROPERTY("ShowStatus", "b", property_get_show_status, 0, 0), |
a3c4eb07 | 2865 | SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.search_path), SD_BUS_VTABLE_PROPERTY_CONST), |
c9e120e0 LP |
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), | |
3e911a0d YW |
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), | |
986935cf | 2871 | SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", property_get_runtime_watchdog, property_set_runtime_watchdog, 0, 0), |
5717062e | 2872 | SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogPreUSec", "t", property_get_pretimeout_watchdog, property_set_pretimeout_watchdog, 0, 0), |
aff3a9e1 | 2873 | SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogPreGovernor", "s", property_get_pretimeout_watchdog_governor, property_set_pretimeout_watchdog_governor, 0, 0), |
986935cf | 2874 | SD_BUS_WRITABLE_PROPERTY("RebootWatchdogUSec", "t", property_get_reboot_watchdog, property_set_reboot_watchdog, 0, 0), |
65224c1d | 2875 | /* The following item is an obsolete alias */ |
986935cf FB |
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), | |
2a12e32e | 2878 | SD_BUS_WRITABLE_PROPERTY("ServiceWatchdogs", "b", bus_property_get_bool, bus_property_set_bool, offsetof(Manager, service_watchdogs), 0), |
b272b74d | 2879 | SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Manager, cgroup_root), 0), |
f755e3b7 | 2880 | SD_BUS_PROPERTY("SystemState", "s", property_get_system_state, 0, 0), |
0b0cb6f3 | 2881 | SD_BUS_PROPERTY("ExitCode", "y", NULL, offsetof(Manager, return_value), 0), |
c9e120e0 LP |
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), | |
dc653bf4 | 2885 | SD_BUS_PROPERTY("DefaultTimeoutAbortUSec", "t", property_get_default_timeout_abort_usec, 0, 0), |
c9e120e0 LP |
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), | |
14702b9c | 2888 | SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST), |
c075f5fc | 2889 | /* The following two items are obsolete alias */ |
14702b9c DDM |
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), | |
c9e120e0 LP |
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), | |
eed67a30 | 2932 | SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
c9e120e0 | 2933 | SD_BUS_PROPERTY("DefaultOOMPolicy", "s", bus_property_get_oom_policy, offsetof(Manager, defaults.oom_policy), SD_BUS_VTABLE_PROPERTY_CONST), |
d4a402e4 | 2934 | SD_BUS_PROPERTY("DefaultOOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
c44a285c | 2935 | SD_BUS_PROPERTY("CtrlAltDelBurstAction", "s", bus_property_get_emergency_action, offsetof(Manager, cad_burst_action), SD_BUS_VTABLE_PROPERTY_CONST), |
66f35161 | 2936 | SD_BUS_PROPERTY("SoftRebootsCount", "u", bus_property_get_unsigned, offsetof(Manager, soft_reboots_count), SD_BUS_VTABLE_PROPERTY_CONST), |
29da53dd | 2937 | |
db6986e0 YW |
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), | |
29da53dd MY |
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), | |
718db961 | 2942 | |
a008b6d7 | 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), | |
e0e7bc82 LB |
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), | |
a008b6d7 | 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, | |
a721cd00 LP |
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, | |
a008b6d7 | 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), | |
94634b4b LP |
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), | |
a008b6d7 | 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), | |
dad97f04 ZJS |
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), | |
a008b6d7 | 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), | |
dad97f04 ZJS |
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), | |
a008b6d7 | 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), | |
293b9aa3 | 3178 | SD_BUS_METHOD_WITH_ARGS("DumpUnitsMatchingPatterns", |
d1d8786c FB |
3179 | SD_BUS_ARGS("as", patterns), |
3180 | SD_BUS_RESULT("s", output), | |
293b9aa3 | 3181 | method_dump_units_matching_patterns, |
d1d8786c | 3182 | SD_BUS_VTABLE_UNPRIVILEGED), |
a008b6d7 | 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), | |
f6cce15b ZJS |
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), | |
a008b6d7 | 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), | |
dad97f04 ZJS |
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, | |
624f685f | 3212 | SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_METHOD_NO_REPLY), |
dad97f04 ZJS |
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)), | |
13ffc607 LP |
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)), | |
dad97f04 ZJS |
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)), | |
a008b6d7 | 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), | |
bf1bea43 MY |
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), | |
a008b6d7 | 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), | |
2ea24611 LP |
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), | |
84c01612 MS |
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, | |
8c35e8a9 | 3397 | SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), |
a008b6d7 | 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), | |
718db961 | 3414 | SD_BUS_SIGNAL("UnitFilesChanged", NULL, 0), |
a008b6d7 | 3415 | SD_BUS_SIGNAL_WITH_ARGS("Reloading", |
3416 | SD_BUS_ARGS("b", active), | |
3417 | 0), | |
718db961 LP |
3418 | |
3419 | SD_BUS_VTABLE_END | |
ea430986 | 3420 | }; |
718db961 | 3421 | |
893f801d LP |
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 | ||
8f8f05a9 | 3437 | static int send_finished(sd_bus *bus, void *userdata) { |
4afd3348 | 3438 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
99534007 | 3439 | usec_t *times = ASSERT_PTR(userdata); |
718db961 LP |
3440 | int r; |
3441 | ||
3442 | assert(bus); | |
718db961 | 3443 | |
cb31470f ZJS |
3444 | r = sd_bus_message_new_signal(bus, |
3445 | &message, | |
3446 | "/org/freedesktop/systemd1", | |
3447 | "org.freedesktop.systemd1.Manager", | |
3448 | "StartupFinished"); | |
718db961 LP |
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 | ||
8f8f05a9 | 3456 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
3457 | } |
3458 | ||
39abcaee | 3459 | void bus_manager_send_finished( |
718db961 LP |
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 | ||
39abcaee LP |
3468 | int r; |
3469 | ||
718db961 LP |
3470 | assert(m); |
3471 | ||
8f8f05a9 LP |
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 | }); | |
39abcaee | 3484 | if (r < 0) |
da927ba9 | 3485 | log_debug_errno(r, "Failed to send finished signal: %m"); |
718db961 LP |
3486 | } |
3487 | ||
8f8f05a9 | 3488 | static int send_reloading(sd_bus *bus, void *userdata) { |
4afd3348 | 3489 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
3490 | int r; |
3491 | ||
3492 | assert(bus); | |
3493 | ||
151b9b96 | 3494 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading"); |
718db961 LP |
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 | ||
8f8f05a9 | 3502 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
3503 | } |
3504 | ||
39abcaee LP |
3505 | void bus_manager_send_reloading(Manager *m, bool active) { |
3506 | int r; | |
3507 | ||
718db961 LP |
3508 | assert(m); |
3509 | ||
8f8f05a9 | 3510 | r = bus_foreach_bus(m, NULL, send_reloading, INT_TO_PTR(active)); |
39abcaee | 3511 | if (r < 0) |
da927ba9 | 3512 | log_debug_errno(r, "Failed to send reloading signal: %m"); |
03455c28 LDM |
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 | } | |
39abcaee | 3523 | |
03455c28 LDM |
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"); | |
718db961 | 3532 | } |