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