summaryrefslogtreecommitdiffstats
path: root/src/systemctl/systemctl-list-units.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:45 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:45 +0000
commitefeb864cb547a2cbf96dc0053a8bdb4d9190b364 (patch)
treec0b83368f18be983fcc763200c4c24d633244588 /src/systemctl/systemctl-list-units.c
parentReleasing progress-linux version 255.5-1~progress7.99u1. (diff)
downloadsystemd-efeb864cb547a2cbf96dc0053a8bdb4d9190b364.tar.xz
systemd-efeb864cb547a2cbf96dc0053a8bdb4d9190b364.zip
Merging upstream version 256.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/systemctl/systemctl-list-units.c')
-rw-r--r--src/systemctl/systemctl-list-units.c68
1 files changed, 44 insertions, 24 deletions
diff --git a/src/systemctl/systemctl-list-units.c b/src/systemctl/systemctl-list-units.c
index fbc04b7..184468e 100644
--- a/src/systemctl/systemctl-list-units.c
+++ b/src/systemctl/systemctl-list-units.c
@@ -127,49 +127,69 @@ static int output_units_list(const UnitInfo *unit_infos, size_t c) {
table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
FOREACH_ARRAY(u, unit_infos, c) {
+ const char *on_loaded = NULL, *on_active = NULL, *on_sub = NULL, *on_circle = NULL;
_cleanup_free_ char *id = NULL;
- const char *on_underline = "", *on_loaded = "", *on_active = "", *on_circle = "";
- bool circle = false, underline = false;
+ bool circle = false, underline;
- if (u + 1 < unit_infos + c &&
- !streq(unit_type_suffix(u->id), unit_type_suffix((u + 1)->id))) {
- on_underline = ansi_underline();
- underline = true;
- }
+ underline = u + 1 < unit_infos + c && !streq(unit_type_suffix(u->id), unit_type_suffix((u + 1)->id));
- if (STR_IN_SET(u->load_state, "error", "not-found", "bad-setting", "masked") && !arg_plain) {
- on_circle = underline ? ansi_highlight_yellow_underline() : ansi_highlight_yellow();
+ if (streq(u->load_state, "not-found")) {
+ on_circle = on_loaded = ansi_highlight_yellow();
circle = true;
- on_loaded = underline ? ansi_highlight_red_underline() : ansi_highlight_red();
- } else if (streq(u->active_state, "failed") && !arg_plain) {
- on_circle = underline ? ansi_highlight_red_underline() : ansi_highlight_red();
+ } else if (STR_IN_SET(u->load_state, "bad-setting", "error", "masked")) {
+ on_loaded = ansi_highlight_red();
+ on_circle = ansi_highlight_yellow();
circle = true;
- on_active = underline ? ansi_highlight_red_underline() : ansi_highlight_red();
- } else {
- on_circle = on_underline;
- on_active = on_underline;
- on_loaded = on_underline;
}
+ if (streq(u->active_state, "failed")) {
+ on_sub = on_active = ansi_highlight_red();
+
+ /* Here override any load_state highlighting */
+ on_circle = ansi_highlight_red();
+ circle = true;
+ } else if (STR_IN_SET(u->active_state, "reloading", "activating", "maintenance", "deactivating")) {
+ on_sub = on_active = ansi_highlight();
+
+ if (!circle) { /* Here we let load_state highlighting win */
+ on_circle = ansi_highlight();
+ circle = true;
+ }
+ } else if (streq(u->active_state, "inactive"))
+ on_sub = on_active = ansi_grey();
+
+ /* As a special case, when this is a service which has not process running, let's grey out
+ * its state, to highlight that a bit */
+ if (!on_sub && endswith(u->id, ".service") && streq(u->sub_state, "exited"))
+ on_sub = ansi_grey();
+
+ if (arg_plain)
+ circle = false;
+
id = format_unit_id(u->id, u->machine);
if (!id)
return log_oom();
r = table_add_many(table,
TABLE_STRING, circle ? special_glyph(SPECIAL_GLYPH_BLACK_CIRCLE) : " ",
- TABLE_SET_BOTH_COLORS, on_circle,
+ TABLE_SET_COLOR, on_circle,
+ TABLE_SET_BOTH_UNDERLINES, underline,
TABLE_STRING, id,
- TABLE_SET_BOTH_COLORS, on_active,
+ TABLE_SET_COLOR, on_active,
+ TABLE_SET_BOTH_UNDERLINES, underline,
TABLE_STRING, u->load_state,
- TABLE_SET_BOTH_COLORS, on_loaded,
+ TABLE_SET_COLOR, on_loaded,
+ TABLE_SET_BOTH_UNDERLINES, underline,
TABLE_STRING, u->active_state,
- TABLE_SET_BOTH_COLORS, on_active,
+ TABLE_SET_COLOR, on_active,
+ TABLE_SET_BOTH_UNDERLINES, underline,
TABLE_STRING, u->sub_state,
- TABLE_SET_BOTH_COLORS, on_active,
+ TABLE_SET_COLOR, on_sub,
+ TABLE_SET_BOTH_UNDERLINES, underline,
TABLE_STRING, u->job_id ? u->job_type: "",
- TABLE_SET_BOTH_COLORS, on_underline,
+ TABLE_SET_BOTH_UNDERLINES, underline,
TABLE_STRING, u->description,
- TABLE_SET_BOTH_COLORS, on_underline);
+ TABLE_SET_BOTH_UNDERLINES, underline);
if (r < 0)
return table_log_add_error(r);