]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loginctl: show a nicer error message when no session/seat is available
authorFrantisek Sumsal <frantisek@sumsal.cz>
Wed, 6 Dec 2023 10:03:06 +0000 (11:03 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 6 Dec 2023 21:02:44 +0000 (22:02 +0100)
When calling loginctl {seat,session}-status without arguments, show a nicer
error message in case there's no suitable session/seat attached to the calling
tty.

Before:
~# loginctl seat-status
Could not get properties: Unknown object '/org/freedesktop/login1/seat/auto'.
~# systemd-run -q -t loginctl seat-status
Could not get properties: Unknown object '/org/freedesktop/login1/seat/auto'.
~# systemd-run -q -t loginctl session-status
Could not get properties: Unknown object '/org/freedesktop/login1/session/auto'.

After:
~# build/loginctl seat-status
Failed to get path for seat 'auto': Session '1' has no seat.
~# systemd-run -q -t build/loginctl seat-status
Failed to get path for seat 'auto': Caller does not belong to any known session and doesn't own any suitable session.
~# systemd-run -q -t build/loginctl session-status
Failed to get path for session 'auto': Caller does not belong to any known session and doesn't own any suitable session.

Resolves: #25199

src/login/loginctl.c

index 3f8f1aa9bedfe82893ad29cdc92aae80443740b0..7fc6efc9da9a3e54bbec1e411d85705e0679b0d7 100644 (file)
@@ -992,11 +992,17 @@ static int show_session(int argc, char *argv[], void *userdata) {
         pager_open(arg_pager_flags);
 
         if (argc <= 1) {
+                _cleanup_free_ char *path = NULL;
+
                 /* If no argument is specified inspect the manager itself */
                 if (properties)
                         return show_properties(bus, "/org/freedesktop/login1");
 
-                return print_session_status_info(bus, "/org/freedesktop/login1/session/auto");
+                r = get_bus_path_by_id(bus, "session", "GetSession", "auto", &path);
+                if (r < 0)
+                        return r;
+
+                return print_session_status_info(bus, path);
         }
 
         for (int i = 1, first = true; i < argc; i++, first = false) {
@@ -1083,11 +1089,17 @@ static int show_seat(int argc, char *argv[], void *userdata) {
         pager_open(arg_pager_flags);
 
         if (argc <= 1) {
+                _cleanup_free_ char *path = NULL;
+
                 /* If no argument is specified inspect the manager itself */
                 if (properties)
                         return show_properties(bus, "/org/freedesktop/login1");
 
-                return print_seat_status_info(bus, "/org/freedesktop/login1/seat/auto");
+                r = get_bus_path_by_id(bus, "seat", "GetSeat", "auto", &path);
+                if (r < 0)
+                        return r;
+
+                return print_seat_status_info(bus, path);
         }
 
         for (int i = 1, first = true; i < argc; i++, first = false) {