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