]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
a7334b09 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2010 Lennart Poettering | |
a7334b09 LP |
6 | ***/ |
7 | ||
ea430986 | 8 | #include <errno.h> |
eed67a30 | 9 | #include <sys/prctl.h> |
ae57dad3 | 10 | #include <sys/statvfs.h> |
871c44a7 | 11 | #include <unistd.h> |
ea430986 | 12 | |
b5efdb8a | 13 | #include "alloc-util.h" |
07630cea | 14 | #include "architecture.h" |
09bde77f | 15 | #include "build.h" |
07630cea | 16 | #include "bus-common-errors.h" |
07630cea | 17 | #include "dbus-execute.h" |
2ea31e5b | 18 | #include "dbus-job.h" |
3ffd4af2 | 19 | #include "dbus-manager.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" | |
ae57dad3 | 29 | #include "parse-util.h" |
07630cea LP |
30 | #include "path-util.h" |
31 | #include "selinux-access.h" | |
8fcde012 | 32 | #include "stat-util.h" |
07630cea LP |
33 | #include "string-util.h" |
34 | #include "strv.h" | |
7ccbd1ae | 35 | #include "syslog-util.h" |
29206d46 | 36 | #include "user-util.h" |
07630cea LP |
37 | #include "virt.h" |
38 | #include "watchdog.h" | |
ea430986 | 39 | |
ae57dad3 LP |
40 | /* Require 16MiB free in /run/systemd for reloading/reexecing. After all we need to serialize our state there, and if |
41 | * we can't we'll fail badly. */ | |
42 | #define RELOAD_DISK_SPACE_MIN (UINT64_C(16) * UINT64_C(1024) * UINT64_C(1024)) | |
43 | ||
b3796dd8 JS |
44 | static UnitFileFlags unit_file_bools_to_flags(bool runtime, bool force) { |
45 | return (runtime ? UNIT_FILE_RUNTIME : 0) | | |
46 | (force ? UNIT_FILE_FORCE : 0); | |
47 | } | |
48 | ||
718db961 LP |
49 | static int property_get_version( |
50 | sd_bus *bus, | |
51 | const char *path, | |
52 | const char *interface, | |
53 | const char *property, | |
54 | sd_bus_message *reply, | |
ebcf1f97 LP |
55 | void *userdata, |
56 | sd_bus_error *error) { | |
718db961 LP |
57 | |
58 | assert(bus); | |
59 | assert(reply); | |
60 | ||
61 | return sd_bus_message_append(reply, "s", PACKAGE_VERSION); | |
62 | } | |
c5d34390 | 63 | |
718db961 LP |
64 | static int property_get_features( |
65 | sd_bus *bus, | |
66 | const char *path, | |
67 | const char *interface, | |
68 | const char *property, | |
69 | sd_bus_message *reply, | |
ebcf1f97 LP |
70 | void *userdata, |
71 | sd_bus_error *error) { | |
718db961 LP |
72 | |
73 | assert(bus); | |
74 | assert(reply); | |
75 | ||
76 | return sd_bus_message_append(reply, "s", SYSTEMD_FEATURES); | |
77 | } | |
78 | ||
79 | static int property_get_virtualization( | |
80 | sd_bus *bus, | |
81 | const char *path, | |
82 | const char *interface, | |
83 | const char *property, | |
84 | sd_bus_message *reply, | |
ebcf1f97 LP |
85 | void *userdata, |
86 | sd_bus_error *error) { | |
718db961 | 87 | |
5c22925a LP |
88 | int v; |
89 | ||
718db961 LP |
90 | assert(bus); |
91 | assert(reply); | |
92 | ||
5c22925a LP |
93 | v = detect_virtualization(); |
94 | ||
95 | /* Make sure to return the empty string when we detect no virtualization, as that is the API. | |
96 | * | |
97 | * https://github.com/systemd/systemd/issues/1423 | |
98 | */ | |
99 | ||
100 | return sd_bus_message_append( | |
101 | reply, "s", | |
102 | v == VIRTUALIZATION_NONE ? "" : virtualization_to_string(v)); | |
718db961 LP |
103 | } |
104 | ||
7452394e LP |
105 | static int property_get_architecture( |
106 | sd_bus *bus, | |
107 | const char *path, | |
108 | const char *interface, | |
109 | const char *property, | |
110 | sd_bus_message *reply, | |
111 | void *userdata, | |
112 | sd_bus_error *error) { | |
113 | ||
114 | assert(bus); | |
115 | assert(reply); | |
116 | ||
117 | return sd_bus_message_append(reply, "s", architecture_to_string(uname_architecture())); | |
118 | } | |
119 | ||
718db961 LP |
120 | static int property_get_tainted( |
121 | sd_bus *bus, | |
122 | const char *path, | |
123 | const char *interface, | |
124 | const char *property, | |
125 | sd_bus_message *reply, | |
ebcf1f97 LP |
126 | void *userdata, |
127 | sd_bus_error *error) { | |
718db961 | 128 | |
af6b0ecc | 129 | _cleanup_free_ char *s = NULL; |
718db961 LP |
130 | Manager *m = userdata; |
131 | ||
132 | assert(bus); | |
133 | assert(reply); | |
bfebab7f | 134 | assert(m); |
c5d34390 | 135 | |
af6b0ecc LP |
136 | s = manager_taint_string(m); |
137 | if (!s) | |
138 | return log_oom(); | |
c5d34390 | 139 | |
af6b0ecc | 140 | return sd_bus_message_append(reply, "s", s); |
c5d34390 LP |
141 | } |
142 | ||
718db961 LP |
143 | static int property_get_log_target( |
144 | sd_bus *bus, | |
145 | const char *path, | |
146 | const char *interface, | |
147 | const char *property, | |
148 | sd_bus_message *reply, | |
ebcf1f97 LP |
149 | void *userdata, |
150 | sd_bus_error *error) { | |
1adf1049 | 151 | |
718db961 LP |
152 | assert(bus); |
153 | assert(reply); | |
1adf1049 | 154 | |
718db961 | 155 | return sd_bus_message_append(reply, "s", log_target_to_string(log_get_target())); |
1adf1049 LP |
156 | } |
157 | ||
718db961 LP |
158 | static int property_set_log_target( |
159 | sd_bus *bus, | |
160 | const char *path, | |
161 | const char *interface, | |
162 | const char *property, | |
163 | sd_bus_message *value, | |
ebcf1f97 LP |
164 | void *userdata, |
165 | sd_bus_error *error) { | |
718db961 | 166 | |
c826cda4 | 167 | const char *t; |
718db961 | 168 | int r; |
c826cda4 | 169 | |
718db961 LP |
170 | assert(bus); |
171 | assert(value); | |
c826cda4 | 172 | |
718db961 LP |
173 | r = sd_bus_message_read(value, "s", &t); |
174 | if (r < 0) | |
175 | return r; | |
c826cda4 AB |
176 | |
177 | return log_set_target_from_string(t); | |
178 | } | |
179 | ||
718db961 LP |
180 | static int property_get_log_level( |
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 | 188 | |
68eda4bd | 189 | _cleanup_free_ char *t = NULL; |
f8b69d1d | 190 | int r; |
1adf1049 | 191 | |
718db961 LP |
192 | assert(bus); |
193 | assert(reply); | |
1adf1049 | 194 | |
f8b69d1d MS |
195 | r = log_level_to_string_alloc(log_get_max_level(), &t); |
196 | if (r < 0) | |
197 | return r; | |
1adf1049 | 198 | |
718db961 | 199 | return sd_bus_message_append(reply, "s", t); |
1adf1049 LP |
200 | } |
201 | ||
718db961 LP |
202 | static int property_set_log_level( |
203 | sd_bus *bus, | |
204 | const char *path, | |
205 | const char *interface, | |
206 | const char *property, | |
207 | sd_bus_message *value, | |
ebcf1f97 LP |
208 | void *userdata, |
209 | sd_bus_error *error) { | |
718db961 | 210 | |
c826cda4 | 211 | const char *t; |
718db961 | 212 | int r; |
c826cda4 | 213 | |
718db961 LP |
214 | assert(bus); |
215 | assert(value); | |
c826cda4 | 216 | |
718db961 LP |
217 | r = sd_bus_message_read(value, "s", &t); |
218 | if (r < 0) | |
219 | return r; | |
c826cda4 | 220 | |
4cee3a78 ZJS |
221 | r = log_set_max_level_from_string(t); |
222 | if (r == 0) | |
223 | log_info("Setting log level to %s.", t); | |
224 | return r; | |
c826cda4 AB |
225 | } |
226 | ||
718db961 LP |
227 | static int property_get_n_names( |
228 | sd_bus *bus, | |
229 | const char *path, | |
230 | const char *interface, | |
231 | const char *property, | |
232 | sd_bus_message *reply, | |
ebcf1f97 LP |
233 | void *userdata, |
234 | sd_bus_error *error) { | |
4f0f902f | 235 | |
718db961 | 236 | Manager *m = userdata; |
4f0f902f | 237 | |
718db961 LP |
238 | assert(bus); |
239 | assert(reply); | |
240 | assert(m); | |
4f0f902f | 241 | |
718db961 | 242 | return sd_bus_message_append(reply, "u", (uint32_t) hashmap_size(m->units)); |
4f0f902f LP |
243 | } |
244 | ||
f755e3b7 LP |
245 | static int property_get_n_failed_units( |
246 | sd_bus *bus, | |
247 | const char *path, | |
248 | const char *interface, | |
249 | const char *property, | |
250 | sd_bus_message *reply, | |
251 | void *userdata, | |
252 | sd_bus_error *error) { | |
253 | ||
254 | Manager *m = userdata; | |
255 | ||
256 | assert(bus); | |
257 | assert(reply); | |
258 | assert(m); | |
259 | ||
260 | return sd_bus_message_append(reply, "u", (uint32_t) set_size(m->failed_units)); | |
261 | } | |
262 | ||
718db961 LP |
263 | static int property_get_n_jobs( |
264 | sd_bus *bus, | |
265 | const char *path, | |
266 | const char *interface, | |
267 | const char *property, | |
268 | sd_bus_message *reply, | |
ebcf1f97 LP |
269 | void *userdata, |
270 | sd_bus_error *error) { | |
4f0f902f | 271 | |
718db961 | 272 | Manager *m = userdata; |
4f0f902f | 273 | |
718db961 LP |
274 | assert(bus); |
275 | assert(reply); | |
276 | assert(m); | |
4f0f902f | 277 | |
718db961 | 278 | return sd_bus_message_append(reply, "u", (uint32_t) hashmap_size(m->jobs)); |
4f0f902f LP |
279 | } |
280 | ||
718db961 LP |
281 | static int property_get_progress( |
282 | sd_bus *bus, | |
283 | const char *path, | |
284 | const char *interface, | |
285 | const char *property, | |
286 | sd_bus_message *reply, | |
ebcf1f97 LP |
287 | void *userdata, |
288 | sd_bus_error *error) { | |
718db961 LP |
289 | |
290 | Manager *m = userdata; | |
05d6a3b6 LP |
291 | double d; |
292 | ||
718db961 LP |
293 | assert(bus); |
294 | assert(reply); | |
bfebab7f | 295 | assert(m); |
05d6a3b6 | 296 | |
49d5666c | 297 | if (MANAGER_IS_FINISHED(m)) |
05d6a3b6 LP |
298 | d = 1.0; |
299 | else | |
300 | d = 1.0 - ((double) hashmap_size(m->jobs) / (double) m->n_installed_jobs); | |
301 | ||
718db961 LP |
302 | return sd_bus_message_append(reply, "d", d); |
303 | } | |
304 | ||
f755e3b7 LP |
305 | static int property_get_system_state( |
306 | sd_bus *bus, | |
307 | const char *path, | |
308 | const char *interface, | |
309 | const char *property, | |
310 | sd_bus_message *reply, | |
311 | void *userdata, | |
312 | sd_bus_error *error) { | |
313 | ||
314 | Manager *m = userdata; | |
315 | ||
316 | assert(bus); | |
317 | assert(reply); | |
318 | assert(m); | |
319 | ||
320 | return sd_bus_message_append(reply, "s", manager_state_to_string(manager_state(m))); | |
321 | } | |
322 | ||
718db961 LP |
323 | static int property_set_runtime_watchdog( |
324 | sd_bus *bus, | |
325 | const char *path, | |
326 | const char *interface, | |
327 | const char *property, | |
328 | sd_bus_message *value, | |
ebcf1f97 LP |
329 | void *userdata, |
330 | sd_bus_error *error) { | |
05d6a3b6 | 331 | |
718db961 LP |
332 | usec_t *t = userdata; |
333 | int r; | |
334 | ||
335 | assert(bus); | |
336 | assert(value); | |
337 | ||
338 | assert_cc(sizeof(usec_t) == sizeof(uint64_t)); | |
339 | ||
340 | r = sd_bus_message_read(value, "t", t); | |
341 | if (r < 0) | |
342 | return r; | |
343 | ||
344 | return watchdog_set_timeout(t); | |
05d6a3b6 LP |
345 | } |
346 | ||
eed67a30 EV |
347 | static int property_get_timer_slack_nsec( |
348 | sd_bus *bus, | |
349 | const char *path, | |
350 | const char *interface, | |
351 | const char *property, | |
352 | sd_bus_message *reply, | |
353 | void *userdata, | |
354 | sd_bus_error *error) { | |
355 | ||
356 | assert(bus); | |
357 | assert(reply); | |
358 | ||
359 | return sd_bus_message_append(reply, "t", (uint64_t) prctl(PR_GET_TIMERSLACK)); | |
360 | } | |
361 | ||
96cc4453 | 362 | 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 |
363 | Unit *u; |
364 | int r; | |
dfae3488 | 365 | |
dfae3488 | 366 | assert(m); |
96cc4453 LP |
367 | assert(message); |
368 | assert(ret_unit); | |
dfae3488 | 369 | |
96cc4453 LP |
370 | /* More or less a wrapper around manager_get_unit() that generates nice errors and has one trick up its sleeve: |
371 | * if the name is specified empty we use the client's unit. */ | |
dfae3488 | 372 | |
1d22e906 | 373 | if (isempty(name)) { |
4afd3348 | 374 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; |
1d22e906 LP |
375 | pid_t pid; |
376 | ||
377 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); | |
378 | if (r < 0) | |
379 | return r; | |
380 | ||
381 | r = sd_bus_creds_get_pid(creds, &pid); | |
382 | if (r < 0) | |
383 | return r; | |
384 | ||
385 | u = manager_get_unit_by_pid(m, pid); | |
386 | if (!u) | |
387 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Client not member of any unit."); | |
388 | } else { | |
389 | u = manager_get_unit(m, name); | |
390 | if (!u) | |
391 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", name); | |
392 | } | |
dfae3488 | 393 | |
96cc4453 LP |
394 | *ret_unit = u; |
395 | return 0; | |
396 | } | |
397 | ||
398 | static int bus_load_unit_by_name(Manager *m, sd_bus_message *message, const char *name, Unit **ret_unit, sd_bus_error *error) { | |
399 | assert(m); | |
400 | assert(message); | |
401 | assert(ret_unit); | |
402 | ||
403 | /* Pretty much the same as bus_get_unit_by_name(), but we also load the unit if necessary. */ | |
404 | ||
405 | if (isempty(name)) | |
406 | return bus_get_unit_by_name(m, message, name, ret_unit, error); | |
407 | ||
408 | return manager_load_unit(m, name, NULL, error, ret_unit); | |
409 | } | |
410 | ||
411 | static int method_get_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
412 | _cleanup_free_ char *path = NULL; | |
413 | Manager *m = userdata; | |
414 | const char *name; | |
415 | Unit *u; | |
416 | int r; | |
417 | ||
418 | assert(message); | |
419 | assert(m); | |
420 | ||
421 | /* Anyone can call this method */ | |
422 | ||
423 | r = sd_bus_message_read(message, "s", &name); | |
424 | if (r < 0) | |
425 | return r; | |
426 | ||
427 | r = bus_get_unit_by_name(m, message, name, &u, error); | |
428 | if (r < 0) | |
429 | return r; | |
430 | ||
8a188de9 | 431 | r = mac_selinux_unit_access_check(u, message, "status", error); |
ebcf1f97 LP |
432 | if (r < 0) |
433 | return r; | |
dfae3488 | 434 | |
718db961 LP |
435 | path = unit_dbus_path(u); |
436 | if (!path) | |
ebcf1f97 | 437 | return -ENOMEM; |
729e3769 | 438 | |
df2d202e | 439 | return sd_bus_reply_method_return(message, "o", path); |
718db961 | 440 | } |
c0576cd6 | 441 | |
19070062 | 442 | static int method_get_unit_by_pid(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
443 | _cleanup_free_ char *path = NULL; |
444 | Manager *m = userdata; | |
445 | pid_t pid; | |
446 | Unit *u; | |
447 | int r; | |
c0576cd6 | 448 | |
718db961 LP |
449 | assert(message); |
450 | assert(m); | |
c0576cd6 | 451 | |
718db961 | 452 | assert_cc(sizeof(pid_t) == sizeof(uint32_t)); |
729e3769 | 453 | |
283868e1 SW |
454 | /* Anyone can call this method */ |
455 | ||
718db961 LP |
456 | r = sd_bus_message_read(message, "u", &pid); |
457 | if (r < 0) | |
ebcf1f97 | 458 | return r; |
07b38ba5 | 459 | if (pid < 0) |
1d22e906 | 460 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PID " PID_FMT, pid); |
718db961 LP |
461 | |
462 | if (pid == 0) { | |
4afd3348 | 463 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; |
5b12334d LP |
464 | |
465 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); | |
466 | if (r < 0) | |
467 | return r; | |
468 | ||
469 | r = sd_bus_creds_get_pid(creds, &pid); | |
718db961 | 470 | if (r < 0) |
ebcf1f97 | 471 | return r; |
729e3769 LP |
472 | } |
473 | ||
718db961 LP |
474 | u = manager_get_unit_by_pid(m, pid); |
475 | if (!u) | |
1fa2f38f | 476 | return sd_bus_error_setf(error, BUS_ERROR_NO_UNIT_FOR_PID, "PID "PID_FMT" does not belong to any loaded unit.", pid); |
c0576cd6 | 477 | |
8a188de9 | 478 | r = mac_selinux_unit_access_check(u, message, "status", error); |
ebcf1f97 LP |
479 | if (r < 0) |
480 | return r; | |
718db961 LP |
481 | |
482 | path = unit_dbus_path(u); | |
483 | if (!path) | |
ebcf1f97 | 484 | return -ENOMEM; |
718db961 | 485 | |
df2d202e | 486 | return sd_bus_reply_method_return(message, "o", path); |
718db961 LP |
487 | } |
488 | ||
4b58153d LP |
489 | static int method_get_unit_by_invocation_id(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
490 | _cleanup_free_ char *path = NULL; | |
491 | Manager *m = userdata; | |
492 | sd_id128_t id; | |
493 | const void *a; | |
494 | Unit *u; | |
495 | size_t sz; | |
496 | int r; | |
497 | ||
498 | assert(message); | |
499 | assert(m); | |
500 | ||
501 | /* Anyone can call this method */ | |
502 | ||
503 | r = sd_bus_message_read_array(message, 'y', &a, &sz); | |
504 | if (r < 0) | |
505 | return r; | |
506 | if (sz == 0) | |
507 | id = SD_ID128_NULL; | |
508 | else if (sz == 16) | |
509 | memcpy(&id, a, sz); | |
510 | else | |
511 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid invocation ID"); | |
512 | ||
513 | if (sd_id128_is_null(id)) { | |
514 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; | |
515 | pid_t pid; | |
516 | ||
517 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); | |
518 | if (r < 0) | |
519 | return r; | |
520 | ||
521 | r = sd_bus_creds_get_pid(creds, &pid); | |
522 | if (r < 0) | |
523 | return r; | |
524 | ||
525 | u = manager_get_unit_by_pid(m, pid); | |
526 | if (!u) | |
527 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Client " PID_FMT " not member of any unit.", pid); | |
528 | } else { | |
529 | u = hashmap_get(m->units_by_invocation_id, &id); | |
530 | if (!u) | |
531 | 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)); | |
532 | } | |
533 | ||
534 | r = mac_selinux_unit_access_check(u, message, "status", error); | |
535 | if (r < 0) | |
536 | return r; | |
537 | ||
538 | /* So here's a special trick: the bus path we return actually references the unit by its invocation ID instead | |
539 | * of the unit name. This means it stays valid only as long as the invocation ID stays the same. */ | |
540 | path = unit_dbus_path_invocation_id(u); | |
541 | if (!path) | |
542 | return -ENOMEM; | |
543 | ||
544 | return sd_bus_reply_method_return(message, "o", path); | |
545 | } | |
546 | ||
19070062 | 547 | static int method_load_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
548 | _cleanup_free_ char *path = NULL; |
549 | Manager *m = userdata; | |
550 | const char *name; | |
551 | Unit *u; | |
552 | int r; | |
c0576cd6 | 553 | |
718db961 LP |
554 | assert(message); |
555 | assert(m); | |
556 | ||
283868e1 SW |
557 | /* Anyone can call this method */ |
558 | ||
718db961 LP |
559 | r = sd_bus_message_read(message, "s", &name); |
560 | if (r < 0) | |
ebcf1f97 | 561 | return r; |
c0576cd6 | 562 | |
96cc4453 LP |
563 | r = bus_load_unit_by_name(m, message, name, &u, error); |
564 | if (r < 0) | |
565 | return r; | |
718db961 | 566 | |
8a188de9 | 567 | r = mac_selinux_unit_access_check(u, message, "status", error); |
ebcf1f97 LP |
568 | if (r < 0) |
569 | return r; | |
c0576cd6 | 570 | |
718db961 LP |
571 | path = unit_dbus_path(u); |
572 | if (!path) | |
ebcf1f97 | 573 | return -ENOMEM; |
718db961 | 574 | |
df2d202e | 575 | return sd_bus_reply_method_return(message, "o", path); |
c0576cd6 LP |
576 | } |
577 | ||
19070062 | 578 | 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 |
579 | const char *name; |
580 | Unit *u; | |
c0576cd6 LP |
581 | int r; |
582 | ||
718db961 LP |
583 | assert(message); |
584 | assert(m); | |
c0576cd6 | 585 | |
718db961 LP |
586 | r = sd_bus_message_read(message, "s", &name); |
587 | if (r < 0) | |
ebcf1f97 | 588 | return r; |
c0576cd6 | 589 | |
ebcf1f97 | 590 | r = manager_load_unit(m, name, NULL, error, &u); |
718db961 | 591 | if (r < 0) |
ebcf1f97 | 592 | return r; |
718db961 | 593 | |
19070062 | 594 | return bus_unit_method_start_generic(message, u, job_type, reload_if_possible, error); |
c0576cd6 LP |
595 | } |
596 | ||
19070062 LP |
597 | static int method_start_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
598 | return method_start_unit_generic(message, userdata, JOB_START, false, error); | |
718db961 | 599 | } |
c757a65b | 600 | |
19070062 LP |
601 | static int method_stop_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
602 | return method_start_unit_generic(message, userdata, JOB_STOP, false, error); | |
718db961 | 603 | } |
c757a65b | 604 | |
19070062 LP |
605 | static int method_reload_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
606 | return method_start_unit_generic(message, userdata, JOB_RELOAD, false, error); | |
718db961 | 607 | } |
c757a65b | 608 | |
19070062 LP |
609 | static int method_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
610 | return method_start_unit_generic(message, userdata, JOB_RESTART, false, error); | |
c757a65b LP |
611 | } |
612 | ||
19070062 LP |
613 | static int method_try_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
614 | return method_start_unit_generic(message, userdata, JOB_TRY_RESTART, false, error); | |
718db961 | 615 | } |
d200735e | 616 | |
19070062 LP |
617 | static int method_reload_or_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
618 | return method_start_unit_generic(message, userdata, JOB_RESTART, true, error); | |
718db961 | 619 | } |
d200735e | 620 | |
19070062 LP |
621 | static int method_reload_or_try_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
622 | return method_start_unit_generic(message, userdata, JOB_TRY_RESTART, true, error); | |
718db961 | 623 | } |
d200735e | 624 | |
19070062 | 625 | static int method_start_unit_replace(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
626 | Manager *m = userdata; |
627 | const char *old_name; | |
628 | Unit *u; | |
1adf1049 | 629 | int r; |
ea430986 | 630 | |
ea430986 LP |
631 | assert(message); |
632 | assert(m); | |
633 | ||
718db961 LP |
634 | r = sd_bus_message_read(message, "s", &old_name); |
635 | if (r < 0) | |
ebcf1f97 | 636 | return r; |
ea430986 | 637 | |
96cc4453 LP |
638 | r = bus_get_unit_by_name(m, message, old_name, &u, error); |
639 | if (r < 0) | |
640 | return r; | |
641 | if (!u->job || u->job->type != JOB_START) | |
ebcf1f97 | 642 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name); |
c0576cd6 | 643 | |
19070062 | 644 | return method_start_unit_generic(message, m, JOB_START, false, error); |
718db961 | 645 | } |
ea430986 | 646 | |
19070062 | 647 | static int method_kill_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
648 | Manager *m = userdata; |
649 | const char *name; | |
650 | Unit *u; | |
651 | int r; | |
ea430986 | 652 | |
718db961 LP |
653 | assert(message); |
654 | assert(m); | |
ea430986 | 655 | |
718db961 LP |
656 | r = sd_bus_message_read(message, "s", &name); |
657 | if (r < 0) | |
ebcf1f97 | 658 | return r; |
598b557b | 659 | |
96cc4453 LP |
660 | r = bus_get_unit_by_name(m, message, name, &u, error); |
661 | if (r < 0) | |
662 | return r; | |
0a524ba7 | 663 | |
19070062 | 664 | return bus_unit_method_kill(message, u, error); |
718db961 | 665 | } |
8a0867d6 | 666 | |
19070062 | 667 | static int method_reset_failed_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
668 | Manager *m = userdata; |
669 | const char *name; | |
670 | Unit *u; | |
671 | int r; | |
8a0867d6 | 672 | |
718db961 LP |
673 | assert(message); |
674 | assert(m); | |
cad45ba1 | 675 | |
718db961 LP |
676 | r = sd_bus_message_read(message, "s", &name); |
677 | if (r < 0) | |
ebcf1f97 | 678 | return r; |
ea430986 | 679 | |
96cc4453 LP |
680 | r = bus_get_unit_by_name(m, message, name, &u, error); |
681 | if (r < 0) | |
682 | return r; | |
5dd9014f | 683 | |
19070062 | 684 | return bus_unit_method_reset_failed(message, u, error); |
718db961 | 685 | } |
5dd9014f | 686 | |
19070062 | 687 | static int method_set_unit_properties(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
688 | Manager *m = userdata; |
689 | const char *name; | |
690 | Unit *u; | |
691 | int r; | |
5dd9014f | 692 | |
718db961 LP |
693 | assert(message); |
694 | assert(m); | |
695 | ||
696 | r = sd_bus_message_read(message, "s", &name); | |
697 | if (r < 0) | |
ebcf1f97 | 698 | return r; |
718db961 | 699 | |
96cc4453 | 700 | r = bus_load_unit_by_name(m, message, name, &u, error); |
e9fd88f2 FB |
701 | if (r < 0) |
702 | return r; | |
703 | ||
704 | r = bus_unit_check_load_state(u, error); | |
705 | if (r < 0) | |
706 | return r; | |
ea430986 | 707 | |
19070062 | 708 | return bus_unit_method_set_properties(message, u, error); |
718db961 LP |
709 | } |
710 | ||
05a98afd LP |
711 | static int method_ref_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
712 | Manager *m = userdata; | |
713 | const char *name; | |
714 | Unit *u; | |
715 | int r; | |
716 | ||
717 | assert(message); | |
718 | assert(m); | |
719 | ||
720 | r = sd_bus_message_read(message, "s", &name); | |
721 | if (r < 0) | |
722 | return r; | |
723 | ||
96cc4453 | 724 | r = bus_load_unit_by_name(m, message, name, &u, error); |
05a98afd LP |
725 | if (r < 0) |
726 | return r; | |
727 | ||
728 | r = bus_unit_check_load_state(u, error); | |
729 | if (r < 0) | |
730 | return r; | |
731 | ||
732 | return bus_unit_method_ref(message, u, error); | |
733 | } | |
734 | ||
735 | static int method_unref_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
736 | Manager *m = userdata; | |
737 | const char *name; | |
738 | Unit *u; | |
739 | int r; | |
740 | ||
741 | assert(message); | |
742 | assert(m); | |
743 | ||
744 | r = sd_bus_message_read(message, "s", &name); | |
745 | if (r < 0) | |
746 | return r; | |
747 | ||
96cc4453 | 748 | r = bus_load_unit_by_name(m, message, name, &u, error); |
05a98afd LP |
749 | if (r < 0) |
750 | return r; | |
751 | ||
752 | r = bus_unit_check_load_state(u, error); | |
753 | if (r < 0) | |
754 | return r; | |
755 | ||
756 | return bus_unit_method_unref(message, u, error); | |
757 | } | |
758 | ||
6900c740 | 759 | static int reply_unit_info(sd_bus_message *reply, Unit *u) { |
760 | _cleanup_free_ char *unit_path = NULL, *job_path = NULL; | |
761 | Unit *following; | |
762 | ||
763 | following = unit_following(u); | |
764 | ||
765 | unit_path = unit_dbus_path(u); | |
766 | if (!unit_path) | |
767 | return -ENOMEM; | |
768 | ||
769 | if (u->job) { | |
770 | job_path = job_dbus_path(u->job); | |
771 | if (!job_path) | |
772 | return -ENOMEM; | |
773 | } | |
774 | ||
775 | return sd_bus_message_append( | |
776 | reply, "(ssssssouso)", | |
777 | u->id, | |
778 | unit_description(u), | |
779 | unit_load_state_to_string(u->load_state), | |
780 | unit_active_state_to_string(unit_active_state(u)), | |
781 | unit_sub_state_to_string(u), | |
782 | following ? following->id : "", | |
783 | unit_path, | |
784 | u->job ? u->job->id : 0, | |
785 | u->job ? job_type_to_string(u->job->type) : "", | |
786 | job_path ? job_path : "/"); | |
787 | } | |
788 | ||
789 | static int method_list_units_by_names(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
790 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
791 | Manager *m = userdata; | |
792 | int r; | |
793 | char **unit; | |
794 | _cleanup_strv_free_ char **units = NULL; | |
795 | ||
796 | assert(message); | |
797 | assert(m); | |
798 | ||
799 | r = sd_bus_message_read_strv(message, &units); | |
800 | if (r < 0) | |
801 | return r; | |
802 | ||
803 | r = sd_bus_message_new_method_return(message, &reply); | |
804 | if (r < 0) | |
805 | return r; | |
806 | ||
807 | r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)"); | |
808 | if (r < 0) | |
809 | return r; | |
810 | ||
811 | STRV_FOREACH(unit, units) { | |
812 | Unit *u; | |
813 | ||
814 | if (!unit_name_is_valid(*unit, UNIT_NAME_ANY)) | |
815 | continue; | |
816 | ||
96cc4453 | 817 | r = bus_load_unit_by_name(m, message, *unit, &u, error); |
6900c740 | 818 | if (r < 0) |
819 | return r; | |
820 | ||
821 | r = reply_unit_info(reply, u); | |
822 | if (r < 0) | |
823 | return r; | |
824 | } | |
825 | ||
826 | r = sd_bus_message_close_container(reply); | |
827 | if (r < 0) | |
828 | return r; | |
829 | ||
830 | return sd_bus_send(NULL, reply, NULL); | |
831 | } | |
832 | ||
291d565a LP |
833 | static int method_get_unit_processes(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
834 | Manager *m = userdata; | |
835 | const char *name; | |
836 | Unit *u; | |
837 | int r; | |
838 | ||
839 | assert(message); | |
840 | assert(m); | |
841 | ||
842 | r = sd_bus_message_read(message, "s", &name); | |
843 | if (r < 0) | |
844 | return r; | |
845 | ||
96cc4453 LP |
846 | r = bus_get_unit_by_name(m, message, name, &u, error); |
847 | if (r < 0) | |
848 | return r; | |
291d565a LP |
849 | |
850 | return bus_unit_method_get_processes(message, u, error); | |
851 | } | |
852 | ||
6592b975 LP |
853 | static int method_attach_processes_to_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
854 | Manager *m = userdata; | |
855 | const char *name; | |
856 | Unit *u; | |
857 | int r; | |
858 | ||
859 | assert(message); | |
860 | assert(m); | |
861 | ||
862 | r = sd_bus_message_read(message, "s", &name); | |
863 | if (r < 0) | |
864 | return r; | |
865 | ||
866 | r = bus_get_unit_by_name(m, message, name, &u, error); | |
867 | if (r < 0) | |
868 | return r; | |
869 | ||
870 | return bus_unit_method_attach_processes(message, u, error); | |
871 | } | |
872 | ||
ab31f6b8 WC |
873 | static int transient_unit_from_message( |
874 | Manager *m, | |
875 | sd_bus_message *message, | |
876 | const char *name, | |
877 | Unit **unit, | |
878 | sd_bus_error *error) { | |
879 | ||
06cc6afa | 880 | UnitType t; |
ab31f6b8 WC |
881 | Unit *u; |
882 | int r; | |
883 | ||
884 | assert(m); | |
885 | assert(message); | |
886 | assert(name); | |
887 | ||
06cc6afa LP |
888 | t = unit_name_to_type(name); |
889 | if (t < 0) | |
890 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit name or type."); | |
891 | ||
892 | if (!unit_vtable[t]->can_transient) | |
893 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit type %s does not support transient units.", unit_type_to_string(t)); | |
894 | ||
ab31f6b8 WC |
895 | r = manager_load_unit(m, name, NULL, error, &u); |
896 | if (r < 0) | |
897 | return r; | |
898 | ||
0f13f3bd | 899 | if (!unit_is_pristine(u)) |
ab31f6b8 WC |
900 | return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name); |
901 | ||
902 | /* OK, the unit failed to load and is unreferenced, now let's | |
903 | * fill in the transient data instead */ | |
904 | r = unit_make_transient(u); | |
905 | if (r < 0) | |
906 | return r; | |
907 | ||
908 | /* Set our properties */ | |
909 | r = bus_unit_set_properties(u, message, UNIT_RUNTIME, false, error); | |
910 | if (r < 0) | |
911 | return r; | |
912 | ||
05a98afd LP |
913 | /* If the client asked for it, automatically add a reference to this unit. */ |
914 | if (u->bus_track_add) { | |
915 | r = bus_unit_track_add_sender(u, message); | |
916 | if (r < 0) | |
917 | return log_error_errno(r, "Failed to watch sender: %m"); | |
918 | } | |
919 | ||
97329d20 | 920 | /* Now load the missing bits of the unit we just created */ |
4f952a3f | 921 | unit_add_to_load_queue(u); |
97329d20 LP |
922 | manager_dispatch_load_queue(m); |
923 | ||
ab31f6b8 WC |
924 | *unit = u; |
925 | ||
926 | return 0; | |
927 | } | |
928 | ||
929 | static int transient_aux_units_from_message( | |
930 | Manager *m, | |
931 | sd_bus_message *message, | |
932 | sd_bus_error *error) { | |
933 | ||
ab31f6b8 WC |
934 | int r; |
935 | ||
936 | assert(m); | |
937 | assert(message); | |
938 | ||
939 | r = sd_bus_message_enter_container(message, 'a', "(sa(sv))"); | |
940 | if (r < 0) | |
941 | return r; | |
942 | ||
943 | while ((r = sd_bus_message_enter_container(message, 'r', "sa(sv)")) > 0) { | |
97329d20 LP |
944 | const char *name = NULL; |
945 | Unit *u; | |
946 | ||
ab31f6b8 WC |
947 | r = sd_bus_message_read(message, "s", &name); |
948 | if (r < 0) | |
949 | return r; | |
950 | ||
951 | r = transient_unit_from_message(m, message, name, &u, error); | |
97329d20 | 952 | if (r < 0) |
ab31f6b8 WC |
953 | return r; |
954 | ||
ab31f6b8 WC |
955 | r = sd_bus_message_exit_container(message); |
956 | if (r < 0) | |
957 | return r; | |
958 | } | |
959 | if (r < 0) | |
960 | return r; | |
961 | ||
962 | r = sd_bus_message_exit_container(message); | |
963 | if (r < 0) | |
964 | return r; | |
965 | ||
966 | return 0; | |
967 | } | |
968 | ||
19070062 | 969 | static int method_start_transient_unit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
970 | const char *name, *smode; |
971 | Manager *m = userdata; | |
972 | JobMode mode; | |
718db961 LP |
973 | Unit *u; |
974 | int r; | |
ea430986 | 975 | |
718db961 LP |
976 | assert(message); |
977 | assert(m); | |
ea430986 | 978 | |
1d22e906 | 979 | r = mac_selinux_access_check(message, "start", error); |
283868e1 SW |
980 | if (r < 0) |
981 | return r; | |
283868e1 | 982 | |
718db961 LP |
983 | r = sd_bus_message_read(message, "ss", &name, &smode); |
984 | if (r < 0) | |
ebcf1f97 | 985 | return r; |
5632e374 | 986 | |
718db961 LP |
987 | mode = job_mode_from_string(smode); |
988 | if (mode < 0) | |
ebcf1f97 | 989 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s is invalid.", smode); |
5632e374 | 990 | |
1d22e906 | 991 | r = bus_verify_manage_units_async(m, message, error); |
718db961 | 992 | if (r < 0) |
ebcf1f97 | 993 | return r; |
1d22e906 LP |
994 | if (r == 0) |
995 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
5632e374 | 996 | |
ab31f6b8 | 997 | r = transient_unit_from_message(m, message, name, &u, error); |
ebcf1f97 LP |
998 | if (r < 0) |
999 | return r; | |
5632e374 | 1000 | |
ab31f6b8 | 1001 | r = transient_aux_units_from_message(m, message, error); |
718db961 | 1002 | if (r < 0) |
ebcf1f97 | 1003 | return r; |
ea430986 | 1004 | |
718db961 | 1005 | /* Finally, start it */ |
19070062 | 1006 | return bus_unit_queue_job(message, u, JOB_START, mode, false, error); |
718db961 | 1007 | } |
ea430986 | 1008 | |
19070062 | 1009 | static int method_get_job(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1010 | _cleanup_free_ char *path = NULL; |
1011 | Manager *m = userdata; | |
1012 | uint32_t id; | |
1013 | Job *j; | |
1014 | int r; | |
ea430986 | 1015 | |
718db961 LP |
1016 | assert(message); |
1017 | assert(m); | |
ea430986 | 1018 | |
283868e1 SW |
1019 | /* Anyone can call this method */ |
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 | |
8a188de9 | 1029 | r = mac_selinux_unit_access_check(j->unit, message, "status", error); |
ebcf1f97 LP |
1030 | if (r < 0) |
1031 | return r; | |
ea430986 | 1032 | |
718db961 LP |
1033 | path = job_dbus_path(j); |
1034 | if (!path) | |
ebcf1f97 | 1035 | return -ENOMEM; |
ea430986 | 1036 | |
df2d202e | 1037 | return sd_bus_reply_method_return(message, "o", path); |
718db961 | 1038 | } |
ea430986 | 1039 | |
19070062 | 1040 | static int method_cancel_job(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1041 | Manager *m = userdata; |
1042 | uint32_t id; | |
1043 | Job *j; | |
1044 | int r; | |
ea430986 | 1045 | |
718db961 LP |
1046 | assert(message); |
1047 | assert(m); | |
ea430986 | 1048 | |
718db961 LP |
1049 | r = sd_bus_message_read(message, "u", &id); |
1050 | if (r < 0) | |
ebcf1f97 | 1051 | return r; |
ea430986 | 1052 | |
718db961 LP |
1053 | j = manager_get_job(m, id); |
1054 | if (!j) | |
ebcf1f97 | 1055 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); |
ea430986 | 1056 | |
19070062 | 1057 | return bus_job_method_cancel(message, j, error); |
718db961 | 1058 | } |
c1e1601e | 1059 | |
19070062 | 1060 | static int method_clear_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1061 | Manager *m = userdata; |
ebcf1f97 | 1062 | int r; |
c1e1601e | 1063 | |
718db961 LP |
1064 | assert(message); |
1065 | assert(m); | |
c1e1601e | 1066 | |
1d22e906 | 1067 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1068 | if (r < 0) |
1069 | return r; | |
1070 | ||
1d22e906 LP |
1071 | r = bus_verify_manage_units_async(m, message, error); |
1072 | if (r < 0) | |
1073 | return r; | |
1074 | if (r == 0) | |
1075 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1076 | ||
718db961 | 1077 | manager_clear_jobs(m); |
c1e1601e | 1078 | |
df2d202e | 1079 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1080 | } |
c1e1601e | 1081 | |
19070062 | 1082 | static int method_reset_failed(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1083 | Manager *m = userdata; |
ebcf1f97 | 1084 | int r; |
cad45ba1 | 1085 | |
718db961 LP |
1086 | assert(message); |
1087 | assert(m); | |
1088 | ||
8a188de9 | 1089 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1090 | if (r < 0) |
1091 | return r; | |
1092 | ||
1d22e906 LP |
1093 | r = bus_verify_manage_units_async(m, message, error); |
1094 | if (r < 0) | |
1095 | return r; | |
1096 | if (r == 0) | |
1097 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1098 | ||
718db961 | 1099 | manager_reset_failed(m); |
c1e1601e | 1100 | |
df2d202e | 1101 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1102 | } |
c1e1601e | 1103 | |
313fe66f | 1104 | static int list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *error, char **states, char **patterns) { |
4afd3348 | 1105 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
718db961 LP |
1106 | Manager *m = userdata; |
1107 | const char *k; | |
1108 | Iterator i; | |
1109 | Unit *u; | |
1110 | int r; | |
c1e1601e | 1111 | |
718db961 LP |
1112 | assert(message); |
1113 | assert(m); | |
b152adec | 1114 | |
283868e1 SW |
1115 | /* Anyone can call this method */ |
1116 | ||
8a188de9 | 1117 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1118 | if (r < 0) |
1119 | return r; | |
cad45ba1 | 1120 | |
df2d202e | 1121 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1122 | if (r < 0) |
ebcf1f97 | 1123 | return r; |
b152adec | 1124 | |
718db961 LP |
1125 | r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)"); |
1126 | if (r < 0) | |
ebcf1f97 | 1127 | return r; |
b152adec | 1128 | |
718db961 | 1129 | HASHMAP_FOREACH_KEY(u, k, m->units, i) { |
718db961 LP |
1130 | if (k != u->id) |
1131 | continue; | |
b152adec | 1132 | |
cdc06ed7 DS |
1133 | if (!strv_isempty(states) && |
1134 | !strv_contains(states, unit_load_state_to_string(u->load_state)) && | |
1135 | !strv_contains(states, unit_active_state_to_string(unit_active_state(u))) && | |
1136 | !strv_contains(states, unit_sub_state_to_string(u))) | |
1137 | continue; | |
1138 | ||
313fe66f | 1139 | if (!strv_isempty(patterns) && |
1140 | !strv_fnmatch_or_empty(patterns, u->id, FNM_NOESCAPE)) | |
1141 | continue; | |
1142 | ||
6900c740 | 1143 | r = reply_unit_info(reply, u); |
718db961 | 1144 | if (r < 0) |
ebcf1f97 | 1145 | return r; |
718db961 | 1146 | } |
4139c1b2 | 1147 | |
718db961 LP |
1148 | r = sd_bus_message_close_container(reply); |
1149 | if (r < 0) | |
ebcf1f97 | 1150 | return r; |
cad45ba1 | 1151 | |
9030ca46 | 1152 | return sd_bus_send(NULL, reply, NULL); |
718db961 | 1153 | } |
4139c1b2 | 1154 | |
19070062 | 1155 | static int method_list_units(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
313fe66f | 1156 | return list_units_filtered(message, userdata, error, NULL, NULL); |
cdc06ed7 DS |
1157 | } |
1158 | ||
19070062 | 1159 | static int method_list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
cdc06ed7 DS |
1160 | _cleanup_strv_free_ char **states = NULL; |
1161 | int r; | |
1162 | ||
1163 | r = sd_bus_message_read_strv(message, &states); | |
1164 | if (r < 0) | |
1165 | return r; | |
1166 | ||
313fe66f | 1167 | return list_units_filtered(message, userdata, error, states, NULL); |
1168 | } | |
1169 | ||
1170 | static int method_list_units_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1171 | _cleanup_strv_free_ char **states = NULL; | |
1172 | _cleanup_strv_free_ char **patterns = NULL; | |
1173 | int r; | |
1174 | ||
1175 | r = sd_bus_message_read_strv(message, &states); | |
1176 | if (r < 0) | |
1177 | return r; | |
1178 | ||
1179 | r = sd_bus_message_read_strv(message, &patterns); | |
1180 | if (r < 0) | |
1181 | return r; | |
1182 | ||
1183 | return list_units_filtered(message, userdata, error, states, patterns); | |
cdc06ed7 DS |
1184 | } |
1185 | ||
19070062 | 1186 | static int method_list_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
4afd3348 | 1187 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
718db961 LP |
1188 | Manager *m = userdata; |
1189 | Iterator i; | |
1190 | Job *j; | |
1191 | int r; | |
4139c1b2 | 1192 | |
718db961 LP |
1193 | assert(message); |
1194 | assert(m); | |
1195 | ||
283868e1 SW |
1196 | /* Anyone can call this method */ |
1197 | ||
8a188de9 | 1198 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1199 | if (r < 0) |
1200 | return r; | |
718db961 | 1201 | |
df2d202e | 1202 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1203 | if (r < 0) |
ebcf1f97 | 1204 | return r; |
718db961 LP |
1205 | |
1206 | r = sd_bus_message_open_container(reply, 'a', "(usssoo)"); | |
1207 | if (r < 0) | |
ebcf1f97 | 1208 | return r; |
718db961 LP |
1209 | |
1210 | HASHMAP_FOREACH(j, m->jobs, i) { | |
1211 | _cleanup_free_ char *unit_path = NULL, *job_path = NULL; | |
1212 | ||
1213 | job_path = job_dbus_path(j); | |
1214 | if (!job_path) | |
ebcf1f97 | 1215 | return -ENOMEM; |
718db961 LP |
1216 | |
1217 | unit_path = unit_dbus_path(j->unit); | |
1218 | if (!unit_path) | |
ebcf1f97 | 1219 | return -ENOMEM; |
718db961 LP |
1220 | |
1221 | r = sd_bus_message_append( | |
1222 | reply, "(usssoo)", | |
1223 | j->id, | |
1302759d | 1224 | j->unit->id, |
718db961 | 1225 | job_type_to_string(j->type), |
1302759d | 1226 | job_state_to_string(j->state), |
718db961 LP |
1227 | job_path, |
1228 | unit_path); | |
cad45ba1 | 1229 | if (r < 0) |
ebcf1f97 | 1230 | return r; |
718db961 | 1231 | } |
5dd9014f | 1232 | |
718db961 LP |
1233 | r = sd_bus_message_close_container(reply); |
1234 | if (r < 0) | |
ebcf1f97 | 1235 | return r; |
5dd9014f | 1236 | |
9030ca46 | 1237 | return sd_bus_send(NULL, reply, NULL); |
718db961 | 1238 | } |
5dd9014f | 1239 | |
19070062 | 1240 | static int method_subscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1241 | Manager *m = userdata; |
1242 | int r; | |
5dd9014f | 1243 | |
718db961 LP |
1244 | assert(message); |
1245 | assert(m); | |
ea430986 | 1246 | |
283868e1 SW |
1247 | /* Anyone can call this method */ |
1248 | ||
8a188de9 | 1249 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1250 | if (r < 0) |
1251 | return r; | |
cad45ba1 | 1252 | |
19070062 | 1253 | if (sd_bus_message_get_bus(message) == m->api_bus) { |
8f8f05a9 LP |
1254 | |
1255 | /* Note that direct bus connection subscribe by | |
1256 | * default, we only track peers on the API bus here */ | |
1257 | ||
1258 | if (!m->subscribed) { | |
19070062 | 1259 | r = sd_bus_track_new(sd_bus_message_get_bus(message), &m->subscribed, NULL, NULL); |
8f8f05a9 LP |
1260 | if (r < 0) |
1261 | return r; | |
1262 | } | |
1263 | ||
1264 | r = sd_bus_track_add_sender(m->subscribed, message); | |
1265 | if (r < 0) | |
1266 | return r; | |
1267 | if (r == 0) | |
1268 | return sd_bus_error_setf(error, BUS_ERROR_ALREADY_SUBSCRIBED, "Client is already subscribed."); | |
1269 | } | |
ea430986 | 1270 | |
df2d202e | 1271 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1272 | } |
ea430986 | 1273 | |
19070062 | 1274 | static int method_unsubscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1275 | Manager *m = userdata; |
1276 | int r; | |
ea430986 | 1277 | |
718db961 LP |
1278 | assert(message); |
1279 | assert(m); | |
ea430986 | 1280 | |
283868e1 SW |
1281 | /* Anyone can call this method */ |
1282 | ||
8a188de9 | 1283 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1284 | if (r < 0) |
1285 | return r; | |
ea430986 | 1286 | |
19070062 | 1287 | if (sd_bus_message_get_bus(message) == m->api_bus) { |
8f8f05a9 LP |
1288 | r = sd_bus_track_remove_sender(m->subscribed, message); |
1289 | if (r < 0) | |
1290 | return r; | |
1291 | if (r == 0) | |
1292 | return sd_bus_error_setf(error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed."); | |
1293 | } | |
ea430986 | 1294 | |
df2d202e | 1295 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1296 | } |
ea430986 | 1297 | |
19070062 | 1298 | static int method_dump(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1299 | _cleanup_free_ char *dump = NULL; |
718db961 | 1300 | Manager *m = userdata; |
ebcf1f97 | 1301 | int r; |
ea430986 | 1302 | |
718db961 LP |
1303 | assert(message); |
1304 | assert(m); | |
ea430986 | 1305 | |
283868e1 SW |
1306 | /* Anyone can call this method */ |
1307 | ||
8a188de9 | 1308 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1309 | if (r < 0) |
1310 | return r; | |
ea430986 | 1311 | |
713f6f90 | 1312 | r = manager_get_dump_string(m, &dump); |
dacd6cee LP |
1313 | if (r < 0) |
1314 | return r; | |
a16e1123 | 1315 | |
df2d202e | 1316 | return sd_bus_reply_method_return(message, "s", dump); |
718db961 | 1317 | } |
cad45ba1 | 1318 | |
36b4a7ba ZJS |
1319 | static int method_refuse_snapshot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1320 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Support for snapshots has been removed."); | |
718db961 | 1321 | } |
cad45ba1 | 1322 | |
ae57dad3 LP |
1323 | static int verify_run_space(const char *message, sd_bus_error *error) { |
1324 | struct statvfs svfs; | |
1325 | uint64_t available; | |
1326 | ||
1327 | if (statvfs("/run/systemd", &svfs) < 0) | |
1328 | return sd_bus_error_set_errnof(error, errno, "Failed to statvfs(/run/systemd): %m"); | |
1329 | ||
1330 | available = (uint64_t) svfs.f_bfree * (uint64_t) svfs.f_bsize; | |
1331 | ||
1332 | if (available < RELOAD_DISK_SPACE_MIN) { | |
1333 | char fb_available[FORMAT_BYTES_MAX], fb_need[FORMAT_BYTES_MAX]; | |
1334 | return sd_bus_error_setf(error, | |
1335 | BUS_ERROR_DISK_FULL, | |
1336 | "%s, not enough space available on /run/systemd. " | |
1337 | "Currently, %s are free, but a safety buffer of %s is enforced.", | |
1338 | message, | |
1339 | format_bytes(fb_available, sizeof(fb_available), available), | |
1340 | format_bytes(fb_need, sizeof(fb_need), RELOAD_DISK_SPACE_MIN)); | |
1341 | } | |
1342 | ||
1343 | return 0; | |
1344 | } | |
1345 | ||
1346 | int verify_run_space_and_log(const char *message) { | |
4dae8ae6 | 1347 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
ae57dad3 LP |
1348 | int r; |
1349 | ||
1350 | r = verify_run_space(message, &error); | |
1351 | if (r < 0) | |
1352 | log_error_errno(r, "%s", bus_error_message(&error, r)); | |
1353 | ||
1354 | return r; | |
1355 | } | |
1356 | ||
19070062 | 1357 | static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1358 | Manager *m = userdata; |
1359 | int r; | |
6652a2b9 | 1360 | |
718db961 LP |
1361 | assert(message); |
1362 | assert(m); | |
6652a2b9 | 1363 | |
ae57dad3 LP |
1364 | r = verify_run_space("Refusing to reload", error); |
1365 | if (r < 0) | |
1366 | return r; | |
1367 | ||
1d22e906 | 1368 | r = mac_selinux_access_check(message, "reload", error); |
283868e1 SW |
1369 | if (r < 0) |
1370 | return r; | |
283868e1 | 1371 | |
1d22e906 | 1372 | r = bus_verify_reload_daemon_async(m, message, error); |
ebcf1f97 LP |
1373 | if (r < 0) |
1374 | return r; | |
1d22e906 LP |
1375 | if (r == 0) |
1376 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
6652a2b9 | 1377 | |
718db961 LP |
1378 | /* Instead of sending the reply back right away, we just |
1379 | * remember that we need to and then send it after the reload | |
1380 | * is finished. That way the caller knows when the reload | |
1381 | * finished. */ | |
6652a2b9 | 1382 | |
718db961 | 1383 | assert(!m->queued_message); |
df2d202e | 1384 | r = sd_bus_message_new_method_return(message, &m->queued_message); |
718db961 | 1385 | if (r < 0) |
ebcf1f97 | 1386 | return r; |
cad45ba1 | 1387 | |
718db961 | 1388 | m->exit_code = MANAGER_RELOAD; |
6652a2b9 | 1389 | |
718db961 LP |
1390 | return 1; |
1391 | } | |
6652a2b9 | 1392 | |
19070062 | 1393 | static int method_reexecute(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1394 | Manager *m = userdata; |
ebcf1f97 | 1395 | int r; |
6652a2b9 | 1396 | |
718db961 LP |
1397 | assert(message); |
1398 | assert(m); | |
6652a2b9 | 1399 | |
ae57dad3 LP |
1400 | r = verify_run_space("Refusing to reexecute", error); |
1401 | if (r < 0) | |
1402 | return r; | |
1403 | ||
1d22e906 | 1404 | r = mac_selinux_access_check(message, "reload", error); |
283868e1 SW |
1405 | if (r < 0) |
1406 | return r; | |
283868e1 | 1407 | |
1d22e906 | 1408 | r = bus_verify_reload_daemon_async(m, message, error); |
ebcf1f97 LP |
1409 | if (r < 0) |
1410 | return r; | |
1d22e906 LP |
1411 | if (r == 0) |
1412 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
cad45ba1 | 1413 | |
718db961 LP |
1414 | /* We don't send a reply back here, the client should |
1415 | * just wait for us disconnecting. */ | |
6652a2b9 | 1416 | |
718db961 LP |
1417 | m->exit_code = MANAGER_REEXECUTE; |
1418 | return 1; | |
1419 | } | |
6652a2b9 | 1420 | |
19070062 | 1421 | static int method_exit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1422 | Manager *m = userdata; |
ebcf1f97 | 1423 | int r; |
6652a2b9 | 1424 | |
718db961 LP |
1425 | assert(message); |
1426 | assert(m); | |
6652a2b9 | 1427 | |
8a188de9 | 1428 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1429 | if (r < 0) |
1430 | return r; | |
cad45ba1 | 1431 | |
287419c1 AC |
1432 | /* Exit() (in contrast to SetExitCode()) is actually allowed even if |
1433 | * we are running on the host. It will fall back on reboot() in | |
1434 | * systemd-shutdown if it cannot do the exit() because it isn't a | |
1435 | * container. */ | |
6652a2b9 | 1436 | |
718db961 | 1437 | m->exit_code = MANAGER_EXIT; |
6652a2b9 | 1438 | |
df2d202e | 1439 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1440 | } |
6652a2b9 | 1441 | |
19070062 | 1442 | static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1443 | Manager *m = userdata; |
ebcf1f97 | 1444 | int r; |
664f88a7 | 1445 | |
718db961 LP |
1446 | assert(message); |
1447 | assert(m); | |
cad45ba1 | 1448 | |
8a188de9 | 1449 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1450 | if (r < 0) |
1451 | return r; | |
664f88a7 | 1452 | |
463d0d15 | 1453 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1454 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers."); |
664f88a7 | 1455 | |
718db961 | 1456 | m->exit_code = MANAGER_REBOOT; |
664f88a7 | 1457 | |
df2d202e | 1458 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1459 | } |
664f88a7 | 1460 | |
19070062 | 1461 | static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1462 | Manager *m = userdata; |
ebcf1f97 | 1463 | int r; |
50913bc0 | 1464 | |
718db961 LP |
1465 | assert(message); |
1466 | assert(m); | |
1137a57c | 1467 | |
8a188de9 | 1468 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1469 | if (r < 0) |
1470 | return r; | |
1137a57c | 1471 | |
463d0d15 | 1472 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1473 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers."); |
1137a57c | 1474 | |
718db961 | 1475 | m->exit_code = MANAGER_POWEROFF; |
1137a57c | 1476 | |
df2d202e | 1477 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1478 | } |
1137a57c | 1479 | |
19070062 | 1480 | static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1481 | Manager *m = userdata; |
ebcf1f97 | 1482 | int r; |
1137a57c | 1483 | |
718db961 LP |
1484 | assert(message); |
1485 | assert(m); | |
8d0e38a2 | 1486 | |
8a188de9 | 1487 | r = mac_selinux_access_check(message, "halt", error); |
ebcf1f97 LP |
1488 | if (r < 0) |
1489 | return r; | |
cad45ba1 | 1490 | |
463d0d15 | 1491 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1492 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Halt is only supported for system managers."); |
8d0e38a2 | 1493 | |
718db961 | 1494 | m->exit_code = MANAGER_HALT; |
8d0e38a2 | 1495 | |
df2d202e | 1496 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1497 | } |
8d0e38a2 | 1498 | |
19070062 | 1499 | static int method_kexec(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 | 1500 | Manager *m = userdata; |
ebcf1f97 | 1501 | int r; |
8d0e38a2 | 1502 | |
718db961 LP |
1503 | assert(message); |
1504 | assert(m); | |
c0576cd6 | 1505 | |
8a188de9 | 1506 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1507 | if (r < 0) |
1508 | return r; | |
cad45ba1 | 1509 | |
463d0d15 | 1510 | if (!MANAGER_IS_SYSTEM(m)) |
ebcf1f97 | 1511 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers."); |
c0576cd6 | 1512 | |
718db961 | 1513 | m->exit_code = MANAGER_KEXEC; |
c0576cd6 | 1514 | |
df2d202e | 1515 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1516 | } |
c0576cd6 | 1517 | |
19070062 | 1518 | static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1519 | char *ri = NULL, *rt = NULL; |
1520 | const char *root, *init; | |
1521 | Manager *m = userdata; | |
ae57dad3 LP |
1522 | struct statvfs svfs; |
1523 | uint64_t available; | |
718db961 | 1524 | int r; |
c0576cd6 | 1525 | |
718db961 LP |
1526 | assert(message); |
1527 | assert(m); | |
c0576cd6 | 1528 | |
ae57dad3 LP |
1529 | if (statvfs("/run/systemd", &svfs) < 0) |
1530 | return sd_bus_error_set_errnof(error, errno, "Failed to statvfs(/run/systemd): %m"); | |
1531 | ||
1532 | available = (uint64_t) svfs.f_bfree * (uint64_t) svfs.f_bsize; | |
1533 | ||
1534 | if (available < RELOAD_DISK_SPACE_MIN) { | |
1535 | char fb_available[FORMAT_BYTES_MAX], fb_need[FORMAT_BYTES_MAX]; | |
1536 | log_warning("Dangerously low amount of free space on /run/systemd, root switching operation might not complete successfuly. " | |
1537 | "Currently, %s are free, but %s are suggested. Proceeding anyway.", | |
1538 | format_bytes(fb_available, sizeof(fb_available), available), | |
1539 | format_bytes(fb_need, sizeof(fb_need), RELOAD_DISK_SPACE_MIN)); | |
1540 | } | |
1541 | ||
8a188de9 | 1542 | r = mac_selinux_access_check(message, "reboot", error); |
ebcf1f97 LP |
1543 | if (r < 0) |
1544 | return r; | |
c0576cd6 | 1545 | |
463d0d15 | 1546 | if (!MANAGER_IS_SYSTEM(m)) |
6ad3b2b6 | 1547 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Root switching is only supported by system manager."); |
c0576cd6 | 1548 | |
718db961 LP |
1549 | r = sd_bus_message_read(message, "ss", &root, &init); |
1550 | if (r < 0) | |
ebcf1f97 | 1551 | return r; |
c0576cd6 | 1552 | |
710028b4 LP |
1553 | if (isempty(root)) |
1554 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "New root directory may not be the empty string."); | |
1555 | if (!path_is_absolute(root)) | |
1556 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "New root path '%s' is not absolute.", root); | |
1557 | if (path_equal(root, "/")) | |
1558 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "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) | |
1564 | return sd_bus_error_set_errnof(error, r, "Failed to determine whether root path '%s' contains an OS tree: %m", root); | |
1565 | if (r == 0) | |
1566 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified switch root path '%s' does not seem to be an OS tree. os-release file is missing.", root); | |
718db961 | 1567 | } else { |
710028b4 | 1568 | _cleanup_free_ char *chased = NULL; |
c0576cd6 | 1569 | |
718db961 | 1570 | if (!path_is_absolute(init)) |
710028b4 | 1571 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path to init binary '%s' not absolute.", init); |
c0576cd6 | 1572 | |
62570f6f | 1573 | r = chase_symlinks(init, root, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &chased); |
710028b4 LP |
1574 | if (r < 0) |
1575 | return sd_bus_error_set_errnof(error, r, "Could not resolve init executable %s: %m", init); | |
1576 | ||
1577 | if (laccess(chased, X_OK) < 0) { | |
1578 | if (errno == EACCES) | |
1579 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Init binary %s is not executable.", init); | |
c0576cd6 | 1580 | |
710028b4 LP |
1581 | return sd_bus_error_set_errnof(error, r, "Could not check whether init binary %s is executable: %m", init); |
1582 | } | |
718db961 LP |
1583 | } |
1584 | ||
1585 | rt = strdup(root); | |
1586 | if (!rt) | |
ebcf1f97 | 1587 | return -ENOMEM; |
718db961 LP |
1588 | |
1589 | if (!isempty(init)) { | |
1590 | ri = strdup(init); | |
1591 | if (!ri) { | |
92b315df | 1592 | free(rt); |
ebcf1f97 | 1593 | return -ENOMEM; |
c0576cd6 | 1594 | } |
718db961 | 1595 | } |
c0576cd6 | 1596 | |
718db961 LP |
1597 | free(m->switch_root); |
1598 | m->switch_root = rt; | |
c0576cd6 | 1599 | |
718db961 LP |
1600 | free(m->switch_root_init); |
1601 | m->switch_root_init = ri; | |
c0576cd6 | 1602 | |
92b315df LP |
1603 | m->exit_code = MANAGER_SWITCH_ROOT; |
1604 | ||
df2d202e | 1605 | return sd_bus_reply_method_return(message, NULL); |
718db961 | 1606 | } |
c0576cd6 | 1607 | |
19070062 | 1608 | static int method_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1609 | _cleanup_strv_free_ char **plus = NULL; |
1610 | Manager *m = userdata; | |
1611 | int r; | |
c0576cd6 | 1612 | |
718db961 LP |
1613 | assert(message); |
1614 | assert(m); | |
cad45ba1 | 1615 | |
8a188de9 | 1616 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1617 | if (r < 0) |
1618 | return r; | |
c0576cd6 | 1619 | |
718db961 LP |
1620 | r = sd_bus_message_read_strv(message, &plus); |
1621 | if (r < 0) | |
ebcf1f97 | 1622 | return r; |
718db961 | 1623 | if (!strv_env_is_valid(plus)) |
ebcf1f97 | 1624 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments"); |
c0576cd6 | 1625 | |
1d22e906 LP |
1626 | r = bus_verify_set_environment_async(m, message, error); |
1627 | if (r < 0) | |
1628 | return r; | |
1629 | if (r == 0) | |
1630 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1631 | ||
718db961 LP |
1632 | r = manager_environment_add(m, NULL, plus); |
1633 | if (r < 0) | |
ebcf1f97 | 1634 | return r; |
c0576cd6 | 1635 | |
df2d202e | 1636 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1637 | } |
1638 | ||
19070062 | 1639 | static int method_unset_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1640 | _cleanup_strv_free_ char **minus = NULL; |
1641 | Manager *m = userdata; | |
1642 | int r; | |
1643 | ||
718db961 LP |
1644 | assert(message); |
1645 | assert(m); | |
1646 | ||
8a188de9 | 1647 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1648 | if (r < 0) |
1649 | return r; | |
c0576cd6 | 1650 | |
718db961 LP |
1651 | r = sd_bus_message_read_strv(message, &minus); |
1652 | if (r < 0) | |
ebcf1f97 | 1653 | return r; |
718db961 LP |
1654 | |
1655 | if (!strv_env_name_or_assignment_is_valid(minus)) | |
ebcf1f97 | 1656 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments"); |
718db961 | 1657 | |
1d22e906 LP |
1658 | r = bus_verify_set_environment_async(m, message, error); |
1659 | if (r < 0) | |
1660 | return r; | |
1661 | if (r == 0) | |
1662 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1663 | ||
718db961 LP |
1664 | r = manager_environment_add(m, minus, NULL); |
1665 | if (r < 0) | |
ebcf1f97 | 1666 | return r; |
718db961 | 1667 | |
df2d202e | 1668 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1669 | } |
1670 | ||
19070062 | 1671 | static int method_unset_and_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1672 | _cleanup_strv_free_ char **minus = NULL, **plus = NULL; |
1673 | Manager *m = userdata; | |
1674 | int r; | |
1675 | ||
718db961 LP |
1676 | assert(message); |
1677 | assert(m); | |
1678 | ||
8a188de9 | 1679 | r = mac_selinux_access_check(message, "reload", error); |
ebcf1f97 LP |
1680 | if (r < 0) |
1681 | return r; | |
718db961 | 1682 | |
eb6c7d20 | 1683 | r = sd_bus_message_read_strv(message, &minus); |
718db961 | 1684 | if (r < 0) |
ebcf1f97 | 1685 | return r; |
718db961 | 1686 | |
eb6c7d20 | 1687 | r = sd_bus_message_read_strv(message, &plus); |
718db961 | 1688 | if (r < 0) |
ebcf1f97 | 1689 | return r; |
718db961 | 1690 | |
718db961 | 1691 | if (!strv_env_name_or_assignment_is_valid(minus)) |
ebcf1f97 | 1692 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments"); |
eb6c7d20 ZJS |
1693 | if (!strv_env_is_valid(plus)) |
1694 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments"); | |
718db961 | 1695 | |
1d22e906 LP |
1696 | r = bus_verify_set_environment_async(m, message, error); |
1697 | if (r < 0) | |
1698 | return r; | |
1699 | if (r == 0) | |
1700 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
1701 | ||
718db961 LP |
1702 | r = manager_environment_add(m, minus, plus); |
1703 | if (r < 0) | |
ebcf1f97 | 1704 | return r; |
718db961 | 1705 | |
df2d202e | 1706 | return sd_bus_reply_method_return(message, NULL); |
718db961 LP |
1707 | } |
1708 | ||
287419c1 | 1709 | static int method_set_exit_code(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
287419c1 | 1710 | Manager *m = userdata; |
29206d46 | 1711 | uint8_t code; |
287419c1 AC |
1712 | int r; |
1713 | ||
1714 | assert(message); | |
1715 | assert(m); | |
1716 | ||
1717 | r = mac_selinux_access_check(message, "exit", error); | |
1718 | if (r < 0) | |
1719 | return r; | |
1720 | ||
1721 | r = sd_bus_message_read_basic(message, 'y', &code); | |
1722 | if (r < 0) | |
1723 | return r; | |
1724 | ||
463d0d15 | 1725 | if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0) |
287419c1 AC |
1726 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "ExitCode can only be set for user service managers or in containers."); |
1727 | ||
1728 | m->return_value = code; | |
1729 | ||
1730 | return sd_bus_reply_method_return(message, NULL); | |
1731 | } | |
1732 | ||
29206d46 LP |
1733 | static int method_lookup_dynamic_user_by_name(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1734 | Manager *m = userdata; | |
1735 | const char *name; | |
1736 | uid_t uid; | |
1737 | int r; | |
1738 | ||
1739 | assert(message); | |
1740 | assert(m); | |
1741 | ||
1742 | r = sd_bus_message_read_basic(message, 's', &name); | |
1743 | if (r < 0) | |
1744 | return r; | |
1745 | ||
1746 | if (!MANAGER_IS_SYSTEM(m)) | |
1747 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Dynamic users are only supported in the system instance."); | |
1748 | if (!valid_user_group_name(name)) | |
1749 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "User name invalid: %s", name); | |
1750 | ||
1751 | r = dynamic_user_lookup_name(m, name, &uid); | |
1752 | if (r == -ESRCH) | |
1753 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, "Dynamic user %s does not exist.", name); | |
1754 | if (r < 0) | |
1755 | return r; | |
1756 | ||
1757 | return sd_bus_reply_method_return(message, "u", (uint32_t) uid); | |
1758 | } | |
1759 | ||
1760 | static int method_lookup_dynamic_user_by_uid(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1761 | _cleanup_free_ char *name = NULL; | |
1762 | Manager *m = userdata; | |
1763 | uid_t uid; | |
1764 | int r; | |
1765 | ||
1766 | assert(message); | |
1767 | assert(m); | |
1768 | ||
1769 | assert_cc(sizeof(uid) == sizeof(uint32_t)); | |
1770 | r = sd_bus_message_read_basic(message, 'u', &uid); | |
1771 | if (r < 0) | |
1772 | return r; | |
1773 | ||
1774 | if (!MANAGER_IS_SYSTEM(m)) | |
1775 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Dynamic users are only supported in the system instance."); | |
1776 | if (!uid_is_valid(uid)) | |
1777 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "User ID invalid: " UID_FMT, uid); | |
1778 | ||
1779 | r = dynamic_user_lookup_uid(m, uid, &name); | |
1780 | if (r == -ESRCH) | |
1781 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, "Dynamic user ID " UID_FMT " does not exist.", uid); | |
1782 | if (r < 0) | |
1783 | return r; | |
1784 | ||
1785 | return sd_bus_reply_method_return(message, "s", name); | |
1786 | } | |
1787 | ||
f9bfa696 YW |
1788 | static int method_get_dynamic_users(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1789 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
1790 | Manager *m = userdata; | |
1791 | DynamicUser *d; | |
1792 | Iterator i; | |
1793 | int r; | |
1794 | ||
1795 | assert(message); | |
1796 | assert(m); | |
1797 | ||
1798 | assert_cc(sizeof(uid_t) == sizeof(uint32_t)); | |
1799 | ||
1800 | if (!MANAGER_IS_SYSTEM(m)) | |
1801 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Dynamic users are only supported in the system instance."); | |
1802 | ||
1803 | r = sd_bus_message_new_method_return(message, &reply); | |
1804 | if (r < 0) | |
1805 | return r; | |
1806 | ||
1807 | r = sd_bus_message_open_container(reply, 'a', "(us)"); | |
1808 | if (r < 0) | |
1809 | return r; | |
1810 | ||
1811 | HASHMAP_FOREACH(d, m->dynamic_users, i) { | |
1812 | uid_t uid; | |
1813 | ||
1814 | r = dynamic_user_current(d, &uid); | |
1815 | if (r == -EAGAIN) /* not realized yet? */ | |
1816 | continue; | |
1817 | if (r < 0) | |
1818 | return sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "Failed to lookup a dynamic user."); | |
1819 | ||
1820 | r = sd_bus_message_append(reply, "(us)", uid, d->name); | |
1821 | if (r < 0) | |
1822 | return r; | |
1823 | } | |
1824 | ||
1825 | r = sd_bus_message_close_container(reply); | |
1826 | if (r < 0) | |
1827 | return r; | |
1828 | ||
1829 | return sd_bus_send(NULL, reply, NULL); | |
1830 | } | |
1831 | ||
313fe66f | 1832 | static int list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error, char **states, char **patterns) { |
4afd3348 | 1833 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
718db961 LP |
1834 | Manager *m = userdata; |
1835 | UnitFileList *item; | |
1836 | Hashmap *h; | |
1837 | Iterator i; | |
1838 | int r; | |
1839 | ||
718db961 LP |
1840 | assert(message); |
1841 | assert(m); | |
1842 | ||
283868e1 SW |
1843 | /* Anyone can call this method */ |
1844 | ||
8a188de9 | 1845 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1846 | if (r < 0) |
1847 | return r; | |
718db961 | 1848 | |
df2d202e | 1849 | r = sd_bus_message_new_method_return(message, &reply); |
718db961 | 1850 | if (r < 0) |
ebcf1f97 | 1851 | return r; |
c0576cd6 | 1852 | |
d5099efc | 1853 | h = hashmap_new(&string_hash_ops); |
718db961 | 1854 | if (!h) |
ebcf1f97 | 1855 | return -ENOMEM; |
c0576cd6 | 1856 | |
313fe66f | 1857 | r = unit_file_get_list(m->unit_file_scope, NULL, h, states, patterns); |
ebcf1f97 | 1858 | if (r < 0) |
718db961 | 1859 | goto fail; |
718db961 LP |
1860 | |
1861 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); | |
ebcf1f97 | 1862 | if (r < 0) |
718db961 | 1863 | goto fail; |
718db961 LP |
1864 | |
1865 | HASHMAP_FOREACH(item, h, i) { | |
1866 | ||
1867 | r = sd_bus_message_append(reply, "(ss)", item->path, unit_file_state_to_string(item->state)); | |
ebcf1f97 | 1868 | if (r < 0) |
718db961 | 1869 | goto fail; |
718db961 | 1870 | } |
c0576cd6 | 1871 | |
718db961 | 1872 | unit_file_list_free(h); |
c0576cd6 | 1873 | |
718db961 LP |
1874 | r = sd_bus_message_close_container(reply); |
1875 | if (r < 0) | |
ebcf1f97 | 1876 | return r; |
8d0e38a2 | 1877 | |
9030ca46 | 1878 | return sd_bus_send(NULL, reply, NULL); |
99504dd4 | 1879 | |
718db961 LP |
1880 | fail: |
1881 | unit_file_list_free(h); | |
1882 | return r; | |
1883 | } | |
99504dd4 | 1884 | |
313fe66f | 1885 | static int method_list_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
1886 | return list_unit_files_by_patterns(message, userdata, error, NULL, NULL); | |
1887 | } | |
1888 | ||
1889 | static int method_list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
1890 | _cleanup_strv_free_ char **states = NULL; | |
1891 | _cleanup_strv_free_ char **patterns = NULL; | |
1892 | int r; | |
1893 | ||
1894 | r = sd_bus_message_read_strv(message, &states); | |
1895 | if (r < 0) | |
1896 | return r; | |
1897 | ||
1898 | r = sd_bus_message_read_strv(message, &patterns); | |
1899 | if (r < 0) | |
1900 | return r; | |
1901 | ||
1902 | return list_unit_files_by_patterns(message, userdata, error, states, patterns); | |
1903 | } | |
1904 | ||
19070062 | 1905 | static int method_get_unit_file_state(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1906 | Manager *m = userdata; |
1907 | const char *name; | |
1908 | UnitFileState state; | |
718db961 | 1909 | int r; |
99504dd4 | 1910 | |
718db961 LP |
1911 | assert(message); |
1912 | assert(m); | |
8e2af478 | 1913 | |
283868e1 SW |
1914 | /* Anyone can call this method */ |
1915 | ||
8a188de9 | 1916 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1917 | if (r < 0) |
1918 | return r; | |
8e2af478 | 1919 | |
718db961 LP |
1920 | r = sd_bus_message_read(message, "s", &name); |
1921 | if (r < 0) | |
ebcf1f97 | 1922 | return r; |
8e2af478 | 1923 | |
463d0d15 | 1924 | r = unit_file_get_state(m->unit_file_scope, NULL, name, &state); |
0ec0deaa LP |
1925 | if (r < 0) |
1926 | return r; | |
8e2af478 | 1927 | |
df2d202e | 1928 | return sd_bus_reply_method_return(message, "s", unit_file_state_to_string(state)); |
718db961 | 1929 | } |
8e2af478 | 1930 | |
19070062 | 1931 | static int method_get_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
1932 | _cleanup_free_ char *default_target = NULL; |
1933 | Manager *m = userdata; | |
718db961 | 1934 | int r; |
c2756a68 | 1935 | |
718db961 LP |
1936 | assert(message); |
1937 | assert(m); | |
c2756a68 | 1938 | |
283868e1 SW |
1939 | /* Anyone can call this method */ |
1940 | ||
8a188de9 | 1941 | r = mac_selinux_access_check(message, "status", error); |
ebcf1f97 LP |
1942 | if (r < 0) |
1943 | return r; | |
c2756a68 | 1944 | |
463d0d15 | 1945 | r = unit_file_get_default(m->unit_file_scope, NULL, &default_target); |
718db961 | 1946 | if (r < 0) |
ebcf1f97 | 1947 | return r; |
c2756a68 | 1948 | |
df2d202e | 1949 | return sd_bus_reply_method_return(message, "s", default_target); |
718db961 | 1950 | } |
c2756a68 | 1951 | |
8f8f05a9 | 1952 | static int send_unit_files_changed(sd_bus *bus, void *userdata) { |
4afd3348 | 1953 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
1954 | int r; |
1955 | ||
1956 | assert(bus); | |
1957 | ||
151b9b96 | 1958 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged"); |
718db961 LP |
1959 | if (r < 0) |
1960 | return r; | |
1961 | ||
8f8f05a9 | 1962 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
1963 | } |
1964 | ||
af3d8113 ZJS |
1965 | /* Create an error reply, using the error information from changes[] |
1966 | * if possible, and fall back to generating an error from error code c. | |
1967 | * The error message only describes the first error. | |
1968 | * | |
1969 | * Coordinate with unit_file_dump_changes() in install.c. | |
1970 | */ | |
1971 | static int install_error( | |
1972 | sd_bus_error *error, | |
1973 | int c, | |
1974 | UnitFileChange *changes, | |
1975 | unsigned n_changes) { | |
1976 | int r; | |
1977 | unsigned i; | |
8e20adca | 1978 | |
af3d8113 | 1979 | for (i = 0; i < n_changes; i++) |
637d6e5b | 1980 | |
af3d8113 | 1981 | switch(changes[i].type) { |
637d6e5b | 1982 | |
af3d8113 ZJS |
1983 | case 0 ... INT_MAX: |
1984 | continue; | |
637d6e5b | 1985 | |
af3d8113 ZJS |
1986 | case -EEXIST: |
1987 | if (changes[i].source) | |
1988 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, | |
1989 | "File %s already exists and is a symlink to %s.", | |
1990 | changes[i].path, changes[i].source); | |
1991 | else | |
1992 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, | |
1993 | "File %s already exists.", | |
1994 | changes[i].path); | |
1995 | goto found; | |
637d6e5b | 1996 | |
af3d8113 ZJS |
1997 | case -ERFKILL: |
1998 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, | |
1999 | "Unit file %s is masked.", changes[i].path); | |
2000 | goto found; | |
637d6e5b | 2001 | |
af3d8113 ZJS |
2002 | case -EADDRNOTAVAIL: |
2003 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_GENERATED, | |
2004 | "Unit %s is transient or generated.", changes[i].path); | |
2005 | goto found; | |
637d6e5b | 2006 | |
af3d8113 ZJS |
2007 | case -ELOOP: |
2008 | r = sd_bus_error_setf(error, BUS_ERROR_UNIT_LINKED, | |
2009 | "Refusing to operate on linked unit file %s", changes[i].path); | |
2010 | goto found; | |
637d6e5b LP |
2011 | |
2012 | case -ENOENT: | |
2013 | r = sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit file %s does not exist.", changes[i].path); | |
2014 | goto found; | |
2015 | ||
af3d8113 ZJS |
2016 | default: |
2017 | r = sd_bus_error_set_errnof(error, changes[i].type, "File %s: %m", changes[i].path); | |
2018 | goto found; | |
2019 | } | |
8e20adca | 2020 | |
637d6e5b LP |
2021 | r = c < 0 ? c : -EINVAL; |
2022 | ||
af3d8113 ZJS |
2023 | found: |
2024 | unit_file_changes_free(changes, n_changes); | |
2025 | return r; | |
8e20adca LP |
2026 | } |
2027 | ||
637d6e5b LP |
2028 | static int reply_unit_file_changes_and_free( |
2029 | Manager *m, | |
2030 | sd_bus_message *message, | |
2031 | int carries_install_info, | |
2032 | UnitFileChange *changes, | |
2033 | unsigned n_changes, | |
2034 | sd_bus_error *error) { | |
2035 | ||
2036 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
2037 | bool bad = false, good = false; | |
2038 | unsigned i; | |
2039 | int r; | |
2040 | ||
2041 | if (unit_file_changes_have_modification(changes, n_changes)) { | |
2042 | r = bus_foreach_bus(m, NULL, send_unit_files_changed, NULL); | |
2043 | if (r < 0) | |
2044 | log_debug_errno(r, "Failed to send UnitFilesChanged signal: %m"); | |
2045 | } | |
2046 | ||
2047 | r = sd_bus_message_new_method_return(message, &reply); | |
2048 | if (r < 0) | |
2049 | goto fail; | |
2050 | ||
2051 | if (carries_install_info >= 0) { | |
2052 | r = sd_bus_message_append(reply, "b", carries_install_info); | |
2053 | if (r < 0) | |
2054 | goto fail; | |
2055 | } | |
2056 | ||
2057 | r = sd_bus_message_open_container(reply, 'a', "(sss)"); | |
2058 | if (r < 0) | |
2059 | goto fail; | |
2060 | ||
2061 | for (i = 0; i < n_changes; i++) { | |
2062 | ||
2063 | if (changes[i].type < 0) { | |
2064 | bad = true; | |
2065 | continue; | |
2066 | } | |
2067 | ||
2068 | r = sd_bus_message_append( | |
2069 | reply, "(sss)", | |
2070 | unit_file_change_type_to_string(changes[i].type), | |
2071 | changes[i].path, | |
2072 | changes[i].source); | |
2073 | if (r < 0) | |
2074 | goto fail; | |
2075 | ||
2076 | good = true; | |
2077 | } | |
2078 | ||
2079 | /* If there was a failed change, and no successful change, then return the first failure as proper method call | |
2080 | * error. */ | |
2081 | if (bad && !good) | |
2082 | return install_error(error, 0, changes, n_changes); | |
2083 | ||
2084 | r = sd_bus_message_close_container(reply); | |
2085 | if (r < 0) | |
2086 | goto fail; | |
2087 | ||
2088 | unit_file_changes_free(changes, n_changes); | |
2089 | return sd_bus_send(NULL, reply, NULL); | |
2090 | ||
2091 | fail: | |
2092 | unit_file_changes_free(changes, n_changes); | |
2093 | return r; | |
2094 | } | |
2095 | ||
718db961 | 2096 | static int method_enable_unit_files_generic( |
718db961 | 2097 | sd_bus_message *message, |
d309c1c3 | 2098 | Manager *m, |
b3796dd8 | 2099 | int (*call)(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, unsigned *n_changes), |
ebcf1f97 LP |
2100 | bool carries_install_info, |
2101 | sd_bus_error *error) { | |
718db961 LP |
2102 | |
2103 | _cleanup_strv_free_ char **l = NULL; | |
2104 | UnitFileChange *changes = NULL; | |
2105 | unsigned n_changes = 0; | |
b3796dd8 | 2106 | UnitFileFlags flags; |
718db961 LP |
2107 | int runtime, force, r; |
2108 | ||
718db961 LP |
2109 | assert(message); |
2110 | assert(m); | |
cad45ba1 | 2111 | |
718db961 LP |
2112 | r = sd_bus_message_read_strv(message, &l); |
2113 | if (r < 0) | |
ebcf1f97 | 2114 | return r; |
90bb85e1 | 2115 | |
d309c1c3 LP |
2116 | r = sd_bus_message_read(message, "bb", &runtime, &force); |
2117 | if (r < 0) | |
2118 | return r; | |
2119 | ||
b3796dd8 JS |
2120 | flags = unit_file_bools_to_flags(runtime, force); |
2121 | ||
1d22e906 LP |
2122 | r = bus_verify_manage_unit_files_async(m, message, error); |
2123 | if (r < 0) | |
2124 | return r; | |
2125 | if (r == 0) | |
2126 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2127 | ||
b3796dd8 | 2128 | r = call(m->unit_file_scope, flags, NULL, l, &changes, &n_changes); |
af3d8113 ZJS |
2129 | if (r < 0) |
2130 | return install_error(error, r, changes, n_changes); | |
718db961 | 2131 | |
637d6e5b | 2132 | return reply_unit_file_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes, error); |
718db961 | 2133 | } |
c87eba54 | 2134 | |
19070062 | 2135 | static int method_enable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2136 | return method_enable_unit_files_generic(message, userdata, unit_file_enable, true, error); |
718db961 | 2137 | } |
ea430986 | 2138 | |
19070062 | 2139 | static int method_reenable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2140 | return method_enable_unit_files_generic(message, userdata, unit_file_reenable, true, error); |
718db961 LP |
2141 | } |
2142 | ||
19070062 | 2143 | static int method_link_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2144 | return method_enable_unit_files_generic(message, userdata, unit_file_link, false, error); |
718db961 LP |
2145 | } |
2146 | ||
b3796dd8 JS |
2147 | static int unit_file_preset_without_mode(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char **files, UnitFileChange **changes, unsigned *n_changes) { |
2148 | return unit_file_preset(scope, flags, root_dir, files, UNIT_FILE_PRESET_FULL, changes, n_changes); | |
d309c1c3 LP |
2149 | } |
2150 | ||
19070062 | 2151 | static int method_preset_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2152 | return method_enable_unit_files_generic(message, userdata, unit_file_preset_without_mode, true, error); |
718db961 LP |
2153 | } |
2154 | ||
19070062 | 2155 | static int method_mask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2156 | return method_enable_unit_files_generic(message, userdata, unit_file_mask, false, error); |
718db961 | 2157 | } |
ea430986 | 2158 | |
19070062 | 2159 | static int method_preset_unit_files_with_mode(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
d309c1c3 LP |
2160 | |
2161 | _cleanup_strv_free_ char **l = NULL; | |
d309c1c3 LP |
2162 | UnitFileChange *changes = NULL; |
2163 | unsigned n_changes = 0; | |
2164 | Manager *m = userdata; | |
2165 | UnitFilePresetMode mm; | |
d309c1c3 | 2166 | int runtime, force, r; |
b3796dd8 | 2167 | UnitFileFlags flags; |
d309c1c3 LP |
2168 | const char *mode; |
2169 | ||
d309c1c3 LP |
2170 | assert(message); |
2171 | assert(m); | |
2172 | ||
2173 | r = sd_bus_message_read_strv(message, &l); | |
2174 | if (r < 0) | |
2175 | return r; | |
2176 | ||
2177 | r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force); | |
2178 | if (r < 0) | |
2179 | return r; | |
2180 | ||
b3796dd8 JS |
2181 | flags = unit_file_bools_to_flags(runtime, force); |
2182 | ||
d309c1c3 LP |
2183 | if (isempty(mode)) |
2184 | mm = UNIT_FILE_PRESET_FULL; | |
2185 | else { | |
2186 | mm = unit_file_preset_mode_from_string(mode); | |
2187 | if (mm < 0) | |
2188 | return -EINVAL; | |
2189 | } | |
2190 | ||
1d22e906 LP |
2191 | r = bus_verify_manage_unit_files_async(m, message, error); |
2192 | if (r < 0) | |
2193 | return r; | |
2194 | if (r == 0) | |
2195 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2196 | ||
b3796dd8 | 2197 | r = unit_file_preset(m->unit_file_scope, flags, NULL, l, mm, &changes, &n_changes); |
af3d8113 ZJS |
2198 | if (r < 0) |
2199 | return install_error(error, r, changes, n_changes); | |
d309c1c3 | 2200 | |
637d6e5b | 2201 | return reply_unit_file_changes_and_free(m, message, r, changes, n_changes, error); |
d309c1c3 LP |
2202 | } |
2203 | ||
718db961 | 2204 | static int method_disable_unit_files_generic( |
718db961 | 2205 | sd_bus_message *message, |
596fc263 | 2206 | Manager *m, |
b3796dd8 | 2207 | int (*call)(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, unsigned *n_changes), |
ebcf1f97 | 2208 | sd_bus_error *error) { |
718db961 LP |
2209 | |
2210 | _cleanup_strv_free_ char **l = NULL; | |
2211 | UnitFileChange *changes = NULL; | |
2212 | unsigned n_changes = 0; | |
718db961 LP |
2213 | int r, runtime; |
2214 | ||
718db961 LP |
2215 | assert(message); |
2216 | assert(m); | |
2217 | ||
df823e23 | 2218 | r = sd_bus_message_read_strv(message, &l); |
ebcf1f97 LP |
2219 | if (r < 0) |
2220 | return r; | |
718db961 | 2221 | |
df823e23 | 2222 | r = sd_bus_message_read(message, "b", &runtime); |
718db961 | 2223 | if (r < 0) |
ebcf1f97 | 2224 | return r; |
718db961 | 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, runtime ? UNIT_FILE_RUNTIME : 0, 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, -1, changes, n_changes, error); |
718db961 | 2237 | } |
ea430986 | 2238 | |
19070062 | 2239 | static int method_disable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2240 | return method_disable_unit_files_generic(message, userdata, unit_file_disable, error); |
ea430986 LP |
2241 | } |
2242 | ||
19070062 | 2243 | static int method_unmask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
9a7c402b | 2244 | return method_disable_unit_files_generic(message, userdata, unit_file_unmask, error); |
718db961 LP |
2245 | } |
2246 | ||
344ca755 LP |
2247 | static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2248 | _cleanup_strv_free_ char **l = NULL; | |
2249 | UnitFileChange *changes = NULL; | |
2250 | unsigned n_changes = 0; | |
2251 | Manager *m = userdata; | |
2252 | int r; | |
2253 | ||
2254 | assert(message); | |
2255 | assert(m); | |
2256 | ||
2257 | r = sd_bus_message_read_strv(message, &l); | |
2258 | if (r < 0) | |
2259 | return r; | |
2260 | ||
2261 | r = bus_verify_manage_unit_files_async(m, message, error); | |
2262 | if (r < 0) | |
2263 | return r; | |
2264 | if (r == 0) | |
2265 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2266 | ||
2267 | r = unit_file_revert(m->unit_file_scope, NULL, l, &changes, &n_changes); | |
af3d8113 ZJS |
2268 | if (r < 0) |
2269 | return install_error(error, r, changes, n_changes); | |
344ca755 | 2270 | |
637d6e5b | 2271 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
344ca755 LP |
2272 | } |
2273 | ||
19070062 | 2274 | static int method_set_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
718db961 LP |
2275 | UnitFileChange *changes = NULL; |
2276 | unsigned n_changes = 0; | |
2277 | Manager *m = userdata; | |
718db961 LP |
2278 | const char *name; |
2279 | int force, r; | |
2280 | ||
718db961 LP |
2281 | assert(message); |
2282 | assert(m); | |
2283 | ||
1d22e906 | 2284 | r = mac_selinux_access_check(message, "enable", error); |
283868e1 SW |
2285 | if (r < 0) |
2286 | return r; | |
283868e1 | 2287 | |
1d22e906 | 2288 | r = sd_bus_message_read(message, "sb", &name, &force); |
ebcf1f97 LP |
2289 | if (r < 0) |
2290 | return r; | |
718db961 | 2291 | |
1d22e906 | 2292 | r = bus_verify_manage_unit_files_async(m, message, error); |
718db961 | 2293 | if (r < 0) |
ebcf1f97 | 2294 | return r; |
1d22e906 LP |
2295 | if (r == 0) |
2296 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
718db961 | 2297 | |
b3796dd8 | 2298 | r = unit_file_set_default(m->unit_file_scope, force ? UNIT_FILE_FORCE : 0, NULL, name, &changes, &n_changes); |
af3d8113 ZJS |
2299 | if (r < 0) |
2300 | return install_error(error, r, changes, n_changes); | |
718db961 | 2301 | |
637d6e5b | 2302 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
718db961 LP |
2303 | } |
2304 | ||
19070062 | 2305 | static int method_preset_all_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
d309c1c3 LP |
2306 | UnitFileChange *changes = NULL; |
2307 | unsigned n_changes = 0; | |
2308 | Manager *m = userdata; | |
2309 | UnitFilePresetMode mm; | |
d309c1c3 | 2310 | const char *mode; |
b3796dd8 | 2311 | UnitFileFlags flags; |
d309c1c3 LP |
2312 | int force, runtime, r; |
2313 | ||
d309c1c3 LP |
2314 | assert(message); |
2315 | assert(m); | |
2316 | ||
8a188de9 | 2317 | r = mac_selinux_access_check(message, "enable", error); |
d309c1c3 LP |
2318 | if (r < 0) |
2319 | return r; | |
2320 | ||
2321 | r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force); | |
2322 | if (r < 0) | |
2323 | return r; | |
2324 | ||
b3796dd8 JS |
2325 | flags = unit_file_bools_to_flags(runtime, force); |
2326 | ||
d309c1c3 LP |
2327 | if (isempty(mode)) |
2328 | mm = UNIT_FILE_PRESET_FULL; | |
2329 | else { | |
2330 | mm = unit_file_preset_mode_from_string(mode); | |
2331 | if (mm < 0) | |
2332 | return -EINVAL; | |
2333 | } | |
2334 | ||
1d22e906 LP |
2335 | r = bus_verify_manage_unit_files_async(m, message, error); |
2336 | if (r < 0) | |
2337 | return r; | |
2338 | if (r == 0) | |
2339 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2340 | ||
b3796dd8 | 2341 | r = unit_file_preset_all(m->unit_file_scope, flags, NULL, mm, &changes, &n_changes); |
af3d8113 ZJS |
2342 | if (r < 0) |
2343 | return install_error(error, r, changes, n_changes); | |
d309c1c3 | 2344 | |
637d6e5b | 2345 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
d309c1c3 LP |
2346 | } |
2347 | ||
19070062 | 2348 | static int method_add_dependency_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
e94937df LN |
2349 | _cleanup_strv_free_ char **l = NULL; |
2350 | Manager *m = userdata; | |
2351 | UnitFileChange *changes = NULL; | |
2352 | unsigned n_changes = 0; | |
e94937df | 2353 | int runtime, force, r; |
596fc263 | 2354 | char *target, *type; |
e94937df | 2355 | UnitDependency dep; |
b3796dd8 | 2356 | UnitFileFlags flags; |
e94937df | 2357 | |
e94937df LN |
2358 | assert(message); |
2359 | assert(m); | |
2360 | ||
2361 | r = bus_verify_manage_unit_files_async(m, message, error); | |
2362 | if (r < 0) | |
2363 | return r; | |
2364 | if (r == 0) | |
2365 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |
2366 | ||
2367 | r = sd_bus_message_read_strv(message, &l); | |
2368 | if (r < 0) | |
2369 | return r; | |
2370 | ||
2371 | r = sd_bus_message_read(message, "ssbb", &target, &type, &runtime, &force); | |
2372 | if (r < 0) | |
2373 | return r; | |
2374 | ||
b3796dd8 JS |
2375 | flags = unit_file_bools_to_flags(runtime, force); |
2376 | ||
e94937df LN |
2377 | dep = unit_dependency_from_string(type); |
2378 | if (dep < 0) | |
2379 | return -EINVAL; | |
2380 | ||
b3796dd8 | 2381 | r = unit_file_add_dependency(m->unit_file_scope, flags, NULL, l, target, dep, &changes, &n_changes); |
af3d8113 ZJS |
2382 | if (r < 0) |
2383 | return install_error(error, r, changes, n_changes); | |
e94937df | 2384 | |
637d6e5b | 2385 | return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); |
e94937df LN |
2386 | } |
2387 | ||
3b3557c4 JS |
2388 | static int method_get_unit_file_links(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2389 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
2390 | UnitFileChange *changes = NULL; | |
2391 | unsigned n_changes = 0, i; | |
2392 | UnitFileFlags flags; | |
2393 | const char *name; | |
2394 | char **p; | |
2395 | int runtime, r; | |
2396 | ||
2397 | r = sd_bus_message_read(message, "sb", &name, &runtime); | |
2398 | if (r < 0) | |
2399 | return r; | |
2400 | ||
2401 | r = sd_bus_message_new_method_return(message, &reply); | |
2402 | if (r < 0) | |
2403 | return r; | |
2404 | ||
2405 | r = sd_bus_message_open_container(reply, SD_BUS_TYPE_ARRAY, "s"); | |
2406 | if (r < 0) | |
2407 | return r; | |
2408 | ||
2409 | p = STRV_MAKE(name); | |
2410 | flags = UNIT_FILE_DRY_RUN | | |
2411 | (runtime ? UNIT_FILE_RUNTIME : 0); | |
2412 | ||
2413 | r = unit_file_disable(UNIT_FILE_SYSTEM, flags, NULL, p, &changes, &n_changes); | |
2414 | if (r < 0) | |
2415 | return log_error_errno(r, "Failed to get file links for %s: %m", name); | |
2416 | ||
2417 | for (i = 0; i < n_changes; i++) | |
2418 | if (changes[i].type == UNIT_FILE_UNLINK) { | |
2419 | r = sd_bus_message_append(reply, "s", changes[i].path); | |
2420 | if (r < 0) | |
2421 | return r; | |
2422 | } | |
2423 | ||
2424 | r = sd_bus_message_close_container(reply); | |
2425 | if (r < 0) | |
2426 | return r; | |
2427 | ||
2428 | return sd_bus_send(NULL, reply, NULL); | |
2429 | } | |
2430 | ||
15ea79f8 LP |
2431 | static int method_get_job_waiting(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
2432 | Manager *m = userdata; | |
2433 | uint32_t id; | |
2434 | Job *j; | |
2435 | int r; | |
2436 | ||
2437 | assert(message); | |
2438 | assert(m); | |
2439 | ||
2440 | r = sd_bus_message_read(message, "u", &id); | |
2441 | if (r < 0) | |
2442 | return r; | |
2443 | ||
2444 | j = manager_get_job(m, id); | |
2445 | if (!j) | |
2446 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); | |
2447 | ||
2448 | return bus_job_method_get_waiting_jobs(message, j, error); | |
2449 | } | |
2450 | ||
718db961 LP |
2451 | const sd_bus_vtable bus_manager_vtable[] = { |
2452 | SD_BUS_VTABLE_START(0), | |
2453 | ||
556089dc LP |
2454 | SD_BUS_PROPERTY("Version", "s", property_get_version, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
2455 | SD_BUS_PROPERTY("Features", "s", property_get_features, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
2456 | SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
7452394e | 2457 | SD_BUS_PROPERTY("Architecture", "s", property_get_architecture, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 2458 | SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
9f9f0342 LP |
2459 | BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FIRMWARE]), SD_BUS_VTABLE_PROPERTY_CONST), |
2460 | BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_LOADER]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2461 | BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_KERNEL]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2462 | BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2463 | BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_USERSPACE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2464 | BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2465 | BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2466 | BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2467 | BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2468 | BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2469 | BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_START]), SD_BUS_VTABLE_PROPERTY_CONST), | |
2470 | BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), | |
718db961 LP |
2471 | SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level, property_set_log_level, 0, 0), |
2472 | SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target, property_set_log_target, 0, 0), | |
2473 | SD_BUS_PROPERTY("NNames", "u", property_get_n_names, 0, 0), | |
03455c28 | 2474 | SD_BUS_PROPERTY("NFailedUnits", "u", property_get_n_failed_units, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
718db961 LP |
2475 | SD_BUS_PROPERTY("NJobs", "u", property_get_n_jobs, 0, 0), |
2476 | SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_installed_jobs), 0), | |
2477 | SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_failed_jobs), 0), | |
2478 | SD_BUS_PROPERTY("Progress", "d", property_get_progress, 0, 0), | |
2479 | SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(Manager, environment), 0), | |
556089dc LP |
2480 | SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool, offsetof(Manager, confirm_spawn), SD_BUS_VTABLE_PROPERTY_CONST), |
2481 | SD_BUS_PROPERTY("ShowStatus", "b", bus_property_get_bool, offsetof(Manager, show_status), SD_BUS_VTABLE_PROPERTY_CONST), | |
a3c4eb07 | 2482 | SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.search_path), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
2483 | SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST), |
2484 | SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST), | |
4c3f1641 LP |
2485 | SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec, property_set_runtime_watchdog, offsetof(Manager, runtime_watchdog), 0), |
2486 | SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec, bus_property_set_usec, offsetof(Manager, shutdown_watchdog), 0), | |
2a12e32e | 2487 | SD_BUS_WRITABLE_PROPERTY("ServiceWatchdogs", "b", bus_property_get_bool, bus_property_set_bool, offsetof(Manager, service_watchdogs), 0), |
b272b74d | 2488 | SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Manager, cgroup_root), 0), |
f755e3b7 | 2489 | SD_BUS_PROPERTY("SystemState", "s", property_get_system_state, 0, 0), |
287419c1 | 2490 | SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned, offsetof(Manager, return_value), 0), |
670a3efe EV |
2491 | SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec, offsetof(Manager, default_timer_accuracy_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
2492 | SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec, offsetof(Manager, default_timeout_start_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
2493 | SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec, offsetof(Manager, default_timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
2494 | SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec, offsetof(Manager, default_restart_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
c075f5fc YW |
2495 | SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST), |
2496 | /* The following two items are obsolete alias */ | |
2497 | SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
2498 | 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 |
2499 | SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned, offsetof(Manager, default_start_limit_burst), SD_BUS_VTABLE_PROPERTY_CONST), |
2500 | SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool, offsetof(Manager, default_cpu_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2501 | SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool, offsetof(Manager, default_blockio_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2502 | SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, default_memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
2503 | SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool, offsetof(Manager, default_tasks_accounting), SD_BUS_VTABLE_PROPERTY_CONST), | |
97eb4231 | 2504 | SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2505 | SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2506 | SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2507 | SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2508 | SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2509 | SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2510 | SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2511 | SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2512 | SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2513 | SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2514 | SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2515 | SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2516 | SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2517 | SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2518 | SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2519 | SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2520 | SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2521 | SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2522 | SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2523 | SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2524 | SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2525 | SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2526 | SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2527 | SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2528 | SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2529 | SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2530 | SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2531 | SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2532 | SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2533 | SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
97eb4231 | 2534 | SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 2535 | SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
0af20ea2 | 2536 | SD_BUS_PROPERTY("DefaultTasksMax", "t", NULL, offsetof(Manager, default_tasks_max), SD_BUS_VTABLE_PROPERTY_CONST), |
eed67a30 | 2537 | SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
718db961 | 2538 | |
adacb957 LP |
2539 | SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
2540 | SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid, SD_BUS_VTABLE_UNPRIVILEGED), | |
4b58153d | 2541 | SD_BUS_METHOD("GetUnitByInvocationID", "ay", "o", method_get_unit_by_invocation_id, SD_BUS_VTABLE_UNPRIVILEGED), |
adacb957 | 2542 | SD_BUS_METHOD("LoadUnit", "s", "o", method_load_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
283868e1 SW |
2543 | SD_BUS_METHOD("StartUnit", "ss", "o", method_start_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
2544 | SD_BUS_METHOD("StartUnitReplace", "sss", "o", method_start_unit_replace, SD_BUS_VTABLE_UNPRIVILEGED), | |
2545 | SD_BUS_METHOD("StopUnit", "ss", "o", method_stop_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2546 | SD_BUS_METHOD("ReloadUnit", "ss", "o", method_reload_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2547 | SD_BUS_METHOD("RestartUnit", "ss", "o", method_restart_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2548 | SD_BUS_METHOD("TryRestartUnit", "ss", "o", method_try_restart_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2549 | SD_BUS_METHOD("ReloadOrRestartUnit", "ss", "o", method_reload_or_restart_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2550 | SD_BUS_METHOD("ReloadOrTryRestartUnit", "ss", "o", method_reload_or_try_restart_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2551 | SD_BUS_METHOD("KillUnit", "ssi", NULL, method_kill_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2552 | SD_BUS_METHOD("ResetFailedUnit", "s", NULL, method_reset_failed_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
2553 | SD_BUS_METHOD("SetUnitProperties", "sba(sv)", NULL, method_set_unit_properties, SD_BUS_VTABLE_UNPRIVILEGED), | |
05a98afd LP |
2554 | SD_BUS_METHOD("RefUnit", "s", NULL, method_ref_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
2555 | SD_BUS_METHOD("UnrefUnit", "s", NULL, method_unref_unit, SD_BUS_VTABLE_UNPRIVILEGED), | |
283868e1 | 2556 | SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
291d565a | 2557 | SD_BUS_METHOD("GetUnitProcesses", "s", "a(sus)", method_get_unit_processes, SD_BUS_VTABLE_UNPRIVILEGED), |
6592b975 | 2558 | SD_BUS_METHOD("AttachProcessesToUnit", "ssau", NULL, method_attach_processes_to_unit, SD_BUS_VTABLE_UNPRIVILEGED), |
adacb957 | 2559 | SD_BUS_METHOD("GetJob", "u", "o", method_get_job, SD_BUS_VTABLE_UNPRIVILEGED), |
15ea79f8 LP |
2560 | SD_BUS_METHOD("GetJobAfter", "u", "a(usssoo)", method_get_job_waiting, SD_BUS_VTABLE_UNPRIVILEGED), |
2561 | SD_BUS_METHOD("GetJobBefore", "u", "a(usssoo)", method_get_job_waiting, SD_BUS_VTABLE_UNPRIVILEGED), | |
283868e1 | 2562 | SD_BUS_METHOD("CancelJob", "u", NULL, method_cancel_job, SD_BUS_VTABLE_UNPRIVILEGED), |
1d22e906 LP |
2563 | SD_BUS_METHOD("ClearJobs", NULL, NULL, method_clear_jobs, SD_BUS_VTABLE_UNPRIVILEGED), |
2564 | SD_BUS_METHOD("ResetFailed", NULL, NULL, method_reset_failed, SD_BUS_VTABLE_UNPRIVILEGED), | |
adacb957 | 2565 | SD_BUS_METHOD("ListUnits", NULL, "a(ssssssouso)", method_list_units, SD_BUS_VTABLE_UNPRIVILEGED), |
cdc06ed7 | 2566 | SD_BUS_METHOD("ListUnitsFiltered", "as", "a(ssssssouso)", method_list_units_filtered, SD_BUS_VTABLE_UNPRIVILEGED), |
313fe66f | 2567 | SD_BUS_METHOD("ListUnitsByPatterns", "asas", "a(ssssssouso)", method_list_units_by_patterns, SD_BUS_VTABLE_UNPRIVILEGED), |
6900c740 | 2568 | SD_BUS_METHOD("ListUnitsByNames", "as", "a(ssssssouso)", method_list_units_by_names, SD_BUS_VTABLE_UNPRIVILEGED), |
adacb957 LP |
2569 | SD_BUS_METHOD("ListJobs", NULL, "a(usssoo)", method_list_jobs, SD_BUS_VTABLE_UNPRIVILEGED), |
2570 | SD_BUS_METHOD("Subscribe", NULL, NULL, method_subscribe, SD_BUS_VTABLE_UNPRIVILEGED), | |
2571 | SD_BUS_METHOD("Unsubscribe", NULL, NULL, method_unsubscribe, SD_BUS_VTABLE_UNPRIVILEGED), | |
2572 | SD_BUS_METHOD("Dump", NULL, "s", method_dump, SD_BUS_VTABLE_UNPRIVILEGED), | |
04b56d9d LP |
2573 | SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_refuse_snapshot, SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), |
2574 | SD_BUS_METHOD("RemoveSnapshot", "s", NULL, method_refuse_snapshot, SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), | |
283868e1 SW |
2575 | SD_BUS_METHOD("Reload", NULL, NULL, method_reload, SD_BUS_VTABLE_UNPRIVILEGED), |
2576 | SD_BUS_METHOD("Reexecute", NULL, NULL, method_reexecute, SD_BUS_VTABLE_UNPRIVILEGED), | |
718db961 | 2577 | SD_BUS_METHOD("Exit", NULL, NULL, method_exit, 0), |
adacb957 LP |
2578 | SD_BUS_METHOD("Reboot", NULL, NULL, method_reboot, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), |
2579 | SD_BUS_METHOD("PowerOff", NULL, NULL, method_poweroff, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2580 | SD_BUS_METHOD("Halt", NULL, NULL, method_halt, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2581 | SD_BUS_METHOD("KExec", NULL, NULL, method_kexec, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
2582 | SD_BUS_METHOD("SwitchRoot", "ss", NULL, method_switch_root, SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), | |
1d22e906 LP |
2583 | SD_BUS_METHOD("SetEnvironment", "as", NULL, method_set_environment, SD_BUS_VTABLE_UNPRIVILEGED), |
2584 | SD_BUS_METHOD("UnsetEnvironment", "as", NULL, method_unset_environment, SD_BUS_VTABLE_UNPRIVILEGED), | |
2585 | SD_BUS_METHOD("UnsetAndSetEnvironment", "asas", NULL, method_unset_and_set_environment, SD_BUS_VTABLE_UNPRIVILEGED), | |
adacb957 | 2586 | SD_BUS_METHOD("ListUnitFiles", NULL, "a(ss)", method_list_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), |
313fe66f | 2587 | SD_BUS_METHOD("ListUnitFilesByPatterns", "asas", "a(ss)", method_list_unit_files_by_patterns, SD_BUS_VTABLE_UNPRIVILEGED), |
adacb957 | 2588 | SD_BUS_METHOD("GetUnitFileState", "s", "s", method_get_unit_file_state, SD_BUS_VTABLE_UNPRIVILEGED), |
283868e1 SW |
2589 | SD_BUS_METHOD("EnableUnitFiles", "asbb", "ba(sss)", method_enable_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), |
2590 | SD_BUS_METHOD("DisableUnitFiles", "asb", "a(sss)", method_disable_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), | |
2591 | SD_BUS_METHOD("ReenableUnitFiles", "asbb", "ba(sss)", method_reenable_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), | |
2592 | SD_BUS_METHOD("LinkUnitFiles", "asbb", "a(sss)", method_link_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), | |
2593 | SD_BUS_METHOD("PresetUnitFiles", "asbb", "ba(sss)", method_preset_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), | |
2594 | SD_BUS_METHOD("PresetUnitFilesWithMode", "assbb", "ba(sss)", method_preset_unit_files_with_mode, SD_BUS_VTABLE_UNPRIVILEGED), | |
2595 | SD_BUS_METHOD("MaskUnitFiles", "asbb", "a(sss)", method_mask_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), | |
2596 | SD_BUS_METHOD("UnmaskUnitFiles", "asb", "a(sss)", method_unmask_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), | |
344ca755 | 2597 | SD_BUS_METHOD("RevertUnitFiles", "as", "a(sss)", method_revert_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), |
283868e1 | 2598 | SD_BUS_METHOD("SetDefaultTarget", "sb", "a(sss)", method_set_default_target, SD_BUS_VTABLE_UNPRIVILEGED), |
adacb957 | 2599 | SD_BUS_METHOD("GetDefaultTarget", NULL, "s", method_get_default_target, SD_BUS_VTABLE_UNPRIVILEGED), |
283868e1 | 2600 | SD_BUS_METHOD("PresetAllUnitFiles", "sbb", "a(sss)", method_preset_all_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), |
e94937df | 2601 | SD_BUS_METHOD("AddDependencyUnitFiles", "asssbb", "a(sss)", method_add_dependency_unit_files, SD_BUS_VTABLE_UNPRIVILEGED), |
3b3557c4 | 2602 | SD_BUS_METHOD("GetUnitFileLinks", "sb", "as", method_get_unit_file_links, SD_BUS_VTABLE_UNPRIVILEGED), |
287419c1 | 2603 | SD_BUS_METHOD("SetExitCode", "y", NULL, method_set_exit_code, SD_BUS_VTABLE_UNPRIVILEGED), |
29206d46 LP |
2604 | SD_BUS_METHOD("LookupDynamicUserByName", "s", "u", method_lookup_dynamic_user_by_name, SD_BUS_VTABLE_UNPRIVILEGED), |
2605 | SD_BUS_METHOD("LookupDynamicUserByUID", "u", "s", method_lookup_dynamic_user_by_uid, SD_BUS_VTABLE_UNPRIVILEGED), | |
f9bfa696 | 2606 | SD_BUS_METHOD("GetDynamicUsers", NULL, "a(us)", method_get_dynamic_users, SD_BUS_VTABLE_UNPRIVILEGED), |
718db961 LP |
2607 | |
2608 | SD_BUS_SIGNAL("UnitNew", "so", 0), | |
2609 | SD_BUS_SIGNAL("UnitRemoved", "so", 0), | |
2610 | SD_BUS_SIGNAL("JobNew", "uos", 0), | |
2611 | SD_BUS_SIGNAL("JobRemoved", "uoss", 0), | |
2612 | SD_BUS_SIGNAL("StartupFinished", "tttttt", 0), | |
2613 | SD_BUS_SIGNAL("UnitFilesChanged", NULL, 0), | |
2614 | SD_BUS_SIGNAL("Reloading", "b", 0), | |
2615 | ||
2616 | SD_BUS_VTABLE_END | |
ea430986 | 2617 | }; |
718db961 | 2618 | |
8f8f05a9 | 2619 | static int send_finished(sd_bus *bus, void *userdata) { |
4afd3348 | 2620 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
2621 | usec_t *times = userdata; |
2622 | int r; | |
2623 | ||
2624 | assert(bus); | |
2625 | assert(times); | |
2626 | ||
151b9b96 | 2627 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished"); |
718db961 LP |
2628 | if (r < 0) |
2629 | return r; | |
2630 | ||
2631 | r = sd_bus_message_append(message, "tttttt", times[0], times[1], times[2], times[3], times[4], times[5]); | |
2632 | if (r < 0) | |
2633 | return r; | |
2634 | ||
8f8f05a9 | 2635 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
2636 | } |
2637 | ||
39abcaee | 2638 | void bus_manager_send_finished( |
718db961 LP |
2639 | Manager *m, |
2640 | usec_t firmware_usec, | |
2641 | usec_t loader_usec, | |
2642 | usec_t kernel_usec, | |
2643 | usec_t initrd_usec, | |
2644 | usec_t userspace_usec, | |
2645 | usec_t total_usec) { | |
2646 | ||
39abcaee LP |
2647 | int r; |
2648 | ||
718db961 LP |
2649 | assert(m); |
2650 | ||
8f8f05a9 LP |
2651 | r = bus_foreach_bus( |
2652 | m, | |
2653 | NULL, | |
2654 | send_finished, | |
2655 | (usec_t[6]) { | |
2656 | firmware_usec, | |
2657 | loader_usec, | |
2658 | kernel_usec, | |
2659 | initrd_usec, | |
2660 | userspace_usec, | |
2661 | total_usec | |
2662 | }); | |
39abcaee | 2663 | if (r < 0) |
da927ba9 | 2664 | log_debug_errno(r, "Failed to send finished signal: %m"); |
718db961 LP |
2665 | } |
2666 | ||
8f8f05a9 | 2667 | static int send_reloading(sd_bus *bus, void *userdata) { |
4afd3348 | 2668 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
718db961 LP |
2669 | int r; |
2670 | ||
2671 | assert(bus); | |
2672 | ||
151b9b96 | 2673 | r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading"); |
718db961 LP |
2674 | if (r < 0) |
2675 | return r; | |
2676 | ||
2677 | r = sd_bus_message_append(message, "b", PTR_TO_INT(userdata)); | |
2678 | if (r < 0) | |
2679 | return r; | |
2680 | ||
8f8f05a9 | 2681 | return sd_bus_send(bus, message, NULL); |
718db961 LP |
2682 | } |
2683 | ||
39abcaee LP |
2684 | void bus_manager_send_reloading(Manager *m, bool active) { |
2685 | int r; | |
2686 | ||
718db961 LP |
2687 | assert(m); |
2688 | ||
8f8f05a9 | 2689 | r = bus_foreach_bus(m, NULL, send_reloading, INT_TO_PTR(active)); |
39abcaee | 2690 | if (r < 0) |
da927ba9 | 2691 | log_debug_errno(r, "Failed to send reloading signal: %m"); |
03455c28 LDM |
2692 | } |
2693 | ||
2694 | static int send_changed_signal(sd_bus *bus, void *userdata) { | |
2695 | assert(bus); | |
2696 | ||
2697 | return sd_bus_emit_properties_changed_strv(bus, | |
2698 | "/org/freedesktop/systemd1", | |
2699 | "org.freedesktop.systemd1.Manager", | |
2700 | NULL); | |
2701 | } | |
39abcaee | 2702 | |
03455c28 LDM |
2703 | void bus_manager_send_change_signal(Manager *m) { |
2704 | int r; | |
2705 | ||
2706 | assert(m); | |
2707 | ||
2708 | r = bus_foreach_bus(m, NULL, send_changed_signal, NULL); | |
2709 | if (r < 0) | |
2710 | log_debug_errno(r, "Failed to send manager change signal: %m"); | |
718db961 | 2711 | } |