From 3ae6e64641d0ba1123e9e33b8f81ddba4699eb94 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 23 May 2025 09:24:24 +0200 Subject: [PATCH] loginctl,machinectl: use LESS_BY() where appropriate And while we are at it, add a lower bound of the display output to 10 for all three cases, because it's pointless outputting someting with less space. --- src/login/loginctl.c | 11 ++--------- src/machine/machinectl.c | 8 +------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 3a4f3c8c9a..0f66c9dee6 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -436,7 +436,6 @@ static int show_unit_cgroup( _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_free_ char *cgroup = NULL; - unsigned c; int r; assert(bus); @@ -450,10 +449,7 @@ static int show_unit_cgroup( if (isempty(cgroup)) return 0; - c = columns(); - if (c > 18) - c -= 18; - + unsigned c = MAX(LESS_BY(columns(), 18U), 10U); r = unit_show_processes(bus, unit, cgroup, prefix, c, get_output_flags(), &error); if (r == -EBADR) { if (arg_transport == BUS_TRANSPORT_REMOTE) @@ -905,10 +901,7 @@ static int print_seat_status_info(sd_bus *bus, const char *path) { return table_log_print_error(r); if (arg_transport == BUS_TRANSPORT_LOCAL) { - unsigned c = columns(); - if (c > 21) - c -= 21; - + unsigned c = MAX(LESS_BY(columns(), 21U), 10U); show_sysfs(i.id, strrepa(" ", STRLEN("Sessions:")), c, get_output_flags()); } diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 6d995099a6..2411a85050 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -416,7 +416,6 @@ static int show_unit_cgroup(sd_bus *bus, const char *unit, pid_t leader) { _cleanup_free_ char *cgroup = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; int r; - unsigned c; assert(bus); assert(unit); @@ -428,12 +427,7 @@ static int show_unit_cgroup(sd_bus *bus, const char *unit, pid_t leader) { if (isempty(cgroup)) return 0; - c = columns(); - if (c > 18) - c -= 18; - else - c = 0; - + unsigned c = MAX(LESS_BY(columns(), 18U), 10U); r = unit_show_processes(bus, unit, cgroup, "\t\t ", c, get_output_flags(), &error); if (r == -EBADR) {