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