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