]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loginctl,machinectl: use LESS_BY() where appropriate
authorLennart Poettering <lennart@poettering.net>
Fri, 23 May 2025 07:24:24 +0000 (09:24 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 23 May 2025 15:23:14 +0000 (00:23 +0900)
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
src/machine/machinectl.c

index 3a4f3c8c9a52635aa23a796a67be5261e6cbd565..0f66c9dee663dd709d33329afccc9ef40f63c5bd 100644 (file)
@@ -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());
         }
 
index 6d995099a645be7b54945794c679799d657e8338..2411a85050d114dc3dae368eb539fbf63064a2f2 100644 (file)
@@ -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) {