From 2cd9f773e29873df1b9f9b09c6c4f78853b16215 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 9 Feb 2021 15:02:21 +0100 Subject: [PATCH 1/2] format-table: don't hit assert if column got less width than it asked for If one field in a specific column has a maximum size limit, other fields in the same column might affected by it and get less than they asked for. Let's make sure we can handle this, and don't assert on this because surprisingly we got less than what we asked for. --- src/shared/format-table.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/shared/format-table.c b/src/shared/format-table.c index 8b9c81664d..e3d8a051a2 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -1993,8 +1993,7 @@ int table_print(Table *t, FILE *f) { if (width[j] < minimum_width[j]) width[j] = minimum_width[j]; - assert(width[j] >= requested_width[j]); - delta = width[j] - requested_width[j]; + delta = LESS_BY(width[j], requested_width[j]); /* Subtract what we just added from the rest */ if (extra > delta) From 619b0c077cbb12b85c9d752779095b99cfd2c66c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 9 Feb 2021 15:03:46 +0100 Subject: [PATCH 2/2] inhibit: cut off overly long "who" fields systemd-inhibit when invoked with a command line will put the whole command line in the "who" field of the inhibitor lock. This can get extremely long for shell expressions, making the table "systemd-inhibit --list" shows ridiculously weirdly formatted. Let's put a limit on the column width: half of the screen, not more. --- src/login/inhibit.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/login/inhibit.c b/src/login/inhibit.c index afb4d7e2e1..20685c18a3 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -90,6 +90,7 @@ static int print_inhibitors(sd_bus *bus) { /* If there's not enough space, shorten the "WHY" column, as it's little more than an explaining comment. */ (void) table_set_weight(table, TABLE_HEADER_CELL(6), 20); + (void) table_set_maximum_width(table, TABLE_HEADER_CELL(0), columns()/2); r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssuu)"); if (r < 0)