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