From: David Tardon Date: Sat, 23 Jul 2022 15:07:52 +0000 (+0200) Subject: systemctl: reduce var. scope and shorten the code a bit X-Git-Tag: v252-rc1~580^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=551d0afe2e471e67e7a23353c8ffc1b0bacaf97f;p=thirdparty%2Fsystemd.git systemctl: reduce var. scope and shorten the code a bit --- diff --git a/src/systemctl/systemctl-list-units.c b/src/systemctl/systemctl-list-units.c index 5b0ce3854d2..a6596ddd0ea 100644 --- a/src/systemctl/systemctl-list-units.c +++ b/src/systemctl/systemctl-list-units.c @@ -350,7 +350,6 @@ static int socket_info_compare(const struct socket_info *a, const struct socket_ static int output_sockets_list(struct socket_info *socket_infos, size_t cs) { _cleanup_(table_unrefp) Table *table = NULL; - const char *on, *off; int r; table = table_new("listen", "type", "unit", "activates"); @@ -401,14 +400,7 @@ static int output_sockets_list(struct socket_info *socket_infos, size_t cs) { r = table_add_cell(table, NULL, TABLE_STRV, s->triggered); if (r < 0) return table_log_add_error(r); - } - - on = ansi_highlight(); - off = ansi_normal(); - } else { - on = ansi_highlight_red(); - off = ansi_normal(); } r = output_table(table); @@ -416,6 +408,11 @@ static int output_sockets_list(struct socket_info *socket_infos, size_t cs) { return r; if (arg_legend != 0) { + const char *on, *off; + + on = cs > 0 ? ansi_highlight() : ansi_highlight_red(); + off = ansi_normal(); + printf("\n%s%zu sockets listed.%s\n", on, cs, off); if (!arg_all) printf("Pass --all to see loaded but inactive sockets, too.\n"); @@ -599,7 +596,6 @@ static int timer_info_compare(const struct timer_info *a, const struct timer_inf static int output_timers_list(struct timer_info *timer_infos, size_t n) { _cleanup_(table_unrefp) Table *table = NULL; - const char *on, *off; int r; assert(timer_infos || n == 0); @@ -641,19 +637,16 @@ static int output_timers_list(struct timer_info *timer_infos, size_t n) { return table_log_add_error(r); } - if (n > 0) { - on = ansi_highlight(); - off = ansi_normal(); - } else { - on = ansi_highlight_red(); - off = ansi_normal(); - } - r = output_table(table); if (r < 0) return r; if (arg_legend != 0) { + const char *on, *off; + + on = n > 0 ? ansi_highlight() : ansi_highlight_red(); + off = ansi_normal(); + printf("\n%s%zu timers listed.%s\n", on, n, off); if (!arg_all) printf("Pass --all to see loaded but inactive timers, too.\n");