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