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