HALF ECHO LEARN / REFERENCE COLLECTION
v262.2src/systemctl/systemctl-show.c
Git blob: 9ef3bbf51f8389fb7cac470db0bab366dffd29ad
Lines 1–1000 of 2,637
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <sys/mount.h>
#include "sd-bus.h"
#include "sd-journal.h"
#include "af-list.h"
#include "bus-error.h"
#include "bus-map-properties.h"
#include "bus-print-properties.h"
#include "bus-unit-procs.h"
#include "bus-unit-util.h"
#include "bus-util.h"
#include "cgroup-show.h"
#include "cpu-set-util.h"
#include "errno-util.h"
#include "escape.h"
#include "exec-util.h"
#include "exit-status.h"
#include "format-util.h"
#include "hexdecoct.h"
#include "hostname-setup.h"
#include "in-addr-util.h"
#include "install.h"
#include "ip-protocol-list.h"
#include "journal-file.h"
#include "list.h"
#include "logs-show.h"
#include "memory-util.h"
#include "numa-util.h"
#include "open-file.h"
#include "output-mode.h"
#include "pager.h"
#include "parse-util.h"
#include "path-util.h"
#include "percent-util.h"
#include "pretty-print.h"
#include "process-util.h"
#include "set.h"
#include "signal-util.h"
#include "sort-util.h"
#include "special.h"
#include "systemctl-list-units.h"
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
#include "systemctl.h"
#include "systemctl-list-machines.h"
#include "systemctl-show.h"
#include "systemctl-util.h"
#include "terminal-util.h"
#include "utf8.h"
static OutputFlags get_output_flags(void) {
return
FLAGS_SET(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) * OUTPUT_SHOW_ALL |
(arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
colors_enabled() * OUTPUT_COLOR |
!arg_quiet * OUTPUT_WARN_CUTOFF;
}
typedef struct ExecStatusInfo {
char *name;
char *path;
char **argv;
bool ignore;
usec_t start_timestamp;
usec_t exit_timestamp;
pid_t pid;
int code;
int status;
ExecCommandFlags flags;
LIST_FIELDS(struct ExecStatusInfo, exec_status_info_list);
} ExecStatusInfo;
static void exec_status_info_free(ExecStatusInfo *i) {
assert(i);
free(i->name);
free(i->path);
strv_free(i->argv);
free(i);
}
static int exec_status_info_deserialize(sd_bus_message *m, ExecStatusInfo *i, bool is_ex_prop) {
_cleanup_strv_free_ char **ex_opts = NULL;
uint64_t start_timestamp, exit_timestamp, start_timestamp_monotonic, exit_timestamp_monotonic;
const char *path;
uint32_t pid;
int32_t code, status;
int ignore, r;
assert(m);
assert(i);
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_STRUCT, is_ex_prop ? "sasasttttuii" : "sasbttttuii");
if (r < 0)
return bus_log_parse_error(r);
if (r == 0)
return 0;
r = sd_bus_message_read(m, "s", &path);
if (r < 0)
return bus_log_parse_error(r);
i->path = strdup(path);
if (!i->path)
return log_oom();
r = sd_bus_message_read_strv(m, &i->argv);
if (r < 0)
return bus_log_parse_error(r);
r = is_ex_prop ? sd_bus_message_read_strv(m, &ex_opts) : sd_bus_message_read(m, "b", &ignore);
if (r < 0)
return bus_log_parse_error(r);
r = sd_bus_message_read(m,
"ttttuii",
&start_timestamp, &start_timestamp_monotonic,
&exit_timestamp, &exit_timestamp_monotonic,
&pid,
&code, &status);
if (r < 0)
return bus_log_parse_error(r);
if (is_ex_prop) {
r = exec_command_flags_from_strv(ex_opts, &i->flags);
if (r < 0)
return log_error_errno(r, "Failed to convert strv to ExecCommandFlags: %m");
i->ignore = FLAGS_SET(i->flags, EXEC_COMMAND_IGNORE_FAILURE);
} else
i->ignore = ignore;
i->start_timestamp = (usec_t) start_timestamp;
i->exit_timestamp = (usec_t) exit_timestamp;
i->pid = (pid_t) pid;
i->code = code;
i->status = status;
r = sd_bus_message_exit_container(m);
if (r < 0)
return bus_log_parse_error(r);
return 1;
}
typedef struct UnitCondition {
char *name;
char *param;
bool trigger;
bool negate;
int tristate;
LIST_FIELDS(struct UnitCondition, conditions);
} UnitCondition;
typedef struct QuotaInfo {
bool quota_enforce;
bool quota_accounting;
uint64_t quota_usage;
uint64_t quota_limit;
} QuotaInfo;
static UnitCondition* unit_condition_free(UnitCondition *c) {
if (!c)
return NULL;
free(c->name);
free(c->param);
return mfree(c);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(UnitCondition*, unit_condition_free);
typedef struct UnitStatusInfo {
const char *id;
const char *load_state;
const char *active_state;
const char *freezer_state;
const char *sub_state;
const char *unit_file_state;
const char *unit_file_preset;
const char *description;
const char *following;
char **documentation;
const char *fragment_path;
const char *source_path;
const char *control_group;
char **dropin_paths;
char **triggered_by;
char **triggers;
const char *load_error;
const char *result;
usec_t inactive_exit_timestamp;
usec_t inactive_exit_timestamp_monotonic;
usec_t active_enter_timestamp;
usec_t active_exit_timestamp;
usec_t inactive_enter_timestamp;
uint64_t runtime_max_sec;
uint32_t job_id;
sd_id128_t invocation_id;
bool need_daemon_reload;
bool transient;
/* Service */
bool running;
pid_t main_pid;
pid_t control_pid;
const char *pid_file;
const char *status_text;
const char *status_bus_error;
const char *status_varlink_error;
int status_errno;
uint32_t fd_store_max;
uint32_t n_fd_store;
usec_t start_timestamp;
usec_t exit_timestamp;
int exit_code, exit_status;
const char *log_namespace;
usec_t condition_timestamp;
bool condition_result;
LIST_HEAD(UnitCondition, conditions);
usec_t assert_timestamp;
bool assert_result;
bool failed_assert_trigger;
bool failed_assert_negate;
const char *failed_assert;
const char *failed_assert_parameter;
usec_t next_elapse_real;
usec_t next_elapse_monotonic;
/* Socket */
unsigned n_accepted;
unsigned n_connections;
unsigned n_refused;
bool accept;
/* Pairs of type, path */
char **listen;
/* Device */
const char *sysfs_path;
/* Mount, Automount */
const char *where;
/* Swap */
const char *what;
/* Slice */
unsigned concurrency_hard_max;
unsigned concurrency_soft_max;
unsigned activating_concurrency_max;
unsigned n_currently_active;
/* CGroup */
uint64_t memory_current;
uint64_t memory_peak;
uint64_t memory_swap_current;
uint64_t memory_swap_peak;
uint64_t memory_zswap_current;
uint64_t memory_min;
uint64_t memory_low;
uint64_t startup_memory_low;
uint64_t memory_high;
uint64_t startup_memory_high;
uint64_t memory_max;
uint64_t startup_memory_max;
uint64_t memory_swap_max;
uint64_t startup_memory_swap_max;
uint64_t memory_zswap_max;
uint64_t startup_memory_zswap_max;
uint64_t memory_limit;
uint64_t memory_available;
uint64_t cpu_usage_nsec;
uint64_t tasks_current;
uint64_t tasks_max;
uint64_t ip_ingress_bytes;
uint64_t ip_egress_bytes;
uint64_t io_read_bytes;
uint64_t io_write_bytes;
/* Exec Quotas */
QuotaInfo exec_directories_quota[_EXEC_DIRECTORY_TYPE_MAX];
LIST_HEAD(ExecStatusInfo, exec_status_info_list);
} UnitStatusInfo;
static void unit_status_info_done(UnitStatusInfo *info) {
strv_free(info->documentation);
strv_free(info->dropin_paths);
strv_free(info->triggered_by);
strv_free(info->triggers);
strv_free(info->listen);
LIST_CLEAR(conditions, info->conditions, unit_condition_free);
LIST_CLEAR(exec_status_info_list, info->exec_status_info_list, exec_status_info_free);
}
static void format_active_state(const char *active_state, const char **active_on, const char **active_off) {
assert(active_on);
assert(active_off);
if (streq_ptr(active_state, "failed")) {
*active_on = ansi_highlight_red();
*active_off = ansi_normal();
} else if (STRPTR_IN_SET(active_state, "active", "reloading", "refreshing")) {
*active_on = ansi_highlight_green();
*active_off = ansi_normal();
} else
*active_on = *active_off = "";
}
static void format_enable_state(const char *enable_state, const char **enable_on, const char **enable_off) {
assert(enable_on);
assert(enable_off);
if (streq_ptr(enable_state, "disabled")) {
*enable_on = ansi_highlight_yellow();
*enable_off = ansi_normal();
} else if (streq_ptr(enable_state, "enabled")) {
*enable_on = ansi_highlight_green();
*enable_off = ansi_normal();
} else
*enable_on = *enable_off = "";
}
static void print_exec_directory_quota(UnitStatusInfo *i, ExecDirectoryType dt) {
assert(i);
if (!IN_SET(dt, EXEC_DIRECTORY_STATE, EXEC_DIRECTORY_CACHE, EXEC_DIRECTORY_LOGS))
return;
if (i->exec_directories_quota[dt].quota_accounting) {
printf(" %s: %s", exec_directory_type_to_string(dt), FORMAT_BYTES(i->exec_directories_quota[dt].quota_usage));
if (i->exec_directories_quota[dt].quota_enforce)
printf(" (max: %s)", FORMAT_BYTES(i->exec_directories_quota[dt].quota_limit));
printf("\n");
}
}
static void print_status_info(
sd_bus *bus,
UnitStatusInfo *i,
bool *ellipsized) {
const char *active_on, *active_off, *on, *off, *ss, *fs;
const char *enable_on, *enable_off, *preset_on, *preset_off;
_cleanup_free_ char *formatted_path = NULL;
usec_t timestamp;
const char *path;
int r;
assert(i);
/* This shows pretty information about a unit. See print_property() for a low-level property
* printer */
format_active_state(i->active_state, &active_on, &active_off);
format_enable_state(i->unit_file_state, &enable_on, &enable_off);
format_enable_state(i->unit_file_preset, &preset_on, &preset_off);
const Glyph icon = unit_active_state_to_glyph(unit_active_state_from_string(i->active_state));
printf("%s%s%s %s", active_on, glyph(icon), active_off, strna(i->id));
if (i->description && !streq_ptr(i->id, i->description))
printf(" - %s", i->description);
printf("\n");
if (i->following)
printf(" Follows: unit currently follows state of %s\n", i->following);
if (STRPTR_IN_SET(i->load_state, "error", "not-found", "bad-setting")) {
on = ansi_highlight_red();
off = ansi_normal();
} else
on = off = "";
path = i->source_path ?: i->fragment_path;
if (path && terminal_urlify_path(path, NULL, &formatted_path) >= 0)
path = formatted_path;
if (!isempty(i->load_error))
printf(" Loaded: %s%s%s (Reason: %s)\n",
on, strna(i->load_state), off, i->load_error);
else if (path && !isempty(i->unit_file_state)) {
bool show_preset = !isempty(i->unit_file_preset) &&
show_preset_for_state(unit_file_state_from_string(i->unit_file_state));
printf(" Loaded: %s%s%s (%s; %s%s%s%s%s%s%s)\n",
on, strna(i->load_state), off,
path,
enable_on, i->unit_file_state, enable_off,
show_preset ? "; preset: " : "",
preset_on, show_preset ? i->unit_file_preset : "", preset_off);
} else if (path)
printf(" Loaded: %s%s%s (%s)\n",
on, strna(i->load_state), off, path);
else
printf(" Loaded: %s%s%s\n",
on, strna(i->load_state), off);
if (i->transient)
printf(" Transient: yes\n");
if (!strv_isempty(i->dropin_paths)) {
_cleanup_free_ char *dir = NULL;
bool last = false;
STRV_FOREACH(dropin, i->dropin_paths) {
_cleanup_free_ char *dropin_formatted = NULL, *dropin_basename = NULL;
const char *df;
if (!dir || last) {
printf(dir ? " " :
" Drop-In: ");
dir = mfree(dir);
r = path_extract_directory(*dropin, &dir);
if (r < 0) {
log_error_errno(r, "Failed to extract directory of '%s': %m", *dropin);
break;
}
printf("%s\n"
" %s", dir,
glyph(GLYPH_TREE_RIGHT));
}
last = ! (*(dropin + 1) && startswith(*(dropin + 1), dir));
r = path_extract_filename(*dropin, &dropin_basename);
if (r < 0) {
log_error_errno(r, "Failed to extract file name of '%s': %m", *dropin);
break;
}
if (terminal_urlify_path(*dropin, dropin_basename, &dropin_formatted) >= 0)
df = dropin_formatted;
else
df = *dropin;
printf("%s%s", df, last ? "\n" : ", ");
}
}
ss = streq_ptr(i->active_state, i->sub_state) ? NULL : i->sub_state;
if (ss)
printf(" Active: %s%s (%s)%s",
active_on, strna(i->active_state), ss, active_off);
else
printf(" Active: %s%s%s",
active_on, strna(i->active_state), active_off);
fs = !isempty(i->freezer_state) && !streq(i->freezer_state, "running") ? i->freezer_state : NULL;
if (fs)
printf(" %s(%s)%s", ansi_highlight_yellow(), fs, ansi_normal());
if (!isempty(i->result) && !streq(i->result, "success"))
printf(" (Result: %s)", i->result);
timestamp = STRPTR_IN_SET(i->active_state, "active", "reloading", "refreshing") ? i->active_enter_timestamp :
STRPTR_IN_SET(i->active_state, "inactive", "failed") ? i->inactive_enter_timestamp :
STRPTR_IN_SET(i->active_state, "activating") ? i->inactive_exit_timestamp :
i->active_exit_timestamp;
if (timestamp_is_set(timestamp)) {
printf(" since %s; %s\n",
FORMAT_TIMESTAMP_STYLE(timestamp, arg_timestamp_style),
FORMAT_TIMESTAMP_RELATIVE(timestamp));
if (streq_ptr(i->active_state, "active") && i->runtime_max_sec < USEC_INFINITY) {
usec_t until_timestamp;
until_timestamp = usec_add(timestamp, i->runtime_max_sec);
printf(" Until: %s; %s\n",
FORMAT_TIMESTAMP_STYLE(until_timestamp, arg_timestamp_style),
FORMAT_TIMESTAMP_RELATIVE(until_timestamp));
}
if (!endswith(i->id, ".target") &&
STRPTR_IN_SET(i->active_state, "inactive", "failed") &&
timestamp_is_set(i->active_enter_timestamp) &&
timestamp_is_set(i->active_exit_timestamp) &&
i->active_exit_timestamp >= i->active_enter_timestamp) {
usec_t duration;
duration = i->active_exit_timestamp - i->active_enter_timestamp;
printf(" Duration: %s\n", FORMAT_TIMESPAN(duration, MSEC_PER_SEC));
}
} else
printf("\n");
if (i->job_id != 0)
printf(" Job: %" PRIu32 "\n", i->job_id);
if (!sd_id128_is_null(i->invocation_id))
printf(" Invocation: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(i->invocation_id));
STRV_FOREACH(t, i->triggered_by) {
UnitActiveState state = _UNIT_ACTIVE_STATE_INVALID;
(void) get_state_one_unit(bus, *t, &state);
format_active_state(unit_active_state_to_string(state), &on, &off);
printf("%s %s%s%s %s\n",
t == i->triggered_by ? "TriggeredBy:" : " ",
on, glyph(unit_active_state_to_glyph(state)), off,
*t);
}
if (endswith(i->id, ".timer")) {
dual_timestamp nw, next = {i->next_elapse_real, i->next_elapse_monotonic};
usec_t next_elapse;
dual_timestamp_now(&nw);
next_elapse = calc_next_elapse(&nw, &next);
if (timestamp_is_set(next_elapse))
printf(" Trigger: %s; %s\n",
FORMAT_TIMESTAMP_STYLE(next_elapse, arg_timestamp_style),
FORMAT_TIMESTAMP_RELATIVE(next_elapse));
else
printf(" Trigger: n/a\n");
}
STRV_FOREACH(t, i->triggers) {
UnitActiveState state = _UNIT_ACTIVE_STATE_INVALID;
(void) get_state_one_unit(bus, *t, &state);
format_active_state(unit_active_state_to_string(state), &on, &off);
printf("%s %s%s%s %s\n",
t == i->triggers ? " Triggers:" : " ",
on, glyph(GLYPH_BLACK_CIRCLE), off,
*t);
}
if (!i->condition_result && i->condition_timestamp > 0) {
int n = 0;
printf(" Condition: start %scondition unmet%s at %s; %s\n",
ansi_highlight_yellow(), ansi_normal(),
FORMAT_TIMESTAMP_STYLE(i->condition_timestamp, arg_timestamp_style),
FORMAT_TIMESTAMP_RELATIVE(i->condition_timestamp));
LIST_FOREACH(conditions, c, i->conditions)
if (c->tristate < 0)
n++;
LIST_FOREACH(conditions, c, i->conditions)
if (c->tristate < 0)
printf(" %s %s=%s%s%s was not met\n",
--n ? glyph(GLYPH_TREE_BRANCH) : glyph(GLYPH_TREE_RIGHT),
c->name,
c->trigger ? "|" : "",
c->negate ? "!" : "",
c->param);
}
if (!i->assert_result && i->assert_timestamp > 0) {
printf(" Assert: start %sassertion failed%s at %s; %s\n",
ansi_highlight_red(), ansi_normal(),
FORMAT_TIMESTAMP_STYLE(i->assert_timestamp, arg_timestamp_style),
FORMAT_TIMESTAMP_RELATIVE(i->assert_timestamp));
if (i->failed_assert_trigger)
printf(" none of the trigger assertions were met\n");
else if (i->failed_assert)
printf(" %s=%s%s was not met\n",
i->failed_assert,
i->failed_assert_negate ? "!" : "",
i->failed_assert_parameter);
}
if (i->sysfs_path)
printf(" Device: %s\n", i->sysfs_path);
if (i->where)
printf(" Where: %s\n", i->where);
if (i->what)
printf(" What: %s\n", i->what);
STRV_FOREACH(t, i->documentation) {
_cleanup_free_ char *formatted = NULL;
const char *q;
if (terminal_urlify(*t, NULL, &formatted) >= 0)
q = formatted;
else
q = *t;
printf(" %*s %s\n", 9, t == i->documentation ? "Docs:" : "", q);
}
STRV_FOREACH_PAIR(t, t2, i->listen)
printf(" %*s %s (%s)\n", 9, t == i->listen ? "Listen:" : "", *t2, *t);
if (i->accept) {
printf(" Accepted: %u; Connected: %u;", i->n_accepted, i->n_connections);
if (i->n_refused)
printf(" Refused: %u", i->n_refused);
printf("\n");
}
LIST_FOREACH(exec_status_info_list, p, i->exec_status_info_list) {
_cleanup_free_ char *argv = NULL;
bool good;
/* Only show exited processes here */
if (p->code == 0)
continue;
/* Don't print ExecXYZEx= properties here since it will appear as a
* duplicate of the non-Ex= variant. */
if (endswith(p->name, "Ex"))
continue;
if (!strv_isempty(p->argv))
argv = quote_command_line(p->argv, SHELL_ESCAPE_EMPTY);
printf(" Process: "PID_FMT" %s=%s ", p->pid, p->name, strna(argv));
good = is_clean_exit(p->code, p->status, EXIT_CLEAN_DAEMON, NULL);
if (!good) {
on = p->ignore ? ansi_highlight_yellow() : ansi_highlight_red();
off = ansi_normal();
} else
on = off = "";
printf("%s(code=%s, ", on, sigchld_code_to_string(p->code));
if (p->code == CLD_EXITED) {
const char *c;
printf("status=%i", p->status);
c = exit_status_to_string(p->status, EXIT_STATUS_LIBC | EXIT_STATUS_SYSTEMD);
if (c)
printf("/%s", c);
} else
printf("signal=%s", signal_to_string(p->status));
printf(")%s\n", off);
if (i->main_pid == p->pid &&
i->start_timestamp == p->start_timestamp &&
i->exit_timestamp == p->start_timestamp)
/* Let's not show this twice */
i->main_pid = 0;
if (p->pid == i->control_pid)
i->control_pid = 0;
}
if (i->main_pid > 0 || i->control_pid > 0) {
if (i->main_pid > 0) {
printf(" Main PID: "PID_FMT, i->main_pid);
if (i->running) {
if (arg_transport == BUS_TRANSPORT_LOCAL) {
_cleanup_free_ char *comm = NULL;
(void) pid_get_comm(i->main_pid, &comm);
if (comm)
printf(" (%s)", comm);
}
} else if (i->exit_code > 0) {
printf(" (code=%s, ", sigchld_code_to_string(i->exit_code));
if (i->exit_code == CLD_EXITED) {
const char *c;
printf("status=%i", i->exit_status);
c = exit_status_to_string(i->exit_status,
EXIT_STATUS_LIBC | EXIT_STATUS_SYSTEMD);
if (c)
printf("/%s", c);
} else
printf("signal=%s", signal_to_string(i->exit_status));
printf(")");
}
}
if (i->control_pid > 0) {
_cleanup_free_ char *c = NULL;
if (i->main_pid > 0)
fputs("; Control PID: ", stdout);
else
fputs(" Cntrl PID: ", stdout); /* if first in column, abbreviated so it fits alignment */
printf(PID_FMT, i->control_pid);
if (arg_transport == BUS_TRANSPORT_LOCAL) {
(void) pid_get_comm(i->control_pid, &c);
if (c)
printf(" (%s)", c);
}
}
printf("\n");
}
if (i->status_text)
printf(" Status: \"%s%s%s\"\n", ansi_highlight_cyan(), i->status_text, ansi_normal());
if (i->status_errno > 0 || i->status_bus_error || i->status_varlink_error) {
const char *prefix = " ";
printf(" Error:");
if (i->status_errno > 0) {
printf("%scode: %i (%s)", prefix, i->status_errno, STRERROR(i->status_errno));
prefix = "; ";
}
if (i->status_bus_error) {
printf("%sD-Bus: %s", prefix, i->status_bus_error);
prefix = "; ";
}
if (i->status_varlink_error) {
printf("%sVarlink: %s", prefix, i->status_varlink_error);
prefix = "; ";
}
putchar('\n');
}
if (endswith(i->id, ".slice")) {
printf(" Act. Units: %u", i->n_currently_active);
if (i->concurrency_soft_max != UINT_MAX || i->concurrency_hard_max != UINT_MAX || i->activating_concurrency_max != UINT_MAX) {
fputs(" (", stdout);
if (i->concurrency_soft_max != UINT_MAX && i->concurrency_soft_max < i->concurrency_hard_max) {
printf("soft limit: %u", i->concurrency_soft_max);
if (i->concurrency_hard_max != UINT_MAX || i->activating_concurrency_max != UINT_MAX)
fputs("; ", stdout);
}
if (i->concurrency_hard_max != UINT_MAX) {
printf("hard limit: %u", i->concurrency_hard_max);
if (i->activating_concurrency_max != UINT_MAX)
fputs("; ", stdout);
}
if (i->activating_concurrency_max != UINT_MAX)
printf("activating limit: %u", i->activating_concurrency_max);
putchar(')');
}
putchar('\n');
}
if (i->ip_ingress_bytes != UINT64_MAX && i->ip_egress_bytes != UINT64_MAX)
printf(" IP: %s in, %s out\n",
FORMAT_BYTES(i->ip_ingress_bytes),
FORMAT_BYTES(i->ip_egress_bytes));
if (i->io_read_bytes != UINT64_MAX && i->io_write_bytes != UINT64_MAX)
printf(" IO: %s read, %s written\n",
FORMAT_BYTES(i->io_read_bytes),
FORMAT_BYTES(i->io_write_bytes));
if (i->tasks_current != UINT64_MAX) {
printf(" Tasks: %" PRIu64, i->tasks_current);
if (i->tasks_max != UINT64_MAX)
printf("%s (limit: %" PRIu64 ")%s\n", ansi_grey(), i->tasks_max, ansi_normal());
else
printf("\n");
}
if (i->n_fd_store > 0 || i->fd_store_max > 0)
printf(" FD Store: %u%s (limit: %u)%s\n", i->n_fd_store, ansi_grey(), i->fd_store_max, ansi_normal());
bool show_memory_peak = i->memory_peak != CGROUP_LIMIT_MAX,
show_memory_swap_peak = !IN_SET(i->memory_swap_peak, 0, CGROUP_LIMIT_MAX);
if (i->memory_current != UINT64_MAX) {
printf(" Memory: %s", FORMAT_BYTES(i->memory_current));
bool show_memory_zswap_current = !IN_SET(i->memory_zswap_current, 0, CGROUP_LIMIT_MAX),
/* Only show the available memory if it was artificially limited. */
show_memory_available = i->memory_available != CGROUP_LIMIT_MAX &&
(i->memory_high != CGROUP_LIMIT_MAX || i->memory_max != CGROUP_LIMIT_MAX);
if (show_memory_peak ||
show_memory_swap_peak || /* We don't need to check memory_swap_current, as if peak is 0 that must also be 0 */
show_memory_zswap_current ||
show_memory_available ||
i->memory_min > 0 ||
i->memory_low > 0 || i->startup_memory_low > 0 ||
i->memory_high != CGROUP_LIMIT_MAX || i->startup_memory_high != CGROUP_LIMIT_MAX ||
i->memory_max != CGROUP_LIMIT_MAX || i->startup_memory_max != CGROUP_LIMIT_MAX ||
i->memory_swap_max != CGROUP_LIMIT_MAX || i->startup_memory_swap_max != CGROUP_LIMIT_MAX ||
i->memory_zswap_max != CGROUP_LIMIT_MAX || i->startup_memory_zswap_max != CGROUP_LIMIT_MAX ||
i->memory_limit != CGROUP_LIMIT_MAX) {
const char *prefix = "";
printf(" (");
if (i->memory_min > 0) {
printf("%smin: %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->memory_min));
prefix = ", ";
}
if (i->memory_low > 0) {
printf("%slow: %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->memory_low));
prefix = ", ";
}
if (i->startup_memory_low > 0) {
printf("%slow (startup): %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->startup_memory_low));
prefix = ", ";
}
if (i->memory_high != CGROUP_LIMIT_MAX) {
printf("%shigh: %s", prefix, FORMAT_BYTES(i->memory_high));
prefix = ", ";
}
if (i->startup_memory_high != CGROUP_LIMIT_MAX) {
printf("%shigh (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_high));
prefix = ", ";
}
if (i->memory_max != CGROUP_LIMIT_MAX) {
printf("%smax: %s", prefix, FORMAT_BYTES(i->memory_max));
prefix = ", ";
}
if (i->startup_memory_max != CGROUP_LIMIT_MAX) {
printf("%smax (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_max));
prefix = ", ";
}
if (i->memory_swap_max != CGROUP_LIMIT_MAX) {
printf("%sswap max: %s", prefix, FORMAT_BYTES(i->memory_swap_max));
prefix = ", ";
}
if (i->startup_memory_swap_max != CGROUP_LIMIT_MAX) {
printf("%sswap max (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_swap_max));
prefix = ", ";
}
if (i->memory_zswap_max != CGROUP_LIMIT_MAX) {
printf("%szswap max: %s", prefix, FORMAT_BYTES(i->memory_zswap_max));
prefix = ", ";
}
if (i->startup_memory_zswap_max != CGROUP_LIMIT_MAX) {
printf("%szswap max (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_zswap_max));
prefix = ", ";
}
if (i->memory_limit != CGROUP_LIMIT_MAX) {
printf("%slimit: %s", prefix, FORMAT_BYTES(i->memory_limit));
prefix = ", ";
}
if (show_memory_available) {
printf("%savailable: %s", prefix, FORMAT_BYTES(i->memory_available));
prefix = ", ";
}
if (show_memory_peak) {
printf("%speak: %s", prefix, FORMAT_BYTES(i->memory_peak));
prefix = ", ";
}
if (show_memory_swap_peak) {
printf("%sswap: %s, swap peak: %s", prefix,
FORMAT_BYTES(i->memory_swap_current), FORMAT_BYTES(i->memory_swap_peak));
prefix = ", ";
}
if (show_memory_zswap_current) {
printf("%szswap: %s", prefix, FORMAT_BYTES(i->memory_zswap_current));
prefix = ", ";
}
printf(")");
}
printf("\n");
} else if (show_memory_peak) {
printf(" Mem peak: %s", FORMAT_BYTES(i->memory_peak));
if (show_memory_swap_peak)
printf(" (swap: %s)", FORMAT_BYTES(i->memory_swap_peak));
putchar('\n');
}
if (i->cpu_usage_nsec != UINT64_MAX)
printf(" CPU: %s\n", FORMAT_TIMESPAN(i->cpu_usage_nsec / NSEC_PER_USEC, USEC_PER_MSEC));
for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++)
print_exec_directory_quota(i, dt);
if (i->control_group) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
static const char prefix[] = " ";
unsigned c;
printf(" CGroup: %s\n", i->control_group);
c = LESS_BY(columns(), strlen(prefix));
r = unit_show_processes(bus, i->id, i->control_group, prefix, c, get_output_flags(), &error);
if (r == -EBADR && arg_transport == BUS_TRANSPORT_LOCAL) {
unsigned k = 0;
pid_t extra[2];
/* Fallback for older systemd versions where the GetUnitProcesses() call is not yet available */
if (i->main_pid > 0)
extra[k++] = i->main_pid;
if (i->control_pid > 0)
extra[k++] = i->control_pid;
show_cgroup_and_extra(i->control_group, prefix, c, extra, k, get_output_flags());
} else if (r < 0)
log_warning_errno(r, "Failed to dump process list for '%s', ignoring: %s",
i->id, bus_error_message(&error, r));
}
if (i->id && arg_transport == BUS_TRANSPORT_LOCAL)
show_journal_by_unit(
stdout,
i->id,
i->log_namespace,
arg_output,
/* n_columns= */ 0,
i->inactive_exit_timestamp_monotonic,
arg_lines,
get_output_flags() | OUTPUT_BEGIN_NEWLINE,
SD_JOURNAL_LOCAL_ONLY,
arg_runtime_scope == RUNTIME_SCOPE_SYSTEM,
ellipsized);
if (i->need_daemon_reload)
warn_unit_file_changed(i->id);
}
static void show_unit_help(UnitStatusInfo *i) {
bool previous_man_page = false;
assert(i);
if (!i->documentation) {
log_info("Documentation for %s not known.", i->id);
return;
}
STRV_FOREACH(doc, i->documentation) {
const char *p;
p = startswith(*doc, "man:");
if (p ? doc != i->documentation : previous_man_page) {
puts("");
fflush(stdout);
}
previous_man_page = p;
if (p)
show_man_page(p, /* null_stdio= */ false);
else {
_cleanup_free_ char *t = NULL;
if ((p = startswith(*doc, "file://")))
(void) terminal_urlify_path(p, NULL, &t);
printf("Additional documentation: %s\n", t ?: p ?: *doc);
}
}
}
static int map_main_pid(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
UnitStatusInfo *i = userdata;
uint32_t u;
int r;