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