]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loginctl: show null fields for unset seat/tty fields of sessions 30216/head
authorLennart Poettering <lennart@poettering.net>
Mon, 27 Nov 2023 14:10:42 +0000 (15:10 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 28 Nov 2023 10:33:01 +0000 (11:33 +0100)
src/login/loginctl.c

index e52555989f0f34b4a73cd0f7d7f357006e706267..3f8f1aa9bedfe82893ad29cdc92aae80443740b0 100644 (file)
@@ -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.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 (i.tty)
+        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);