From: Lennart Poettering Date: Fri, 23 May 2025 07:24:24 +0000 (+0200) Subject: loginctl,machinectl: use LESS_BY() where appropriate X-Git-Tag: v258-rc1~511 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ae6e64641d0ba1123e9e33b8f81ddba4699eb94;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 3a4f3c8c9a5..0f66c9dee66 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 6d995099a64..2411a85050d 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) {