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