Debian Codegraph @

src/systemctl/systemctl-show.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <sys/mount.h>
4
5 #include "sd-bus.h"
6 #include "sd-journal.h"
7
8 #include "af-list.h"
9 #include "bus-error.h"
10 #include "bus-map-properties.h"
11 #include "bus-print-properties.h"
12 #include "bus-unit-procs.h"
13 #include "bus-unit-util.h"
14 #include "bus-util.h"
15 #include "cgroup-show.h"
16 #include "cpu-set-util.h"
17 #include "errno-util.h"
18 #include "exec-util.h"
19 #include "exit-status.h"
20 #include "format-util.h"
21 #include "hexdecoct.h"
22 #include "hostname-setup.h"
23 #include "in-addr-util.h"
24 #include "install.h"
25 #include "ip-protocol-list.h"
26 #include "journal-file.h"
27 #include "list.h"
28 #include "logs-show.h"
29 #include "memory-util.h"
30 #include "numa-util.h"
31 #include "open-file.h"
32 #include "output-mode.h"
33 #include "pager.h"
34 #include "parse-util.h"
35 #include "path-util.h"
36 #include "percent-util.h"
37 #include "pretty-print.h"
38 #include "process-util.h"
39 #include "set.h"
40 #include "signal-util.h"
41 #include "sort-util.h"
42 #include "special.h"
43 #include "systemctl-list-units.h"
44 #include "string-table.h"
45 #include "string-util.h"
46 #include "strv.h"
47 #include "systemctl.h"
48 #include "systemctl-list-machines.h"
49 #include "systemctl-show.h"
50 #include "systemctl-util.h"
51 #include "terminal-util.h"
52 #include "utf8.h"
53
54 static OutputFlags get_output_flags(void) {
55 return
56 FLAGS_SET(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) * OUTPUT_SHOW_ALL |
57 (arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
58 colors_enabled() * OUTPUT_COLOR |
59 !arg_quiet * OUTPUT_WARN_CUTOFF;
60 }
61
62 typedef struct ExecStatusInfo {
63 char *name;
64
65 char *path;
66 char **argv;
67
68 bool ignore;
69
70 usec_t start_timestamp;
71 usec_t exit_timestamp;
72 pid_t pid;
73 int code;
74 int status;
75
76 ExecCommandFlags flags;
77
78 LIST_FIELDS(struct ExecStatusInfo, exec_status_info_list);
79 } ExecStatusInfo;
80
81 static void exec_status_info_free(ExecStatusInfo *i) {
82 assert(i);
83
84 free(i->name);
85 free(i->path);
86 strv_free(i->argv);
87 free(i);
88 }
89
90 static int exec_status_info_deserialize(sd_bus_message *m, ExecStatusInfo *i, bool is_ex_prop) {
91 _cleanup_strv_free_ char **ex_opts = NULL;
92 uint64_t start_timestamp, exit_timestamp, start_timestamp_monotonic, exit_timestamp_monotonic;
93 const char *path;
94 uint32_t pid;
95 int32_t code, status;
96 int ignore, r;
97
98 assert(m);
99 assert(i);
100
101 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_STRUCT, is_ex_prop ? "sasasttttuii" : "sasbttttuii");
102 if (r < 0)
103 return bus_log_parse_error(r);
104 if (r == 0)
105 return 0;
106
107 r = sd_bus_message_read(m, "s", &path);
108 if (r < 0)
109 return bus_log_parse_error(r);
110
111 i->path = strdup(path);
112 if (!i->path)
113 return log_oom();
114
115 r = sd_bus_message_read_strv(m, &i->argv);
116 if (r < 0)
117 return bus_log_parse_error(r);
118
119 r = is_ex_prop ? sd_bus_message_read_strv(m, &ex_opts) : sd_bus_message_read(m, "b", &ignore);
120 if (r < 0)
121 return bus_log_parse_error(r);
122
123 r = sd_bus_message_read(m,
124 "ttttuii",
125 &start_timestamp, &start_timestamp_monotonic,
126 &exit_timestamp, &exit_timestamp_monotonic,
127 &pid,
128 &code, &status);
129 if (r < 0)
130 return bus_log_parse_error(r);
131
132 if (is_ex_prop) {
133 r = exec_command_flags_from_strv(ex_opts, &i->flags);
134 if (r < 0)
135 return log_error_errno(r, "Failed to convert strv to ExecCommandFlags: %m");
136
137 i->ignore = FLAGS_SET(i->flags, EXEC_COMMAND_IGNORE_FAILURE);
138 } else
139 i->ignore = ignore;
140
141 i->start_timestamp = (usec_t) start_timestamp;
142 i->exit_timestamp = (usec_t) exit_timestamp;
143 i->pid = (pid_t) pid;
144 i->code = code;
145 i->status = status;
146
147 r = sd_bus_message_exit_container(m);
148 if (r < 0)
149 return bus_log_parse_error(r);
150
151 return 1;
152 }
153
154 typedef struct UnitCondition {
155 char *name;
156 char *param;
157 bool trigger;
158 bool negate;
159 int tristate;
160
161 LIST_FIELDS(struct UnitCondition, conditions);
162 } UnitCondition;
163
164 typedef struct QuotaInfo {
165 bool quota_enforce;
166 bool quota_accounting;
167 uint64_t quota_usage;
168 uint64_t quota_limit;
169 } QuotaInfo;
170
171 static UnitCondition* unit_condition_free(UnitCondition *c) {
172 if (!c)
173 return NULL;
174
175 free(c->name);
176 free(c->param);
177 return mfree(c);
178 }
179 DEFINE_TRIVIAL_CLEANUP_FUNC(UnitCondition*, unit_condition_free);
180
181 typedef struct UnitStatusInfo {
182 const char *id;
183 const char *load_state;
184 const char *active_state;
185 const char *freezer_state;
186 const char *sub_state;
187 const char *unit_file_state;
188 const char *unit_file_preset;
189
190 const char *description;
191 const char *following;
192
193 char **documentation;
194
195 const char *fragment_path;
196 const char *source_path;
197 const char *control_group;
198
199 char **dropin_paths;
200
201 char **triggered_by;
202 char **triggers;
203
204 const char *load_error;
205 const char *result;
206
207 usec_t inactive_exit_timestamp;
208 usec_t inactive_exit_timestamp_monotonic;
209 usec_t active_enter_timestamp;
210 usec_t active_exit_timestamp;
211 usec_t inactive_enter_timestamp;
212
213 uint64_t runtime_max_sec;
214
215 uint32_t job_id;
216
217 sd_id128_t invocation_id;
218
219 bool need_daemon_reload;
220 bool transient;
221
222 /* Service */
223 bool running;
224 pid_t main_pid;
225 pid_t control_pid;
226 const char *pid_file;
227 const char *status_text;
228 const char *status_bus_error;
229 const char *status_varlink_error;
230 int status_errno;
231
232 uint32_t fd_store_max;
233 uint32_t n_fd_store;
234
235 usec_t start_timestamp;
236 usec_t exit_timestamp;
237
238 int exit_code, exit_status;
239
240 const char *log_namespace;
241
242 usec_t condition_timestamp;
243 bool condition_result;
244 LIST_HEAD(UnitCondition, conditions);
245
246 usec_t assert_timestamp;
247 bool assert_result;
248 bool failed_assert_trigger;
249 bool failed_assert_negate;
250 const char *failed_assert;
251 const char *failed_assert_parameter;
252 usec_t next_elapse_real;
253 usec_t next_elapse_monotonic;
254
255 /* Socket */
256 unsigned n_accepted;
257 unsigned n_connections;
258 unsigned n_refused;
259 bool accept;
260
261 /* Pairs of type, path */
262 char **listen;
263
264 /* Device */
265 const char *sysfs_path;
266
267 /* Mount, Automount */
268 const char *where;
269
270 /* Swap */
271 const char *what;
272
273 /* Slice */
274 unsigned concurrency_hard_max;
275 unsigned concurrency_soft_max;
276 unsigned n_currently_active;
277
278 /* CGroup */
279 uint64_t memory_current;
280 uint64_t memory_peak;
281 uint64_t memory_swap_current;
282 uint64_t memory_swap_peak;
283 uint64_t memory_zswap_current;
284 uint64_t memory_min;
285 uint64_t memory_low;
286 uint64_t startup_memory_low;
287 uint64_t memory_high;
288 uint64_t startup_memory_high;
289 uint64_t memory_max;
290 uint64_t startup_memory_max;
291 uint64_t memory_swap_max;
292 uint64_t startup_memory_swap_max;
293 uint64_t memory_zswap_max;
294 uint64_t startup_memory_zswap_max;
295 uint64_t memory_limit;
296 uint64_t memory_available;
297 uint64_t cpu_usage_nsec;
298 uint64_t tasks_current;
299 uint64_t tasks_max;
300 uint64_t ip_ingress_bytes;
301 uint64_t ip_egress_bytes;
302 uint64_t io_read_bytes;
303 uint64_t io_write_bytes;
304
305 /* Exec Quotas */
306 QuotaInfo exec_directories_quota[_EXEC_DIRECTORY_TYPE_MAX];
307
308 LIST_HEAD(ExecStatusInfo, exec_status_info_list);
309 } UnitStatusInfo;
310
311 static void unit_status_info_done(UnitStatusInfo *info) {
312 strv_free(info->documentation);
313 strv_free(info->dropin_paths);
314 strv_free(info->triggered_by);
315 strv_free(info->triggers);
316 strv_free(info->listen);
317
318 LIST_CLEAR(conditions, info->conditions, unit_condition_free);
319 LIST_CLEAR(exec_status_info_list, info->exec_status_info_list, exec_status_info_free);
320 }
321
322 static void format_active_state(const char *active_state, const char **active_on, const char **active_off) {
323 assert(active_on);
324 assert(active_off);
325
326 if (streq_ptr(active_state, "failed")) {
327 *active_on = ansi_highlight_red();
328 *active_off = ansi_normal();
329 } else if (STRPTR_IN_SET(active_state, "active", "reloading", "refreshing")) {
330 *active_on = ansi_highlight_green();
331 *active_off = ansi_normal();
332 } else
333 *active_on = *active_off = "";
334 }
335
336 static void format_enable_state(const char *enable_state, const char **enable_on, const char **enable_off) {
337 assert(enable_on);
338 assert(enable_off);
339
340 if (streq_ptr(enable_state, "disabled")) {
341 *enable_on = ansi_highlight_yellow();
342 *enable_off = ansi_normal();
343 } else if (streq_ptr(enable_state, "enabled")) {
344 *enable_on = ansi_highlight_green();
345 *enable_off = ansi_normal();
346 } else
347 *enable_on = *enable_off = "";
348 }
349
350 static void print_exec_directory_quota(UnitStatusInfo *i, ExecDirectoryType dt) {
351 assert(i);
352
353 if (!IN_SET(dt, EXEC_DIRECTORY_STATE, EXEC_DIRECTORY_CACHE, EXEC_DIRECTORY_LOGS))
354 return;
355
356 if (i->exec_directories_quota[dt].quota_accounting) {
357 printf(" %s: %s", exec_directory_type_to_string(dt), FORMAT_BYTES(i->exec_directories_quota[dt].quota_usage));
358
359 if (i->exec_directories_quota[dt].quota_enforce)
360 printf(" (max: %s)", FORMAT_BYTES(i->exec_directories_quota[dt].quota_limit));
361
362 printf("\n");
363 }
364 }
365
366 static void print_status_info(
367 sd_bus *bus,
368 UnitStatusInfo *i,
369 bool *ellipsized) {
370
371 const char *active_on, *active_off, *on, *off, *ss, *fs;
372 const char *enable_on, *enable_off, *preset_on, *preset_off;
373 _cleanup_free_ char *formatted_path = NULL;
374 usec_t timestamp;
375 const char *path;
376 int r;
377
378 assert(i);
379
380 /* This shows pretty information about a unit. See print_property() for a low-level property
381 * printer */
382
383 format_active_state(i->active_state, &active_on, &active_off);
384 format_enable_state(i->unit_file_state, &enable_on, &enable_off);
385 format_enable_state(i->unit_file_preset, &preset_on, &preset_off);
386
387 const Glyph icon = unit_active_state_to_glyph(unit_active_state_from_string(i->active_state));
388
389 printf("%s%s%s %s", active_on, glyph(icon), active_off, strna(i->id));
390
391 if (i->description && !streq_ptr(i->id, i->description))
392 printf(" - %s", i->description);
393
394 printf("\n");
395
396 if (i->following)
397 printf(" Follows: unit currently follows state of %s\n", i->following);
398
399 if (STRPTR_IN_SET(i->load_state, "error", "not-found", "bad-setting")) {
400 on = ansi_highlight_red();
401 off = ansi_normal();
402 } else
403 on = off = "";
404
405 path = i->source_path ?: i->fragment_path;
406 if (path && terminal_urlify_path(path, NULL, &formatted_path) >= 0)
407 path = formatted_path;
408
409 if (!isempty(i->load_error))
410 printf(" Loaded: %s%s%s (Reason: %s)\n",
411 on, strna(i->load_state), off, i->load_error);
412 else if (path && !isempty(i->unit_file_state)) {
413 bool show_preset = !isempty(i->unit_file_preset) &&
414 show_preset_for_state(unit_file_state_from_string(i->unit_file_state));
415
416 printf(" Loaded: %s%s%s (%s; %s%s%s%s%s%s%s)\n",
417 on, strna(i->load_state), off,
418 path,
419 enable_on, i->unit_file_state, enable_off,
420 show_preset ? "; preset: " : "",
421 preset_on, show_preset ? i->unit_file_preset : "", preset_off);
422
423 } else if (path)
424 printf(" Loaded: %s%s%s (%s)\n",
425 on, strna(i->load_state), off, path);
426 else
427 printf(" Loaded: %s%s%s\n",
428 on, strna(i->load_state), off);
429
430 if (i->transient)
431 printf(" Transient: yes\n");
432
433 if (!strv_isempty(i->dropin_paths)) {
434 _cleanup_free_ char *dir = NULL;
435 bool last = false;
436
437 STRV_FOREACH(dropin, i->dropin_paths) {
438 _cleanup_free_ char *dropin_formatted = NULL, *dropin_basename = NULL;
439 const char *df;
440
441 if (!dir || last) {
442 printf(dir ? " " :
443 " Drop-In: ");
444
445 dir = mfree(dir);
446
447 r = path_extract_directory(*dropin, &dir);
448 if (r < 0) {
449 log_error_errno(r, "Failed to extract directory of '%s': %m", *dropin);
450 break;
451 }
452
453 printf("%s\n"
454 " %s", dir,
455 glyph(GLYPH_TREE_RIGHT));
456 }
457
458 last = ! (*(dropin + 1) && startswith(*(dropin + 1), dir));
459
460 r = path_extract_filename(*dropin, &dropin_basename);
461 if (r < 0) {
462 log_error_errno(r, "Failed to extract file name of '%s': %m", *dropin);
463 break;
464 }
465
466 if (terminal_urlify_path(*dropin, dropin_basename, &dropin_formatted) >= 0)
467 df = dropin_formatted;
468 else
469 df = *dropin;
470
471 printf("%s%s", df, last ? "\n" : ", ");
472 }
473 }
474
475 ss = streq_ptr(i->active_state, i->sub_state) ? NULL : i->sub_state;
476 if (ss)
477 printf(" Active: %s%s (%s)%s",
478 active_on, strna(i->active_state), ss, active_off);
479 else
480 printf(" Active: %s%s%s",
481 active_on, strna(i->active_state), active_off);
482
483 fs = !isempty(i->freezer_state) && !streq(i->freezer_state, "running") ? i->freezer_state : NULL;
484 if (fs)
485 printf(" %s(%s)%s", ansi_highlight_yellow(), fs, ansi_normal());
486
487 if (!isempty(i->result) && !streq(i->result, "success"))
488 printf(" (Result: %s)", i->result);
489
490 timestamp = STRPTR_IN_SET(i->active_state, "active", "reloading", "refreshing") ? i->active_enter_timestamp :
491 STRPTR_IN_SET(i->active_state, "inactive", "failed") ? i->inactive_enter_timestamp :
492 STRPTR_IN_SET(i->active_state, "activating") ? i->inactive_exit_timestamp :
493 i->active_exit_timestamp;
494
495 if (timestamp_is_set(timestamp)) {
496 printf(" since %s; %s\n",
497 FORMAT_TIMESTAMP_STYLE(timestamp, arg_timestamp_style),
498 FORMAT_TIMESTAMP_RELATIVE(timestamp));
499 if (streq_ptr(i->active_state, "active") && i->runtime_max_sec < USEC_INFINITY) {
500 usec_t until_timestamp;
501
502 until_timestamp = usec_add(timestamp, i->runtime_max_sec);
503 printf(" Until: %s; %s\n",
504 FORMAT_TIMESTAMP_STYLE(until_timestamp, arg_timestamp_style),
505 FORMAT_TIMESTAMP_RELATIVE(until_timestamp));
506 }
507
508 if (!endswith(i->id, ".target") &&
509 STRPTR_IN_SET(i->active_state, "inactive", "failed") &&
510 timestamp_is_set(i->active_enter_timestamp) &&
511 timestamp_is_set(i->active_exit_timestamp) &&
512 i->active_exit_timestamp >= i->active_enter_timestamp) {
513
514 usec_t duration;
515
516 duration = i->active_exit_timestamp - i->active_enter_timestamp;
517 printf(" Duration: %s\n", FORMAT_TIMESPAN(duration, MSEC_PER_SEC));
518 }
519 } else
520 printf("\n");
521
522 if (i->job_id != 0)
523 printf(" Job: %" PRIu32 "\n", i->job_id);
524
525 if (!sd_id128_is_null(i->invocation_id))
526 printf(" Invocation: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(i->invocation_id));
527
528 STRV_FOREACH(t, i->triggered_by) {
529 UnitActiveState state = _UNIT_ACTIVE_STATE_INVALID;
530
531 (void) get_state_one_unit(bus, *t, &state);
532 format_active_state(unit_active_state_to_string(state), &on, &off);
533
534 printf("%s %s%s%s %s\n",
535 t == i->triggered_by ? "TriggeredBy:" : " ",
536 on, glyph(unit_active_state_to_glyph(state)), off,
537 *t);
538 }
539
540 if (endswith(i->id, ".timer")) {
541 dual_timestamp nw, next = {i->next_elapse_real, i->next_elapse_monotonic};
542 usec_t next_elapse;
543
544 dual_timestamp_now(&nw);
545 next_elapse = calc_next_elapse(&nw, &next);
546
547 if (timestamp_is_set(next_elapse))
548 printf(" Trigger: %s; %s\n",
549 FORMAT_TIMESTAMP_STYLE(next_elapse, arg_timestamp_style),
550 FORMAT_TIMESTAMP_RELATIVE(next_elapse));
551 else
552 printf(" Trigger: n/a\n");
553 }
554
555 STRV_FOREACH(t, i->triggers) {
556 UnitActiveState state = _UNIT_ACTIVE_STATE_INVALID;
557
558 (void) get_state_one_unit(bus, *t, &state);
559 format_active_state(unit_active_state_to_string(state), &on, &off);
560
561 printf("%s %s%s%s %s\n",
562 t == i->triggers ? " Triggers:" : " ",
563 on, glyph(GLYPH_BLACK_CIRCLE), off,
564 *t);
565 }
566
567 if (!i->condition_result && i->condition_timestamp > 0) {
568 int n = 0;
569
570 printf(" Condition: start %scondition unmet%s at %s; %s\n",
571 ansi_highlight_yellow(), ansi_normal(),
572 FORMAT_TIMESTAMP_STYLE(i->condition_timestamp, arg_timestamp_style),
573 FORMAT_TIMESTAMP_RELATIVE(i->condition_timestamp));
574
575 LIST_FOREACH(conditions, c, i->conditions)
576 if (c->tristate < 0)
577 n++;
578
579 LIST_FOREACH(conditions, c, i->conditions)
580 if (c->tristate < 0)
581 printf(" %s %s=%s%s%s was not met\n",
582 --n ? glyph(GLYPH_TREE_BRANCH) : glyph(GLYPH_TREE_RIGHT),
583 c->name,
584 c->trigger ? "|" : "",
585 c->negate ? "!" : "",
586 c->param);
587 }
588
589 if (!i->assert_result && i->assert_timestamp > 0) {
590 printf(" Assert: start %sassertion failed%s at %s; %s\n",
591 ansi_highlight_red(), ansi_normal(),
592 FORMAT_TIMESTAMP_STYLE(i->assert_timestamp, arg_timestamp_style),
593 FORMAT_TIMESTAMP_RELATIVE(i->assert_timestamp));
594 if (i->failed_assert_trigger)
595 printf(" none of the trigger assertions were met\n");
596 else if (i->failed_assert)
597 printf(" %s=%s%s was not met\n",
598 i->failed_assert,
599 i->failed_assert_negate ? "!" : "",
600 i->failed_assert_parameter);
601 }
602
603 if (i->sysfs_path)
604 printf(" Device: %s\n", i->sysfs_path);
605 if (i->where)
606 printf(" Where: %s\n", i->where);
607 if (i->what)
608 printf(" What: %s\n", i->what);
609
610 STRV_FOREACH(t, i->documentation) {
611 _cleanup_free_ char *formatted = NULL;
612 const char *q;
613
614 if (terminal_urlify(*t, NULL, &formatted) >= 0)
615 q = formatted;
616 else
617 q = *t;
618
619 printf(" %*s %s\n", 9, t == i->documentation ? "Docs:" : "", q);
620 }
621
622 STRV_FOREACH_PAIR(t, t2, i->listen)
623 printf(" %*s %s (%s)\n", 9, t == i->listen ? "Listen:" : "", *t2, *t);
624
625 if (i->accept) {
626 printf(" Accepted: %u; Connected: %u;", i->n_accepted, i->n_connections);
627 if (i->n_refused)
628 printf(" Refused: %u", i->n_refused);
629 printf("\n");
630 }
631
632 LIST_FOREACH(exec_status_info_list, p, i->exec_status_info_list) {
633 _cleanup_free_ char *argv = NULL;
634 bool good;
635
636 /* Only show exited processes here */
637 if (p->code == 0)
638 continue;
639
640 /* Don't print ExecXYZEx= properties here since it will appear as a
641 * duplicate of the non-Ex= variant. */
642 if (endswith(p->name, "Ex"))
643 continue;
644
645 argv = strv_join(p->argv, " ");
646 printf(" Process: "PID_FMT" %s=%s ", p->pid, p->name, strna(argv));
647
648 good = is_clean_exit(p->code, p->status, EXIT_CLEAN_DAEMON, NULL);
649 if (!good) {
650 on = p->ignore ? ansi_highlight_yellow() : ansi_highlight_red();
651 off = ansi_normal();
652 } else
653 on = off = "";
654
655 printf("%s(code=%s, ", on, sigchld_code_to_string(p->code));
656
657 if (p->code == CLD_EXITED) {
658 const char *c;
659
660 printf("status=%i", p->status);
661
662 c = exit_status_to_string(p->status, EXIT_STATUS_LIBC | EXIT_STATUS_SYSTEMD);
663 if (c)
664 printf("/%s", c);
665
666 } else
667 printf("signal=%s", signal_to_string(p->status));
668
669 printf(")%s\n", off);
670
671 if (i->main_pid == p->pid &&
672 i->start_timestamp == p->start_timestamp &&
673 i->exit_timestamp == p->start_timestamp)
674 /* Let's not show this twice */
675 i->main_pid = 0;
676
677 if (p->pid == i->control_pid)
678 i->control_pid = 0;
679 }
680
681 if (i->main_pid > 0 || i->control_pid > 0) {
682 if (i->main_pid > 0) {
683 printf(" Main PID: "PID_FMT, i->main_pid);
684
685 if (i->running) {
686
687 if (arg_transport == BUS_TRANSPORT_LOCAL) {
688 _cleanup_free_ char *comm = NULL;
689
690 (void) pid_get_comm(i->main_pid, &comm);
691 if (comm)
692 printf(" (%s)", comm);
693 }
694
695 } else if (i->exit_code > 0) {
696 printf(" (code=%s, ", sigchld_code_to_string(i->exit_code));
697
698 if (i->exit_code == CLD_EXITED) {
699 const char *c;
700
701 printf("status=%i", i->exit_status);
702
703 c = exit_status_to_string(i->exit_status,
704 EXIT_STATUS_LIBC | EXIT_STATUS_SYSTEMD);
705 if (c)
706 printf("/%s", c);
707
708 } else
709 printf("signal=%s", signal_to_string(i->exit_status));
710 printf(")");
711 }
712 }
713
714 if (i->control_pid > 0) {
715 _cleanup_free_ char *c = NULL;
716
717 if (i->main_pid > 0)
718 fputs("; Control PID: ", stdout);
719 else
720 fputs(" Cntrl PID: ", stdout); /* if first in column, abbreviated so it fits alignment */
721
722 printf(PID_FMT, i->control_pid);
723
724 if (arg_transport == BUS_TRANSPORT_LOCAL) {
725 (void) pid_get_comm(i->control_pid, &c);
726 if (c)
727 printf(" (%s)", c);
728 }
729 }
730
731 printf("\n");
732 }
733
734 if (i->status_text)
735 printf(" Status: \"%s%s%s\"\n", ansi_highlight_cyan(), i->status_text, ansi_normal());
736
737 if (i->status_errno > 0 || i->status_bus_error || i->status_varlink_error) {
738 const char *prefix = " ";
739
740 printf(" Error:");
741
742 if (i->status_errno > 0) {
743 printf("%scode: %i (%s)", prefix, i->status_errno, STRERROR(i->status_errno));
744 prefix = "; ";
745 }
746 if (i->status_bus_error) {
747 printf("%sD-Bus: %s", prefix, i->status_bus_error);
748 prefix = "; ";
749 }
750 if (i->status_varlink_error) {
751 printf("%sVarlink: %s", prefix, i->status_varlink_error);
752 prefix = "; ";
753 }
754
755 putchar('\n');
756 }
757
758 if (endswith(i->id, ".slice")) {
759 printf(" Act. Units: %u", i->n_currently_active);
760
761 if (i->concurrency_soft_max != UINT_MAX || i->concurrency_hard_max != UINT_MAX) {
762 fputs(" (", stdout);
763
764 if (i->concurrency_soft_max != UINT_MAX && i->concurrency_soft_max < i->concurrency_hard_max) {
765 printf("soft limit: %u", i->concurrency_soft_max);
766 if (i->concurrency_hard_max != UINT_MAX)
767 fputs("; ", stdout);
768 }
769 if (i->concurrency_hard_max != UINT_MAX)
770 printf("hard limit: %u", i->concurrency_hard_max);
771
772 putchar(')');
773 }
774
775 putchar('\n');
776 }
777
778 if (i->ip_ingress_bytes != UINT64_MAX && i->ip_egress_bytes != UINT64_MAX)
779 printf(" IP: %s in, %s out\n",
780 FORMAT_BYTES(i->ip_ingress_bytes),
781 FORMAT_BYTES(i->ip_egress_bytes));
782
783 if (i->io_read_bytes != UINT64_MAX && i->io_write_bytes != UINT64_MAX)
784 printf(" IO: %s read, %s written\n",
785 FORMAT_BYTES(i->io_read_bytes),
786 FORMAT_BYTES(i->io_write_bytes));
787
788 if (i->tasks_current != UINT64_MAX) {
789 printf(" Tasks: %" PRIu64, i->tasks_current);
790
791 if (i->tasks_max != UINT64_MAX)
792 printf("%s (limit: %" PRIu64 ")%s\n", ansi_grey(), i->tasks_max, ansi_normal());
793 else
794 printf("\n");
795 }
796
797 if (i->n_fd_store > 0 || i->fd_store_max > 0)
798 printf(" FD Store: %u%s (limit: %u)%s\n", i->n_fd_store, ansi_grey(), i->fd_store_max, ansi_normal());
799
800 bool show_memory_peak = i->memory_peak != CGROUP_LIMIT_MAX,
801 show_memory_swap_peak = !IN_SET(i->memory_swap_peak, 0, CGROUP_LIMIT_MAX);
802
803 if (i->memory_current != UINT64_MAX) {
804 printf(" Memory: %s", FORMAT_BYTES(i->memory_current));
805
806 bool show_memory_zswap_current = !IN_SET(i->memory_zswap_current, 0, CGROUP_LIMIT_MAX),
807 /* Only show the available memory if it was artificially limited. */
808 show_memory_available = i->memory_available != CGROUP_LIMIT_MAX &&
809 (i->memory_high != CGROUP_LIMIT_MAX || i->memory_max != CGROUP_LIMIT_MAX);
810 if (show_memory_peak ||
811 show_memory_swap_peak || /* We don't need to check memory_swap_current, as if peak is 0 that must also be 0 */
812 show_memory_zswap_current ||
813 show_memory_available ||
814 i->memory_min > 0 ||
815 i->memory_low > 0 || i->startup_memory_low > 0 ||
816 i->memory_high != CGROUP_LIMIT_MAX || i->startup_memory_high != CGROUP_LIMIT_MAX ||
817 i->memory_max != CGROUP_LIMIT_MAX || i->startup_memory_max != CGROUP_LIMIT_MAX ||
818 i->memory_swap_max != CGROUP_LIMIT_MAX || i->startup_memory_swap_max != CGROUP_LIMIT_MAX ||
819 i->memory_zswap_max != CGROUP_LIMIT_MAX || i->startup_memory_zswap_max != CGROUP_LIMIT_MAX ||
820 i->memory_limit != CGROUP_LIMIT_MAX) {
821 const char *prefix = "";
822
823 printf(" (");
824 if (i->memory_min > 0) {
825 printf("%smin: %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->memory_min));
826 prefix = ", ";
827 }
828 if (i->memory_low > 0) {
829 printf("%slow: %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->memory_low));
830 prefix = ", ";
831 }
832 if (i->startup_memory_low > 0) {
833 printf("%slow (startup): %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->startup_memory_low));
834 prefix = ", ";
835 }
836 if (i->memory_high != CGROUP_LIMIT_MAX) {
837 printf("%shigh: %s", prefix, FORMAT_BYTES(i->memory_high));
838 prefix = ", ";
839 }
840 if (i->startup_memory_high != CGROUP_LIMIT_MAX) {
841 printf("%shigh (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_high));
842 prefix = ", ";
843 }
844 if (i->memory_max != CGROUP_LIMIT_MAX) {
845 printf("%smax: %s", prefix, FORMAT_BYTES(i->memory_max));
846 prefix = ", ";
847 }
848 if (i->startup_memory_max != CGROUP_LIMIT_MAX) {
849 printf("%smax (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_max));
850 prefix = ", ";
851 }
852 if (i->memory_swap_max != CGROUP_LIMIT_MAX) {
853 printf("%sswap max: %s", prefix, FORMAT_BYTES(i->memory_swap_max));
854 prefix = ", ";
855 }
856 if (i->startup_memory_swap_max != CGROUP_LIMIT_MAX) {
857 printf("%sswap max (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_swap_max));
858 prefix = ", ";
859 }
860 if (i->memory_zswap_max != CGROUP_LIMIT_MAX) {
861 printf("%szswap max: %s", prefix, FORMAT_BYTES(i->memory_zswap_max));
862 prefix = ", ";
863 }
864 if (i->startup_memory_zswap_max != CGROUP_LIMIT_MAX) {
865 printf("%szswap max (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_zswap_max));
866 prefix = ", ";
867 }
868 if (i->memory_limit != CGROUP_LIMIT_MAX) {
869 printf("%slimit: %s", prefix, FORMAT_BYTES(i->memory_limit));
870 prefix = ", ";
871 }
872 if (show_memory_available) {
873 printf("%savailable: %s", prefix, FORMAT_BYTES(i->memory_available));
874 prefix = ", ";
875 }
876 if (show_memory_peak) {
877 printf("%speak: %s", prefix, FORMAT_BYTES(i->memory_peak));
878 prefix = ", ";
879 }
880 if (show_memory_swap_peak) {
881 printf("%sswap: %s, swap peak: %s", prefix,
882 FORMAT_BYTES(i->memory_swap_current), FORMAT_BYTES(i->memory_swap_peak));
883 prefix = ", ";
884 }
885 if (show_memory_zswap_current) {
886 printf("%szswap: %s", prefix, FORMAT_BYTES(i->memory_zswap_current));
887 prefix = ", ";
888 }
889 printf(")");
890 }
891 printf("\n");
892
893 } else if (show_memory_peak) {
894 printf(" Mem peak: %s", FORMAT_BYTES(i->memory_peak));
895
896 if (show_memory_swap_peak)
897 printf(" (swap: %s)", FORMAT_BYTES(i->memory_swap_peak));
898
899 putchar('\n');
900 }
901
902 if (i->cpu_usage_nsec != UINT64_MAX)
903 printf(" CPU: %s\n", FORMAT_TIMESPAN(i->cpu_usage_nsec / NSEC_PER_USEC, USEC_PER_MSEC));
904
905 for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++)
906 print_exec_directory_quota(i, dt);
907
908 if (i->control_group) {
909 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
910 static const char prefix[] = " ";
911 unsigned c;
912
913 printf(" CGroup: %s\n", i->control_group);
914
915 c = LESS_BY(columns(), strlen(prefix));
916
917 r = unit_show_processes(bus, i->id, i->control_group, prefix, c, get_output_flags(), &error);
918 if (r == -EBADR && arg_transport == BUS_TRANSPORT_LOCAL) {
919 unsigned k = 0;
920 pid_t extra[2];
921
922 /* Fallback for older systemd versions where the GetUnitProcesses() call is not yet available */
923
924 if (i->main_pid > 0)
925 extra[k++] = i->main_pid;
926
927 if (i->control_pid > 0)
928 extra[k++] = i->control_pid;
929
930 show_cgroup_and_extra(i->control_group, prefix, c, extra, k, get_output_flags());
931 } else if (r < 0)
932 log_warning_errno(r, "Failed to dump process list for '%s', ignoring: %s",
933 i->id, bus_error_message(&error, r));
934 }
935
936 if (i->id && arg_transport == BUS_TRANSPORT_LOCAL)
937 show_journal_by_unit(
938 stdout,
939 i->id,
940 i->log_namespace,
941 arg_output,
942 /* n_columns= */ 0,
943 i->inactive_exit_timestamp_monotonic,
944 arg_lines,
945 get_output_flags() | OUTPUT_BEGIN_NEWLINE,
946 SD_JOURNAL_LOCAL_ONLY,
947 arg_runtime_scope == RUNTIME_SCOPE_SYSTEM,
948 ellipsized);
949
950 if (i->need_daemon_reload)
951 warn_unit_file_changed(i->id);
952 }
953
954 static void show_unit_help(UnitStatusInfo *i) {
955 bool previous_man_page = false;
956
957 assert(i);
958
959 if (!i->documentation) {
960 log_info("Documentation for %s not known.", i->id);
961 return;
962 }
963
964 STRV_FOREACH(doc, i->documentation) {
965 const char *p;
966
967 p = startswith(*doc, "man:");
968
969 if (p ? doc != i->documentation : previous_man_page) {
970 puts("");
971 fflush(stdout);
972 }
973
974 previous_man_page = p;
975
976 if (p)
977 show_man_page(p, /* null_stdio= */ false);
978 else {
979 _cleanup_free_ char *t = NULL;
980
981 if ((p = startswith(*doc, "file://")))
982 (void) terminal_urlify_path(p, NULL, &t);
983
984 printf("Additional documentation: %s\n", t ?: p ?: *doc);
985 }
986 }
987 }
988
989 static int map_main_pid(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
990 UnitStatusInfo *i = userdata;
991 uint32_t u;
992 int r;
993
994 r = sd_bus_message_read(m, "u", &u);
995 if (r < 0)
996 return r;
997
998 i->main_pid = (pid_t) u;
999 i->running = u > 0;
1000
1001 return 0;
1002 }
1003
1004 static int map_load_error(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
1005 const char *message, **p = userdata;
1006 int r;
1007
1008 r = sd_bus_message_read(m, "(ss)", NULL, &message);
1009 if (r < 0)
1010 return r;
1011
1012 if (!isempty(message))
1013 *p = message;
1014
1015 return 0;
1016 }
1017
1018 static int map_listen(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
1019 const char *type, *path;
1020 char ***p = userdata;
1021 int r;
1022
1023 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(ss)");
1024 if (r < 0)
1025 return r;
1026
1027 while ((r = sd_bus_message_read(m, "(ss)", &type, &path)) > 0) {
1028
1029 r = strv_extend_many(p, type, path);
1030 if (r < 0)
1031 return r;
1032 }
1033 if (r < 0)
1034 return r;
1035
1036 r = sd_bus_message_exit_container(m);
1037 if (r < 0)
1038 return r;
1039
1040 return 0;
1041 }
1042
1043 static int map_conditions(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
1044 UnitStatusInfo *i = userdata;
1045 const char *cond, *param;
1046 int trigger, negate;
1047 int32_t state;
1048 int r;
1049
1050 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(sbbsi)");
1051 if (r < 0)
1052 return r;
1053
1054 while ((r = sd_bus_message_read(m, "(sbbsi)", &cond, &trigger, &negate, &param, &state)) > 0) {
1055 _cleanup_(unit_condition_freep) UnitCondition *c = NULL;
1056
1057 c = new(UnitCondition, 1);
1058 if (!c)
1059 return -ENOMEM;
1060
1061 *c = (UnitCondition) {
1062 .name = strdup(cond),
1063 .param = strdup(param),
1064 .trigger = trigger,
1065 .negate = negate,
1066 .tristate = state,
1067 };
1068
1069 if (!c->name || !c->param)
1070 return -ENOMEM;
1071
1072 LIST_PREPEND(conditions, i->conditions, TAKE_PTR(c));
1073 }
1074 if (r < 0)
1075 return r;
1076
1077 r = sd_bus_message_exit_container(m);
1078 if (r < 0)
1079 return r;
1080
1081 return 0;
1082 }
1083
1084 static int map_asserts(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
1085 UnitStatusInfo *i = userdata;
1086 const char *cond, *param;
1087 int trigger, negate;
1088 int32_t state;
1089 int r;
1090
1091 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(sbbsi)");
1092 if (r < 0)
1093 return r;
1094
1095 while ((r = sd_bus_message_read(m, "(sbbsi)", &cond, &trigger, &negate, &param, &state)) > 0) {
1096 if (state < 0 && (!trigger || !i->failed_assert)) {
1097 i->failed_assert = cond;
1098 i->failed_assert_trigger = trigger;
1099 i->failed_assert_negate = negate;
1100 i->failed_assert_parameter = param;
1101 }
1102 }
1103 if (r < 0)
1104 return r;
1105
1106 r = sd_bus_message_exit_container(m);
1107 if (r < 0)
1108 return r;
1109
1110 return 0;
1111 }
1112
1113 static int map_exec(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
1114 _cleanup_free_ ExecStatusInfo *info = NULL;
1115 ExecStatusInfo *last;
1116 UnitStatusInfo *i = userdata;
1117 bool is_ex_prop = endswith(member, "Ex");
1118 int r;
1119
1120 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, is_ex_prop ? "(sasasttttuii)" : "(sasbttttuii)");
1121 if (r < 0)
1122 return r;
1123
1124 info = new0(ExecStatusInfo, 1);
1125 if (!info)
1126 return -ENOMEM;
1127
1128 last = LIST_FIND_TAIL(exec_status_info_list, i->exec_status_info_list);
1129
1130 while ((r = exec_status_info_deserialize(m, info, is_ex_prop)) > 0) {
1131
1132 info->name = strdup(member);
1133 if (!info->name)
1134 return -ENOMEM;
1135
1136 LIST_INSERT_AFTER(exec_status_info_list, i->exec_status_info_list, last, info);
1137 last = info;
1138
1139 info = new0(ExecStatusInfo, 1);
1140 if (!info)
1141 return -ENOMEM;
1142 }
1143 if (r < 0)
1144 return r;
1145
1146 r = sd_bus_message_exit_container(m);
1147 if (r < 0)
1148 return r;
1149
1150 return 0;
1151 }
1152
1153 static int map_quota(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
1154 int r;
1155 QuotaInfo *qi = ASSERT_PTR(userdata);
1156 uint64_t quota_usage, quota_limit;
1157
1158 r = sd_bus_message_read(m, "(tt)", &quota_usage, &quota_limit);
1159 if (r < 0)
1160 return r;
1161
1162 *qi = (QuotaInfo) {
1163 .quota_enforce = quota_limit != UINT64_MAX,
1164 .quota_accounting = quota_usage != UINT64_MAX,
1165 .quota_usage = quota_usage,
1166 .quota_limit = quota_limit
1167 };
1168
1169 return 0;
1170 }
1171
1172 static int print_property(const char *name, const char *expected_value, sd_bus_message *m, BusPrintPropertyFlags flags) {
1173 char bus_type;
1174 const char *contents;
1175 int r;
1176
1177 assert(name);
1178 assert(m);
1179
1180 /* This is a low-level property printer, see print_status_info() for the nicer output */
1181
1182 r = sd_bus_message_peek_type(m, &bus_type, &contents);
1183 if (r < 0)
1184 return r;
1185
1186 switch (bus_type) {
1187
1188 case SD_BUS_TYPE_INT32:
1189 if (endswith(name, "ActionExitStatus")) {
1190 int32_t i;
1191
1192 r = sd_bus_message_read_basic(m, bus_type, &i);
1193 if (r < 0)
1194 return r;
1195
1196 if (i >= 0 && i <= 255)
1197 bus_print_property_valuef(name, expected_value, flags, "%"PRIi32, i);
1198 else if (FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY))
1199 bus_print_property_value(name, expected_value, flags, "[not set]");
1200
1201 return 1;
1202 } else if (streq(name, "NUMAPolicy")) {
1203 int32_t i;
1204
1205 r = sd_bus_message_read_basic(m, bus_type, &i);
1206 if (r < 0)
1207 return r;
1208
1209 bus_print_property_valuef(name, expected_value, flags, "%s", strna(mpol_to_string(i)));
1210
1211 return 1;
1212 }
1213 break;
1214
1215 case SD_BUS_TYPE_UINT64:
1216 if (bus_property_is_timestamp(name)) {
1217 uint64_t timestamp;
1218
1219 r = sd_bus_message_read_basic(m, bus_type, &timestamp);
1220 if (r < 0)
1221 return r;
1222
1223 bus_print_property_value(name, expected_value, flags, FORMAT_TIMESTAMP_STYLE(timestamp, arg_timestamp_style));
1224
1225 return 1;
1226 }
1227 break;
1228
1229 case SD_BUS_TYPE_STRUCT:
1230
1231 if (contents[0] == SD_BUS_TYPE_UINT32 && streq(name, "Job")) {
1232 uint32_t u;
1233
1234 r = sd_bus_message_read(m, "(uo)", &u, NULL);
1235 if (r < 0)
1236 return bus_log_parse_error(r);
1237
1238 if (u > 0)
1239 bus_print_property_valuef(name, expected_value, flags, "%"PRIu32, u);
1240 else
1241 bus_print_property_value(name, expected_value, flags, NULL);
1242
1243 return 1;
1244
1245 } else if (contents[0] == SD_BUS_TYPE_STRING && streq(name, "Unit")) {
1246 const char *s;
1247
1248 r = sd_bus_message_read(m, "(so)", &s, NULL);
1249 if (r < 0)
1250 return bus_log_parse_error(r);
1251
1252 bus_print_property_value(name, expected_value, flags, s);
1253
1254 return 1;
1255
1256 } else if (contents[0] == SD_BUS_TYPE_STRING && streq(name, "LoadError")) {
1257 const char *a = NULL, *b = NULL;
1258
1259 r = sd_bus_message_read(m, "(ss)", &a, &b);
1260 if (r < 0)
1261 return bus_log_parse_error(r);
1262
1263 if (!isempty(a) || !isempty(b))
1264 bus_print_property_valuef(name, expected_value, flags, "%s \"%s\"", strempty(a), strempty(b));
1265 else
1266 bus_print_property_value(name, expected_value, flags, NULL);
1267
1268 return 1;
1269
1270 } else if (STR_IN_SET(name, "SystemCallFilter", "SystemCallLog", "RestrictAddressFamilies", "RestrictNetworkInterfaces", "RestrictFileSystems")) {
1271 _cleanup_strv_free_ char **l = NULL;
1272 int allow_list;
1273
1274 r = sd_bus_message_enter_container(m, 'r', "bas");
1275 if (r < 0)
1276 return bus_log_parse_error(r);
1277
1278 r = sd_bus_message_read(m, "b", &allow_list);
1279 if (r < 0)
1280 return bus_log_parse_error(r);
1281
1282 r = sd_bus_message_read_strv(m, &l);
1283 if (r < 0)
1284 return bus_log_parse_error(r);
1285
1286 r = sd_bus_message_exit_container(m);
1287 if (r < 0)
1288 return bus_log_parse_error(r);
1289
1290 if (FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) || allow_list || !strv_isempty(l)) {
1291 bool first = true;
1292
1293 if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE)) {
1294 fputs(name, stdout);
1295 fputc('=', stdout);
1296 }
1297
1298 if (!allow_list)
1299 fputc('~', stdout);
1300
1301 STRV_FOREACH(i, l) {
1302 if (first)
1303 first = false;
1304 else
1305 fputc(' ', stdout);
1306
1307 fputs(*i, stdout);
1308 }
1309 fputc('\n', stdout);
1310 }
1311
1312 return 1;
1313
1314 } else if (STR_IN_SET(name, "SELinuxContext", "AppArmorProfile", "SmackProcessLabel")) {
1315 int ignore;
1316 const char *s;
1317
1318 r = sd_bus_message_read(m, "(bs)", &ignore, &s);
1319 if (r < 0)
1320 return bus_log_parse_error(r);
1321
1322 if (!isempty(s))
1323 bus_print_property_valuef(name, expected_value, flags, "%s%s", ignore ? "-" : "", s);
1324 else
1325 bus_print_property_value(name, expected_value, flags, NULL);
1326
1327 return 1;
1328
1329 } else if (endswith(name, "ExitStatus") && streq(contents, "aiai")) {
1330 const int32_t *status, *signal;
1331 size_t n_status, n_signal;
1332
1333 r = sd_bus_message_enter_container(m, 'r', "aiai");
1334 if (r < 0)
1335 return bus_log_parse_error(r);
1336
1337 r = sd_bus_message_read_array(m, 'i', (const void **) &status, &n_status);
1338 if (r < 0)
1339 return bus_log_parse_error(r);
1340
1341 r = sd_bus_message_read_array(m, 'i', (const void **) &signal, &n_signal);
1342 if (r < 0)
1343 return bus_log_parse_error(r);
1344
1345 r = sd_bus_message_exit_container(m);
1346 if (r < 0)
1347 return bus_log_parse_error(r);
1348
1349 n_status /= sizeof(int32_t);
1350 n_signal /= sizeof(int32_t);
1351
1352 if (FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) || n_status > 0 || n_signal > 0) {
1353 bool first = true;
1354
1355 if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE)) {
1356 fputs(name, stdout);
1357 fputc('=', stdout);
1358 }
1359
1360 for (size_t i = 0; i < n_status; i++) {
1361 if (first)
1362 first = false;
1363 else
1364 fputc(' ', stdout);
1365
1366 printf("%"PRIi32, status[i]);
1367 }
1368
1369 for (size_t i = 0; i < n_signal; i++) {
1370 const char *str;
1371
1372 str = signal_to_string((int) signal[i]);
1373
1374 if (first)
1375 first = false;
1376 else
1377 fputc(' ', stdout);
1378
1379 if (str)
1380 fputs(str, stdout);
1381 else
1382 printf("%"PRIi32, status[i]);
1383 }
1384
1385 fputc('\n', stdout);
1386 }
1387 return 1;
1388 } else if (STR_IN_SET(name, "StateDirectoryQuota", "CacheDirectoryQuota", "LogsDirectoryQuota")) {
1389 uint64_t quota_absolute;
1390 uint32_t quota_scale;
1391 const char *quota_enforce;
1392
1393 r = sd_bus_message_read(m, "(tus)", &quota_absolute, &quota_scale, &quota_enforce);
1394 if (r < 0)
1395 return r;
1396
1397 r = parse_boolean(quota_enforce);
1398 if (r < 0)
1399 return r;
1400
1401 if (!r)
1402 bus_print_property_value(name, expected_value, flags, "[not set]");
1403 else if (quota_absolute != UINT64_MAX)
1404 bus_print_property_valuef(name, expected_value, flags, "%" PRIu64, quota_absolute);
1405 else
1406 bus_print_property_valuef(name, expected_value, flags, "%d%%", UINT32_SCALE_TO_PERCENT(quota_scale));
1407
1408 return 1;
1409 }
1410
1411 break;
1412
1413 case SD_BUS_TYPE_ARRAY:
1414
1415 if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "EnvironmentFiles")) {
1416 const char *path;
1417 int ignore;
1418
1419 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(sb)");
1420 if (r < 0)
1421 return bus_log_parse_error(r);
1422
1423 while ((r = sd_bus_message_read(m, "(sb)", &path, &ignore)) > 0)
1424 bus_print_property_valuef(name, expected_value, flags, "%s (ignore_errors=%s)", path, yes_no(ignore));
1425 if (r < 0)
1426 return bus_log_parse_error(r);
1427
1428 r = sd_bus_message_exit_container(m);
1429 if (r < 0)
1430 return bus_log_parse_error(r);
1431
1432 return 1;
1433
1434 } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "Paths")) {
1435 const char *type, *path;
1436
1437 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(ss)");
1438 if (r < 0)
1439 return bus_log_parse_error(r);
1440
1441 while ((r = sd_bus_message_read(m, "(ss)", &type, &path)) > 0)
1442 bus_print_property_valuef(name, expected_value, flags, "%s (%s)", path, type);
1443 if (r < 0)
1444 return bus_log_parse_error(r);
1445
1446 r = sd_bus_message_exit_container(m);
1447 if (r < 0)
1448 return bus_log_parse_error(r);
1449
1450 return 1;
1451
1452 } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "Listen")) {
1453 const char *type, *path;
1454
1455 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(ss)");
1456 if (r < 0)
1457 return bus_log_parse_error(r);
1458
1459 while ((r = sd_bus_message_read(m, "(ss)", &type, &path)) > 0)
1460 bus_print_property_valuef(name, expected_value, flags, "%s (%s)", path, type);
1461 if (r < 0)
1462 return bus_log_parse_error(r);
1463
1464 r = sd_bus_message_exit_container(m);
1465 if (r < 0)
1466 return bus_log_parse_error(r);
1467
1468 return 1;
1469
1470 } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "TimersMonotonic")) {
1471 const char *base;
1472 uint64_t v, next_elapse;
1473
1474 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(stt)");
1475 if (r < 0)
1476 return bus_log_parse_error(r);
1477
1478 while ((r = sd_bus_message_read(m, "(stt)", &base, &v, &next_elapse)) > 0)
1479 bus_print_property_valuef(name, expected_value, flags,
1480 "{ %s=%s ; next_elapse=%s }",
1481 base,
1482 strna(FORMAT_TIMESPAN(v, 0)),
1483 strna(FORMAT_TIMESPAN(next_elapse, 0)));
1484 if (r < 0)
1485 return bus_log_parse_error(r);
1486
1487 r = sd_bus_message_exit_container(m);
1488 if (r < 0)
1489 return bus_log_parse_error(r);
1490
1491 return 1;
1492
1493 } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "TimersCalendar")) {
1494 const char *base, *spec;
1495 uint64_t next_elapse;
1496
1497 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(sst)");
1498 if (r < 0)
1499 return bus_log_parse_error(r);
1500
1501 while ((r = sd_bus_message_read(m, "(sst)", &base, &spec, &next_elapse)) > 0)
1502 bus_print_property_valuef(name, expected_value, flags,
1503 "{ %s=%s ; next_elapse=%s }", base, spec,
1504 FORMAT_TIMESTAMP_STYLE(next_elapse, arg_timestamp_style));
1505 if (r < 0)
1506 return bus_log_parse_error(r);
1507
1508 r = sd_bus_message_exit_container(m);
1509 if (r < 0)
1510 return bus_log_parse_error(r);
1511
1512 return 1;
1513
1514 } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && startswith(name, "Exec")) {
1515 ExecStatusInfo info = {};
1516 bool is_ex_prop = endswith(name, "Ex");
1517
1518 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, is_ex_prop ? "(sasasttttuii)" : "(sasbttttuii)");
1519 if (r < 0)
1520 return bus_log_parse_error(r);
1521
1522 while ((r = exec_status_info_deserialize(m, &info, is_ex_prop)) > 0) {
1523 _cleanup_strv_free_ char **optv = NULL;
1524 _cleanup_free_ char *tt = NULL, *o = NULL;
1525
1526 tt = strv_join(info.argv, " ");
1527
1528 if (is_ex_prop) {
1529 r = exec_command_flags_to_strv(info.flags, &optv);
1530 if (r < 0)
1531 return log_error_errno(r, "Failed to convert ExecCommandFlags to strv: %m");
1532
1533 o = strv_join(optv, " ");
1534
1535 bus_print_property_valuef(name, expected_value, flags,
1536 "{ path=%s ; argv[]=%s ; flags=%s ; start_time=[%s] ; stop_time=[%s] ; pid="PID_FMT" ; code=%s ; status=%i%s%s }",
1537 strna(info.path),
1538 strna(tt),
1539 strna(o),
1540 strna(FORMAT_TIMESTAMP_STYLE(info.start_timestamp, arg_timestamp_style)),
1541 strna(FORMAT_TIMESTAMP_STYLE(info.exit_timestamp, arg_timestamp_style)),
1542 info.pid,
1543 sigchld_code_to_string(info.code),
1544 info.status,
1545 info.code == CLD_EXITED ? "" : "/",
1546 strempty(info.code == CLD_EXITED ? NULL : signal_to_string(info.status)));
1547 } else
1548 bus_print_property_valuef(name, expected_value, flags,
1549 "{ path=%s ; argv[]=%s ; ignore_errors=%s ; start_time=[%s] ; stop_time=[%s] ; pid="PID_FMT" ; code=%s ; status=%i%s%s }",
1550 strna(info.path),
1551 strna(tt),
1552 yes_no(info.ignore),
1553 strna(FORMAT_TIMESTAMP_STYLE(info.start_timestamp, arg_timestamp_style)),
1554 strna(FORMAT_TIMESTAMP_STYLE(info.exit_timestamp, arg_timestamp_style)),
1555 info.pid,
1556 sigchld_code_to_string(info.code),
1557 info.status,
1558 info.code == CLD_EXITED ? "" : "/",
1559 strempty(info.code == CLD_EXITED ? NULL : signal_to_string(info.status)));
1560
1561 free(info.path);
1562 strv_free(info.argv);
1563 zero(info);
1564 }
1565
1566 r = sd_bus_message_exit_container(m);
1567 if (r < 0)
1568 return bus_log_parse_error(r);
1569
1570 return 1;
1571
1572 } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "DeviceAllow")) {
1573 const char *path, *rwm;
1574
1575 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(ss)");
1576 if (r < 0)
1577 return bus_log_parse_error(r);
1578
1579 while ((r = sd_bus_message_read(m, "(ss)", &path, &rwm)) > 0)
1580 bus_print_property_valuef(name, expected_value, flags, "%s %s", strna(path), strna(rwm));
1581 if (r < 0)
1582 return bus_log_parse_error(r);
1583
1584 r = sd_bus_message_exit_container(m);
1585 if (r < 0)
1586 return bus_log_parse_error(r);
1587
1588 return 1;
1589
1590 } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "IODeviceWeight")) {
1591 const char *path;
1592 uint64_t weight;
1593
1594 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(st)");
1595 if (r < 0)
1596 return bus_log_parse_error(r);
1597
1598 while ((r = sd_bus_message_read(m, "(st)", &path, &weight)) > 0)
1599 bus_print_property_valuef(name, expected_value, flags, "%s %"PRIu64, strna(path), weight);
1600 if (r < 0)
1601 return bus_log_parse_error(r);
1602
1603 r = sd_bus_message_exit_container(m);
1604 if (r < 0)
1605 return bus_log_parse_error(r);
1606
1607 return 1;
1608
1609 } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN &&
1610 cgroup_io_limit_type_from_string(name) >= 0) {
1611 const char *path;
1612 uint64_t bandwidth;
1613
1614 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(st)");
1615 if (r < 0)
1616 return bus_log_parse_error(r);
1617
1618 while ((r = sd_bus_message_read(m, "(st)", &path, &bandwidth)) > 0)
1619 bus_print_property_valuef(name, expected_value, flags, "%s %"PRIu64, strna(path), bandwidth);
1620 if (r < 0)
1621 return bus_log_parse_error(r);
1622
1623 r = sd_bus_message_exit_container(m);
1624 if (r < 0)
1625 return bus_log_parse_error(r);
1626
1627 return 1;
1628
1629 } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN &&
1630 streq(name, "IODeviceLatencyTargetUSec")) {
1631 const char *path;
1632 uint64_t target;
1633
1634 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(st)");
1635 if (r < 0)
1636 return bus_log_parse_error(r);
1637
1638 while ((r = sd_bus_message_read(m, "(st)", &path, &target)) > 0)
1639 bus_print_property_valuef(name, expected_value, flags, "%s %s", strna(path),
1640 FORMAT_TIMESPAN(target, 1));
1641 if (r < 0)
1642 return bus_log_parse_error(r);
1643
1644 r = sd_bus_message_exit_container(m);
1645 if (r < 0)
1646 return bus_log_parse_error(r);
1647
1648 return 1;
1649
1650 } else if (contents[0] == SD_BUS_TYPE_BYTE && STR_IN_SET(name, "StandardInputData", "RootHashSignature")) {
1651 _cleanup_free_ char *h = NULL;
1652 const void *p;
1653 size_t sz;
1654 ssize_t n;
1655
1656 r = sd_bus_message_read_array(m, 'y', &p, &sz);
1657 if (r < 0)
1658 return bus_log_parse_error(r);
1659
1660 n = base64mem(p, sz, &h);
1661 if (n < 0)
1662 return log_oom();
1663
1664 bus_print_property_value(name, expected_value, flags, h);
1665
1666 return 1;
1667
1668 } else if (STR_IN_SET(name, "IPAddressAllow", "IPAddressDeny")) {
1669 _cleanup_free_ char *addresses = NULL;
1670
1671 r = sd_bus_message_enter_container(m, 'a', "(iayu)");
1672 if (r < 0)
1673 return bus_log_parse_error(r);
1674
1675 for (;;) {
1676 uint32_t prefixlen;
1677 int32_t family;
1678 const void *ap;
1679 size_t an;
1680
1681 r = sd_bus_message_enter_container(m, 'r', "iayu");
1682 if (r < 0)
1683 return bus_log_parse_error(r);
1684 if (r == 0)
1685 break;
1686
1687 r = sd_bus_message_read(m, "i", &family);
1688 if (r < 0)
1689 return bus_log_parse_error(r);
1690
1691 r = sd_bus_message_read_array(m, 'y', &ap, &an);
1692 if (r < 0)
1693 return bus_log_parse_error(r);
1694
1695 r = sd_bus_message_read(m, "u", &prefixlen);
1696 if (r < 0)
1697 return bus_log_parse_error(r);
1698
1699 r = sd_bus_message_exit_container(m);
1700 if (r < 0)
1701 return bus_log_parse_error(r);
1702
1703 if (!IN_SET(family, AF_INET, AF_INET6))
1704 continue;
1705
1706 if (an != FAMILY_ADDRESS_SIZE(family))
1707 continue;
1708
1709 if (prefixlen > FAMILY_ADDRESS_SIZE(family) * 8)
1710 continue;
1711
1712 if (!strextend_with_separator(&addresses, " ",
1713 IN_ADDR_PREFIX_TO_STRING(family, ap, prefixlen)))
1714 return log_oom();
1715 }
1716
1717 r = sd_bus_message_exit_container(m);
1718 if (r < 0)
1719 return bus_log_parse_error(r);
1720
1721 bus_print_property_value(name, expected_value, flags, addresses);
1722
1723 return 1;
1724
1725 } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) {
1726 _cleanup_free_ char *paths = NULL;
1727 const char *source, *dest;
1728 int ignore_enoent;
1729 uint64_t rbind;
1730
1731 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(ssbt)");
1732 if (r < 0)
1733 return bus_log_parse_error(r);
1734
1735 while ((r = sd_bus_message_read(m, "(ssbt)", &source, &dest, &ignore_enoent, &rbind)) > 0) {
1736 _cleanup_free_ char *str = NULL;
1737
1738 if (isempty(source))
1739 continue;
1740
1741 if (asprintf(&str, "%s%s%s%s%s",
1742 ignore_enoent ? "-" : "",
1743 source,
1744 isempty(dest) ? "" : ":",
1745 strempty(dest),
1746 rbind == MS_REC ? ":rbind" : "") < 0)
1747 return log_oom();
1748
1749 if (!strextend_with_separator(&paths, " ", str))
1750 return log_oom();
1751 }
1752 if (r < 0)
1753 return bus_log_parse_error(r);
1754
1755 r = sd_bus_message_exit_container(m);
1756 if (r < 0)
1757 return bus_log_parse_error(r);
1758
1759 bus_print_property_value(name, expected_value, flags, paths);
1760
1761 return 1;
1762
1763 } else if (streq(name, "TemporaryFileSystem")) {
1764 _cleanup_free_ char *paths = NULL;
1765 const char *target, *option;
1766
1767 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(ss)");
1768 if (r < 0)
1769 return bus_log_parse_error(r);
1770
1771 while ((r = sd_bus_message_read(m, "(ss)", &target, &option)) > 0) {
1772 _cleanup_free_ char *str = NULL;
1773
1774 if (isempty(target))
1775 continue;
1776
1777 if (asprintf(&str, "%s%s%s", target, isempty(option) ? "" : ":", strempty(option)) < 0)
1778 return log_oom();
1779
1780 if (!strextend_with_separator(&paths, " ", str))
1781 return log_oom();
1782 }
1783 if (r < 0)
1784 return bus_log_parse_error(r);
1785
1786 r = sd_bus_message_exit_container(m);
1787 if (r < 0)
1788 return bus_log_parse_error(r);
1789
1790 bus_print_property_value(name, expected_value, flags, paths);
1791
1792 return 1;
1793
1794 } else if (streq(name, "LogExtraFields")) {
1795 _cleanup_free_ char *fields = NULL;
1796 const void *p;
1797 size_t sz;
1798
1799 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "ay");
1800 if (r < 0)
1801 return bus_log_parse_error(r);
1802
1803 while ((r = sd_bus_message_read_array(m, 'y', &p, &sz)) > 0) {
1804 _cleanup_free_ char *str = NULL;
1805 const char *eq;
1806
1807 if (memchr(p, 0, sz))
1808 continue;
1809
1810 eq = memchr(p, '=', sz);
1811 if (!eq)
1812 continue;
1813
1814 if (!journal_field_valid(p, eq - (const char*) p, false))
1815 continue;
1816
1817 str = malloc(sz + 1);
1818 if (!str)
1819 return log_oom();
1820
1821 memcpy(str, p, sz);
1822 str[sz] = '\0';
1823
1824 if (!utf8_is_valid(str))
1825 continue;
1826
1827 if (!strextend_with_separator(&fields, " ", str))
1828 return log_oom();
1829 }
1830 if (r < 0)
1831 return bus_log_parse_error(r);
1832
1833 r = sd_bus_message_exit_container(m);
1834 if (r < 0)
1835 return bus_log_parse_error(r);
1836
1837 bus_print_property_value(name, expected_value, flags, fields);
1838
1839 return 1;
1840 } else if (contents[0] == SD_BUS_TYPE_BYTE &&
1841 STR_IN_SET(name,
1842 "CPUAffinity", "NUMAMask", "AllowedCPUs", "AllowedMemoryNodes",
1843 "EffectiveCPUs", "EffectiveMemoryNodes")) {
1844
1845 _cleanup_free_ char *affinity = NULL;
1846 _cleanup_(cpu_set_done) CPUSet set = {};
1847 const void *a;
1848 size_t n;
1849
1850 r = sd_bus_message_read_array(m, 'y', &a, &n);
1851 if (r < 0)
1852 return bus_log_parse_error(r);
1853
1854 r = cpu_set_from_dbus(a, n, &set);
1855 if (r < 0)
1856 return log_error_errno(r, "Failed to deserialize %s: %m", name);
1857
1858 affinity = cpu_set_to_range_string(&set);
1859 if (!affinity)
1860 return log_oom();
1861
1862 bus_print_property_value(name, expected_value, flags, affinity);
1863
1864 return 1;
1865 } else if (streq(name, "LogFilterPatterns")) {
1866 int is_allowlist;
1867 const char *pattern;
1868
1869 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(bs)");
1870 if (r < 0)
1871 return bus_log_parse_error(r);
1872
1873 while ((r = sd_bus_message_read(m, "(bs)", &is_allowlist, &pattern)) > 0)
1874 bus_print_property_valuef(name, expected_value, flags, "%s%s", is_allowlist ? "" : "~", pattern);
1875 if (r < 0)
1876 return bus_log_parse_error(r);
1877
1878 r = sd_bus_message_exit_container(m);
1879 if (r < 0)
1880 return bus_log_parse_error(r);
1881
1882 return 1;
1883
1884 } else if (streq(name, "RootImageOptions")) {
1885 const char *a, *p;
1886
1887 /* In config files, the syntax allows the partition name to be omitted. Here, we
1888 * always print the partition name, also because we have no way of knowing if it was
1889 * originally omitted or not. We also print the partitions on separate lines. */
1890
1891 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(ss)");
1892 if (r < 0)
1893 return bus_log_parse_error(r);
1894
1895 while ((r = sd_bus_message_read(m, "(ss)", &a, &p)) > 0)
1896 bus_print_property_valuef(name, expected_value, flags, "%s:%s", a, p);
1897 if (r < 0)
1898 return bus_log_parse_error(r);
1899
1900 r = sd_bus_message_exit_container(m);
1901 if (r < 0)
1902 return bus_log_parse_error(r);
1903
1904 return 1;
1905
1906 } else if (streq(name, "MountImages")) {
1907 _cleanup_free_ char *paths = NULL;
1908
1909 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(ssba(ss))");
1910 if (r < 0)
1911 return bus_log_parse_error(r);
1912
1913 for (;;) {
1914 _cleanup_free_ char *str = NULL;
1915 const char *source, *destination, *partition, *mount_options;
1916 int ignore_enoent;
1917
1918 r = sd_bus_message_enter_container(m, 'r', "ssba(ss)");
1919 if (r < 0)
1920 return bus_log_parse_error(r);
1921 if (r == 0)
1922 break;
1923
1924 r = sd_bus_message_read(m, "ssb", &source, &destination, &ignore_enoent);
1925 if (r < 0)
1926 return bus_log_parse_error(r);
1927
1928 str = strjoin(ignore_enoent ? "-" : "",
1929 source,
1930 ":",
1931 destination);
1932 if (!str)
1933 return log_oom();
1934
1935 r = sd_bus_message_enter_container(m, 'a', "(ss)");
1936 if (r < 0)
1937 return bus_log_parse_error(r);
1938
1939 while ((r = sd_bus_message_read(m, "(ss)", &partition, &mount_options)) > 0)
1940 if (!strextend_with_separator(&str, ":", partition, mount_options))
1941 return log_oom();
1942 if (r < 0)
1943 return bus_log_parse_error(r);
1944
1945 if (!strextend_with_separator(&paths, " ", str))
1946 return log_oom();
1947
1948 r = sd_bus_message_exit_container(m);
1949 if (r < 0)
1950 return bus_log_parse_error(r);
1951
1952 r = sd_bus_message_exit_container(m);
1953 if (r < 0)
1954 return bus_log_parse_error(r);
1955 }
1956
1957 r = sd_bus_message_exit_container(m);
1958 if (r < 0)
1959 return bus_log_parse_error(r);
1960
1961 bus_print_property_value(name, expected_value, flags, paths);
1962
1963 return 1;
1964
1965 } else if (streq(name, "ExtensionImages")) {
1966 _cleanup_free_ char *paths = NULL;
1967
1968 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(sba(ss))");
1969 if (r < 0)
1970 return bus_log_parse_error(r);
1971
1972 for (;;) {
1973 _cleanup_free_ char *str = NULL;
1974 const char *source, *partition, *mount_options;
1975 int ignore_enoent;
1976
1977 r = sd_bus_message_enter_container(m, 'r', "sba(ss)");
1978 if (r < 0)
1979 return bus_log_parse_error(r);
1980 if (r == 0)
1981 break;
1982
1983 r = sd_bus_message_read(m, "sb", &source, &ignore_enoent);
1984 if (r < 0)
1985 return bus_log_parse_error(r);
1986
1987 str = strjoin(ignore_enoent ? "-" : "", source);
1988 if (!str)
1989 return log_oom();
1990
1991 r = sd_bus_message_enter_container(m, 'a', "(ss)");
1992 if (r < 0)
1993 return bus_log_parse_error(r);
1994
1995 while ((r = sd_bus_message_read(m, "(ss)", &partition, &mount_options)) > 0)
1996 if (!strextend_with_separator(&str, ":", partition, mount_options))
1997 return log_oom();
1998 if (r < 0)
1999 return bus_log_parse_error(r);
2000
2001 if (!strextend_with_separator(&paths, " ", str))
2002 return log_oom();
2003
2004 r = sd_bus_message_exit_container(m);
2005 if (r < 0)
2006 return bus_log_parse_error(r);
2007
2008 r = sd_bus_message_exit_container(m);
2009 if (r < 0)
2010 return bus_log_parse_error(r);
2011 }
2012
2013 r = sd_bus_message_exit_container(m);
2014 if (r < 0)
2015 return bus_log_parse_error(r);
2016
2017 bus_print_property_value(name, expected_value, flags, paths);
2018
2019 return 1;
2020
2021 } else if (streq(name, "BPFProgram")) {
2022 const char *a, *p;
2023
2024 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(ss)");
2025 if (r < 0)
2026 return bus_log_parse_error(r);
2027
2028 while ((r = sd_bus_message_read(m, "(ss)", &a, &p)) > 0)
2029 bus_print_property_valuef(name, expected_value, flags, "%s:%s", a, p);
2030 if (r < 0)
2031 return bus_log_parse_error(r);
2032
2033 r = sd_bus_message_exit_container(m);
2034 if (r < 0)
2035 return bus_log_parse_error(r);
2036
2037 return 1;
2038 } else if (STR_IN_SET(name, "SocketBindAllow", "SocketBindDeny")) {
2039 uint16_t nr_ports, port_min;
2040 int32_t af, ip_protocol;
2041
2042 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(iiqq)");
2043 if (r < 0)
2044 return bus_log_parse_error(r);
2045 while ((r = sd_bus_message_read(m, "(iiqq)", &af, &ip_protocol, &nr_ports, &port_min)) > 0) {
2046 const char *family, *colon1, *protocol = "", *colon2 = "";
2047
2048 family = strempty(af_to_ipv4_ipv6(af));
2049 colon1 = isempty(family) ? "" : ":";
2050
2051 if (ip_protocol != 0) {
2052 protocol = ip_protocol_to_tcp_udp(ip_protocol);
2053 colon2 = "";
2054 }
2055
2056 if (nr_ports == 0)
2057 bus_print_property_valuef(name, expected_value, flags, "%s%s%s%sany",
2058 family, colon1, protocol, colon2);
2059 else if (nr_ports == 1)
2060 bus_print_property_valuef(
2061 name, expected_value, flags, "%s%s%s%s%hu",
2062 family, colon1, protocol, colon2, port_min);
2063 else
2064 bus_print_property_valuef(
2065 name, expected_value, flags, "%s%s%s%s%hu-%hu",
2066 family, colon1, protocol, colon2, port_min,
2067 (uint16_t) (port_min + nr_ports - 1));
2068 }
2069 if (r < 0)
2070 return bus_log_parse_error(r);
2071
2072 r = sd_bus_message_exit_container(m);
2073 if (r < 0)
2074 return bus_log_parse_error(r);
2075
2076 return 1;
2077 } else if (STR_IN_SET(name, "StateDirectorySymlink", "RuntimeDirectorySymlink", "CacheDirectorySymlink", "LogsDirectorySymlink")) {
2078 const char *a, *p;
2079 uint64_t symlink_flags;
2080
2081 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(sst)");
2082 if (r < 0)
2083 return bus_log_parse_error(r);
2084
2085 while ((r = sd_bus_message_read(m, "(sst)", &a, &p, &symlink_flags)) > 0)
2086 bus_print_property_valuef(name, expected_value, flags, "%s:%s", a, p);
2087 if (r < 0)
2088 return bus_log_parse_error(r);
2089
2090 r = sd_bus_message_exit_container(m);
2091 if (r < 0)
2092 return bus_log_parse_error(r);
2093
2094 return 1;
2095 } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "OpenFile")) {
2096 char *path, *fdname;
2097 uint64_t offlags;
2098
2099 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(sst)");
2100 if (r < 0)
2101 return bus_log_parse_error(r);
2102
2103 while ((r = sd_bus_message_read(m, "(sst)", &path, &fdname, &offlags)) > 0) {
2104 _cleanup_free_ char *ofs = NULL;
2105
2106 r = open_file_to_string(
2107 &(OpenFile){
2108 .path = path,
2109 .fdname = fdname,
2110 .flags = offlags,
2111 },
2112 &ofs);
2113 if (r < 0)
2114 return log_error_errno(
2115 r, "Failed to convert OpenFile= value to string: %m");
2116
2117 bus_print_property_value(name, expected_value, flags, ofs);
2118 }
2119 if (r < 0)
2120 return bus_log_parse_error(r);
2121
2122 r = sd_bus_message_exit_container(m);
2123 if (r < 0)
2124 return bus_log_parse_error(r);
2125
2126 return 1;
2127 } else if (streq(name, "ExtraFileDescriptorNames")) {
2128 _cleanup_strv_free_ char **extra_fd_names = NULL;
2129 _cleanup_free_ char *joined = NULL;
2130
2131 r = sd_bus_message_read_strv(m, &extra_fd_names);
2132 if (r < 0)
2133 return bus_log_parse_error(r);
2134
2135 joined = strv_join(extra_fd_names, " ");
2136 if (!joined)
2137 return log_oom();
2138
2139 bus_print_property_value(name, expected_value, flags, joined);
2140
2141 return 1;
2142 }
2143
2144 break;
2145 }
2146
2147 return 0;
2148 }
2149
2150 typedef enum SystemctlShowMode{
2151 SYSTEMCTL_SHOW_PROPERTIES,
2152 SYSTEMCTL_SHOW_STATUS,
2153 SYSTEMCTL_SHOW_HELP,
2154 _SYSTEMCTL_SHOW_MODE_MAX,
2155 _SYSTEMCTL_SHOW_MODE_INVALID = -EINVAL,
2156 } SystemctlShowMode;
2157
2158 static const char* const systemctl_show_mode_table[_SYSTEMCTL_SHOW_MODE_MAX] = {
2159 [SYSTEMCTL_SHOW_PROPERTIES] = "show",
2160 [SYSTEMCTL_SHOW_STATUS] = "status",
2161 [SYSTEMCTL_SHOW_HELP] = "help",
2162 };
2163
2164 DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(systemctl_show_mode, SystemctlShowMode);
2165
2166 static int show_one(
2167 sd_bus *bus,
2168 const char *path,
2169 const char *unit,
2170 SystemctlShowMode show_mode,
2171 bool *new_line,
2172 bool *ellipsized) {
2173
2174 static const struct bus_properties_map property_map[] = {
2175 { "Id", "s", NULL, offsetof(UnitStatusInfo, id) },
2176 { "LoadState", "s", NULL, offsetof(UnitStatusInfo, load_state) },
2177 { "ActiveState", "s", NULL, offsetof(UnitStatusInfo, active_state) },
2178 { "FreezerState", "s", NULL, offsetof(UnitStatusInfo, freezer_state) },
2179 { "Documentation", "as", NULL, offsetof(UnitStatusInfo, documentation) },
2180 {}
2181 }, status_map[] = {
2182 { "Id", "s", NULL, offsetof(UnitStatusInfo, id) },
2183 { "LoadState", "s", NULL, offsetof(UnitStatusInfo, load_state) },
2184 { "ActiveState", "s", NULL, offsetof(UnitStatusInfo, active_state) },
2185 { "FreezerState", "s", NULL, offsetof(UnitStatusInfo, freezer_state) },
2186 { "SubState", "s", NULL, offsetof(UnitStatusInfo, sub_state) },
2187 { "Job", "(uo)", bus_map_job_id, offsetof(UnitStatusInfo, job_id) },
2188 { "UnitFileState", "s", NULL, offsetof(UnitStatusInfo, unit_file_state) },
2189 { "UnitFilePreset", "s", NULL, offsetof(UnitStatusInfo, unit_file_preset) },
2190 { "Description", "s", NULL, offsetof(UnitStatusInfo, description) },
2191 { "Following", "s", NULL, offsetof(UnitStatusInfo, following) },
2192 { "Documentation", "as", NULL, offsetof(UnitStatusInfo, documentation) },
2193 { "FragmentPath", "s", NULL, offsetof(UnitStatusInfo, fragment_path) },
2194 { "SourcePath", "s", NULL, offsetof(UnitStatusInfo, source_path) },
2195 { "ControlGroup", "s", NULL, offsetof(UnitStatusInfo, control_group) },
2196 { "DropInPaths", "as", NULL, offsetof(UnitStatusInfo, dropin_paths) },
2197 { "LoadError", "(ss)", map_load_error, offsetof(UnitStatusInfo, load_error) },
2198 { "Result", "s", NULL, offsetof(UnitStatusInfo, result) },
2199 { "TriggeredBy", "as", NULL, offsetof(UnitStatusInfo, triggered_by) },
2200 { "Triggers", "as", NULL, offsetof(UnitStatusInfo, triggers) },
2201 { "InactiveExitTimestamp", "t", NULL, offsetof(UnitStatusInfo, inactive_exit_timestamp) },
2202 { "InactiveExitTimestampMonotonic", "t", NULL, offsetof(UnitStatusInfo, inactive_exit_timestamp_monotonic) },
2203 { "ActiveEnterTimestamp", "t", NULL, offsetof(UnitStatusInfo, active_enter_timestamp) },
2204 { "ActiveExitTimestamp", "t", NULL, offsetof(UnitStatusInfo, active_exit_timestamp) },
2205 { "InactiveEnterTimestamp", "t", NULL, offsetof(UnitStatusInfo, inactive_enter_timestamp) },
2206 { "RuntimeMaxUSec", "t", NULL, offsetof(UnitStatusInfo, runtime_max_sec) },
2207 { "InvocationID", "ay", bus_map_id128, offsetof(UnitStatusInfo, invocation_id) },
2208 { "NeedDaemonReload", "b", NULL, offsetof(UnitStatusInfo, need_daemon_reload) },
2209 { "Transient", "b", NULL, offsetof(UnitStatusInfo, transient) },
2210 { "ExecMainPID", "u", NULL, offsetof(UnitStatusInfo, main_pid) },
2211 { "MainPID", "u", map_main_pid, 0 },
2212 { "ControlPID", "u", NULL, offsetof(UnitStatusInfo, control_pid) },
2213 { "PIDFile", "s", NULL, offsetof(UnitStatusInfo, pid_file) },
2214 { "StatusText", "s", NULL, offsetof(UnitStatusInfo, status_text) },
2215 { "StatusErrno", "i", NULL, offsetof(UnitStatusInfo, status_errno) },
2216 { "StatusBusError", "s", NULL, offsetof(UnitStatusInfo, status_bus_error) },
2217 { "StatusVarlinkError", "s", NULL, offsetof(UnitStatusInfo, status_varlink_error) },
2218 { "FileDescriptorStoreMax", "u", NULL, offsetof(UnitStatusInfo, fd_store_max) },
2219 { "NFileDescriptorStore", "u", NULL, offsetof(UnitStatusInfo, n_fd_store) },
2220 { "ExecMainStartTimestamp", "t", NULL, offsetof(UnitStatusInfo, start_timestamp) },
2221 { "ExecMainExitTimestamp", "t", NULL, offsetof(UnitStatusInfo, exit_timestamp) },
2222 { "ExecMainCode", "i", NULL, offsetof(UnitStatusInfo, exit_code) },
2223 { "ExecMainStatus", "i", NULL, offsetof(UnitStatusInfo, exit_status) },
2224 { "LogNamespace", "s", NULL, offsetof(UnitStatusInfo, log_namespace) },
2225 { "ConditionTimestamp", "t", NULL, offsetof(UnitStatusInfo, condition_timestamp) },
2226 { "ConditionResult", "b", NULL, offsetof(UnitStatusInfo, condition_result) },
2227 { "Conditions", "a(sbbsi)", map_conditions, 0 },
2228 { "AssertTimestamp", "t", NULL, offsetof(UnitStatusInfo, assert_timestamp) },
2229 { "AssertResult", "b", NULL, offsetof(UnitStatusInfo, assert_result) },
2230 { "Asserts", "a(sbbsi)", map_asserts, 0 },
2231 { "NextElapseUSecRealtime", "t", NULL, offsetof(UnitStatusInfo, next_elapse_real) },
2232 { "NextElapseUSecMonotonic", "t", NULL, offsetof(UnitStatusInfo, next_elapse_monotonic) },
2233 { "NAccepted", "u", NULL, offsetof(UnitStatusInfo, n_accepted) },
2234 { "NConnections", "u", NULL, offsetof(UnitStatusInfo, n_connections) },
2235 { "NRefused", "u", NULL, offsetof(UnitStatusInfo, n_refused) },
2236 { "Accept", "b", NULL, offsetof(UnitStatusInfo, accept) },
2237 { "Listen", "a(ss)", map_listen, offsetof(UnitStatusInfo, listen) },
2238 { "SysFSPath", "s", NULL, offsetof(UnitStatusInfo, sysfs_path) },
2239 { "Where", "s", NULL, offsetof(UnitStatusInfo, where) },
2240 { "What", "s", NULL, offsetof(UnitStatusInfo, what) },
2241 { "ConcurrencyHardMax", "u", NULL, offsetof(UnitStatusInfo, concurrency_hard_max) },
2242 { "ConcurrencySoftMax", "u", NULL, offsetof(UnitStatusInfo, concurrency_soft_max) },
2243 { "NCurrentlyActive", "u", NULL, offsetof(UnitStatusInfo, n_currently_active) },
2244 { "MemoryCurrent", "t", NULL, offsetof(UnitStatusInfo, memory_current) },
2245 { "MemoryPeak", "t", NULL, offsetof(UnitStatusInfo, memory_peak) },
2246 { "MemorySwapCurrent", "t", NULL, offsetof(UnitStatusInfo, memory_swap_current) },
2247 { "MemorySwapPeak", "t", NULL, offsetof(UnitStatusInfo, memory_swap_peak) },
2248 { "MemoryZSwapCurrent", "t", NULL, offsetof(UnitStatusInfo, memory_zswap_current) },
2249 { "MemoryAvailable", "t", NULL, offsetof(UnitStatusInfo, memory_available) },
2250 { "MemoryMin", "t", NULL, offsetof(UnitStatusInfo, memory_min) },
2251 { "MemoryLow", "t", NULL, offsetof(UnitStatusInfo, memory_low) },
2252 { "StartupMemoryLow", "t", NULL, offsetof(UnitStatusInfo, startup_memory_low) },
2253 { "MemoryHigh", "t", NULL, offsetof(UnitStatusInfo, memory_high) },
2254 { "StartupMemoryHigh", "t", NULL, offsetof(UnitStatusInfo, startup_memory_high) },
2255 { "MemoryMax", "t", NULL, offsetof(UnitStatusInfo, memory_max) },
2256 { "StartupMemoryMax", "t", NULL, offsetof(UnitStatusInfo, startup_memory_max) },
2257 { "MemorySwapMax", "t", NULL, offsetof(UnitStatusInfo, memory_swap_max) },
2258 { "StartupMemorySwapMax", "t", NULL, offsetof(UnitStatusInfo, startup_memory_swap_max) },
2259 { "MemoryZSwapMax", "t", NULL, offsetof(UnitStatusInfo, memory_zswap_max) },
2260 { "StartupMemoryZSwapMax", "t", NULL, offsetof(UnitStatusInfo, startup_memory_zswap_max) },
2261 { "MemoryLimit", "t", NULL, offsetof(UnitStatusInfo, memory_limit) },
2262 { "CPUUsageNSec", "t", NULL, offsetof(UnitStatusInfo, cpu_usage_nsec) },
2263 { "TasksCurrent", "t", NULL, offsetof(UnitStatusInfo, tasks_current) },
2264 { "TasksMax", "t", NULL, offsetof(UnitStatusInfo, tasks_max) },
2265 { "IPIngressBytes", "t", NULL, offsetof(UnitStatusInfo, ip_ingress_bytes) },
2266 { "IPEgressBytes", "t", NULL, offsetof(UnitStatusInfo, ip_egress_bytes) },
2267 { "IOReadBytes", "t", NULL, offsetof(UnitStatusInfo, io_read_bytes) },
2268 { "IOWriteBytes", "t", NULL, offsetof(UnitStatusInfo, io_write_bytes) },
2269 { "StateDirectoryQuotaUsage", "(tt)", map_quota, offsetof(UnitStatusInfo, exec_directories_quota[EXEC_DIRECTORY_STATE]) },
2270 { "CacheDirectoryQuotaUsage", "(tt)", map_quota, offsetof(UnitStatusInfo, exec_directories_quota[EXEC_DIRECTORY_CACHE]) },
2271 { "LogsDirectoryQuotaUsage", "(tt)", map_quota, offsetof(UnitStatusInfo, exec_directories_quota[EXEC_DIRECTORY_LOGS]) },
2272 { "ExecCondition", "a(sasbttttuii)", map_exec, 0 },
2273 { "ExecConditionEx", "a(sasasttttuii)", map_exec, 0 },
2274 { "ExecStartPre", "a(sasbttttuii)", map_exec, 0 },
2275 { "ExecStartPreEx", "a(sasasttttuii)", map_exec, 0 },
2276 { "ExecStart", "a(sasbttttuii)", map_exec, 0 },
2277 { "ExecStartEx", "a(sasasttttuii)", map_exec, 0 },
2278 { "ExecStartPost", "a(sasbttttuii)", map_exec, 0 },
2279 { "ExecStartPostEx", "a(sasasttttuii)", map_exec, 0 },
2280 { "ExecReload", "a(sasbttttuii)", map_exec, 0 },
2281 { "ExecReloadEx", "a(sasasttttuii)", map_exec, 0 },
2282 { "ExecReloadPost", "a(sasbttttuii)", map_exec, 0 },
2283 { "ExecReloadPostEx", "a(sasasttttuii)", map_exec, 0 },
2284 { "ExecStopPre", "a(sasbttttuii)", map_exec, 0 },
2285 { "ExecStop", "a(sasbttttuii)", map_exec, 0 },
2286 { "ExecStopEx", "a(sasasttttuii)", map_exec, 0 },
2287 { "ExecStopPost", "a(sasbttttuii)", map_exec, 0 },
2288 { "ExecStopPostEx", "a(sasasttttuii)", map_exec, 0 },
2289 {}
2290 };
2291
2292 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
2293 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
2294 _cleanup_set_free_ Set *found_properties = NULL;
2295 _cleanup_(unit_status_info_done) UnitStatusInfo info = {
2296 .runtime_max_sec = USEC_INFINITY,
2297 .memory_current = UINT64_MAX,
2298 .memory_high = CGROUP_LIMIT_MAX,
2299 .startup_memory_high = CGROUP_LIMIT_MAX,
2300 .memory_max = CGROUP_LIMIT_MAX,
2301 .startup_memory_max = CGROUP_LIMIT_MAX,
2302 .memory_swap_max = CGROUP_LIMIT_MAX,
2303 .startup_memory_swap_max = CGROUP_LIMIT_MAX,
2304 .memory_zswap_max = CGROUP_LIMIT_MAX,
2305 .startup_memory_zswap_max = CGROUP_LIMIT_MAX,
2306 .memory_limit = CGROUP_LIMIT_MAX,
2307 .memory_peak = CGROUP_LIMIT_MAX,
2308 .memory_swap_current = CGROUP_LIMIT_MAX,
2309 .memory_swap_peak = CGROUP_LIMIT_MAX,
2310 .memory_zswap_current = CGROUP_LIMIT_MAX,
2311 .memory_available = CGROUP_LIMIT_MAX,
2312 .cpu_usage_nsec = UINT64_MAX,
2313 .tasks_current = UINT64_MAX,
2314 .tasks_max = UINT64_MAX,
2315 .ip_ingress_bytes = UINT64_MAX,
2316 .ip_egress_bytes = UINT64_MAX,
2317 .io_read_bytes = UINT64_MAX,
2318 .io_write_bytes = UINT64_MAX,
2319 };
2320 int r;
2321
2322 assert(path);
2323 assert(new_line);
2324
2325 log_debug("Showing one %s", path);
2326
2327 r = bus_map_all_properties(
2328 bus,
2329 "org.freedesktop.systemd1",
2330 path,
2331 show_mode == SYSTEMCTL_SHOW_STATUS ? status_map : property_map,
2332 BUS_MAP_BOOLEAN_AS_BOOL,
2333 &error,
2334 &reply,
2335 &info);
2336 if (r < 0)
2337 return log_error_errno(r, "Failed to get properties: %s", bus_error_message(&error, r));
2338
2339 if (unit && streq_ptr(info.load_state, "not-found") && streq_ptr(info.active_state, "inactive")) {
2340 log_full(show_mode == SYSTEMCTL_SHOW_PROPERTIES ? LOG_DEBUG : LOG_ERR,
2341 "Unit %s could not be found.", unit);
2342
2343 if (show_mode == SYSTEMCTL_SHOW_STATUS)
2344 return EXIT_PROGRAM_OR_SERVICES_STATUS_UNKNOWN;
2345 if (show_mode == SYSTEMCTL_SHOW_HELP)
2346 return -ENOENT;
2347 }
2348
2349 if (*new_line)
2350 printf("\n");
2351
2352 *new_line = true;
2353
2354 if (show_mode == SYSTEMCTL_SHOW_STATUS) {
2355 print_status_info(bus, &info, ellipsized);
2356
2357 if (info.active_state && !STR_IN_SET(info.active_state, "active", "reloading", "refreshing"))
2358 return EXIT_PROGRAM_NOT_RUNNING;
2359
2360 return EXIT_PROGRAM_RUNNING_OR_SERVICE_OK;
2361
2362 } else if (show_mode == SYSTEMCTL_SHOW_HELP) {
2363 show_unit_help(&info);
2364 return 0;
2365 }
2366
2367 r = sd_bus_message_rewind(reply, true);
2368 if (r < 0)
2369 return log_error_errno(r, "Failed to rewind: %s", bus_error_message(&error, r));
2370
2371 r = bus_message_print_all_properties(reply, print_property, arg_properties, arg_print_flags, &found_properties);
2372 if (r < 0)
2373 return bus_log_parse_error(r);
2374
2375 STRV_FOREACH(pp, arg_properties)
2376 if (!set_contains(found_properties, *pp))
2377 log_debug("Property %s does not exist.", *pp);
2378
2379 return 0;
2380 }
2381
2382 static int show_all(
2383 sd_bus *bus,
2384 SystemctlShowMode show_mode,
2385 bool *new_line,
2386 bool *ellipsized) {
2387
2388 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
2389 _cleanup_free_ UnitInfo *unit_infos = NULL;
2390 unsigned c;
2391 int r, ret = 0;
2392
2393 r = get_unit_list(bus, NULL, NULL, &unit_infos, 0, &reply);
2394 if (r < 0)
2395 return r;
2396
2397 pager_open(arg_pager_flags);
2398
2399 c = (unsigned) r;
2400
2401 typesafe_qsort(unit_infos, c, unit_info_compare);
2402
2403 for (const UnitInfo *u = unit_infos; u < unit_infos + c; u++) {
2404 _cleanup_free_ char *p = NULL;
2405
2406 p = unit_dbus_path_from_name(u->id);
2407 if (!p)
2408 return log_oom();
2409
2410 r = show_one(bus, p, u->id, show_mode, new_line, ellipsized);
2411 if (r < 0)
2412 return r;
2413 if (r > 0 && ret == 0)
2414 ret = r;
2415 }
2416
2417 return ret;
2418 }
2419
2420 static int show_system_status(sd_bus *bus) {
2421 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
2422 _cleanup_(machine_info_clear) struct machine_info mi = {};
2423 static const char prefix[] = " ";
2424 _cleanup_free_ char *hn = NULL;
2425 const char *on, *off;
2426 unsigned c;
2427 int r;
2428
2429 hn = gethostname_malloc();
2430 if (!hn)
2431 return log_oom();
2432
2433 r = bus_map_all_properties(
2434 bus,
2435 "org.freedesktop.systemd1",
2436 "/org/freedesktop/systemd1",
2437 machine_info_property_map,
2438 BUS_MAP_STRDUP,
2439 &error,
2440 NULL,
2441 &mi);
2442 if (r < 0)
2443 return log_error_errno(r, "Failed to read server status: %s", bus_error_message(&error, r));
2444
2445 if (streq_ptr(mi.state, "degraded")) {
2446 on = ansi_highlight_red();
2447 off = ansi_normal();
2448 } else if (streq_ptr(mi.state, "running")) {
2449 on = ansi_highlight_green();
2450 off = ansi_normal();
2451 } else {
2452 on = ansi_highlight_yellow();
2453 off = ansi_normal();
2454 }
2455
2456 printf("%s%s%s %s\n", on, glyph(GLYPH_BLACK_CIRCLE), off, arg_host ?: hn);
2457
2458 printf(" State: %s%s%s\n",
2459 on, strna(mi.state), off);
2460
2461 printf(" Units: %" PRIu32 " loaded (incl. loaded aliases)\n", mi.n_names);
2462 printf(" Jobs: %" PRIu32 " queued\n", mi.n_jobs);
2463 printf(" Failed: %" PRIu32 " units\n", mi.n_failed_units);
2464
2465 printf(" Since: %s; %s\n",
2466 FORMAT_TIMESTAMP_STYLE(mi.timestamp, arg_timestamp_style),
2467 FORMAT_TIMESTAMP_RELATIVE(mi.timestamp));
2468
2469 printf(" systemd: %s\n", mi.version);
2470
2471 if (!isempty(mi.tainted))
2472 printf(" Tainted: %s%s%s\n", ansi_highlight_yellow(), mi.tainted, ansi_normal());
2473
2474 printf(" CGroup: %s\n", empty_to_root(mi.control_group));
2475
2476 c = LESS_BY(columns(), strlen(prefix));
2477
2478 r = unit_show_processes(bus, SPECIAL_ROOT_SLICE, mi.control_group, prefix, c, get_output_flags(), &error);
2479 if (r == -EBADR && arg_transport == BUS_TRANSPORT_LOCAL) /* Compatibility for really old systemd versions */
2480 show_cgroup(strempty(mi.control_group), prefix, c, get_output_flags());
2481 else if (r < 0)
2482 log_warning_errno(r, "Failed to dump process list for '%s', ignoring: %s",
2483 arg_host ?: hn, bus_error_message(&error, r));
2484
2485 return 0;
2486 }
2487
2488 int verb_show(int argc, char *argv[], uintptr_t _data, void *userdata) {
2489 bool new_line = false, ellipsized = false;
2490 SystemctlShowMode show_mode;
2491 int r, ret = 0;
2492 sd_bus *bus;
2493
2494 assert(argv);
2495
2496 show_mode = systemctl_show_mode_from_string(argv[0]);
2497 if (show_mode < 0)
2498 return log_error_errno(show_mode, "Invalid argument '%s'.", argv[0]);
2499
2500 if (show_mode == SYSTEMCTL_SHOW_HELP && argc <= 1)
2501 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
2502 "'help' command expects one or more unit names.\n"
2503 "(Alternatively, help for systemctl itself may be shown with --help)");
2504
2505 r = acquire_bus(BUS_MANAGER, &bus);
2506 if (r < 0)
2507 return r;
2508
2509 pager_open(arg_pager_flags);
2510
2511 if (argc <= 1) {
2512 /* If no argument or filter is specified inspect the manager itself:
2513 * systemctl status → we show status of the manager
2514 * systemctl status --all → status of the manager + status of all units
2515 * systemctl status --state=… → status of units in listed states
2516 * systemctl status --type=… → status of units of listed types
2517 * systemctl status --failed → status of failed units, mirroring systemctl list-units --failed
2518 */
2519
2520 if (!arg_states && !arg_types) {
2521 if (show_mode == SYSTEMCTL_SHOW_PROPERTIES)
2522 /* systemctl show --all → show properties of the manager */
2523 return show_one(bus, "/org/freedesktop/systemd1", NULL, show_mode, &new_line, &ellipsized);
2524
2525 r = show_system_status(bus);
2526 if (r < 0)
2527 return r;
2528
2529 new_line = true;
2530 }
2531
2532 if (arg_all || arg_states || arg_types)
2533 ret = show_all(bus, show_mode, &new_line, &ellipsized);
2534 } else {
2535 _cleanup_free_ char **patterns = NULL;
2536
2537 STRV_FOREACH(name, strv_skip(argv, 1)) {
2538 _cleanup_free_ char *path = NULL, *unit = NULL;
2539 uint32_t id;
2540
2541 if (safe_atou32(*name, &id) < 0) {
2542 if (strv_push(&patterns, *name) < 0)
2543 return log_oom();
2544
2545 continue;
2546 } else if (show_mode == SYSTEMCTL_SHOW_PROPERTIES) {
2547 /* Interpret as job id */
2548 if (asprintf(&path, "/org/freedesktop/systemd1/job/%u", id) < 0)
2549 return log_oom();
2550
2551 } else {
2552 /* Interpret as PID */
2553 r = lookup_unit_by_pidref(bus, (pid_t) id, &unit, &path);
2554 if (r < 0) {
2555 RET_GATHER(ret, r);
2556 continue;
2557 }
2558 }
2559
2560 r = show_one(bus, path, unit, show_mode, &new_line, &ellipsized);
2561 if (r < 0)
2562 return r;
2563 if (r > 0 && ret == 0)
2564 ret = r;
2565 }
2566
2567 if (!strv_isempty(patterns)) {
2568 _cleanup_strv_free_ char **names = NULL;
2569
2570 r = expand_unit_names(bus, patterns, NULL, &names, NULL);
2571 if (r < 0)
2572 return log_error_errno(r, "Failed to expand names: %m");
2573
2574 r = maybe_extend_with_unit_dependencies(bus, &names);
2575 if (r < 0)
2576 return r;
2577
2578 STRV_FOREACH(name, names) {
2579 _cleanup_free_ char *path = NULL;
2580
2581 path = unit_dbus_path_from_name(*name);
2582 if (!path)
2583 return log_oom();
2584
2585 r = show_one(bus, path, *name, show_mode, &new_line, &ellipsized);
2586 if (r < 0)
2587 return r;
2588 if (r > 0 && ret == 0)
2589 ret = r;
2590 }
2591 }
2592 }
2593
2594 if (ellipsized && !arg_quiet)
2595 printf("Hint: Some lines were ellipsized, use -l to show in full.\n");
2596
2597 return ret;
2598 }