From 082dd188d24766a5577b26d0386bbac76cbd5aaa Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 27 Nov 2023 15:00:12 +0100 Subject: [PATCH 1/3] logind: align columns of a table --- src/login/logind-user.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 641050f8ba..c6133077f0 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -861,12 +861,12 @@ void user_update_last_session_timer(User *u) { } static const char* const user_state_table[_USER_STATE_MAX] = { - [USER_OFFLINE] = "offline", - [USER_OPENING] = "opening", + [USER_OFFLINE] = "offline", + [USER_OPENING] = "opening", [USER_LINGERING] = "lingering", - [USER_ONLINE] = "online", - [USER_ACTIVE] = "active", - [USER_CLOSING] = "closing" + [USER_ONLINE] = "online", + [USER_ACTIVE] = "active", + [USER_CLOSING] = "closing" }; DEFINE_STRING_TABLE_LOOKUP(user_state, UserState); From 8bfa22f07923ac38b9098b0da481ef98dab2a1bc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 27 Nov 2023 15:09:53 +0100 Subject: [PATCH 2/3] loginctl: set appropriate ersatz strings for all tables --- src/login/loginctl.c | 11 +++++++++++ test/units/testsuite-35.sh | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/login/loginctl.c b/src/login/loginctl.c index fdf899c37f..e52555989f 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -180,6 +180,8 @@ static int list_sessions(int argc, char *argv[], void *userdata) { (void) table_set_align_percent(table, TABLE_HEADER_CELL(0), 100); (void) table_set_align_percent(table, TABLE_HEADER_CELL(1), 100); + (void) table_set_ersatz_string(table, TABLE_ERSATZ_DASH); + for (;;) { _cleanup_(sd_bus_error_free) sd_bus_error e = SD_BUS_ERROR_NULL; const char *id, *user, *seat, *object; @@ -259,6 +261,7 @@ static int list_users(int argc, char *argv[], void *userdata) { return log_oom(); (void) table_set_align_percent(table, TABLE_HEADER_CELL(0), 100); + (void) table_set_ersatz_string(table, TABLE_ERSATZ_DASH); for (;;) { _cleanup_(sd_bus_error_free) sd_bus_error error_property = SD_BUS_ERROR_NULL; @@ -328,6 +331,8 @@ static int list_seats(int argc, char *argv[], void *userdata) { if (!table) return log_oom(); + (void) table_set_ersatz_string(table, TABLE_ERSATZ_DASH); + for (;;) { const char *seat; @@ -504,6 +509,8 @@ static int print_session_status_info(sd_bus *bus, const char *path) { if (!table) return log_oom(); + (void) table_set_ersatz_string(table, TABLE_ERSATZ_NA); + if (dual_timestamp_is_set(&i.timestamp)) { r = table_add_cell(table, NULL, TABLE_FIELD, "Since"); if (r < 0) @@ -692,6 +699,8 @@ static int print_user_status_info(sd_bus *bus, const char *path) { if (!table) return log_oom(); + (void) table_set_ersatz_string(table, TABLE_ERSATZ_NA); + if (dual_timestamp_is_set(&i.timestamp)) { r = table_add_cell(table, NULL, TABLE_FIELD, "Since"); if (r < 0) @@ -790,6 +799,8 @@ static int print_seat_status_info(sd_bus *bus, const char *path) { if (!table) return log_oom(); + (void) table_set_ersatz_string(table, TABLE_ERSATZ_NA); + if (!strv_isempty(i.sessions)) { _cleanup_strv_free_ char **sessions = TAKE_PTR(i.sessions); diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh index fa942091e6..36e26da885 100755 --- a/test/units/testsuite-35.sh +++ b/test/units/testsuite-35.sh @@ -544,7 +544,7 @@ testcase_list_users_sessions_seats() { assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $5 }')" tty2 assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $6 }')" active assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $7 }')" no - assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $8 }')" '' + assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $8 }')" '-' loginctl list-seats --no-legend | grep -Fwq "${seat?}" From febfec0849616cb8d7d63f66c6dc05ca48a6a1e7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 27 Nov 2023 15:10:42 +0100 Subject: [PATCH 3/3] loginctl: show null fields for unset seat/tty fields of sessions --- src/login/loginctl.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/login/loginctl.c b/src/login/loginctl.c index e52555989f..3f8f1aa9be 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -208,8 +208,8 @@ static int list_sessions(int argc, char *argv[], void *userdata) { TABLE_STRING, id, TABLE_UID, (uid_t) uid, TABLE_STRING, user, - TABLE_STRING, seat, - TABLE_STRING, strna(i.tty), + TABLE_STRING, empty_to_null(seat), + TABLE_STRING, empty_to_null(i.tty), TABLE_STRING, i.state, TABLE_BOOLEAN, i.idle_hint); if (r < 0) @@ -547,22 +547,25 @@ static int print_session_status_info(sd_bus *bus, const char *path) { return table_log_add_error(r); } - r = table_add_cell(table, NULL, TABLE_FIELD, "Seat"); - if (r < 0) - return table_log_add_error(r); - if (i.vtnr > 0) - r = table_add_cell_stringf(table, NULL, "%s; vc%u", i.seat, i.vtnr); - else - r = table_add_cell(table, NULL, TABLE_STRING, i.seat); - if (r < 0) - return table_log_add_error(r); + if (!isempty(i.seat)) { + r = table_add_cell(table, NULL, TABLE_FIELD, "Seat"); + if (r < 0) + return table_log_add_error(r); - if (i.tty) + if (i.vtnr > 0) + r = table_add_cell_stringf(table, NULL, "%s; vc%u", i.seat, i.vtnr); + else + r = table_add_cell(table, NULL, TABLE_STRING, i.seat); + if (r < 0) + return table_log_add_error(r); + } + + if (!isempty(i.tty)) r = table_add_many(table, TABLE_FIELD, "TTY", TABLE_STRING, i.tty); - else if (i.display) + else if (!isempty(i.display)) r = table_add_many(table, TABLE_FIELD, "Display", TABLE_STRING, i.display);