From: Frantisek Sumsal Date: Wed, 6 Dec 2023 10:03:06 +0000 (+0100) Subject: loginctl: show a nicer error message when no session/seat is available X-Git-Tag: v256-rc1~1591 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b28940ca10ff1223f42a9ffdf8acfa92eeb443a7;p=thirdparty%2Fsystemd.git loginctl: show a nicer error message when no session/seat is available 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 --- diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 3f8f1aa9bed..7fc6efc9da9 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -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) {