]>
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) { |
03b4a607 LP |
829 | /* We don't bother with GENERIC_UNIT_LOAD or GENERIC_UNIT_VALIDATE_LOADED here, as it shouldn't |
830 | * matter whether a unit is loaded for killing any processes in the unit's cgroup. */ | |
42561fc9 | 831 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_kill, 0); |
718db961 | 832 | } |
8a0867d6 | 833 | |
0f23564a | 834 | static int method_kill_unit_subgroup(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
03b4a607 LP |
835 | /* We don't bother with GENERIC_UNIT_LOAD or GENERIC_UNIT_VALIDATE_LOADED here, as it shouldn't |
836 | * matter whether a unit is loaded for killing any processes in the unit's cgroup. */ | |
0f23564a LP |
837 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_kill_subgroup, 0); |
838 | } | |
839 | ||
4d3bac56 LP |
840 | static int method_clean_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
841 | /* Load the unit if necessary, in order to load it, and insist on the unit being loaded to be | |
842 | * cleaned */ | |
843 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_clean, GENERIC_UNIT_LOAD|GENERIC_UNIT_VALIDATE_LOADED); | |
844 | } | |
845 | ||
d9e45bc3 | 846 | static int method_freeze_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
47266ea2 MY |
847 | /* Only active units can be frozen, which must be properly loaded already */ |
848 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_freeze, GENERIC_UNIT_VALIDATE_LOADED); | |
d9e45bc3 MS |
849 | } |
850 | ||
851 | static int method_thaw_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
47266ea2 MY |
852 | /* Same as freeze above */ |
853 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_thaw, GENERIC_UNIT_VALIDATE_LOADED); | |
d9e45bc3 MS |
854 | } |
855 | ||
19070062 | 856 | static int method_reset_failed_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
857 | /* Don't load the unit (because unloaded units can't be in failed state), and don't insist on the |
858 | * unit to be loaded properly (since a failed unit might have its unit file disappeared) */ | |
859 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_reset_failed, 0); | |
718db961 | 860 | } |
5dd9014f | 861 | |
19070062 | 862 | static int method_set_unit_properties(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
863 | /* Only change properties on fully loaded units, and load them in order to set properties */ |
864 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_set_properties, GENERIC_UNIT_LOAD|GENERIC_UNIT_VALIDATE_LOADED); | |
718db961 LP |
865 | } |
866 | ||
5e8deb94 LB |
867 | static int method_bind_mount_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
868 | /* Only add mounts on fully loaded units */ | |
869 | return method_generic_unit_operation(message, userdata, error, bus_service_method_bind_mount, GENERIC_UNIT_VALIDATE_LOADED); | |
870 | } | |
871 | ||
af477139 LB |
872 | static int method_mount_image_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
873 | /* Only add mounts on fully loaded units */ | |
874 | return method_generic_unit_operation(message, userdata, error, bus_service_method_mount_image, GENERIC_UNIT_VALIDATE_LOADED); | |
875 | } | |
876 | ||
05a98afd | 877 | static int method_ref_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
878 | /* Only allow reffing of fully loaded units, and make sure reffing a unit loads it. */ |
879 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_ref, GENERIC_UNIT_LOAD|GENERIC_UNIT_VALIDATE_LOADED); | |
05a98afd LP |
880 | } |
881 | ||
882 | static int method_unref_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
42561fc9 LP |
883 | /* Dropping a ref OTOH should not require the unit to still be loaded. And since a reffed unit is a |
884 | * loaded unit there's no need to load the unit for unreffing it. */ | |
885 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_unref, 0); | |
05a98afd LP |
886 | } |
887 | ||
6900c740 | 888 | static int reply_unit_info(sd_bus_message *reply, Unit *u) { |
889 | _cleanup_free_ char *unit_path = NULL, *job_path = NULL; | |
890 | Unit *following; | |
891 | ||
892 | following = unit_following(u); | |
893 | ||
894 | unit_path = unit_dbus_path(u); | |
895 | if (!unit_path) | |
896 | return -ENOMEM; | |
897 | ||
898 | if (u->job) { | |
899 | job_path = job_dbus_path(u->job); | |
900 | if (!job_path) | |
901 | return -ENOMEM; | |
902 | } | |
903 | ||
904 | return sd_bus_message_append( | |
905 | reply, "(ssssssouso)", | |
906 | u->id, | |
907 | unit_description(u), | |
908 | unit_load_state_to_string(u->load_state), | |
909 | unit_active_state_to_string(unit_active_state(u)), | |
910 | unit_sub_state_to_string(u), | |
911 | following ? following->id : "", | |
912 | unit_path, | |
913 | u->job ? u->job->id : 0, | |
914 | u->job ? job_type_to_string(u->job->type) : "", | |
c1d95b71 | 915 | empty_to_root(job_path)); |
6900c740 | 916 | } |
917 | ||
918 | static int method_list_units_by_names(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
919 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
99534007 | 920 | Manager *m = ASSERT_PTR(userdata); |
6900c740 | 921 | int r; |
6900c740 | 922 | _cleanup_strv_free_ char **units = NULL; |
923 | ||
924 | assert(message); | |
6900c740 | 925 | |
926 | r = sd_bus_message_read_strv(message, &units); | |
927 | if (r < 0) | |
928 | return r; | |
929 | ||
930 | r = sd_bus_message_new_method_return(message, &reply); | |
931 | if (r < 0) | |
932 | return r; | |
933 | ||
934 | r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)"); | |
935 | if (r < 0) | |
936 | return r; | |
937 | ||
938 | STRV_FOREACH(unit, units) { | |
939 | Unit *u; | |
940 | ||
941 | if (!unit_name_is_valid(*unit, UNIT_NAME_ANY)) | |
942 | continue; | |
943 | ||
96cc4453 | 944 | r = bus_load_unit_by_name(m, message, *unit, &u, error); |
6900c740 | 945 | if (r < 0) |
946 | return r; | |
947 | ||
948 | r = reply_unit_info(reply, u); | |
949 | if (r < 0) | |
950 | return r; | |
951 | } | |
952 | ||
953 | r = sd_bus_message_close_container(reply); | |
954 | if (r < 0) | |
955 | return r; | |
956 | ||
51cc3825 | 957 | return sd_bus_message_send(reply); |
6900c740 | 958 | } |
959 | ||
291d565a | 960 | static int method_get_unit_processes(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
ad68a4e5 MY |
961 | /* Don't load a unit actively (since it won't have any processes if it's not loaded), but don't |
962 | * insist on the unit being loaded either (because even improperly loaded units might still have | |
963 | * processes around). */ | |
964 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_get_processes, /* flags = */ 0); | |
291d565a LP |
965 | } |
966 | ||
6592b975 | 967 | static int method_attach_processes_to_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
42561fc9 LP |
968 | /* Don't allow attaching new processes to units that aren't loaded. Don't bother with loading a unit |
969 | * for this purpose though, as an unloaded unit is a stopped unit, and we don't allow attaching | |
970 | * processes to stopped units anyway. */ | |
971 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_attach_processes, GENERIC_UNIT_VALIDATE_LOADED); | |
6592b975 LP |
972 | } |
973 | ||
94634b4b LP |
974 | static int method_remove_subgroup_from_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
975 | /* Don't allow removal of subgroups from units that aren't loaded. But allow loading the unit, since | |
976 | * this is clean-up work, that is OK to do when the unit is stopped already. */ | |
977 | return method_generic_unit_operation(message, userdata, error, bus_unit_method_remove_subgroup, GENERIC_UNIT_LOAD|GENERIC_UNIT_VALIDATE_LOADED); | |
978 | } | |
979 | ||
ab31f6b8 WC |
980 | static int transient_unit_from_message( |
981 | Manager *m, | |
982 | sd_bus_message *message, | |
983 | const char *name, | |
9fdb1c63 | 984 | Unit **ret_unit, |
ab31f6b8 WC |
985 | sd_bus_error *error) { |
986 | ||
06cc6afa | 987 | UnitType t; |
ab31f6b8 WC |
988 | Unit *u; |
989 | int r; | |
990 | ||
991 | assert(m); | |
992 | assert(message); | |
993 | assert(name); | |
994 | ||
06cc6afa LP |
995 | t = unit_name_to_type(name); |
996 | if (t < 0) | |
cb31470f | 997 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
a5ddad27 | 998 | "Invalid unit name or type: %s", name); |
06cc6afa LP |
999 | |
1000 | if (!unit_vtable[t]->can_transient) | |
cb31470f ZJS |
1001 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
1002 | "Unit type %s does not support transient units.", | |
1003 | unit_type_to_string(t)); | |
06cc6afa | 1004 | |
ab31f6b8 WC |
1005 | r = manager_load_unit(m, name, NULL, error, &u); |
1006 | if (r < 0) | |
1007 | return r; | |
1008 | ||
0f13f3bd | 1009 | if (!unit_is_pristine(u)) |
cb31470f | 1010 | return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, |
1f832446 | 1011 | "Unit %s was already loaded or has a fragment file.", name); |
ab31f6b8 WC |
1012 | |
1013 | /* OK, the unit failed to load and is unreferenced, now let's | |
1014 | * fill in the transient data instead */ | |
1015 | r = unit_make_transient(u); | |
1016 | if (r < 0) | |
1017 | return r; | |
1018 | ||
1019 | /* Set our properties */ | |
1020 | r = bus_unit_set_properties(u, message, UNIT_RUNTIME, false, error); | |
1021 | if (r < 0) | |
1022 | return r; | |
1023 | ||
05a98afd LP |
1024 | /* If the client asked for it, automatically add a reference to this unit. */ |
1025 | if (u->bus_track_add) { | |
1026 | r = bus_unit_track_add_sender(u, message); | |
1027 | if (r < 0) | |
1028 | return log_error_errno(r, "Failed to watch sender: %m"); | |
1029 | } | |
1030 | ||
97329d20 | 1031 | /* Now load the missing bits of the unit we just created */ |
4f952a3f | 1032 | unit_add_to_load_queue(u); |
97329d20 LP |
1033 | manager_dispatch_load_queue(m); |
1034 | ||
9fdb1c63 YW |
1035 | if (ret_unit) |
1036 | *ret_unit = u; | |
ab31f6b8 WC |
1037 | |
1038 | return 0; | |
1039 | } | |
1040 | ||
1041 | static int transient_aux_units_from_message( | |
1042 | Manager *m, | |
1043 | sd_bus_message *message, | |
1044 | sd_bus_error *error) { | |
1045 | ||
ab31f6b8 WC |
1046 | int r; |
1047 | ||
1048 | assert(m); | |
1049 | assert(message); | |
1050 | ||
1051 | r = sd_bus_message_enter_container(message, 'a', "(sa(sv))"); | |
1052 | if (r < 0) | |
1053 | return r; | |
1054 | ||
1055 | while ((r = sd_bus_message_enter_container(message, 'r', "sa(sv)")) > 0) { | |
9fdb1c63 | 1056 | const char *name; |
97329d20 | 1057 | |
ab31f6b8 WC |
1058 | r = sd_bus_message_read(message, "s", &name); |
1059 | if (r < 0) | |
1060 | return r; | |
1061 | ||
26208dd4 | 1062 | r = transient_unit_from_message(m, message, name, /* ret_unit = */ NULL, error); |
97329d20 | 1063 | if (r < 0) |
ab31f6b8 WC |
1064 | return r; |
1065 | ||
ab31f6b8 WC |
1066 | r = sd_bus_message_exit_container(message); |
1067 | if (r < 0) | |
1068 | return r; | |
1069 | } | |
1070 | if (r < 0) | |
1071 | return r; | |
1072 | ||
1073 | r = sd_bus_message_exit_container(message); | |
1074 | if (r < 0) | |
1075 | return r; | |
1076 | ||
1077 | return 0; | |
1078 | } | |
1079 | ||
19070062 | 1080 | static int method_start_transient_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1081 | const char *name, *smode; |
99534007 | 1082 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 1083 | JobMode mode; |
718db961 LP |
1084 | Unit *u; |
1085 | int r; | |
ea430986 | 1086 | |
718db961 | 1087 | assert(message); |
ea430986 | 1088 | |
1d22e906 | 1089 | r = mac_selinux_access_check(message, "start", error); |
283868e1 SW |
1090 | if (r < 0) |
1091 | return r; | |
283868e1 | 1092 | |
718db961 LP |
1093 | r = sd_bus_message_read(message, "ss", &name, &smode); |
1094 | if (r < 0) | |
ebcf1f97 | 1095 | return r; |
5632e374 | 1096 | |
718db961 LP |
1097 | mode = job_mode_from_string(smode); |
1098 | if (mode < 0) | |
ebcf1f97 | 1099 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s is invalid.", smode); |
5632e374 | 1100 | |
3a437f52 RRZ |
1101 | r = bus_verify_manage_units_async_impl( |
1102 | m, | |
1103 | name, | |
1104 | "start", | |
4e0bdf95 | 1105 | N_("Authentication is required to start transient unit '$(unit)'."), |
3a437f52 RRZ |
1106 | message, |
1107 | error); | |
718db961 | 1108 | if (r < 0) |
ebcf1f97 | 1109 | return r; |
1d22e906 LP |
1110 | if (r == 0) |
1111 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
5632e374 | 1112 | |
ab31f6b8 | 1113 | r = transient_unit_from_message(m, message, name, &u, error); |
ebcf1f97 LP |
1114 | if (r < 0) |
1115 | return r; | |
5632e374 | 1116 | |
ab31f6b8 | 1117 | r = transient_aux_units_from_message(m, message, error); |
718db961 | 1118 | if (r < 0) |
ebcf1f97 | 1119 | return r; |
ea430986 | 1120 | |
718db961 | 1121 | /* Finally, start it */ |
50cbaba4 | 1122 | return bus_unit_queue_job(message, u, JOB_START, mode, 0, error); |
718db961 | 1123 | } |
ea430986 | 1124 | |
19070062 | 1125 | static int method_get_job(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1126 | _cleanup_free_ char *path = NULL; |
99534007 | 1127 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
1128 | uint32_t id; |
1129 | Job *j; | |
1130 | int r; | |
ea430986 | 1131 | |
718db961 | 1132 | assert(message); |
ea430986 | 1133 | |
283868e1 SW |
1134 | /* Anyone can call this method */ |
1135 | ||
718db961 LP |
1136 | r = sd_bus_message_read(message, "u", &id); |
1137 | if (r < 0) | |
ebcf1f97 | 1138 | return r; |
ea430986 | 1139 | |
718db961 LP |
1140 | j = manager_get_job(m, id); |
1141 | if (!j) | |
ebcf1f97 | 1142 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); |
ea430986 | 1143 | |
8a188de9 | 1144 | r = mac_selinux_unit_access_check(j->unit, message, "status", error); |
ebcf1f97 LP |
1145 | if (r < 0) |
1146 | return r; | |
ea430986 | 1147 | |
718db961 LP |
1148 | path = job_dbus_path(j); |
1149 | if (!path) | |
ebcf1f97 | 1150 | return -ENOMEM; |
ea430986 | 1151 | |
df2d202e | 1152 | return sd_bus_reply_method_return(message, "o", path); |
718db961 | 1153 | } |
ea430986 | 1154 | |
19070062 | 1155 | static int method_cancel_job(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1156 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
1157 | uint32_t id; |
1158 | Job *j; | |
1159 | int r; | |
ea430986 | 1160 | |
718db961 | 1161 | assert(message); |
ea430986 | 1162 | |
718db961 LP |
1163 | r = sd_bus_message_read(message, "u", &id); |
1164 | if (r < 0) | |
ebcf1f97 | 1165 | return r; |
ea430986 | 1166 | |
718db961 LP |
1167 | j = manager_get_job(m, id); |
1168 | if (!j) | |
ebcf1f97 | 1169 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); |
ea430986 | 1170 | |
19070062 | 1171 | return bus_job_method_cancel(message, j, error); |
718db961 | 1172 | } |
c1e1601e | 1173 | |
19070062 | 1174 | static int method_clear_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1175 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1176 | int r; |
c1e1601e | 1177 | |
718db961 | 1178 | assert(message); |
c1e1601e | 1179 | |
1d22e906 | 1180 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1181 | if (r < 0) |
1182 | return r; | |
1183 | ||
1d22e906 LP |
1184 | r = bus_verify_manage_units_async(m, message, error); |
1185 | if (r < 0) | |
1186 | return r; | |
1187 | if (r == 0) | |
1188 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1189 | ||
718db961 | 1190 | manager_clear_jobs(m); |
c1e1601e | 1191 | |
df2d202e | 1192 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1193 | } |
c1e1601e | 1194 | |
19070062 | 1195 | static int method_reset_failed(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1196 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1197 | int r; |
cad45ba1 | 1198 | |
718db961 | 1199 | assert(message); |
718db961 | 1200 | |
8a188de9 | 1201 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1202 | if (r < 0) |
1203 | return r; | |
1204 | ||
1d22e906 LP |
1205 | r = bus_verify_manage_units_async(m, message, error); |
1206 | if (r < 0) | |
1207 | return r; | |
1208 | if (r == 0) | |
1209 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1210 | ||
718db961 | 1211 | manager_reset_failed(m); |
c1e1601e | 1212 | |
df2d202e | 1213 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1214 | } |
c1e1601e | 1215 | |
313fe66f | 1216 | static int list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *error, char **states, char **patterns) { |
4afd3348 | 1217 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
99534007 | 1218 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 1219 | const char *k; |
718db961 LP |
1220 | Unit *u; |
1221 | int r; | |
c1e1601e | 1222 | |
718db961 | 1223 | assert(message); |
b152adec | 1224 | |
283868e1 SW |
1225 | /* Anyone can call this method */ |
1226 | ||
8a188de9 | 1227 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1228 | if (r < 0) |
1229 | return r; | |
cad45ba1 | 1230 | |
df2d202e | 1231 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1232 | if (r < 0) |
ebcf1f97 | 1233 | return r; |
b152adec | 1234 | |
718db961 LP |
1235 | r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)"); |
1236 | if (r < 0) | |
ebcf1f97 | 1237 | return r; |
b152adec | 1238 | |
90e74a66 | 1239 | HASHMAP_FOREACH_KEY(u, k, m->units) { |
718db961 LP |
1240 | if (k != u->id) |
1241 | continue; | |
b152adec | 1242 | |
6e0f9593 | 1243 | if (!unit_passes_filter(u, states, patterns)) |
313fe66f | 1244 | continue; |
1245 | ||
6900c740 | 1246 | r = reply_unit_info(reply, u); |
718db961 | 1247 | if (r < 0) |
ebcf1f97 | 1248 | return r; |
718db961 | 1249 | } |
4139c1b2 | 1250 | |
718db961 LP |
1251 | r = sd_bus_message_close_container(reply); |
1252 | if (r < 0) | |
ebcf1f97 | 1253 | return r; |
cad45ba1 | 1254 | |
51cc3825 | 1255 | return sd_bus_message_send(reply); |
718db961 | 1256 | } |
4139c1b2 | 1257 | |
19070062 | 1258 | static int method_list_units(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
313fe66f | 1259 | return list_units_filtered(message, userdata, error, NULL, NULL); |
cdc06ed7 DS |
1260 | } |
1261 | ||
19070062 | 1262 | static int method_list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
cdc06ed7 DS |
1263 | _cleanup_strv_free_ char **states = NULL; |
1264 | int r; | |
1265 | ||
1266 | r = sd_bus_message_read_strv(message, &states); | |
1267 | if (r < 0) | |
1268 | return r; | |
1269 | ||
313fe66f | 1270 | return list_units_filtered(message, userdata, error, states, NULL); |
1271 | } | |
1272 | ||
1273 | static int method_list_units_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1274 | _cleanup_strv_free_ char **states = NULL; | |
1275 | _cleanup_strv_free_ char **patterns = NULL; | |
1276 | int r; | |
1277 | ||
1278 | r = sd_bus_message_read_strv(message, &states); | |
1279 | if (r < 0) | |
1280 | return r; | |
1281 | ||
1282 | r = sd_bus_message_read_strv(message, &patterns); | |
1283 | if (r < 0) | |
1284 | return r; | |
1285 | ||
1286 | return list_units_filtered(message, userdata, error, states, patterns); | |
cdc06ed7 DS |
1287 | } |
1288 | ||
19070062 | 1289 | static int method_list_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
4afd3348 | 1290 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
99534007 | 1291 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
1292 | Job *j; |
1293 | int r; | |
4139c1b2 | 1294 | |
718db961 | 1295 | assert(message); |
718db961 | 1296 | |
283868e1 SW |
1297 | /* Anyone can call this method */ |
1298 | ||
8a188de9 | 1299 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1300 | if (r < 0) |
1301 | return r; | |
718db961 | 1302 | |
df2d202e | 1303 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1304 | if (r < 0) |
ebcf1f97 | 1305 | return r; |
718db961 LP |
1306 | |
1307 | r = sd_bus_message_open_container(reply, 'a', "(usssoo)"); | |
1308 | if (r < 0) | |
ebcf1f97 | 1309 | return r; |
718db961 | 1310 | |
90e74a66 | 1311 | HASHMAP_FOREACH(j, m->jobs) { |
718db961 LP |
1312 | _cleanup_free_ char *unit_path = NULL, *job_path = NULL; |
1313 | ||
1314 | job_path = job_dbus_path(j); | |
1315 | if (!job_path) | |
ebcf1f97 | 1316 | return -ENOMEM; |
718db961 LP |
1317 | |
1318 | unit_path = unit_dbus_path(j->unit); | |
1319 | if (!unit_path) | |
ebcf1f97 | 1320 | return -ENOMEM; |
718db961 LP |
1321 | |
1322 | r = sd_bus_message_append( | |
1323 | reply, "(usssoo)", | |
1324 | j->id, | |
1302759d | 1325 | j->unit->id, |
718db961 | 1326 | job_type_to_string(j->type), |
1302759d | 1327 | job_state_to_string(j->state), |
718db961 LP |
1328 | job_path, |
1329 | unit_path); | |
cad45ba1 | 1330 | if (r < 0) |
ebcf1f97 | 1331 | return r; |
718db961 | 1332 | } |
5dd9014f | 1333 | |
718db961 LP |
1334 | r = sd_bus_message_close_container(reply); |
1335 | if (r < 0) | |
ebcf1f97 | 1336 | return r; |
5dd9014f | 1337 | |
51cc3825 | 1338 | return sd_bus_message_send(reply); |
718db961 | 1339 | } |
5dd9014f | 1340 | |
19070062 | 1341 | static int method_subscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1342 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 1343 | int r; |
5dd9014f | 1344 | |
718db961 | 1345 | assert(message); |
ea430986 | 1346 | |
283868e1 SW |
1347 | /* Anyone can call this method */ |
1348 | ||
8a188de9 | 1349 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1350 | if (r < 0) |
1351 | return r; | |
cad45ba1 | 1352 | |
19070062 | 1353 | if (sd_bus_message_get_bus(message) == m->api_bus) { |
8f8f05a9 LP |
1354 | |
1355 | /* Note that direct bus connection subscribe by | |
1356 | * default, we only track peers on the API bus here */ | |
1357 | ||
1358 | if (!m->subscribed) { | |
19070062 | 1359 | r = sd_bus_track_new(sd_bus_message_get_bus(message), &m->subscribed, NULL, NULL); |
8f8f05a9 LP |
1360 | if (r < 0) |
1361 | return r; | |
1362 | } | |
1363 | ||
1364 | r = sd_bus_track_add_sender(m->subscribed, message); | |
1365 | if (r < 0) | |
1366 | return r; | |
1367 | if (r == 0) | |
1b09b81c | 1368 | return sd_bus_error_set(error, BUS_ERROR_ALREADY_SUBSCRIBED, "Client is already subscribed."); |
8f8f05a9 | 1369 | } |
ea430986 | 1370 | |
df2d202e | 1371 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1372 | } |
ea430986 | 1373 | |
19070062 | 1374 | static int method_unsubscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1375 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 1376 | int r; |
ea430986 | 1377 | |
718db961 | 1378 | assert(message); |
ea430986 | 1379 | |
283868e1 SW |
1380 | /* Anyone can call this method */ |
1381 | ||
8a188de9 | 1382 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1383 | if (r < 0) |
1384 | return r; | |
ea430986 | 1385 | |
19070062 | 1386 | if (sd_bus_message_get_bus(message) == m->api_bus) { |
8f8f05a9 LP |
1387 | r = sd_bus_track_remove_sender(m->subscribed, message); |
1388 | if (r < 0) | |
1389 | return r; | |
1390 | if (r == 0) | |
1b09b81c | 1391 | return sd_bus_error_set(error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed."); |
8f8f05a9 | 1392 | } |
ea430986 | 1393 | |
df2d202e | 1394 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1395 | } |
ea430986 | 1396 | |
d1d8786c FB |
1397 | static int dump_impl( |
1398 | sd_bus_message *message, | |
1399 | void *userdata, | |
1400 | sd_bus_error *error, | |
1401 | char **patterns, | |
1402 | int (*reply)(sd_bus_message *, char *)) { | |
1403 | ||
718db961 | 1404 | _cleanup_free_ char *dump = NULL; |
99534007 | 1405 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1406 | int r; |
ea430986 | 1407 | |
718db961 | 1408 | assert(message); |
ea430986 | 1409 | |
d9365956 LB |
1410 | /* 'status' access is the bare minimum always needed for this, as the policy might straight out |
1411 | * forbid a client from querying any information from systemd, regardless of any rate limiting. */ | |
8a188de9 | 1412 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1413 | if (r < 0) |
1414 | return r; | |
ea430986 | 1415 | |
d9365956 LB |
1416 | /* Rate limit reached? Check if the caller is privileged/allowed by policy to bypass this. We |
1417 | * check the rate limit first to avoid the expensive roundtrip to polkit when not needed. */ | |
1418 | if (!ratelimit_below(&m->dump_ratelimit)) { | |
1419 | /* We need a way for SELinux to constrain the operation when the rate limit is active, even | |
1420 | * if polkit would allow it, but we cannot easily add new named permissions, so we need to | |
1421 | * use an existing one. Reload/reexec are also slow but non-destructive/modifying | |
1422 | * operations, and can cause PID1 to stall. So it seems similar enough in terms of security | |
1423 | * considerations and impact, and thus use the same access check for dumps which, given the | |
1424 | * large amount of data to fetch, can stall PID1 for quite some time. */ | |
ba4c69a0 | 1425 | r = mac_selinux_access_check(message, "reload", /* error = */ NULL); |
d9365956 LB |
1426 | if (r < 0) |
1427 | goto ratelimited; | |
1428 | ||
ba4c69a0 | 1429 | r = bus_verify_bypass_dump_ratelimit_async(m, message, /* error = */ NULL); |
d9365956 LB |
1430 | if (r < 0) |
1431 | goto ratelimited; | |
1432 | if (r == 0) | |
1433 | /* No authorization for now, but the async polkit stuff will call us again when it | |
1434 | * has it */ | |
1435 | return 1; | |
1436 | } | |
1437 | ||
d1d8786c | 1438 | r = manager_get_dump_string(m, patterns, &dump); |
dacd6cee LP |
1439 | if (r < 0) |
1440 | return r; | |
a16e1123 | 1441 | |
c0a1bfac | 1442 | return reply(message, dump); |
d9365956 LB |
1443 | |
1444 | ratelimited: | |
1445 | log_warning("Dump request rejected due to rate limit on unprivileged callers, blocked for %s.", | |
1446 | FORMAT_TIMESPAN(ratelimit_left(&m->dump_ratelimit), USEC_PER_SEC)); | |
1447 | return sd_bus_error_setf(error, | |
1448 | SD_BUS_ERROR_LIMITS_EXCEEDED, | |
1449 | "Dump request rejected due to rate limit on unprivileged callers, blocked for %s.", | |
1450 | FORMAT_TIMESPAN(ratelimit_left(&m->dump_ratelimit), USEC_PER_SEC)); | |
c0a1bfac DT |
1451 | } |
1452 | ||
1453 | static int reply_dump(sd_bus_message *message, char *dump) { | |
df2d202e | 1454 | return sd_bus_reply_method_return(message, "s", dump); |
718db961 | 1455 | } |
cad45ba1 | 1456 | |
c0a1bfac | 1457 | static int method_dump(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
d1d8786c | 1458 | return dump_impl(message, userdata, error, NULL, reply_dump); |
c0a1bfac DT |
1459 | } |
1460 | ||
1461 | static int reply_dump_by_fd(sd_bus_message *message, char *dump) { | |
254d1313 | 1462 | _cleanup_close_ int fd = -EBADF; |
c0a1bfac | 1463 | |
a87a9625 | 1464 | fd = memfd_new_and_seal_string("dump", dump); |
c0a1bfac DT |
1465 | if (fd < 0) |
1466 | return fd; | |
1467 | ||
1468 | return sd_bus_reply_method_return(message, "h", fd); | |
1469 | } | |
1470 | ||
1471 | static int method_dump_by_fd(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
d1d8786c FB |
1472 | return dump_impl(message, userdata, error, NULL, reply_dump_by_fd); |
1473 | } | |
1474 | ||
f6cce15b ZJS |
1475 | static int dump_units_matching_patterns( |
1476 | sd_bus_message *message, | |
1477 | void *userdata, | |
1478 | sd_bus_error *error, | |
1479 | int (*reply)(sd_bus_message *, char *)) { | |
d1d8786c FB |
1480 | _cleanup_strv_free_ char **patterns = NULL; |
1481 | int r; | |
1482 | ||
1483 | r = sd_bus_message_read_strv(message, &patterns); | |
1484 | if (r < 0) | |
1485 | return r; | |
1486 | ||
f6cce15b ZJS |
1487 | return dump_impl(message, userdata, error, patterns, reply); |
1488 | } | |
1489 | ||
1490 | static int method_dump_units_matching_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1491 | return dump_units_matching_patterns(message, userdata, error, reply_dump); | |
1492 | } | |
1493 | ||
1494 | static int method_dump_units_matching_patterns_by_fd(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1495 | return dump_units_matching_patterns(message, userdata, error, reply_dump_by_fd); | |
c0a1bfac DT |
1496 | } |
1497 | ||
36b4a7ba | 1498 | static int method_refuse_snapshot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1b09b81c | 1499 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, "Support for snapshots has been removed."); |
718db961 | 1500 | } |
cad45ba1 | 1501 | |
4895bacc | 1502 | static void log_caller(sd_bus_message *message, Manager *manager, const char *method) { |
9524c2fd | 1503 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; |
ff21827f | 1504 | _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; |
9524c2fd LB |
1505 | |
1506 | assert(message); | |
1507 | assert(manager); | |
4895bacc | 1508 | assert(method); |
9524c2fd | 1509 | |
ff21827f | 1510 | 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 |
1511 | return; |
1512 | ||
ff21827f MY |
1513 | /* We need at least the PID, otherwise there's nothing to log, the rest is optional. */ |
1514 | if (bus_creds_get_pidref(creds, &pidref) < 0) | |
9524c2fd LB |
1515 | return; |
1516 | ||
ff21827f MY |
1517 | const char *comm = NULL; |
1518 | Unit *caller; | |
1519 | ||
9524c2fd | 1520 | (void) sd_bus_creds_get_comm(creds, &comm); |
ff21827f | 1521 | caller = manager_get_unit_by_pidref(manager, &pidref); |
9524c2fd | 1522 | |
4ee41be8 DDM |
1523 | log_notice("%s requested from client PID " PID_FMT "%s%s%s%s%s%s...", |
1524 | method, pidref.pid, | |
1525 | comm ? " ('" : "", strempty(comm), comm ? "')" : "", | |
1526 | caller ? " (unit " : "", caller ? caller->id : "", caller ? ")" : ""); | |
9524c2fd LB |
1527 | } |
1528 | ||
19070062 | 1529 | static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1530 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 1531 | int r; |
6652a2b9 | 1532 | |
718db961 | 1533 | assert(message); |
6652a2b9 | 1534 | |
1d22e906 | 1535 | r = mac_selinux_access_check(message, "reload", error); |
283868e1 SW |
1536 | if (r < 0) |
1537 | return r; | |
283868e1 | 1538 | |
1d22e906 | 1539 | r = bus_verify_reload_daemon_async(m, message, error); |
ebcf1f97 LP |
1540 | if (r < 0) |
1541 | return r; | |
1d22e906 LP |
1542 | if (r == 0) |
1543 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
6652a2b9 | 1544 | |
9524c2fd | 1545 | /* Write a log message noting the unit or process who requested the Reload() */ |
71322b95 | 1546 | log_caller(message, m, "Reload"); |
9524c2fd | 1547 | |
856bfaeb | 1548 | /* Check the rate limit after the authorization succeeds, to avoid denial-of-service issues. */ |
8312b17a | 1549 | if (!ratelimit_below(&m->reload_reexec_ratelimit)) { |
856bfaeb | 1550 | log_warning("Reloading request rejected due to rate limit."); |
a5ddad27 LP |
1551 | return sd_bus_error_set(error, |
1552 | SD_BUS_ERROR_LIMITS_EXCEEDED, | |
1553 | "Reload() request rejected due to rate limit."); | |
856bfaeb LB |
1554 | } |
1555 | ||
718db961 LP |
1556 | /* Instead of sending the reply back right away, we just |
1557 | * remember that we need to and then send it after the reload | |
1558 | * is finished. That way the caller knows when the reload | |
1559 | * finished. */ | |
6652a2b9 | 1560 | |
209de525 LP |
1561 | assert(!m->pending_reload_message); |
1562 | r = sd_bus_message_new_method_return(message, &m->pending_reload_message); | |
718db961 | 1563 | if (r < 0) |
ebcf1f97 | 1564 | return r; |
cad45ba1 | 1565 | |
af41e508 | 1566 | m->objective = MANAGER_RELOAD; |
6652a2b9 | 1567 | |
718db961 LP |
1568 | return 1; |
1569 | } | |
6652a2b9 | 1570 | |
19070062 | 1571 | static int method_reexecute(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1572 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1573 | int r; |
6652a2b9 | 1574 | |
718db961 | 1575 | assert(message); |
6652a2b9 | 1576 | |
1d22e906 | 1577 | r = mac_selinux_access_check(message, "reload", error); |
283868e1 SW |
1578 | if (r < 0) |
1579 | return r; | |
283868e1 | 1580 | |
1d22e906 | 1581 | r = bus_verify_reload_daemon_async(m, message, error); |
ebcf1f97 LP |
1582 | if (r < 0) |
1583 | return r; | |
1d22e906 LP |
1584 | if (r == 0) |
1585 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
cad45ba1 | 1586 | |
4895bacc | 1587 | /* Write a log message noting the unit or process who requested the Reexecute() */ |
71322b95 | 1588 | log_caller(message, m, "Reexecution"); |
4895bacc | 1589 | |
8312b17a LB |
1590 | /* Check the rate limit after the authorization succeeds, to avoid denial-of-service issues. */ |
1591 | if (!ratelimit_below(&m->reload_reexec_ratelimit)) { | |
71322b95 | 1592 | log_warning("Reexecution request rejected due to rate limit."); |
a5ddad27 LP |
1593 | return sd_bus_error_set(error, |
1594 | SD_BUS_ERROR_LIMITS_EXCEEDED, | |
1595 | "Reexecute() request rejected due to rate limit."); | |
8312b17a LB |
1596 | } |
1597 | ||
718db961 LP |
1598 | /* We don't send a reply back here, the client should |
1599 | * just wait for us disconnecting. */ | |
6652a2b9 | 1600 | |
af41e508 | 1601 | m->objective = MANAGER_REEXECUTE; |
718db961 LP |
1602 | return 1; |
1603 | } | |
6652a2b9 | 1604 | |
19070062 | 1605 | static int method_exit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1606 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1607 | int r; |
6652a2b9 | 1608 | |
718db961 | 1609 | assert(message); |
6652a2b9 | 1610 | |
8a188de9 | 1611 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1612 | if (r < 0) |
1613 | return r; | |
cad45ba1 | 1614 | |
acb0f501 DDM |
1615 | log_caller(message, m, "Exit"); |
1616 | ||
287419c1 AC |
1617 | /* Exit() (in contrast to SetExitCode()) is actually allowed even if |
1618 | * we are running on the host. It will fall back on reboot() in | |
1619 | * systemd-shutdown if it cannot do the exit() because it isn't a | |
1620 | * container. */ | |
6652a2b9 | 1621 | |
af41e508 | 1622 | m->objective = MANAGER_EXIT; |
6652a2b9 | 1623 | |
df2d202e | 1624 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1625 | } |
6652a2b9 | 1626 | |
19070062 | 1627 | static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1628 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1629 | int r; |
664f88a7 | 1630 | |
718db961 | 1631 | assert(message); |
cad45ba1 | 1632 | |
463d0d15 | 1633 | if (!MANAGER_IS_SYSTEM(m)) |
a85fe612 MY |
1634 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, |
1635 | "Reboot is only supported by system manager."); | |
664f88a7 | 1636 | |
541aadff MY |
1637 | r = mac_selinux_access_check(message, "reboot", error); |
1638 | if (r < 0) | |
1639 | return r; | |
1640 | ||
acb0f501 DDM |
1641 | log_caller(message, m, "Reboot"); |
1642 | ||
af41e508 | 1643 | m->objective = MANAGER_REBOOT; |
664f88a7 | 1644 | |
df2d202e | 1645 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1646 | } |
664f88a7 | 1647 | |
13ffc607 | 1648 | static int method_soft_reboot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
13ffc607 | 1649 | Manager *m = ASSERT_PTR(userdata); |
b80ae4bc | 1650 | _cleanup_free_ char *rt = NULL; |
13ffc607 LP |
1651 | const char *root; |
1652 | int r; | |
1653 | ||
1654 | assert(message); | |
1655 | ||
236cd485 MY |
1656 | if (!MANAGER_IS_SYSTEM(m)) |
1657 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, | |
1658 | "Soft reboot is only supported by system manager."); | |
1659 | ||
13ffc607 LP |
1660 | r = mac_selinux_access_check(message, "reboot", error); |
1661 | if (r < 0) | |
1662 | return r; | |
1663 | ||
1664 | r = sd_bus_message_read(message, "s", &root); | |
1665 | if (r < 0) | |
1666 | return r; | |
1667 | ||
1668 | if (!isempty(root)) { | |
1669 | if (!path_is_valid(root)) | |
1670 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, | |
1671 | "New root directory '%s' must be a valid path.", root); | |
1672 | if (!path_is_absolute(root)) | |
1673 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, | |
1674 | "New root directory path '%s' is not absolute.", root); | |
1675 | ||
b80ae4bc MY |
1676 | r = path_simplify_alloc(root, &rt); |
1677 | if (r < 0) | |
1678 | return r; | |
13ffc607 LP |
1679 | } |
1680 | ||
acb0f501 DDM |
1681 | log_caller(message, m, "Soft reboot"); |
1682 | ||
13ffc607 LP |
1683 | free_and_replace(m->switch_root, rt); |
1684 | m->objective = MANAGER_SOFT_REBOOT; | |
1685 | ||
1686 | return sd_bus_reply_method_return(message, NULL); | |
1687 | } | |
1688 | ||
19070062 | 1689 | static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1690 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1691 | int r; |
50913bc0 | 1692 | |
718db961 | 1693 | assert(message); |
1137a57c | 1694 | |
463d0d15 | 1695 | if (!MANAGER_IS_SYSTEM(m)) |
a85fe612 MY |
1696 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, |
1697 | "Powering off is only supported by system manager."); | |
1137a57c | 1698 | |
541aadff MY |
1699 | r = mac_selinux_access_check(message, "halt", error); |
1700 | if (r < 0) | |
1701 | return r; | |
1702 | ||
acb0f501 DDM |
1703 | log_caller(message, m, "Poweroff"); |
1704 | ||
af41e508 | 1705 | m->objective = MANAGER_POWEROFF; |
1137a57c | 1706 | |
df2d202e | 1707 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1708 | } |
1137a57c | 1709 | |
19070062 | 1710 | static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1711 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1712 | int r; |
1137a57c | 1713 | |
718db961 | 1714 | assert(message); |
8d0e38a2 | 1715 | |
463d0d15 | 1716 | if (!MANAGER_IS_SYSTEM(m)) |
a85fe612 MY |
1717 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, |
1718 | "Halt is only supported by system manager."); | |
8d0e38a2 | 1719 | |
541aadff MY |
1720 | r = mac_selinux_access_check(message, "halt", error); |
1721 | if (r < 0) | |
1722 | return r; | |
1723 | ||
acb0f501 DDM |
1724 | log_caller(message, m, "Halt"); |
1725 | ||
af41e508 | 1726 | m->objective = MANAGER_HALT; |
8d0e38a2 | 1727 | |
df2d202e | 1728 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1729 | } |
8d0e38a2 | 1730 | |
19070062 | 1731 | static int method_kexec(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1732 | Manager *m = ASSERT_PTR(userdata); |
ebcf1f97 | 1733 | int r; |
8d0e38a2 | 1734 | |
718db961 | 1735 | assert(message); |
c0576cd6 | 1736 | |
463d0d15 | 1737 | if (!MANAGER_IS_SYSTEM(m)) |
a85fe612 MY |
1738 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, |
1739 | "KExec is only supported by system manager."); | |
c0576cd6 | 1740 | |
541aadff MY |
1741 | r = mac_selinux_access_check(message, "reboot", error); |
1742 | if (r < 0) | |
1743 | return r; | |
1744 | ||
acb0f501 DDM |
1745 | log_caller(message, m, "Kexec"); |
1746 | ||
af41e508 | 1747 | m->objective = MANAGER_KEXEC; |
c0576cd6 | 1748 | |
df2d202e | 1749 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1750 | } |
c0576cd6 | 1751 | |
19070062 | 1752 | static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1753 | Manager *m = ASSERT_PTR(userdata); |
b80ae4bc | 1754 | _cleanup_free_ char *ri = NULL, *rt = NULL; |
13ffc607 | 1755 | const char *root, *init; |
718db961 | 1756 | int r; |
c0576cd6 | 1757 | |
718db961 | 1758 | assert(message); |
c0576cd6 | 1759 | |
541aadff MY |
1760 | if (!MANAGER_IS_SYSTEM(m)) |
1761 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, | |
1762 | "Root switching is only supported by system manager."); | |
1763 | ||
8a188de9 | 1764 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1765 | if (r < 0) |
1766 | return r; | |
c0576cd6 | 1767 | |
718db961 LP |
1768 | r = sd_bus_message_read(message, "ss", &root, &init); |
1769 | if (r < 0) | |
ebcf1f97 | 1770 | return r; |
c0576cd6 | 1771 | |
5ae89ef3 LP |
1772 | if (isempty(root)) |
1773 | /* If path is not specified, default to "/sysroot" which is what we generally expect initrds | |
1774 | * to use */ | |
1775 | root = "/sysroot"; | |
1776 | else { | |
1777 | if (!path_is_valid(root)) | |
a85fe612 MY |
1778 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, |
1779 | "New root directory must be a valid path."); | |
b0c5f0e1 | 1780 | |
5ae89ef3 LP |
1781 | if (!path_is_absolute(root)) |
1782 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, | |
1783 | "New root path '%s' is not absolute.", root); | |
b0c5f0e1 MY |
1784 | |
1785 | r = path_is_root(root); | |
1786 | if (r < 0) | |
1787 | return sd_bus_error_set_errnof(error, r, | |
1788 | "Failed to check if new root directory '%s' is the same as old root: %m", | |
1789 | root); | |
1790 | if (r > 0) | |
a85fe612 MY |
1791 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, |
1792 | "New root directory cannot be the old root directory."); | |
5ae89ef3 | 1793 | } |
c0576cd6 | 1794 | |
718db961 | 1795 | /* Safety check */ |
4da159bc | 1796 | if (!in_initrd()) |
a85fe612 MY |
1797 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, |
1798 | "Not in initrd, refusing switch-root operation."); | |
4da159bc MY |
1799 | |
1800 | r = path_is_os_tree(root); | |
1801 | if (r < 0) | |
1802 | return sd_bus_error_set_errnof(error, r, | |
1803 | "Failed to determine whether root path '%s' contains an OS tree: %m", | |
1804 | root); | |
1805 | if (r == 0) | |
1806 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, | |
1807 | "Specified switch root path '%s' does not seem to be an OS tree. os-release file is missing.", | |
1808 | root); | |
1809 | ||
1810 | if (!isempty(init)) { | |
5f4c9c27 LP |
1811 | if (!path_is_valid(init)) |
1812 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, | |
1813 | "Path to init binary '%s' is not a valid path.", init); | |
1814 | ||
718db961 | 1815 | if (!path_is_absolute(init)) |
cb31470f ZJS |
1816 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
1817 | "Path to init binary '%s' not absolute.", init); | |
c0576cd6 | 1818 | |
f461a28d | 1819 | r = chase_and_access(init, root, CHASE_PREFIX_ROOT, X_OK, NULL); |
e10086ac LP |
1820 | if (r == -EACCES) |
1821 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, | |
1822 | "Init binary %s is not executable.", init); | |
710028b4 | 1823 | if (r < 0) |
cb31470f ZJS |
1824 | return sd_bus_error_set_errnof(error, r, |
1825 | "Could not resolve init executable %s: %m", init); | |
718db961 LP |
1826 | } |
1827 | ||
b80ae4bc MY |
1828 | r = path_simplify_alloc(root, &rt); |
1829 | if (r < 0) | |
1830 | return r; | |
718db961 LP |
1831 | |
1832 | if (!isempty(init)) { | |
b80ae4bc MY |
1833 | r = path_simplify_alloc(init, &ri); |
1834 | if (r < 0) | |
1835 | return r; | |
718db961 | 1836 | } |
c0576cd6 | 1837 | |
87a19bfe YW |
1838 | free_and_replace(m->switch_root, rt); |
1839 | free_and_replace(m->switch_root_init, ri); | |
c0576cd6 | 1840 | |
af41e508 | 1841 | m->objective = MANAGER_SWITCH_ROOT; |
92b315df | 1842 | |
df2d202e | 1843 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1844 | } |
c0576cd6 | 1845 | |
19070062 | 1846 | static int method_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1847 | _cleanup_strv_free_ char **plus = NULL; |
99534007 | 1848 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 1849 | int r; |
c0576cd6 | 1850 | |
718db961 | 1851 | assert(message); |
cad45ba1 | 1852 | |
8a188de9 | 1853 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1854 | if (r < 0) |
1855 | return r; | |
c0576cd6 | 1856 | |
718db961 LP |
1857 | r = sd_bus_message_read_strv(message, &plus); |
1858 | if (r < 0) | |
ebcf1f97 | 1859 | return r; |
718db961 | 1860 | if (!strv_env_is_valid(plus)) |
1b09b81c | 1861 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments"); |
c0576cd6 | 1862 | |
1d22e906 LP |
1863 | r = bus_verify_set_environment_async(m, message, error); |
1864 | if (r < 0) | |
1865 | return r; | |
1866 | if (r == 0) | |
1867 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1868 | ||
1ad6e8b3 | 1869 | r = manager_client_environment_modify(m, NULL, plus); |
718db961 | 1870 | if (r < 0) |
ebcf1f97 | 1871 | return r; |
c0576cd6 | 1872 | |
df2d202e | 1873 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1874 | } |
1875 | ||
19070062 | 1876 | static int method_unset_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1877 | _cleanup_strv_free_ char **minus = NULL; |
99534007 | 1878 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
1879 | int r; |
1880 | ||
718db961 | 1881 | assert(message); |
718db961 | 1882 | |
8a188de9 | 1883 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1884 | if (r < 0) |
1885 | return r; | |
c0576cd6 | 1886 | |
718db961 LP |
1887 | r = sd_bus_message_read_strv(message, &minus); |
1888 | if (r < 0) | |
ebcf1f97 | 1889 | return r; |
718db961 LP |
1890 | |
1891 | if (!strv_env_name_or_assignment_is_valid(minus)) | |
a5ddad27 LP |
1892 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, |
1893 | "Invalid environment variable names or assignments"); | |
718db961 | 1894 | |
1d22e906 LP |
1895 | r = bus_verify_set_environment_async(m, message, error); |
1896 | if (r < 0) | |
1897 | return r; | |
1898 | if (r == 0) | |
1899 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1900 | ||
1ad6e8b3 | 1901 | r = manager_client_environment_modify(m, minus, NULL); |
718db961 | 1902 | if (r < 0) |
ebcf1f97 | 1903 | return r; |
718db961 | 1904 | |
df2d202e | 1905 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1906 | } |
1907 | ||
19070062 | 1908 | static int method_unset_and_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1909 | _cleanup_strv_free_ char **minus = NULL, **plus = NULL; |
99534007 | 1910 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
1911 | int r; |
1912 | ||
718db961 | 1913 | assert(message); |
718db961 | 1914 | |
8a188de9 | 1915 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1916 | if (r < 0) |
1917 | return r; | |
718db961 | 1918 | |
eb6c7d20 | 1919 | r = sd_bus_message_read_strv(message, &minus); |
718db961 | 1920 | if (r < 0) |
ebcf1f97 | 1921 | return r; |
718db961 | 1922 | |
eb6c7d20 | 1923 | r = sd_bus_message_read_strv(message, &plus); |
718db961 | 1924 | if (r < 0) |
ebcf1f97 | 1925 | return r; |
718db961 | 1926 | |
718db961 | 1927 | if (!strv_env_name_or_assignment_is_valid(minus)) |
a5ddad27 LP |
1928 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, |
1929 | "Invalid environment variable names or assignments"); | |
eb6c7d20 | 1930 | if (!strv_env_is_valid(plus)) |
a5ddad27 LP |
1931 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, |
1932 | "Invalid environment assignments"); | |
718db961 | 1933 | |
1d22e906 LP |
1934 | r = bus_verify_set_environment_async(m, message, error); |
1935 | if (r < 0) | |
1936 | return r; | |
1937 | if (r == 0) | |
1938 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1939 | ||
1ad6e8b3 | 1940 | r = manager_client_environment_modify(m, minus, plus); |
718db961 | 1941 | if (r < 0) |
ebcf1f97 | 1942 | return r; |
718db961 | 1943 | |
df2d202e | 1944 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1945 | } |
1946 | ||
287419c1 | 1947 | static int method_set_exit_code(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1948 | Manager *m = ASSERT_PTR(userdata); |
29206d46 | 1949 | uint8_t code; |
287419c1 AC |
1950 | int r; |
1951 | ||
1952 | assert(message); | |
287419c1 AC |
1953 | |
1954 | r = mac_selinux_access_check(message, "exit", error); | |
1955 | if (r < 0) | |
1956 | return r; | |
1957 | ||
1958 | r = sd_bus_message_read_basic(message, 'y', &code); | |
1959 | if (r < 0) | |
1960 | return r; | |
1961 | ||
287419c1 AC |
1962 | m->return_value = code; |
1963 | ||
1964 | return sd_bus_reply_method_return(message, NULL); | |
1965 | } | |
1966 | ||
29206d46 | 1967 | static int method_lookup_dynamic_user_by_name(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 1968 | Manager *m = ASSERT_PTR(userdata); |
29206d46 LP |
1969 | const char *name; |
1970 | uid_t uid; | |
1971 | int r; | |
1972 | ||
1973 | assert(message); | |
29206d46 LP |
1974 | |
1975 | r = sd_bus_message_read_basic(message, 's', &name); | |
1976 | if (r < 0) | |
1977 | return r; | |
1978 | ||
1979 | if (!MANAGER_IS_SYSTEM(m)) | |
a5ddad27 LP |
1980 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, |
1981 | "Dynamic users are only supported in the system instance."); | |
7a8867ab | 1982 | if (!valid_user_group_name(name, VALID_USER_RELAX)) |
cb31470f ZJS |
1983 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
1984 | "User name invalid: %s", name); | |
29206d46 LP |
1985 | |
1986 | r = dynamic_user_lookup_name(m, name, &uid); | |
1987 | if (r == -ESRCH) | |
cb31470f ZJS |
1988 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, |
1989 | "Dynamic user %s does not exist.", name); | |
29206d46 LP |
1990 | if (r < 0) |
1991 | return r; | |
1992 | ||
1993 | return sd_bus_reply_method_return(message, "u", (uint32_t) uid); | |
1994 | } | |
1995 | ||
1996 | static int method_lookup_dynamic_user_by_uid(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1997 | _cleanup_free_ char *name = NULL; | |
99534007 | 1998 | Manager *m = ASSERT_PTR(userdata); |
29206d46 LP |
1999 | uid_t uid; |
2000 | int r; | |
2001 | ||
2002 | assert(message); | |
29206d46 | 2003 | |
60d0a509 | 2004 | assert_cc(sizeof(uid_t) == sizeof(uint32_t)); |
29206d46 LP |
2005 | r = sd_bus_message_read_basic(message, 'u', &uid); |
2006 | if (r < 0) | |
2007 | return r; | |
2008 | ||
2009 | if (!MANAGER_IS_SYSTEM(m)) | |
a5ddad27 LP |
2010 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, |
2011 | "Dynamic users are only supported in the system instance."); | |
29206d46 | 2012 | if (!uid_is_valid(uid)) |
cb31470f ZJS |
2013 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
2014 | "User ID invalid: " UID_FMT, uid); | |
29206d46 LP |
2015 | |
2016 | r = dynamic_user_lookup_uid(m, uid, &name); | |
2017 | if (r == -ESRCH) | |
cb31470f ZJS |
2018 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, |
2019 | "Dynamic user ID " UID_FMT " does not exist.", uid); | |
29206d46 LP |
2020 | if (r < 0) |
2021 | return r; | |
2022 | ||
2023 | return sd_bus_reply_method_return(message, "s", name); | |
2024 | } | |
2025 | ||
f9bfa696 YW |
2026 | static int method_get_dynamic_users(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2027 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
99534007 | 2028 | Manager *m = ASSERT_PTR(userdata); |
f9bfa696 | 2029 | DynamicUser *d; |
f9bfa696 YW |
2030 | int r; |
2031 | ||
2032 | assert(message); | |
f9bfa696 YW |
2033 | |
2034 | assert_cc(sizeof(uid_t) == sizeof(uint32_t)); | |
2035 | ||
2036 | if (!MANAGER_IS_SYSTEM(m)) | |
a5ddad27 LP |
2037 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, |
2038 | "Dynamic users are only supported in the system instance."); | |
f9bfa696 YW |
2039 | |
2040 | r = sd_bus_message_new_method_return(message, &reply); | |
2041 | if (r < 0) | |
2042 | return r; | |
2043 | ||
2044 | r = sd_bus_message_open_container(reply, 'a', "(us)"); | |
2045 | if (r < 0) | |
2046 | return r; | |
2047 | ||
90e74a66 | 2048 | HASHMAP_FOREACH(d, m->dynamic_users) { |
f9bfa696 YW |
2049 | uid_t uid; |
2050 | ||
2051 | r = dynamic_user_current(d, &uid); | |
2052 | if (r == -EAGAIN) /* not realized yet? */ | |
2053 | continue; | |
2054 | if (r < 0) | |
a5ddad27 LP |
2055 | return sd_bus_error_set(error, SD_BUS_ERROR_FAILED, |
2056 | "Failed to look up a dynamic user."); | |
f9bfa696 YW |
2057 | |
2058 | r = sd_bus_message_append(reply, "(us)", uid, d->name); | |
2059 | if (r < 0) | |
2060 | return r; | |
2061 | } | |
2062 | ||
2063 | r = sd_bus_message_close_container(reply); | |
2064 | if (r < 0) | |
2065 | return r; | |
2066 | ||
51cc3825 | 2067 | return sd_bus_message_send(reply); |
f9bfa696 YW |
2068 | } |
2069 | ||
70666e28 | 2070 | static int method_enqueue_marked_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 2071 | Manager *m = ASSERT_PTR(userdata); |
70666e28 ZJS |
2072 | int r; |
2073 | ||
2074 | assert(message); | |
70666e28 ZJS |
2075 | |
2076 | r = mac_selinux_access_check(message, "start", error); | |
2077 | if (r < 0) | |
2078 | return r; | |
2079 | ||
2080 | r = bus_verify_manage_units_async(m, message, error); | |
2081 | if (r < 0) | |
2082 | return r; | |
2083 | if (r == 0) | |
2084 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2085 | ||
1ae9b0cf | 2086 | log_info("Queuing reload/restart jobs for marked units%s", glyph(GLYPH_ELLIPSIS)); |
70666e28 ZJS |
2087 | |
2088 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
2089 | r = sd_bus_message_new_method_return(message, &reply); | |
2090 | if (r < 0) | |
2091 | return r; | |
2092 | ||
2093 | r = sd_bus_message_open_container(reply, 'a', "o"); | |
2094 | if (r < 0) | |
2095 | return r; | |
2096 | ||
2097 | Unit *u; | |
2098 | char *k; | |
2099 | int ret = 0; | |
2100 | HASHMAP_FOREACH_KEY(u, k, m->units) { | |
2101 | /* ignore aliases */ | |
2102 | if (u->id != k) | |
2103 | continue; | |
2104 | ||
2105 | BusUnitQueueFlags flags; | |
1e4e5572 | 2106 | if (BIT_SET(u->markers, UNIT_MARKER_NEEDS_RESTART)) |
70666e28 | 2107 | flags = 0; |
1e4e5572 | 2108 | else if (BIT_SET(u->markers, UNIT_MARKER_NEEDS_RELOAD)) |
70666e28 ZJS |
2109 | flags = BUS_UNIT_QUEUE_RELOAD_IF_POSSIBLE; |
2110 | else | |
2111 | continue; | |
2112 | ||
2113 | r = mac_selinux_unit_access_check(u, message, "start", error); | |
2114 | if (r >= 0) | |
2115 | r = bus_unit_queue_job_one(message, u, | |
2116 | JOB_TRY_RESTART, JOB_FAIL, flags, | |
2117 | reply, error); | |
bb44fd07 ZJS |
2118 | if (ERRNO_IS_NEG_RESOURCE(r)) |
2119 | return r; | |
70666e28 | 2120 | if (r < 0) { |
70666e28 ZJS |
2121 | if (ret >= 0) |
2122 | ret = r; | |
2123 | sd_bus_error_free(error); | |
2124 | } | |
2125 | } | |
2126 | ||
2127 | if (ret < 0) | |
2128 | return sd_bus_error_set_errnof(error, ret, | |
2129 | "Failed to enqueue some jobs, see logs for details: %m"); | |
2130 | ||
2131 | r = sd_bus_message_close_container(reply); | |
2132 | if (r < 0) | |
2133 | return r; | |
2134 | ||
51cc3825 | 2135 | return sd_bus_message_send(reply); |
70666e28 ZJS |
2136 | } |
2137 | ||
313fe66f | 2138 | static int list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error, char **states, char **patterns) { |
99534007 | 2139 | Manager *m = ASSERT_PTR(userdata); |
ca3c95c1 | 2140 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
5d2a48da | 2141 | _cleanup_hashmap_free_ Hashmap *h = NULL; |
718db961 LP |
2142 | int r; |
2143 | ||
718db961 | 2144 | assert(message); |
718db961 | 2145 | |
283868e1 SW |
2146 | /* Anyone can call this method */ |
2147 | ||
8a188de9 | 2148 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
2149 | if (r < 0) |
2150 | return r; | |
718db961 | 2151 | |
df2d202e | 2152 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 2153 | if (r < 0) |
ebcf1f97 | 2154 | return r; |
c0576cd6 | 2155 | |
ca3c95c1 | 2156 | r = unit_file_get_list(m->runtime_scope, /* root_dir = */ NULL, states, patterns, &h); |
ebcf1f97 | 2157 | if (r < 0) |
066ba68e | 2158 | return r; |
718db961 LP |
2159 | |
2160 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); | |
ebcf1f97 | 2161 | if (r < 0) |
066ba68e | 2162 | return r; |
718db961 | 2163 | |
ca3c95c1 | 2164 | UnitFileList *item; |
90e74a66 | 2165 | HASHMAP_FOREACH(item, h) { |
718db961 | 2166 | r = sd_bus_message_append(reply, "(ss)", item->path, unit_file_state_to_string(item->state)); |
ebcf1f97 | 2167 | if (r < 0) |
066ba68e | 2168 | return r; |
718db961 | 2169 | } |
c0576cd6 | 2170 | |
718db961 LP |
2171 | r = sd_bus_message_close_container(reply); |
2172 | if (r < 0) | |
ebcf1f97 | 2173 | return r; |
8d0e38a2 | 2174 | |
51cc3825 | 2175 | return sd_bus_message_send(reply); |
718db961 | 2176 | } |
99504dd4 | 2177 | |
313fe66f | 2178 | static int method_list_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2179 | return list_unit_files_by_patterns(message, userdata, error, NULL, NULL); | |
2180 | } | |
2181 | ||
2182 | static int method_list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
2183 | _cleanup_strv_free_ char **states = NULL; | |
2184 | _cleanup_strv_free_ char **patterns = NULL; | |
2185 | int r; | |
2186 | ||
2187 | r = sd_bus_message_read_strv(message, &states); | |
2188 | if (r < 0) | |
2189 | return r; | |
2190 | ||
2191 | r = sd_bus_message_read_strv(message, &patterns); | |
2192 | if (r < 0) | |
2193 | return r; | |
2194 | ||
2195 | return list_unit_files_by_patterns(message, userdata, error, states, patterns); | |
2196 | } | |
2197 | ||
19070062 | 2198 | static int method_get_unit_file_state(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 2199 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
2200 | const char *name; |
2201 | UnitFileState state; | |
718db961 | 2202 | int r; |
99504dd4 | 2203 | |
718db961 | 2204 | assert(message); |
8e2af478 | 2205 | |
283868e1 SW |
2206 | /* Anyone can call this method */ |
2207 | ||
8a188de9 | 2208 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
2209 | if (r < 0) |
2210 | return r; | |
8e2af478 | 2211 | |
718db961 LP |
2212 | r = sd_bus_message_read(message, "s", &name); |
2213 | if (r < 0) | |
ebcf1f97 | 2214 | return r; |
8e2af478 | 2215 | |
4870133b | 2216 | r = unit_file_get_state(m->runtime_scope, NULL, name, &state); |
0ec0deaa LP |
2217 | if (r < 0) |
2218 | return r; | |
8e2af478 | 2219 | |
df2d202e | 2220 | return sd_bus_reply_method_return(message, "s", unit_file_state_to_string(state)); |
718db961 | 2221 | } |
8e2af478 | 2222 | |
19070062 | 2223 | static int method_get_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 2224 | _cleanup_free_ char *default_target = NULL; |
99534007 | 2225 | Manager *m = ASSERT_PTR(userdata); |
718db961 | 2226 | int r; |
c2756a68 | 2227 | |
718db961 | 2228 | assert(message); |
c2756a68 | 2229 | |
283868e1 SW |
2230 | /* Anyone can call this method */ |
2231 | ||
8a188de9 | 2232 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
2233 | if (r < 0) |
2234 | return r; | |
c2756a68 | 2235 | |
4870133b | 2236 | r = unit_file_get_default(m->runtime_scope, NULL, &default_target); |
7c78a193 | 2237 | if (r == -ERFKILL) |
a5ddad27 | 2238 | return sd_bus_error_set(error, BUS_ERROR_UNIT_MASKED, "Default target unit file is masked."); |
718db961 | 2239 | if (r < 0) |
ebcf1f97 | 2240 | return r; |
c2756a68 | 2241 | |
df2d202e | 2242 | return sd_bus_reply_method_return(message, "s", default_target); |
718db961 | 2243 | } |
c2756a68 | 2244 | |
8f8f05a9 | 2245 | static int send_unit_files_changed(sd_bus *bus, void *userdata) { |
4afd3348 | 2246 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
2247 | int r; |
2248 | ||
2249 | assert(bus); | |
2250 | ||
cb31470f ZJS |
2251 | r = sd_bus_message_new_signal(bus, &message, |
2252 | "/org/freedesktop/systemd1", | |
2253 | "org.freedesktop.systemd1.Manager", | |
2254 | "UnitFilesChanged"); | |
718db961 LP |
2255 | if (r < 0) |
2256 | return r; | |
2257 | ||
8f8f05a9 | 2258 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
2259 | } |
2260 | ||
d69cba3b MY |
2261 | static void manager_unit_files_changed(Manager *m, const InstallChange *changes, size_t n_changes) { |
2262 | int r; | |
2263 | ||
2264 | assert(m); | |
2265 | assert(changes || n_changes == 0); | |
2266 | ||
2267 | if (!install_changes_have_modification(changes, n_changes)) | |
2268 | return; | |
2269 | ||
2270 | /* See comments for this variable in manager.h */ | |
2271 | m->unit_file_state_outdated = true; | |
2272 | ||
2273 | r = bus_foreach_bus(m, NULL, send_unit_files_changed, NULL); | |
2274 | if (r < 0) | |
2275 | log_debug_errno(r, "Failed to send UnitFilesChanged signal, ignoring: %m"); | |
2276 | } | |
2277 | ||
af3d8113 ZJS |
2278 | static int install_error( |
2279 | sd_bus_error *error, | |
2280 | int c, | |
cd44ec5a | 2281 | InstallChange *changes, |
da6053d0 LP |
2282 | size_t n_changes) { |
2283 | ||
d41f08bd MY |
2284 | int r; |
2285 | ||
2286 | /* Create an error reply, using the error information from changes[] if possible, and fall back to | |
2287 | * generating an error from error code c. The error message only describes the first error. */ | |
2288 | ||
2289 | assert(changes || n_changes == 0); | |
2290 | ||
f8888b9a | 2291 | CLEANUP_ARRAY(changes, n_changes, install_changes_free); |
8e20adca | 2292 | |
d41f08bd MY |
2293 | FOREACH_ARRAY(i, changes, n_changes) { |
2294 | _cleanup_free_ char *err_message = NULL; | |
2295 | const char *bus_error; | |
2296 | ||
2297 | if (i->type >= 0) | |
2298 | continue; | |
637d6e5b | 2299 | |
d41f08bd MY |
2300 | r = install_change_dump_error(i, &err_message, &bus_error); |
2301 | if (r == -ENOMEM) | |
2302 | return r; | |
2303 | if (r < 0) | |
2304 | return sd_bus_error_set_errnof(error, r, "File %s: %m", i->path); | |
c89d0c3b | 2305 | |
d41f08bd MY |
2306 | return sd_bus_error_set(error, bus_error, err_message); |
2307 | } | |
8e20adca | 2308 | |
f8888b9a | 2309 | return c < 0 ? c : -EINVAL; |
8e20adca LP |
2310 | } |
2311 | ||
cd44ec5a | 2312 | static int reply_install_changes_and_free( |
637d6e5b LP |
2313 | Manager *m, |
2314 | sd_bus_message *message, | |
2315 | int carries_install_info, | |
cd44ec5a | 2316 | InstallChange *changes, |
da6053d0 | 2317 | size_t n_changes, |
637d6e5b LP |
2318 | sd_bus_error *error) { |
2319 | ||
2320 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
2321 | bool bad = false, good = false; | |
637d6e5b LP |
2322 | int r; |
2323 | ||
8c2d0d3a LP |
2324 | CLEANUP_ARRAY(changes, n_changes, install_changes_free); |
2325 | ||
637d6e5b LP |
2326 | r = sd_bus_message_new_method_return(message, &reply); |
2327 | if (r < 0) | |
8c2d0d3a | 2328 | return r; |
637d6e5b LP |
2329 | |
2330 | if (carries_install_info >= 0) { | |
2331 | r = sd_bus_message_append(reply, "b", carries_install_info); | |
2332 | if (r < 0) | |
8c2d0d3a | 2333 | return r; |
637d6e5b LP |
2334 | } |
2335 | ||
2336 | r = sd_bus_message_open_container(reply, 'a', "(sss)"); | |
2337 | if (r < 0) | |
8c2d0d3a | 2338 | return r; |
637d6e5b | 2339 | |
d41f08bd MY |
2340 | FOREACH_ARRAY(i, changes, n_changes) { |
2341 | if (i->type < 0) { | |
637d6e5b LP |
2342 | bad = true; |
2343 | continue; | |
2344 | } | |
2345 | ||
2346 | r = sd_bus_message_append( | |
2347 | reply, "(sss)", | |
d41f08bd MY |
2348 | install_change_type_to_string(i->type), |
2349 | i->path, | |
2350 | i->source); | |
637d6e5b | 2351 | if (r < 0) |
8c2d0d3a | 2352 | return r; |
637d6e5b LP |
2353 | |
2354 | good = true; | |
2355 | } | |
2356 | ||
cb31470f ZJS |
2357 | /* If there was a failed change, and no successful change, then return the first failure as proper |
2358 | * method call error. */ | |
637d6e5b | 2359 | if (bad && !good) |
8c2d0d3a | 2360 | return install_error(error, 0, TAKE_PTR(changes), n_changes); |
637d6e5b LP |
2361 | |
2362 | r = sd_bus_message_close_container(reply); | |
2363 | if (r < 0) | |
8c2d0d3a | 2364 | return r; |
637d6e5b | 2365 | |
51cc3825 | 2366 | return sd_bus_message_send(reply); |
637d6e5b LP |
2367 | } |
2368 | ||
718db961 | 2369 | static int method_enable_unit_files_generic( |
718db961 | 2370 | sd_bus_message *message, |
d309c1c3 | 2371 | Manager *m, |
e9e77e44 | 2372 | int (*call)(RuntimeScope scope, UnitFileFlags flags, const char *root_dir, char * const *files, InstallChange **changes, size_t *n_changes), |
ebcf1f97 LP |
2373 | bool carries_install_info, |
2374 | sd_bus_error *error) { | |
718db961 LP |
2375 | |
2376 | _cleanup_strv_free_ char **l = NULL; | |
cd44ec5a | 2377 | InstallChange *changes = NULL; |
da6053d0 | 2378 | size_t n_changes = 0; |
b3796dd8 | 2379 | UnitFileFlags flags; |
83654007 | 2380 | int r; |
718db961 | 2381 | |
718db961 LP |
2382 | assert(message); |
2383 | assert(m); | |
cad45ba1 | 2384 | |
718db961 LP |
2385 | r = sd_bus_message_read_strv(message, &l); |
2386 | if (r < 0) | |
ebcf1f97 | 2387 | return r; |
90bb85e1 | 2388 | |
83654007 LB |
2389 | if (sd_bus_message_is_method_call(message, NULL, "EnableUnitFilesWithFlags")) { |
2390 | uint64_t raw_flags; | |
d309c1c3 | 2391 | |
83654007 LB |
2392 | r = sd_bus_message_read(message, "t", &raw_flags); |
2393 | if (r < 0) | |
2394 | return r; | |
2395 | if ((raw_flags & ~_UNIT_FILE_FLAGS_MASK_PUBLIC) != 0) | |
2396 | return -EINVAL; | |
2397 | flags = raw_flags; | |
2398 | } else { | |
2399 | int runtime, force; | |
2400 | ||
2401 | r = sd_bus_message_read(message, "bb", &runtime, &force); | |
2402 | if (r < 0) | |
2403 | return r; | |
2404 | flags = unit_file_bools_to_flags(runtime, force); | |
2405 | } | |
b3796dd8 | 2406 | |
1d22e906 LP |
2407 | r = bus_verify_manage_unit_files_async(m, message, error); |
2408 | if (r < 0) | |
2409 | return r; | |
2410 | if (r == 0) | |
2411 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2412 | ||
4870133b | 2413 | r = call(m->runtime_scope, flags, NULL, l, &changes, &n_changes); |
d69cba3b | 2414 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2415 | if (r < 0) |
2416 | return install_error(error, r, changes, n_changes); | |
718db961 | 2417 | |
cd44ec5a | 2418 | return reply_install_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes, error); |
718db961 | 2419 | } |
c87eba54 | 2420 | |
83654007 | 2421 | static int method_enable_unit_files_with_flags(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 2422 | return method_enable_unit_files_generic(message, userdata, unit_file_enable, /* carries_install_info = */ true, error); |
83654007 LB |
2423 | } |
2424 | ||
19070062 | 2425 | static int method_enable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 2426 | return method_enable_unit_files_generic(message, userdata, unit_file_enable, /* carries_install_info = */ true, error); |
718db961 | 2427 | } |
ea430986 | 2428 | |
19070062 | 2429 | static int method_reenable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 2430 | return method_enable_unit_files_generic(message, userdata, unit_file_reenable, /* carries_install_info = */ true, error); |
718db961 LP |
2431 | } |
2432 | ||
19070062 | 2433 | static int method_link_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 2434 | return method_enable_unit_files_generic(message, userdata, unit_file_link, /* carries_install_info = */ false, error); |
718db961 LP |
2435 | } |
2436 | ||
e9e77e44 | 2437 | 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 | 2438 | return unit_file_preset(scope, flags, root_dir, files, UNIT_FILE_PRESET_FULL, changes, n_changes); |
d309c1c3 LP |
2439 | } |
2440 | ||
19070062 | 2441 | static int method_preset_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 2442 | return method_enable_unit_files_generic(message, userdata, unit_file_preset_without_mode, /* carries_install_info = */ true, error); |
718db961 LP |
2443 | } |
2444 | ||
19070062 | 2445 | static int method_mask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2d8cc7a7 | 2446 | return method_enable_unit_files_generic(message, userdata, unit_file_mask, /* carries_install_info = */ false, error); |
718db961 | 2447 | } |
ea430986 | 2448 | |
19070062 | 2449 | static int method_preset_unit_files_with_mode(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
d309c1c3 LP |
2450 | |
2451 | _cleanup_strv_free_ char **l = NULL; | |
cd44ec5a | 2452 | InstallChange *changes = NULL; |
da6053d0 | 2453 | size_t n_changes = 0; |
99534007 | 2454 | Manager *m = ASSERT_PTR(userdata); |
8331b221 | 2455 | UnitFilePresetMode preset_mode; |
d309c1c3 | 2456 | int runtime, force, r; |
b3796dd8 | 2457 | UnitFileFlags flags; |
d309c1c3 LP |
2458 | const char *mode; |
2459 | ||
d309c1c3 | 2460 | assert(message); |
d309c1c3 LP |
2461 | |
2462 | r = sd_bus_message_read_strv(message, &l); | |
2463 | if (r < 0) | |
2464 | return r; | |
2465 | ||
2466 | r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force); | |
2467 | if (r < 0) | |
2468 | return r; | |
2469 | ||
b3796dd8 JS |
2470 | flags = unit_file_bools_to_flags(runtime, force); |
2471 | ||
d309c1c3 | 2472 | if (isempty(mode)) |
8331b221 | 2473 | preset_mode = UNIT_FILE_PRESET_FULL; |
d309c1c3 | 2474 | else { |
8331b221 ZJS |
2475 | preset_mode = unit_file_preset_mode_from_string(mode); |
2476 | if (preset_mode < 0) | |
d309c1c3 LP |
2477 | return -EINVAL; |
2478 | } | |
2479 | ||
1d22e906 LP |
2480 | r = bus_verify_manage_unit_files_async(m, message, error); |
2481 | if (r < 0) | |
2482 | return r; | |
2483 | if (r == 0) | |
2484 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2485 | ||
4870133b | 2486 | r = unit_file_preset(m->runtime_scope, flags, NULL, l, preset_mode, &changes, &n_changes); |
d69cba3b | 2487 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2488 | if (r < 0) |
2489 | return install_error(error, r, changes, n_changes); | |
d309c1c3 | 2490 | |
cd44ec5a | 2491 | return reply_install_changes_and_free(m, message, r, changes, n_changes, error); |
d309c1c3 LP |
2492 | } |
2493 | ||
718db961 | 2494 | static int method_disable_unit_files_generic( |
718db961 | 2495 | sd_bus_message *message, |
596fc263 | 2496 | Manager *m, |
e9e77e44 | 2497 | int (*call)(RuntimeScope scope, UnitFileFlags flags, const char *root_dir, char * const *files, InstallChange **changes, size_t *n_changes), |
bf1bea43 | 2498 | bool carries_install_info, |
ebcf1f97 | 2499 | sd_bus_error *error) { |
718db961 LP |
2500 | |
2501 | _cleanup_strv_free_ char **l = NULL; | |
cd44ec5a | 2502 | InstallChange *changes = NULL; |
83654007 | 2503 | UnitFileFlags flags; |
da6053d0 | 2504 | size_t n_changes = 0; |
83654007 | 2505 | int r; |
718db961 | 2506 | |
718db961 LP |
2507 | assert(message); |
2508 | assert(m); | |
2509 | ||
df823e23 | 2510 | r = sd_bus_message_read_strv(message, &l); |
ebcf1f97 LP |
2511 | if (r < 0) |
2512 | return r; | |
718db961 | 2513 | |
bf1bea43 MY |
2514 | if (sd_bus_message_is_method_call(message, NULL, "DisableUnitFilesWithFlags") || |
2515 | sd_bus_message_is_method_call(message, NULL, "DisableUnitFilesWithFlagsAndInstallInfo")) { | |
83654007 LB |
2516 | uint64_t raw_flags; |
2517 | ||
2518 | r = sd_bus_message_read(message, "t", &raw_flags); | |
2519 | if (r < 0) | |
2520 | return r; | |
2521 | if ((raw_flags & ~_UNIT_FILE_FLAGS_MASK_PUBLIC) != 0 || | |
2522 | FLAGS_SET(raw_flags, UNIT_FILE_FORCE)) | |
2523 | return -EINVAL; | |
2524 | flags = raw_flags; | |
2525 | } else { | |
2526 | int runtime; | |
2527 | ||
2528 | r = sd_bus_message_read(message, "b", &runtime); | |
2529 | if (r < 0) | |
2530 | return r; | |
2531 | flags = unit_file_bools_to_flags(runtime, false); | |
2532 | } | |
718db961 | 2533 | |
1d22e906 LP |
2534 | r = bus_verify_manage_unit_files_async(m, message, error); |
2535 | if (r < 0) | |
2536 | return r; | |
2537 | if (r == 0) | |
2538 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2539 | ||
4870133b | 2540 | r = call(m->runtime_scope, flags, NULL, l, &changes, &n_changes); |
d69cba3b | 2541 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2542 | if (r < 0) |
2543 | return install_error(error, r, changes, n_changes); | |
718db961 | 2544 | |
bf1bea43 | 2545 | return reply_install_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes, error); |
718db961 | 2546 | } |
ea430986 | 2547 | |
83654007 | 2548 | static int method_disable_unit_files_with_flags(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
bf1bea43 MY |
2549 | return method_disable_unit_files_generic(message, userdata, unit_file_disable, /* carries_install_info = */ false, error); |
2550 | } | |
2551 | ||
2552 | static int method_disable_unit_files_with_flags_and_install_info(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
2553 | return method_disable_unit_files_generic(message, userdata, unit_file_disable, /* carries_install_info = */ true, error); | |
83654007 LB |
2554 | } |
2555 | ||
19070062 | 2556 | static int method_disable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
bf1bea43 | 2557 | return method_disable_unit_files_generic(message, userdata, unit_file_disable, /* carries_install_info = */ false, error); |
ea430986 LP |
2558 | } |
2559 | ||
19070062 | 2560 | static int method_unmask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
bf1bea43 | 2561 | return method_disable_unit_files_generic(message, userdata, unit_file_unmask, /* carries_install_info = */ false, error); |
718db961 LP |
2562 | } |
2563 | ||
344ca755 LP |
2564 | static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2565 | _cleanup_strv_free_ char **l = NULL; | |
cd44ec5a | 2566 | InstallChange *changes = NULL; |
da6053d0 | 2567 | size_t n_changes = 0; |
99534007 | 2568 | Manager *m = ASSERT_PTR(userdata); |
344ca755 LP |
2569 | int r; |
2570 | ||
2571 | assert(message); | |
344ca755 LP |
2572 | |
2573 | r = sd_bus_message_read_strv(message, &l); | |
2574 | if (r < 0) | |
2575 | return r; | |
2576 | ||
2577 | r = bus_verify_manage_unit_files_async(m, message, error); | |
2578 | if (r < 0) | |
2579 | return r; | |
2580 | if (r == 0) | |
2581 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2582 | ||
4870133b | 2583 | r = unit_file_revert(m->runtime_scope, NULL, l, &changes, &n_changes); |
d69cba3b | 2584 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2585 | if (r < 0) |
2586 | return install_error(error, r, changes, n_changes); | |
344ca755 | 2587 | |
cd44ec5a | 2588 | return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); |
344ca755 LP |
2589 | } |
2590 | ||
19070062 | 2591 | static int method_set_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
cd44ec5a | 2592 | InstallChange *changes = NULL; |
da6053d0 | 2593 | size_t n_changes = 0; |
99534007 | 2594 | Manager *m = ASSERT_PTR(userdata); |
718db961 LP |
2595 | const char *name; |
2596 | int force, r; | |
2597 | ||
718db961 | 2598 | assert(message); |
718db961 | 2599 | |
1d22e906 | 2600 | r = mac_selinux_access_check(message, "enable", error); |
283868e1 SW |
2601 | if (r < 0) |
2602 | return r; | |
283868e1 | 2603 | |
1d22e906 | 2604 | r = sd_bus_message_read(message, "sb", &name, &force); |
ebcf1f97 LP |
2605 | if (r < 0) |
2606 | return r; | |
718db961 | 2607 | |
1d22e906 | 2608 | r = bus_verify_manage_unit_files_async(m, message, error); |
718db961 | 2609 | if (r < 0) |
ebcf1f97 | 2610 | return r; |
1d22e906 LP |
2611 | if (r == 0) |
2612 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
718db961 | 2613 | |
4870133b | 2614 | r = unit_file_set_default(m->runtime_scope, force ? UNIT_FILE_FORCE : 0, NULL, name, &changes, &n_changes); |
d69cba3b | 2615 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2616 | if (r < 0) |
2617 | return install_error(error, r, changes, n_changes); | |
718db961 | 2618 | |
cd44ec5a | 2619 | return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); |
718db961 LP |
2620 | } |
2621 | ||
19070062 | 2622 | static int method_preset_all_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
cd44ec5a | 2623 | InstallChange *changes = NULL; |
da6053d0 | 2624 | size_t n_changes = 0; |
99534007 | 2625 | Manager *m = ASSERT_PTR(userdata); |
8331b221 | 2626 | UnitFilePresetMode preset_mode; |
d309c1c3 | 2627 | const char *mode; |
b3796dd8 | 2628 | UnitFileFlags flags; |
d309c1c3 LP |
2629 | int force, runtime, r; |
2630 | ||
d309c1c3 | 2631 | assert(message); |
d309c1c3 | 2632 | |
8a188de9 | 2633 | r = mac_selinux_access_check(message, "enable", error); |
d309c1c3 LP |
2634 | if (r < 0) |
2635 | return r; | |
2636 | ||
2637 | r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force); | |
2638 | if (r < 0) | |
2639 | return r; | |
2640 | ||
b3796dd8 JS |
2641 | flags = unit_file_bools_to_flags(runtime, force); |
2642 | ||
d309c1c3 | 2643 | if (isempty(mode)) |
8331b221 | 2644 | preset_mode = UNIT_FILE_PRESET_FULL; |
d309c1c3 | 2645 | else { |
8331b221 ZJS |
2646 | preset_mode = unit_file_preset_mode_from_string(mode); |
2647 | if (preset_mode < 0) | |
d309c1c3 LP |
2648 | return -EINVAL; |
2649 | } | |
2650 | ||
1d22e906 LP |
2651 | r = bus_verify_manage_unit_files_async(m, message, error); |
2652 | if (r < 0) | |
2653 | return r; | |
2654 | if (r == 0) | |
2655 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2656 | ||
4870133b | 2657 | r = unit_file_preset_all(m->runtime_scope, flags, NULL, preset_mode, &changes, &n_changes); |
d69cba3b | 2658 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2659 | if (r < 0) |
2660 | return install_error(error, r, changes, n_changes); | |
d309c1c3 | 2661 | |
cd44ec5a | 2662 | return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); |
d309c1c3 LP |
2663 | } |
2664 | ||
19070062 | 2665 | static int method_add_dependency_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
e94937df | 2666 | _cleanup_strv_free_ char **l = NULL; |
99534007 | 2667 | Manager *m = ASSERT_PTR(userdata); |
cd44ec5a | 2668 | InstallChange *changes = NULL; |
da6053d0 | 2669 | size_t n_changes = 0; |
e94937df | 2670 | int runtime, force, r; |
596fc263 | 2671 | char *target, *type; |
e94937df | 2672 | UnitDependency dep; |
b3796dd8 | 2673 | UnitFileFlags flags; |
e94937df | 2674 | |
e94937df | 2675 | assert(message); |
e94937df LN |
2676 | |
2677 | r = bus_verify_manage_unit_files_async(m, message, error); | |
2678 | if (r < 0) | |
2679 | return r; | |
2680 | if (r == 0) | |
2681 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2682 | ||
2683 | r = sd_bus_message_read_strv(message, &l); | |
2684 | if (r < 0) | |
2685 | return r; | |
2686 | ||
2687 | r = sd_bus_message_read(message, "ssbb", &target, &type, &runtime, &force); | |
2688 | if (r < 0) | |
2689 | return r; | |
2690 | ||
b3796dd8 JS |
2691 | flags = unit_file_bools_to_flags(runtime, force); |
2692 | ||
e94937df | 2693 | dep = unit_dependency_from_string(type); |
d87dc74e | 2694 | if (dep < 0 || !IN_SET(dep, UNIT_WANTS, UNIT_REQUIRES)) |
e94937df LN |
2695 | return -EINVAL; |
2696 | ||
4870133b | 2697 | r = unit_file_add_dependency(m->runtime_scope, flags, NULL, l, target, dep, &changes, &n_changes); |
d69cba3b | 2698 | manager_unit_files_changed(m, changes, n_changes); |
af3d8113 ZJS |
2699 | if (r < 0) |
2700 | return install_error(error, r, changes, n_changes); | |
e94937df | 2701 | |
cd44ec5a | 2702 | return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); |
e94937df LN |
2703 | } |
2704 | ||
3b3557c4 JS |
2705 | static int method_get_unit_file_links(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2706 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
47c57b48 | 2707 | Manager *m = ASSERT_PTR(userdata); |
cd44ec5a | 2708 | InstallChange *changes = NULL; |
da6053d0 | 2709 | size_t n_changes = 0, i; |
3b3557c4 | 2710 | const char *name; |
3b3557c4 JS |
2711 | int runtime, r; |
2712 | ||
2a711edd DT |
2713 | CLEANUP_ARRAY(changes, n_changes, install_changes_free); |
2714 | ||
3b3557c4 JS |
2715 | r = sd_bus_message_read(message, "sb", &name, &runtime); |
2716 | if (r < 0) | |
2717 | return r; | |
2718 | ||
2719 | r = sd_bus_message_new_method_return(message, &reply); | |
2720 | if (r < 0) | |
2721 | return r; | |
2722 | ||
2723 | r = sd_bus_message_open_container(reply, SD_BUS_TYPE_ARRAY, "s"); | |
2724 | if (r < 0) | |
2725 | return r; | |
2726 | ||
4870133b | 2727 | r = unit_file_disable(m->runtime_scope, |
47c57b48 YW |
2728 | UNIT_FILE_DRY_RUN | (runtime ? UNIT_FILE_RUNTIME : 0), |
2729 | NULL, STRV_MAKE(name), &changes, &n_changes); | |
2a711edd DT |
2730 | if (r < 0) |
2731 | return log_error_errno(r, "Failed to get file links for %s: %m", name); | |
3b3557c4 JS |
2732 | |
2733 | for (i = 0; i < n_changes; i++) | |
f8662fee | 2734 | if (changes[i].type == INSTALL_CHANGE_UNLINK) { |
3b3557c4 JS |
2735 | r = sd_bus_message_append(reply, "s", changes[i].path); |
2736 | if (r < 0) | |
2a711edd | 2737 | return r; |
3b3557c4 JS |
2738 | } |
2739 | ||
2740 | r = sd_bus_message_close_container(reply); | |
2741 | if (r < 0) | |
2a711edd | 2742 | return r; |
a12ba535 | 2743 | |
51cc3825 | 2744 | return sd_bus_message_send(reply); |
3b3557c4 JS |
2745 | } |
2746 | ||
15ea79f8 | 2747 | static int method_get_job_waiting(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 2748 | Manager *m = ASSERT_PTR(userdata); |
15ea79f8 LP |
2749 | uint32_t id; |
2750 | Job *j; | |
2751 | int r; | |
2752 | ||
2753 | assert(message); | |
15ea79f8 LP |
2754 | |
2755 | r = sd_bus_message_read(message, "u", &id); | |
2756 | if (r < 0) | |
2757 | return r; | |
2758 | ||
2759 | j = manager_get_job(m, id); | |
2760 | if (!j) | |
2761 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); | |
2762 | ||
2763 | return bus_job_method_get_waiting_jobs(message, j, error); | |
2764 | } | |
2765 | ||
c20076a8 | 2766 | static int method_abandon_scope(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 2767 | Manager *m = ASSERT_PTR(userdata); |
c20076a8 LP |
2768 | const char *name; |
2769 | Unit *u; | |
2770 | int r; | |
2771 | ||
2772 | assert(message); | |
c20076a8 LP |
2773 | |
2774 | r = sd_bus_message_read(message, "s", &name); | |
2775 | if (r < 0) | |
2776 | return r; | |
2777 | ||
2778 | r = bus_get_unit_by_name(m, message, name, &u, error); | |
2779 | if (r < 0) | |
2780 | return r; | |
2781 | ||
2782 | if (u->type != UNIT_SCOPE) | |
cb31470f ZJS |
2783 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
2784 | "Unit '%s' is not a scope unit, refusing.", name); | |
c20076a8 LP |
2785 | |
2786 | return bus_scope_method_abandon(message, u, error); | |
2787 | } | |
2788 | ||
0bb007f7 | 2789 | static int method_set_show_status(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
99534007 | 2790 | Manager *m = ASSERT_PTR(userdata); |
0bb007f7 FB |
2791 | ShowStatus mode = _SHOW_STATUS_INVALID; |
2792 | const char *t; | |
2793 | int r; | |
2794 | ||
0bb007f7 FB |
2795 | assert(message); |
2796 | ||
4db62561 ZJS |
2797 | r = mac_selinux_access_check(message, "reload", error); |
2798 | if (r < 0) | |
2799 | return r; | |
2800 | ||
2801 | r = bus_verify_set_environment_async(m, message, error); | |
2802 | if (r < 0) | |
2803 | return r; | |
2804 | if (r == 0) | |
2805 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2806 | ||
0bb007f7 FB |
2807 | r = sd_bus_message_read(message, "s", &t); |
2808 | if (r < 0) | |
2809 | return r; | |
2810 | ||
2811 | if (!isempty(t)) { | |
2812 | mode = show_status_from_string(t); | |
2813 | if (mode < 0) | |
cb31470f ZJS |
2814 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
2815 | "Invalid show status '%s'", t); | |
0bb007f7 FB |
2816 | } |
2817 | ||
43bba15a | 2818 | manager_override_show_status(m, mode, "bus"); |
0bb007f7 FB |
2819 | |
2820 | return sd_bus_reply_method_return(message, NULL); | |
2821 | } | |
2822 | ||
2ea24611 LP |
2823 | static int method_dump_unit_descriptor_store(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2824 | return method_generic_unit_operation(message, userdata, error, bus_service_method_dump_file_descriptor_store, 0); | |
2825 | } | |
2826 | ||
84c01612 | 2827 | static int method_start_aux_scope(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
8c35e8a9 | 2828 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, "StartAuxiliaryScope() method has been removed."); |
84c01612 MS |
2829 | } |
2830 | ||
718db961 LP |
2831 | const sd_bus_vtable bus_manager_vtable[] = { |
2832 | SD_BUS_VTABLE_START(0), | |
2833 | ||
556089dc LP |
2834 | SD_BUS_PROPERTY("Version", "s", property_get_version, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
2835 | SD_BUS_PROPERTY("Features", "s", property_get_features, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
2836 | SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
1257274a | 2837 | SD_BUS_PROPERTY("ConfidentialVirtualization", "s", property_get_confidential_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
7452394e | 2838 | SD_BUS_PROPERTY("Architecture", "s", property_get_architecture, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 2839 | SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
9f9f0342 LP |
2840 | BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FIRMWARE]), SD_BUS_VTABLE_PROPERTY_CONST), |
2841 | BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_LOADER]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2842 | BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_KERNEL]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2843 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2844 | BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_USERSPACE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2845 | BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
b3f54861 | 2846 | BUS_PROPERTY_DUAL_TIMESTAMP("ShutdownStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SHUTDOWN_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
9f9f0342 LP |
2847 | BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
2848 | BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2849 | BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2850 | BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2851 | BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2852 | BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
49fbe940 | 2853 | BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD]), SD_BUS_VTABLE_PROPERTY_CONST), |
665a9774 YW |
2854 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDSecurityStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_SECURITY_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
2855 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDSecurityFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_SECURITY_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2856 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_GENERATORS_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2857 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_GENERATORS_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2858 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2859 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
25141692 LP |
2860 | SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level, property_set_log_level, 0, 0), |
2861 | SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target, property_set_log_target, 0, 0), | |
3ff52e8f YW |
2862 | SD_BUS_PROPERTY("NNames", "u", property_get_hashmap_size, offsetof(Manager, units), 0), |
2863 | SD_BUS_PROPERTY("NFailedUnits", "u", property_get_set_size, offsetof(Manager, failed_units), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
2864 | SD_BUS_PROPERTY("NJobs", "u", property_get_hashmap_size, offsetof(Manager, jobs), 0), | |
718db961 LP |
2865 | SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_installed_jobs), 0), |
2866 | SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_failed_jobs), 0), | |
2867 | SD_BUS_PROPERTY("Progress", "d", property_get_progress, 0, 0), | |
1ad6e8b3 | 2868 | SD_BUS_PROPERTY("Environment", "as", property_get_environment, 0, 0), |
556089dc | 2869 | SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool, offsetof(Manager, confirm_spawn), SD_BUS_VTABLE_PROPERTY_CONST), |
52d2566a | 2870 | SD_BUS_PROPERTY("ShowStatus", "b", property_get_show_status, 0, 0), |
a3c4eb07 | 2871 | SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.search_path), SD_BUS_VTABLE_PROPERTY_CONST), |
c9e120e0 LP |
2872 | SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output, offsetof(Manager, defaults.std_output), SD_BUS_VTABLE_PROPERTY_CONST), |
2873 | SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output, offsetof(Manager, defaults.std_error), SD_BUS_VTABLE_PROPERTY_CONST), | |
3e911a0d YW |
2874 | SD_BUS_PROPERTY("WatchdogDevice", "s", property_get_watchdog_device, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
2875 | SD_BUS_PROPERTY("WatchdogLastPingTimestamp", "t", property_get_watchdog_last_ping_realtime, 0, 0), | |
2876 | SD_BUS_PROPERTY("WatchdogLastPingTimestampMonotonic", "t", property_get_watchdog_last_ping_monotonic, 0, 0), | |
986935cf | 2877 | SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", property_get_runtime_watchdog, property_set_runtime_watchdog, 0, 0), |
5717062e | 2878 | SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogPreUSec", "t", property_get_pretimeout_watchdog, property_set_pretimeout_watchdog, 0, 0), |
aff3a9e1 | 2879 | SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogPreGovernor", "s", property_get_pretimeout_watchdog_governor, property_set_pretimeout_watchdog_governor, 0, 0), |
986935cf | 2880 | SD_BUS_WRITABLE_PROPERTY("RebootWatchdogUSec", "t", property_get_reboot_watchdog, property_set_reboot_watchdog, 0, 0), |
65224c1d | 2881 | /* The following item is an obsolete alias */ |
986935cf FB |
2882 | SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", property_get_reboot_watchdog, property_set_reboot_watchdog, 0, SD_BUS_VTABLE_HIDDEN), |
2883 | SD_BUS_WRITABLE_PROPERTY("KExecWatchdogUSec", "t", property_get_kexec_watchdog, property_set_kexec_watchdog, 0, 0), | |
2a12e32e | 2884 | SD_BUS_WRITABLE_PROPERTY("ServiceWatchdogs", "b", bus_property_get_bool, bus_property_set_bool, offsetof(Manager, service_watchdogs), 0), |
b272b74d | 2885 | SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Manager, cgroup_root), 0), |
f755e3b7 | 2886 | SD_BUS_PROPERTY("SystemState", "s", property_get_system_state, 0, 0), |
0b0cb6f3 | 2887 | SD_BUS_PROPERTY("ExitCode", "y", NULL, offsetof(Manager, return_value), 0), |
c9e120e0 LP |
2888 | SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.timer_accuracy_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
2889 | SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.timeout_start_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
2890 | SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
dc653bf4 | 2891 | SD_BUS_PROPERTY("DefaultTimeoutAbortUSec", "t", property_get_default_timeout_abort_usec, 0, 0), |
c9e120e0 LP |
2892 | SD_BUS_PROPERTY("DefaultDeviceTimeoutUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.device_timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
2893 | SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.restart_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
14702b9c | 2894 | SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST), |
c075f5fc | 2895 | /* The following two items are obsolete alias */ |
14702b9c DDM |
2896 | SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
2897 | SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
2898 | SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned, offsetof(Manager, defaults.start_limit.burst), SD_BUS_VTABLE_PROPERTY_CONST), | |
c9e120e0 LP |
2899 | SD_BUS_PROPERTY("DefaultIOAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.io_accounting), SD_BUS_VTABLE_PROPERTY_CONST), |
2900 | SD_BUS_PROPERTY("DefaultIPAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.ip_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2901 | SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2902 | SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.tasks_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2903 | SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2904 | SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2905 | SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2906 | SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2907 | SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2908 | SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2909 | SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2910 | SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2911 | SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2912 | SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2913 | SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2914 | SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2915 | SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2916 | SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2917 | SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2918 | SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2919 | SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2920 | SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2921 | SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2922 | SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2923 | SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2924 | SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2925 | SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2926 | SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2927 | SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2928 | SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2929 | SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2930 | SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2931 | SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2932 | SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2933 | SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2934 | SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2935 | SD_BUS_PROPERTY("DefaultTasksMax", "t", bus_property_get_tasks_max, offsetof(Manager, defaults.tasks_max), 0), | |
2936 | SD_BUS_PROPERTY("DefaultMemoryPressureThresholdUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.memory_pressure_threshold_usec), 0), | |
2937 | SD_BUS_PROPERTY("DefaultMemoryPressureWatch", "s", bus_property_get_cgroup_pressure_watch, offsetof(Manager, defaults.memory_pressure_watch), 0), | |
eed67a30 | 2938 | SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
c9e120e0 | 2939 | SD_BUS_PROPERTY("DefaultOOMPolicy", "s", bus_property_get_oom_policy, offsetof(Manager, defaults.oom_policy), SD_BUS_VTABLE_PROPERTY_CONST), |
d4a402e4 | 2940 | SD_BUS_PROPERTY("DefaultOOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
97998d1c | 2941 | SD_BUS_PROPERTY("DefaultRestrictSUIDSGID", "b", bus_property_get_bool, offsetof(Manager, defaults.restrict_suid_sgid), SD_BUS_VTABLE_PROPERTY_CONST), |
c44a285c | 2942 | SD_BUS_PROPERTY("CtrlAltDelBurstAction", "s", bus_property_get_emergency_action, offsetof(Manager, cad_burst_action), SD_BUS_VTABLE_PROPERTY_CONST), |
66f35161 | 2943 | SD_BUS_PROPERTY("SoftRebootsCount", "u", bus_property_get_unsigned, offsetof(Manager, soft_reboots_count), SD_BUS_VTABLE_PROPERTY_CONST), |
29da53dd | 2944 | |
db6986e0 YW |
2945 | /* deprecated cgroup v1 property */ |
2946 | 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 |
2947 | /* see comment in bus_cgroup_vtable */ |
2948 | 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 | 2949 | |
a008b6d7 | 2950 | SD_BUS_METHOD_WITH_ARGS("GetUnit", |
2951 | SD_BUS_ARGS("s", name), | |
2952 | SD_BUS_RESULT("o", unit), | |
2953 | method_get_unit, | |
2954 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2955 | SD_BUS_METHOD_WITH_ARGS("GetUnitByPID", | |
2956 | SD_BUS_ARGS("u", pid), | |
2957 | SD_BUS_RESULT("o", unit), | |
2958 | method_get_unit_by_pid, | |
2959 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2960 | SD_BUS_METHOD_WITH_ARGS("GetUnitByInvocationID", | |
2961 | SD_BUS_ARGS("ay", invocation_id), | |
2962 | SD_BUS_RESULT("o", unit), | |
2963 | method_get_unit_by_invocation_id, | |
2964 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2965 | SD_BUS_METHOD_WITH_ARGS("GetUnitByControlGroup", | |
2966 | SD_BUS_ARGS("s", cgroup), | |
2967 | SD_BUS_RESULT("o", unit), | |
2968 | method_get_unit_by_control_group, | |
2969 | SD_BUS_VTABLE_UNPRIVILEGED), | |
e0e7bc82 LB |
2970 | SD_BUS_METHOD_WITH_ARGS("GetUnitByPIDFD", |
2971 | SD_BUS_ARGS("h", pidfd), | |
2972 | SD_BUS_RESULT("o", unit, "s", unit_id, "ay", invocation_id), | |
2973 | method_get_unit_by_pidfd, | |
2974 | SD_BUS_VTABLE_UNPRIVILEGED), | |
a008b6d7 | 2975 | SD_BUS_METHOD_WITH_ARGS("LoadUnit", |
2976 | SD_BUS_ARGS("s", name), | |
2977 | SD_BUS_RESULT("o", unit), | |
2978 | method_load_unit, | |
2979 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2980 | SD_BUS_METHOD_WITH_ARGS("StartUnit", | |
2981 | SD_BUS_ARGS("s", name, "s", mode), | |
2982 | SD_BUS_RESULT("o", job), | |
2983 | method_start_unit, | |
2984 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2985 | SD_BUS_METHOD_WITH_ARGS("StartUnitWithFlags", | |
2986 | SD_BUS_ARGS("s", name, "s", mode, "t", flags), | |
2987 | SD_BUS_RESULT("o", job), | |
2988 | method_start_unit, | |
2989 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2990 | SD_BUS_METHOD_WITH_ARGS("StartUnitReplace", | |
2991 | SD_BUS_ARGS("s", old_unit, "s", new_unit, "s", mode), | |
2992 | SD_BUS_RESULT("o", job), | |
2993 | method_start_unit_replace, | |
2994 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2995 | SD_BUS_METHOD_WITH_ARGS("StopUnit", | |
2996 | SD_BUS_ARGS("s", name, "s", mode), | |
2997 | SD_BUS_RESULT("o", job), | |
2998 | method_stop_unit, | |
2999 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3000 | SD_BUS_METHOD_WITH_ARGS("ReloadUnit", | |
3001 | SD_BUS_ARGS("s", name, "s", mode), | |
3002 | SD_BUS_RESULT("o", job), | |
3003 | method_reload_unit, | |
3004 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3005 | SD_BUS_METHOD_WITH_ARGS("RestartUnit", | |
3006 | SD_BUS_ARGS("s", name, "s", mode), | |
3007 | SD_BUS_RESULT("o", job), | |
3008 | method_restart_unit, | |
3009 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3010 | SD_BUS_METHOD_WITH_ARGS("TryRestartUnit", | |
3011 | SD_BUS_ARGS("s", name, "s", mode), | |
3012 | SD_BUS_RESULT("o", job), | |
3013 | method_try_restart_unit, | |
3014 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3015 | SD_BUS_METHOD_WITH_ARGS("ReloadOrRestartUnit", | |
3016 | SD_BUS_ARGS("s", name, "s", mode), | |
3017 | SD_BUS_RESULT("o", job), | |
3018 | method_reload_or_restart_unit, | |
3019 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3020 | SD_BUS_METHOD_WITH_ARGS("ReloadOrTryRestartUnit", | |
3021 | SD_BUS_ARGS("s", name, "s", mode), | |
3022 | SD_BUS_RESULT("o", job), | |
3023 | method_reload_or_try_restart_unit, | |
3024 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3025 | SD_BUS_METHOD_WITH_ARGS("EnqueueUnitJob", | |
3026 | SD_BUS_ARGS("s", name, "s", job_type, "s", job_mode), | |
3027 | SD_BUS_RESULT("u", job_id, "o", job_path, "s", unit_id, "o", unit_path, "s", job_type, "a(uosos)", affected_jobs), | |
3028 | method_enqueue_unit_job, | |
3029 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3030 | SD_BUS_METHOD_WITH_ARGS("KillUnit", | |
3031 | SD_BUS_ARGS("s", name, "s", whom, "i", signal), | |
3032 | SD_BUS_NO_RESULT, | |
a721cd00 LP |
3033 | method_kill_unit, |
3034 | SD_BUS_VTABLE_UNPRIVILEGED), | |
0f23564a LP |
3035 | SD_BUS_METHOD_WITH_ARGS("KillUnitSubgroup", |
3036 | SD_BUS_ARGS("s", name, "s", whom, "s", subgroup, "i", signal), | |
3037 | SD_BUS_NO_RESULT, | |
3038 | method_kill_unit_subgroup, | |
3039 | SD_BUS_VTABLE_UNPRIVILEGED), | |
a721cd00 LP |
3040 | SD_BUS_METHOD_WITH_ARGS("QueueSignalUnit", |
3041 | SD_BUS_ARGS("s", name, "s", whom, "i", signal, "i", value), | |
3042 | SD_BUS_NO_RESULT, | |
a008b6d7 | 3043 | method_kill_unit, |
3044 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3045 | SD_BUS_METHOD_WITH_ARGS("CleanUnit", | |
3046 | SD_BUS_ARGS("s", name, "as", mask), | |
3047 | SD_BUS_NO_RESULT, | |
3048 | method_clean_unit, | |
3049 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3050 | SD_BUS_METHOD_WITH_ARGS("FreezeUnit", | |
3051 | SD_BUS_ARGS("s", name), | |
3052 | SD_BUS_NO_RESULT, | |
3053 | method_freeze_unit, | |
3054 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3055 | SD_BUS_METHOD_WITH_ARGS("ThawUnit", | |
3056 | SD_BUS_ARGS("s", name), | |
3057 | SD_BUS_NO_RESULT, | |
3058 | method_thaw_unit, | |
3059 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3060 | SD_BUS_METHOD_WITH_ARGS("ResetFailedUnit", | |
3061 | SD_BUS_ARGS("s", name), | |
3062 | SD_BUS_NO_RESULT, | |
3063 | method_reset_failed_unit, | |
3064 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3065 | SD_BUS_METHOD_WITH_ARGS("SetUnitProperties", | |
3066 | SD_BUS_ARGS("s", name, "b", runtime, "a(sv)", properties), | |
3067 | SD_BUS_NO_RESULT, | |
3068 | method_set_unit_properties, | |
3069 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3070 | SD_BUS_METHOD_WITH_ARGS("BindMountUnit", | |
3071 | SD_BUS_ARGS("s", name, "s", source, "s", destination, "b", read_only, "b", mkdir), | |
3072 | SD_BUS_NO_RESULT, | |
3073 | method_bind_mount_unit, | |
3074 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3075 | SD_BUS_METHOD_WITH_ARGS("MountImageUnit", | |
3076 | SD_BUS_ARGS("s", name, "s", source, "s", destination, "b", read_only, "b", mkdir, "a(ss)", options), | |
3077 | SD_BUS_NO_RESULT, | |
3078 | method_mount_image_unit, | |
3079 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3080 | SD_BUS_METHOD_WITH_ARGS("RefUnit", | |
3081 | SD_BUS_ARGS("s", name), | |
3082 | SD_BUS_NO_RESULT, | |
3083 | method_ref_unit, | |
3084 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3085 | SD_BUS_METHOD_WITH_ARGS("UnrefUnit", | |
3086 | SD_BUS_ARGS("s", name), | |
3087 | SD_BUS_NO_RESULT, | |
3088 | method_unref_unit, | |
3089 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3090 | SD_BUS_METHOD_WITH_ARGS("StartTransientUnit", | |
3091 | SD_BUS_ARGS("s", name, "s", mode, "a(sv)", properties, "a(sa(sv))", aux), | |
3092 | SD_BUS_RESULT("o", job), | |
3093 | method_start_transient_unit, | |
3094 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3095 | SD_BUS_METHOD_WITH_ARGS("GetUnitProcesses", | |
3096 | SD_BUS_ARGS("s", name), | |
3097 | SD_BUS_RESULT("a(sus)", processes), | |
3098 | method_get_unit_processes, | |
3099 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3100 | SD_BUS_METHOD_WITH_ARGS("AttachProcessesToUnit", | |
3101 | SD_BUS_ARGS("s", unit_name, "s", subcgroup, "au", pids), | |
3102 | SD_BUS_NO_RESULT, | |
3103 | method_attach_processes_to_unit, | |
3104 | SD_BUS_VTABLE_UNPRIVILEGED), | |
94634b4b LP |
3105 | SD_BUS_METHOD_WITH_ARGS("RemoveSubgroupFromUnit", |
3106 | SD_BUS_ARGS("s", unit_name, "s", subcgroup, "t", flags), | |
3107 | SD_BUS_NO_RESULT, | |
3108 | method_remove_subgroup_from_unit, | |
3109 | SD_BUS_VTABLE_UNPRIVILEGED), | |
a008b6d7 | 3110 | SD_BUS_METHOD_WITH_ARGS("AbandonScope", |
3111 | SD_BUS_ARGS("s", name), | |
3112 | SD_BUS_NO_RESULT, | |
3113 | method_abandon_scope, | |
3114 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3115 | SD_BUS_METHOD_WITH_ARGS("GetJob", | |
3116 | SD_BUS_ARGS("u", id), | |
3117 | SD_BUS_RESULT("o", job), | |
3118 | method_get_job, | |
3119 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3120 | SD_BUS_METHOD_WITH_ARGS("GetJobAfter", | |
3121 | SD_BUS_ARGS("u", id), | |
3122 | SD_BUS_RESULT("a(usssoo)", jobs), | |
3123 | method_get_job_waiting, | |
3124 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3125 | SD_BUS_METHOD_WITH_ARGS("GetJobBefore", | |
3126 | SD_BUS_ARGS("u", id), | |
3127 | SD_BUS_RESULT("a(usssoo)", jobs), | |
3128 | method_get_job_waiting, | |
3129 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3130 | SD_BUS_METHOD_WITH_ARGS("CancelJob", | |
3131 | SD_BUS_ARGS("u", id), | |
3132 | SD_BUS_NO_RESULT, | |
3133 | method_cancel_job, | |
3134 | SD_BUS_VTABLE_UNPRIVILEGED), | |
dad97f04 ZJS |
3135 | SD_BUS_METHOD("ClearJobs", |
3136 | NULL, | |
3137 | NULL, | |
3138 | method_clear_jobs, | |
3139 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3140 | SD_BUS_METHOD("ResetFailed", | |
3141 | NULL, | |
3142 | NULL, | |
3143 | method_reset_failed, | |
3144 | SD_BUS_VTABLE_UNPRIVILEGED), | |
a008b6d7 | 3145 | SD_BUS_METHOD_WITH_ARGS("SetShowStatus", |
3146 | SD_BUS_ARGS("s", mode), | |
3147 | SD_BUS_NO_RESULT, | |
3148 | method_set_show_status, | |
3149 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3150 | SD_BUS_METHOD_WITH_ARGS("ListUnits", | |
3151 | SD_BUS_NO_ARGS, | |
3152 | SD_BUS_RESULT("a(ssssssouso)", units), | |
3153 | method_list_units, | |
3154 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3155 | SD_BUS_METHOD_WITH_ARGS("ListUnitsFiltered", | |
3156 | SD_BUS_ARGS("as", states), | |
3157 | SD_BUS_RESULT("a(ssssssouso)", units), | |
3158 | method_list_units_filtered, | |
3159 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3160 | SD_BUS_METHOD_WITH_ARGS("ListUnitsByPatterns", | |
3161 | SD_BUS_ARGS("as", states, "as", patterns), | |
3162 | SD_BUS_RESULT("a(ssssssouso)", units), | |
3163 | method_list_units_by_patterns, | |
3164 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3165 | SD_BUS_METHOD_WITH_ARGS("ListUnitsByNames", | |
3166 | SD_BUS_ARGS("as", names), | |
3167 | SD_BUS_RESULT("a(ssssssouso)", units), | |
3168 | method_list_units_by_names, | |
3169 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3170 | SD_BUS_METHOD_WITH_ARGS("ListJobs", | |
3171 | SD_BUS_NO_ARGS, | |
3172 | SD_BUS_RESULT("a(usssoo)", jobs), | |
3173 | method_list_jobs, | |
3174 | SD_BUS_VTABLE_UNPRIVILEGED), | |
dad97f04 ZJS |
3175 | SD_BUS_METHOD("Subscribe", |
3176 | NULL, | |
3177 | NULL, | |
3178 | method_subscribe, | |
3179 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3180 | SD_BUS_METHOD("Unsubscribe", | |
3181 | NULL, | |
3182 | NULL, | |
3183 | method_unsubscribe, | |
3184 | SD_BUS_VTABLE_UNPRIVILEGED), | |
a008b6d7 | 3185 | SD_BUS_METHOD_WITH_ARGS("Dump", |
3186 | SD_BUS_NO_ARGS, | |
3187 | SD_BUS_RESULT("s", output), | |
3188 | method_dump, | |
3189 | SD_BUS_VTABLE_UNPRIVILEGED), | |
293b9aa3 | 3190 | SD_BUS_METHOD_WITH_ARGS("DumpUnitsMatchingPatterns", |
d1d8786c FB |
3191 | SD_BUS_ARGS("as", patterns), |
3192 | SD_BUS_RESULT("s", output), | |
293b9aa3 | 3193 | method_dump_units_matching_patterns, |
d1d8786c | 3194 | SD_BUS_VTABLE_UNPRIVILEGED), |
a008b6d7 | 3195 | SD_BUS_METHOD_WITH_ARGS("DumpByFileDescriptor", |
3196 | SD_BUS_NO_ARGS, | |
3197 | SD_BUS_RESULT("h", fd), | |
3198 | method_dump_by_fd, | |
3199 | SD_BUS_VTABLE_UNPRIVILEGED), | |
f6cce15b ZJS |
3200 | SD_BUS_METHOD_WITH_ARGS("DumpUnitsMatchingPatternsByFileDescriptor", |
3201 | SD_BUS_ARGS("as", patterns), | |
3202 | SD_BUS_RESULT("h", fd), | |
3203 | method_dump_units_matching_patterns_by_fd, | |
3204 | SD_BUS_VTABLE_UNPRIVILEGED), | |
a008b6d7 | 3205 | SD_BUS_METHOD_WITH_ARGS("CreateSnapshot", |
3206 | SD_BUS_ARGS("s", name, "b", cleanup), | |
3207 | SD_BUS_RESULT("o", unit), | |
3208 | method_refuse_snapshot, | |
3209 | SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), | |
3210 | SD_BUS_METHOD_WITH_ARGS("RemoveSnapshot", | |
3211 | SD_BUS_ARGS("s", name), | |
3212 | SD_BUS_NO_RESULT, | |
3213 | method_refuse_snapshot, | |
3214 | SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), | |
dad97f04 ZJS |
3215 | SD_BUS_METHOD("Reload", |
3216 | NULL, | |
3217 | NULL, | |
3218 | method_reload, | |
3219 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3220 | SD_BUS_METHOD("Reexecute", | |
3221 | NULL, | |
3222 | NULL, | |
3223 | method_reexecute, | |
624f685f | 3224 | SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_METHOD_NO_REPLY), |
dad97f04 ZJS |
3225 | SD_BUS_METHOD("Exit", |
3226 | NULL, | |
3227 | NULL, | |
3228 | method_exit, | |
3229 | 0), | |
3230 | SD_BUS_METHOD("Reboot", | |
3231 | NULL, | |
3232 | NULL, | |
3233 | method_reboot, | |
3234 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
13ffc607 LP |
3235 | SD_BUS_METHOD_WITH_ARGS("SoftReboot", |
3236 | SD_BUS_ARGS("s", new_root), | |
3237 | SD_BUS_NO_RESULT, | |
3238 | method_soft_reboot, | |
3239 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
dad97f04 ZJS |
3240 | SD_BUS_METHOD("PowerOff", |
3241 | NULL, | |
3242 | NULL, | |
3243 | method_poweroff, | |
3244 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
3245 | SD_BUS_METHOD("Halt", | |
3246 | NULL, | |
3247 | NULL, | |
3248 | method_halt, | |
3249 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
3250 | SD_BUS_METHOD("KExec", | |
3251 | NULL, | |
3252 | NULL, | |
3253 | method_kexec, | |
3254 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
a008b6d7 | 3255 | SD_BUS_METHOD_WITH_ARGS("SwitchRoot", |
3256 | SD_BUS_ARGS("s", new_root, "s", init), | |
3257 | SD_BUS_NO_RESULT, | |
3258 | method_switch_root, | |
3259 | SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
3260 | SD_BUS_METHOD_WITH_ARGS("SetEnvironment", | |
3261 | SD_BUS_ARGS("as", assignments), | |
3262 | SD_BUS_NO_RESULT, | |
3263 | method_set_environment, | |
3264 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3265 | SD_BUS_METHOD_WITH_ARGS("UnsetEnvironment", | |
3266 | SD_BUS_ARGS("as", names), | |
3267 | SD_BUS_NO_RESULT, | |
3268 | method_unset_environment, | |
3269 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3270 | SD_BUS_METHOD_WITH_ARGS("UnsetAndSetEnvironment", | |
3271 | SD_BUS_ARGS("as", names, "as", assignments), | |
3272 | SD_BUS_NO_RESULT, | |
3273 | method_unset_and_set_environment, | |
3274 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3275 | SD_BUS_METHOD_WITH_ARGS("EnqueueMarkedJobs", | |
3276 | SD_BUS_NO_ARGS, | |
3277 | SD_BUS_RESULT("ao", jobs), | |
3278 | method_enqueue_marked_jobs, | |
3279 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3280 | SD_BUS_METHOD_WITH_ARGS("ListUnitFiles", | |
3281 | SD_BUS_NO_ARGS, | |
3282 | SD_BUS_RESULT("a(ss)", unit_files), | |
3283 | method_list_unit_files, | |
3284 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3285 | SD_BUS_METHOD_WITH_ARGS("ListUnitFilesByPatterns", | |
3286 | SD_BUS_ARGS("as", states, "as", patterns), | |
3287 | SD_BUS_RESULT("a(ss)", unit_files), | |
3288 | method_list_unit_files_by_patterns, | |
3289 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3290 | SD_BUS_METHOD_WITH_ARGS("GetUnitFileState", | |
3291 | SD_BUS_ARGS("s", file), | |
3292 | SD_BUS_RESULT("s", state), | |
3293 | method_get_unit_file_state, | |
3294 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3295 | SD_BUS_METHOD_WITH_ARGS("EnableUnitFiles", | |
3296 | SD_BUS_ARGS("as", files, "b", runtime, "b", force), | |
3297 | SD_BUS_RESULT("b", carries_install_info, "a(sss)", changes), | |
3298 | method_enable_unit_files, | |
3299 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3300 | SD_BUS_METHOD_WITH_ARGS("DisableUnitFiles", | |
3301 | SD_BUS_ARGS("as", files, "b", runtime), | |
3302 | SD_BUS_RESULT("a(sss)", changes), | |
3303 | method_disable_unit_files, | |
3304 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3305 | SD_BUS_METHOD_WITH_ARGS("EnableUnitFilesWithFlags", | |
3306 | SD_BUS_ARGS("as", files, "t", flags), | |
3307 | SD_BUS_RESULT("b", carries_install_info, "a(sss)", changes), | |
3308 | method_enable_unit_files_with_flags, | |
3309 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3310 | SD_BUS_METHOD_WITH_ARGS("DisableUnitFilesWithFlags", | |
3311 | SD_BUS_ARGS("as", files, "t", flags), | |
3312 | SD_BUS_RESULT("a(sss)", changes), | |
3313 | method_disable_unit_files_with_flags, | |
3314 | SD_BUS_VTABLE_UNPRIVILEGED), | |
bf1bea43 MY |
3315 | SD_BUS_METHOD_WITH_ARGS("DisableUnitFilesWithFlagsAndInstallInfo", |
3316 | SD_BUS_ARGS("as", files, "t", flags), | |
3317 | SD_BUS_RESULT("b", carries_install_info, "a(sss)", changes), | |
3318 | method_disable_unit_files_with_flags_and_install_info, | |
3319 | SD_BUS_VTABLE_UNPRIVILEGED), | |
a008b6d7 | 3320 | SD_BUS_METHOD_WITH_ARGS("ReenableUnitFiles", |
3321 | SD_BUS_ARGS("as", files, "b", runtime, "b", force), | |
3322 | SD_BUS_RESULT("b", carries_install_info, "a(sss)", changes), | |
3323 | method_reenable_unit_files, | |
3324 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3325 | SD_BUS_METHOD_WITH_ARGS("LinkUnitFiles", | |
3326 | SD_BUS_ARGS("as", files, "b", runtime, "b", force), | |
3327 | SD_BUS_RESULT("a(sss)", changes), | |
3328 | method_link_unit_files, | |
3329 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3330 | SD_BUS_METHOD_WITH_ARGS("PresetUnitFiles", | |
3331 | SD_BUS_ARGS("as", files, "b", runtime, "b", force), | |
3332 | SD_BUS_RESULT("b", carries_install_info, "a(sss)", changes), | |
3333 | method_preset_unit_files, | |
3334 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3335 | SD_BUS_METHOD_WITH_ARGS("PresetUnitFilesWithMode", | |
3336 | SD_BUS_ARGS("as", files, "s", mode, "b", runtime, "b", force), | |
3337 | SD_BUS_RESULT("b", carries_install_info, "a(sss)", changes), | |
3338 | method_preset_unit_files_with_mode, | |
3339 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3340 | SD_BUS_METHOD_WITH_ARGS("MaskUnitFiles", | |
3341 | SD_BUS_ARGS("as", files, "b", runtime, "b", force), | |
3342 | SD_BUS_RESULT("a(sss)", changes), | |
3343 | method_mask_unit_files, | |
3344 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3345 | SD_BUS_METHOD_WITH_ARGS("UnmaskUnitFiles", | |
3346 | SD_BUS_ARGS("as", files, "b", runtime), | |
3347 | SD_BUS_RESULT("a(sss)", changes), | |
3348 | method_unmask_unit_files, | |
3349 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3350 | SD_BUS_METHOD_WITH_ARGS("RevertUnitFiles", | |
3351 | SD_BUS_ARGS("as", files), | |
3352 | SD_BUS_RESULT("a(sss)", changes), | |
3353 | method_revert_unit_files, | |
3354 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3355 | SD_BUS_METHOD_WITH_ARGS("SetDefaultTarget", | |
3356 | SD_BUS_ARGS("s", name, "b", force), | |
3357 | SD_BUS_RESULT("a(sss)", changes), | |
3358 | method_set_default_target, | |
3359 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3360 | SD_BUS_METHOD_WITH_ARGS("GetDefaultTarget", | |
3361 | SD_BUS_NO_ARGS, | |
3362 | SD_BUS_RESULT("s", name), | |
3363 | method_get_default_target, | |
3364 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3365 | SD_BUS_METHOD_WITH_ARGS("PresetAllUnitFiles", | |
3366 | SD_BUS_ARGS("s", mode, "b", runtime, "b", force), | |
3367 | SD_BUS_RESULT("a(sss)", changes), | |
3368 | method_preset_all_unit_files, | |
3369 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3370 | SD_BUS_METHOD_WITH_ARGS("AddDependencyUnitFiles", | |
3371 | SD_BUS_ARGS("as", files, "s", target, "s", type, "b", runtime, "b", force), | |
3372 | SD_BUS_RESULT("a(sss)", changes), | |
3373 | method_add_dependency_unit_files, | |
3374 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3375 | SD_BUS_METHOD_WITH_ARGS("GetUnitFileLinks", | |
3376 | SD_BUS_ARGS("s", name, "b", runtime), | |
3377 | SD_BUS_RESULT("as", links), | |
3378 | method_get_unit_file_links, | |
3379 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3380 | SD_BUS_METHOD_WITH_ARGS("SetExitCode", | |
3381 | SD_BUS_ARGS("y", number), | |
3382 | SD_BUS_NO_RESULT, | |
3383 | method_set_exit_code, | |
3384 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3385 | SD_BUS_METHOD_WITH_ARGS("LookupDynamicUserByName", | |
3386 | SD_BUS_ARGS("s", name), | |
3387 | SD_BUS_RESULT("u", uid), | |
3388 | method_lookup_dynamic_user_by_name, | |
3389 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3390 | SD_BUS_METHOD_WITH_ARGS("LookupDynamicUserByUID", | |
3391 | SD_BUS_ARGS("u", uid), | |
3392 | SD_BUS_RESULT("s", name), | |
3393 | method_lookup_dynamic_user_by_uid, | |
3394 | SD_BUS_VTABLE_UNPRIVILEGED), | |
3395 | SD_BUS_METHOD_WITH_ARGS("GetDynamicUsers", | |
3396 | SD_BUS_NO_ARGS, | |
3397 | SD_BUS_RESULT("a(us)", users), | |
3398 | method_get_dynamic_users, | |
3399 | SD_BUS_VTABLE_UNPRIVILEGED), | |
2ea24611 LP |
3400 | SD_BUS_METHOD_WITH_ARGS("DumpUnitFileDescriptorStore", |
3401 | SD_BUS_ARGS("s", name), | |
3402 | SD_BUS_RESULT("a(suuutuusu)", entries), | |
3403 | method_dump_unit_descriptor_store, | |
3404 | SD_BUS_VTABLE_UNPRIVILEGED), | |
84c01612 MS |
3405 | SD_BUS_METHOD_WITH_ARGS("StartAuxiliaryScope", |
3406 | SD_BUS_ARGS("s", name, "ah", pidfds, "t", flags, "a(sv)", properties), | |
3407 | SD_BUS_RESULT("o", job), | |
3408 | method_start_aux_scope, | |
8c35e8a9 | 3409 | SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), |
a008b6d7 | 3410 | |
3411 | SD_BUS_SIGNAL_WITH_ARGS("UnitNew", | |
3412 | SD_BUS_ARGS("s", id, "o", unit), | |
3413 | 0), | |
3414 | SD_BUS_SIGNAL_WITH_ARGS("UnitRemoved", | |
3415 | SD_BUS_ARGS("s", id, "o", unit), | |
3416 | 0), | |
3417 | SD_BUS_SIGNAL_WITH_ARGS("JobNew", | |
3418 | SD_BUS_ARGS("u", id, "o", job, "s", unit), | |
3419 | 0), | |
3420 | SD_BUS_SIGNAL_WITH_ARGS("JobRemoved", | |
3421 | SD_BUS_ARGS("u", id, "o", job, "s", unit, "s", result), | |
3422 | 0), | |
3423 | SD_BUS_SIGNAL_WITH_ARGS("StartupFinished", | |
3424 | SD_BUS_ARGS("t", firmware, "t", loader, "t", kernel, "t", initrd, "t", userspace, "t", total), | |
3425 | 0), | |
718db961 | 3426 | SD_BUS_SIGNAL("UnitFilesChanged", NULL, 0), |
a008b6d7 | 3427 | SD_BUS_SIGNAL_WITH_ARGS("Reloading", |
3428 | SD_BUS_ARGS("b", active), | |
3429 | 0), | |
718db961 LP |
3430 | |
3431 | SD_BUS_VTABLE_END | |
ea430986 | 3432 | }; |
718db961 | 3433 | |
893f801d LP |
3434 | const sd_bus_vtable bus_manager_log_control_vtable[] = { |
3435 | SD_BUS_VTABLE_START(0), | |
3436 | ||
3437 | /* We define a private version of this interface here, since we want slightly different | |
3438 | * implementations for the setters. We'll still use the generic getters however, and we share the | |
3439 | * setters with the implementations for the Manager interface above (which pre-dates the generic | |
3440 | * service API interface). */ | |
3441 | ||
3442 | SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level, property_set_log_level, 0, 0), | |
3443 | SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target, property_set_log_target, 0, 0), | |
3444 | SD_BUS_PROPERTY("SyslogIdentifier", "s", bus_property_get_syslog_identifier, 0, 0), | |
3445 | ||
3446 | SD_BUS_VTABLE_END, | |
3447 | }; | |
3448 | ||
8f8f05a9 | 3449 | static int send_finished(sd_bus *bus, void *userdata) { |
4afd3348 | 3450 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
99534007 | 3451 | usec_t *times = ASSERT_PTR(userdata); |
718db961 LP |
3452 | int r; |
3453 | ||
3454 | assert(bus); | |
718db961 | 3455 | |
cb31470f ZJS |
3456 | r = sd_bus_message_new_signal(bus, |
3457 | &message, | |
3458 | "/org/freedesktop/systemd1", | |
3459 | "org.freedesktop.systemd1.Manager", | |
3460 | "StartupFinished"); | |
718db961 LP |
3461 | if (r < 0) |
3462 | return r; | |
3463 | ||
3464 | r = sd_bus_message_append(message, "tttttt", times[0], times[1], times[2], times[3], times[4], times[5]); | |
3465 | if (r < 0) | |
3466 | return r; | |
3467 | ||
8f8f05a9 | 3468 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
3469 | } |
3470 | ||
39abcaee | 3471 | void bus_manager_send_finished( |
718db961 LP |
3472 | Manager *m, |
3473 | usec_t firmware_usec, | |
3474 | usec_t loader_usec, | |
3475 | usec_t kernel_usec, | |
3476 | usec_t initrd_usec, | |
3477 | usec_t userspace_usec, | |
3478 | usec_t total_usec) { | |
3479 | ||
39abcaee LP |
3480 | int r; |
3481 | ||
718db961 LP |
3482 | assert(m); |
3483 | ||
8f8f05a9 LP |
3484 | r = bus_foreach_bus( |
3485 | m, | |
3486 | NULL, | |
3487 | send_finished, | |
3488 | (usec_t[6]) { | |
3489 | firmware_usec, | |
3490 | loader_usec, | |
3491 | kernel_usec, | |
3492 | initrd_usec, | |
3493 | userspace_usec, | |
3494 | total_usec | |
3495 | }); | |
39abcaee | 3496 | if (r < 0) |
da927ba9 | 3497 | log_debug_errno(r, "Failed to send finished signal: %m"); |
718db961 LP |
3498 | } |
3499 | ||
8f8f05a9 | 3500 | static int send_reloading(sd_bus *bus, void *userdata) { |
4afd3348 | 3501 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
3502 | int r; |
3503 | ||
3504 | assert(bus); | |
3505 | ||
151b9b96 | 3506 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading"); |
718db961 LP |
3507 | if (r < 0) |
3508 | return r; | |
3509 | ||
3510 | r = sd_bus_message_append(message, "b", PTR_TO_INT(userdata)); | |
3511 | if (r < 0) | |
3512 | return r; | |
3513 | ||
8f8f05a9 | 3514 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
3515 | } |
3516 | ||
39abcaee LP |
3517 | void bus_manager_send_reloading(Manager *m, bool active) { |
3518 | int r; | |
3519 | ||
718db961 LP |
3520 | assert(m); |
3521 | ||
8f8f05a9 | 3522 | r = bus_foreach_bus(m, NULL, send_reloading, INT_TO_PTR(active)); |
39abcaee | 3523 | if (r < 0) |
da927ba9 | 3524 | log_debug_errno(r, "Failed to send reloading signal: %m"); |
03455c28 LDM |
3525 | } |
3526 | ||
3527 | static int send_changed_signal(sd_bus *bus, void *userdata) { | |
3528 | assert(bus); | |
3529 | ||
3530 | return sd_bus_emit_properties_changed_strv(bus, | |
3531 | "/org/freedesktop/systemd1", | |
3532 | "org.freedesktop.systemd1.Manager", | |
3533 | NULL); | |
3534 | } | |
39abcaee | 3535 | |
03455c28 LDM |
3536 | void bus_manager_send_change_signal(Manager *m) { |
3537 | int r; | |
3538 | ||
3539 | assert(m); | |
3540 | ||
3541 | r = bus_foreach_bus(m, NULL, send_changed_signal, NULL); | |
3542 | if (r < 0) | |
3543 | log_debug_errno(r, "Failed to send manager change signal: %m"); | |
718db961 | 3544 | } |