From 7fbdd8c323e5f7696dfd86c019754c0791ee9b39 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sun, 14 Jan 2024 21:18:07 +0800 Subject: [PATCH 1/5] man: don't use versioned standard-options no-pager-255 was added in #29184, which I reviewed and agreed. However, as #30887 came up, I reconsidered it a bit, and now I actually think that this should be removed. We add new tools that refer to these standard options. During the process, some options are also promoted to be standard ones. I think a more sane practice is to generally keep old tools in the loop, rather than overloading the standard-options with versions. --- man/standard-options.xml | 14 +------------- man/systemd-path.xml | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/man/standard-options.xml b/man/standard-options.xml index 2813134828..87058ad657 100644 --- a/man/standard-options.xml +++ b/man/standard-options.xml @@ -3,9 +3,7 @@ "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> - - + @@ -31,16 +29,6 @@ - - - - - Do not pipe output into a pager. - - - - - diff --git a/man/systemd-path.xml b/man/systemd-path.xml index d5a14bc171..153a9bd0d5 100644 --- a/man/systemd-path.xml +++ b/man/systemd-path.xml @@ -59,7 +59,7 @@ - + From b3cb952c033ce53f25cf853796afc34102344f08 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sun, 14 Jan 2024 21:52:27 +0800 Subject: [PATCH 2/5] logind-dbus: introduce ListSessionsEx() call As per https://github.com/systemd/systemd/pull/30884#discussion_r1448938737 --- man/org.freedesktop.login1.xml | 21 ++++++++-- src/login/logind-dbus.c | 59 +++++++++++++++++++++++++++ src/login/org.freedesktop.login1.conf | 4 ++ 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/man/org.freedesktop.login1.xml b/man/org.freedesktop.login1.xml index f647b1cb5b..9151926e64 100644 --- a/man/org.freedesktop.login1.xml +++ b/man/org.freedesktop.login1.xml @@ -53,6 +53,7 @@ node /org/freedesktop/login1 { GetSeat(in s seat_id, out o object_path); ListSessions(out a(susso) sessions); + ListSessionsEx(out a(sussussbto) sessions); ListUsers(out a(uso) users); ListSeats(out a(so) seats); ListInhibitors(out a(ssssuu) inhibitors); @@ -315,6 +316,8 @@ node /org/freedesktop/login1 { + + @@ -549,8 +552,17 @@ node /org/freedesktop/login1 { is any. ListSessions() returns an array of all current sessions. The structures in - the array consist of the following fields: session id, user id, user name, seat id, session object - path. If a session does not have a seat attached, the seat id field will be an empty string. + the array consist of the following fields: session id, user id, + user name, seat id, and session object path. + If a session does not have a seat attached, the seat id field will be an empty string. + + ListSessionsEx() returns an array of all current sessions with more metadata + than ListSessions(). The structures in the array consist of the following fields: + session id, user id, user name, + seat id, leader pid, session class, + tty name, idle hint, idle hint monotonic timestamp, + and session object path. tty and seat id fields + could be empty, if the session has no associated tty or session has no seat attached, respectively. ListUsers() returns an array of all currently logged in users. The structures in the array consist of the following fields: user id, user name, user object path. @@ -1559,8 +1571,9 @@ node /org/freedesktop/login1/session/1 { PrepareForShutdownWithMetadata and CreateSessionWithPIDFD() were added in version 255. Sleep(), - CanSleep(), and - SleepOperation were added in version 256. + CanSleep(), + SleepOperation, and + ListSessionsEx() were added in version 256. Session Objects diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 932eb42b4e..8221f76fbf 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -591,6 +591,60 @@ static int method_list_sessions(sd_bus_message *message, void *userdata, sd_bus_ return sd_bus_send(NULL, reply, NULL); } +static int method_list_sessions_ex(sd_bus_message *message, void *userdata, sd_bus_error *error) { + Manager *m = ASSERT_PTR(userdata); + _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; + int r; + + assert(message); + + r = sd_bus_message_new_method_return(message, &reply); + if (r < 0) + return r; + + r = sd_bus_message_open_container(reply, 'a', "(sussussbto)"); + if (r < 0) + return r; + + Session *s; + HASHMAP_FOREACH(s, m->sessions) { + _cleanup_free_ char *path = NULL; + dual_timestamp idle_ts; + bool idle; + + assert(s->user); + + path = session_bus_path(s); + if (!path) + return -ENOMEM; + + r = session_get_idle_hint(s, &idle_ts); + if (r < 0) + return r; + idle = r > 0; + + r = sd_bus_message_append(reply, "(sussussbto)", + s->id, + (uint32_t) s->user->user_record->uid, + s->user->user_record->user_name, + s->seat ? s->seat->id : "", + (uint32_t) s->leader.pid, + session_class_to_string(s->class), + s->tty, + idle, + idle_ts.monotonic, + path); + if (r < 0) + return r; + } + + r = sd_bus_message_close_container(reply); + if (r < 0) + return r; + + return sd_bus_send(NULL, reply, NULL); +} + static int method_list_users(sd_bus_message *message, void *userdata, sd_bus_error *error) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; Manager *m = ASSERT_PTR(userdata); @@ -3636,6 +3690,11 @@ static const sd_bus_vtable manager_vtable[] = { SD_BUS_RESULT("a(susso)", sessions), method_list_sessions, SD_BUS_VTABLE_UNPRIVILEGED), + SD_BUS_METHOD_WITH_ARGS("ListSessionsEx", + SD_BUS_NO_ARGS, + SD_BUS_RESULT("a(sussussbto)", sessions), + method_list_sessions_ex, + SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD_WITH_ARGS("ListUsers", SD_BUS_NO_ARGS, SD_BUS_RESULT("a(uso)", users), diff --git a/src/login/org.freedesktop.login1.conf b/src/login/org.freedesktop.login1.conf index d33e89d5be..e49496fce8 100644 --- a/src/login/org.freedesktop.login1.conf +++ b/src/login/org.freedesktop.login1.conf @@ -62,6 +62,10 @@ send_interface="org.freedesktop.login1.Manager" send_member="ListSessions"/> + + From 4a3e43ddc57779294f928ed2a61564221d252334 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sun, 14 Jan 2024 22:16:32 +0800 Subject: [PATCH 3/5] loginctl: show more info in list-sessions (ListSessionsEx()) At the same time, 8b6c039a1ac73da006bfe9d5735515bba12ef3c4 is reverted, i.e. session state is removed from the output. It was added to workaround #26744, and doesn't really make too much sense after the issue is properly fixed. --- src/login/loginctl.c | 139 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 113 insertions(+), 26 deletions(-) diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 9b76a63990..04ba845cbc 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -144,49 +144,91 @@ static int show_table(Table *table, const char *word) { return 0; } -static int list_sessions(int argc, char *argv[], void *userdata) { +static int list_sessions_table_add(Table *table, sd_bus_message *reply) { + int r; + + assert(table); + assert(reply); + + r = sd_bus_message_enter_container(reply, 'a', "(sussussbto)"); + if (r < 0) + return bus_log_parse_error(r); + + for (;;) { + const char *session_id, *user, *seat, *class, *tty; + uint32_t uid, leader_pid; + int idle; + uint64_t idle_timestamp_monotonic; + + r = sd_bus_message_read(reply, "(sussussbto)", + &session_id, + &uid, + &user, + &seat, + &leader_pid, + &class, + &tty, + &idle, + &idle_timestamp_monotonic, + /* object = */ NULL); + if (r < 0) + return bus_log_parse_error(r); + if (r == 0) + break; + + r = table_add_many(table, + TABLE_STRING, session_id, + TABLE_UID, (uid_t) uid, + TABLE_STRING, user, + TABLE_STRING, empty_to_null(seat), + TABLE_PID, (pid_t) leader_pid, + TABLE_STRING, class, + TABLE_STRING, empty_to_null(tty), + TABLE_BOOLEAN, idle); + if (r < 0) + return table_log_add_error(r); + + if (idle) + r = table_add_cell(table, NULL, TABLE_TIMESTAMP_RELATIVE_MONOTONIC, &idle_timestamp_monotonic); + else + r = table_add_cell(table, NULL, TABLE_EMPTY, NULL); + if (r < 0) + return table_log_add_error(r); + } + + r = sd_bus_message_exit_container(reply); + if (r < 0) + return bus_log_parse_error(r); + + return 0; +} + +static int list_sessions_table_add_fallback(Table *table, sd_bus_message *reply, sd_bus *bus) { static const struct bus_properties_map map[] = { + { "Leader", "u", NULL, offsetof(SessionStatusInfo, leader) }, + { "Class", "s", NULL, offsetof(SessionStatusInfo, class) }, + { "TTY", "s", NULL, offsetof(SessionStatusInfo, tty) }, { "IdleHint", "b", NULL, offsetof(SessionStatusInfo, idle_hint) }, { "IdleSinceHintMonotonic", "t", NULL, offsetof(SessionStatusInfo, idle_hint_timestamp.monotonic) }, - { "State", "s", NULL, offsetof(SessionStatusInfo, state) }, - { "TTY", "s", NULL, offsetof(SessionStatusInfo, tty) }, {}, }; - _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; - _cleanup_(table_unrefp) Table *table = NULL; - sd_bus *bus = ASSERT_PTR(userdata); int r; - assert(argv); - - pager_open(arg_pager_flags); - - r = bus_call_method(bus, bus_login_mgr, "ListSessions", &error, &reply, NULL); - if (r < 0) - return log_error_errno(r, "Failed to list sessions: %s", bus_error_message(&error, r)); + assert(table); + assert(reply); + assert(bus); r = sd_bus_message_enter_container(reply, 'a', "(susso)"); if (r < 0) return bus_log_parse_error(r); - table = table_new("session", "uid", "user", "seat", "tty", "state", "idle", "since"); - if (!table) - return log_oom(); - - /* Right-align the first two fields (since they are numeric) */ - (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; + _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; const char *id, *user, *seat, *object; uint32_t uid; - _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; SessionStatusInfo i = {}; r = sd_bus_message_read(reply, "(susso)", &id, &uid, &user, &seat, &object); @@ -209,8 +251,9 @@ static int list_sessions(int argc, char *argv[], void *userdata) { TABLE_UID, (uid_t) uid, TABLE_STRING, user, TABLE_STRING, empty_to_null(seat), + TABLE_PID, i.leader, + TABLE_STRING, i.class, TABLE_STRING, empty_to_null(i.tty), - TABLE_STRING, i.state, TABLE_BOOLEAN, i.idle_hint); if (r < 0) return table_log_add_error(r); @@ -227,6 +270,50 @@ static int list_sessions(int argc, char *argv[], void *userdata) { if (r < 0) return bus_log_parse_error(r); + return 0; +} + +static int list_sessions(int argc, char *argv[], void *userdata) { + sd_bus *bus = ASSERT_PTR(userdata); + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; + _cleanup_(table_unrefp) Table *table = NULL; + bool use_ex = true; + int r; + + assert(argv); + + pager_open(arg_pager_flags); + + r = bus_call_method(bus, bus_login_mgr, "ListSessionsEx", &error, &reply, NULL); + if (r < 0) { + if (sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_METHOD)) { + sd_bus_error_free(&error); + + use_ex = false; + r = bus_call_method(bus, bus_login_mgr, "ListSessions", &error, &reply, NULL); + } + if (r < 0) + return log_error_errno(r, "Failed to list sessions: %s", bus_error_message(&error, r)); + } + + table = table_new("session", "uid", "user", "seat", "leader", "class", "tty", "idle", "since"); + if (!table) + return log_oom(); + + /* Right-align the first two fields (since they are numeric) */ + (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); + + if (use_ex) + r = list_sessions_table_add(table, reply); + else + r = list_sessions_table_add_fallback(table, reply, bus); + if (r < 0) + return r; + return show_table(table, "sessions"); } From ea54517476521a35fd10790664f2525a03c582b6 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 16 Jan 2024 18:07:40 +0800 Subject: [PATCH 4/5] loginctl: add --json= and -j, decouple list-* from --output= --output= is documented to only affect journal output in *-status. Let's use --json= and -j standard options for list-* instead. --- man/loginctl.xml | 13 +++++--- shell-completion/bash/loginctl | 7 ++-- src/login/loginctl.c | 58 ++++++++++++++++++---------------- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/man/loginctl.xml b/man/loginctl.xml index 8a093c6e29..099de1dfe5 100644 --- a/man/loginctl.xml +++ b/man/loginctl.xml @@ -50,7 +50,8 @@ list-sessions - List current sessions. + List current sessions. The JSON format output can be toggled using + or option. @@ -145,8 +146,8 @@ list-users - List currently logged in users. - + List currently logged in users. The JSON format output can be toggled using + or option. @@ -225,8 +226,8 @@ list-seats - List currently available seats on the local - system. + List currently available seats on the local system. The JSON format output can be + toggled using or option. @@ -411,6 +412,8 @@ + + diff --git a/shell-completion/bash/loginctl b/shell-completion/bash/loginctl index b307e428be..e6c476742b 100644 --- a/shell-completion/bash/loginctl +++ b/shell-completion/bash/loginctl @@ -42,9 +42,9 @@ _loginctl () { local -A OPTS=( [STANDALONE]='--all -a --help -h --no-pager --version - --no-legend --no-ask-password -l --full --value' + --no-legend --no-ask-password -l --full --value -j' [ARG]='--host -H --kill-whom --property -p --signal -s -M --machine - -n --lines -o --output -P' + -n --lines -o --output -P --json' ) if __contains_word "$prev" ${OPTS[ARG]}; then @@ -68,6 +68,9 @@ _loginctl () { --output|-o) comps=$( loginctl --output=help 2>/dev/null ) ;; + --json) + comps=$( loginctl --json=help 2>/dev/null ) + ;; esac COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) return 0 diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 04ba845cbc..b9c34cfc0f 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -44,6 +44,7 @@ static BusPrintPropertyFlags arg_print_flags = 0; static bool arg_full = false; static PagerFlags arg_pager_flags = 0; static bool arg_legend = true; +static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF; static const char *arg_kill_whom = NULL; static int arg_signal = SIGTERM; static BusTransport arg_transport = BUS_TRANSPORT_LOCAL; @@ -113,32 +114,25 @@ static OutputFlags get_output_flags(void) { colors_enabled() * OUTPUT_COLOR; } -static int show_table(Table *table, const char *word) { +static int list_table_print(Table *table, const char *type) { int r; assert(table); - assert(word); + assert(type); - if (!table_isempty(table) || OUTPUT_MODE_IS_JSON(arg_output)) { - r = table_set_sort(table, (size_t) 0); - if (r < 0) - return table_log_sort_error(r); + r = table_set_sort(table, (size_t) 0); + if (r < 0) + return table_log_sort_error(r); - table_set_header(table, arg_legend); - - if (OUTPUT_MODE_IS_JSON(arg_output)) - r = table_print_json(table, NULL, output_mode_to_json_format_flags(arg_output) | JSON_FORMAT_COLOR_AUTO); - else - r = table_print(table, NULL); - if (r < 0) - return table_log_print_error(r); - } + r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend); + if (r < 0) + return r; if (arg_legend) { if (table_isempty(table)) - printf("No %s.\n", word); + printf("No %s.\n", type); else - printf("\n%zu %s listed.\n", table_get_rows(table) - 1, word); + printf("\n%zu %s listed.\n", table_get_rows(table) - 1, type); } return 0; @@ -283,8 +277,6 @@ static int list_sessions(int argc, char *argv[], void *userdata) { assert(argv); - pager_open(arg_pager_flags); - r = bus_call_method(bus, bus_login_mgr, "ListSessionsEx", &error, &reply, NULL); if (r < 0) { if (sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_METHOD)) { @@ -314,7 +306,7 @@ static int list_sessions(int argc, char *argv[], void *userdata) { if (r < 0) return r; - return show_table(table, "sessions"); + return list_table_print(table, "sessions"); } static int list_users(int argc, char *argv[], void *userdata) { @@ -333,8 +325,6 @@ static int list_users(int argc, char *argv[], void *userdata) { assert(argv); - pager_open(arg_pager_flags); - r = bus_call_method(bus, bus_login_mgr, "ListUsers", &error, &reply, NULL); if (r < 0) return log_error_errno(r, "Failed to list users: %s", bus_error_message(&error, r)); @@ -392,7 +382,7 @@ static int list_users(int argc, char *argv[], void *userdata) { if (r < 0) return bus_log_parse_error(r); - return show_table(table, "users"); + return list_table_print(table, "users"); } static int list_seats(int argc, char *argv[], void *userdata) { @@ -404,8 +394,6 @@ static int list_seats(int argc, char *argv[], void *userdata) { assert(argv); - pager_open(arg_pager_flags); - r = bus_call_method(bus, bus_login_mgr, "ListSeats", &error, &reply, NULL); if (r < 0) return log_error_errno(r, "Failed to list seats: %s", bus_error_message(&error, r)); @@ -438,7 +426,7 @@ static int list_seats(int argc, char *argv[], void *userdata) { if (r < 0) return bus_log_parse_error(r); - return show_table(table, "seats"); + return list_table_print(table, "seats"); } static int show_unit_cgroup( @@ -1551,6 +1539,7 @@ static int parse_argv(int argc, char *argv[]) { ARG_VALUE, ARG_NO_PAGER, ARG_NO_LEGEND, + ARG_JSON, ARG_KILL_WHOM, ARG_NO_ASK_PASSWORD, }; @@ -1564,6 +1553,7 @@ static int parse_argv(int argc, char *argv[]) { { "full", no_argument, NULL, 'l' }, { "no-pager", no_argument, NULL, ARG_NO_PAGER }, { "no-legend", no_argument, NULL, ARG_NO_LEGEND }, + { "json", required_argument, NULL, ARG_JSON }, { "kill-whom", required_argument, NULL, ARG_KILL_WHOM }, { "signal", required_argument, NULL, 's' }, { "host", required_argument, NULL, 'H' }, @@ -1579,7 +1569,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "hp:P:als:H:M:n:o:", options, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "hp:P:als:H:M:n:o:j", options, NULL)) >= 0) switch (c) { @@ -1633,7 +1623,19 @@ static int parse_argv(int argc, char *argv[]) { if (arg_output < 0) return log_error_errno(arg_output, "Unknown output '%s'.", optarg); - if (OUTPUT_MODE_IS_JSON(arg_output)) + break; + + case 'j': + arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO; + arg_legend = false; + break; + + case ARG_JSON: + r = parse_json_argument(optarg, &arg_json_format_flags); + if (r <= 0) + return r; + + if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) arg_legend = false; break; From a37928d34c323fd3f596d04655c694843385fff1 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 16 Jan 2024 19:38:17 +0800 Subject: [PATCH 5/5] TEST-35-LOGIN: test changes to list-sessions --- test/units/testsuite-35.sh | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh index 5c230c0a45..e9af67f358 100755 --- a/test/units/testsuite-35.sh +++ b/test/units/testsuite-35.sh @@ -258,7 +258,7 @@ cleanup_session() ( systemctl stop getty@tty2.service - for s in $(loginctl --no-legend list-sessions | grep tty | awk '$3 == "logind-test-user" { print $1 }'); do + for s in $(loginctl --no-legend list-sessions | grep -v manager | awk '$3 == "logind-test-user" { print $1 }'); do echo "INFO: stopping session $s" loginctl terminate-session "$s" done @@ -308,18 +308,18 @@ check_session() ( local seat session leader_pid - if [[ $(loginctl --no-legend | grep tty | grep -c "logind-test-user") != 1 ]]; then + if [[ $(loginctl --no-legend | grep -v manager | grep -c "logind-test-user") != 1 ]]; then echo "no session or multiple sessions for logind-test-user." >&2 return 1 fi - seat=$(loginctl --no-legend | grep tty | grep 'logind-test-user *seat' | awk '{ print $4 }') + seat=$(loginctl --no-legend | grep -v manager | grep 'logind-test-user *seat' | awk '{ print $4 }') if [[ -z "$seat" ]]; then echo "no seat found for user logind-test-user" >&2 return 1 fi - session=$(loginctl --no-legend | grep tty | awk '$3 == "logind-test-user" { print $1 }') + session=$(loginctl --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $1 }') if [[ -z "$session" ]]; then echo "no session found for user logind-test-user" >&2 return 1 @@ -364,7 +364,7 @@ EOF check_session && break done check_session - assert_eq "$(loginctl --no-legend | grep tty | awk '$3=="logind-test-user" { print $5 }')" "tty2" + assert_eq "$(loginctl --no-legend | grep -v manager | awk '$3=="logind-test-user" { print $7 }')" "tty2" } testcase_sanity_check() { @@ -382,6 +382,8 @@ testcase_sanity_check() { # the seat/session autodetection work-ish systemd-run --user --pipe --wait -M "logind-test-user@.host" bash -eux <<\EOF loginctl list-sessions + loginctl list-sessions -j + loginctl list-sessions --json=short loginctl session-status loginctl show-session loginctl show-session -P DelayInhibited @@ -455,7 +457,7 @@ EOF udevadm info "$dev" # trigger logind and activate session - loginctl activate "$(loginctl --no-legend | grep tty | awk '$3 == "logind-test-user" { print $1 }')" + loginctl activate "$(loginctl --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $1 }')" # check ACL sleep 1 @@ -496,7 +498,7 @@ testcase_lock_idle_action() { return fi - if loginctl --no-legend | grep tty | grep -q logind-test-user; then + if loginctl --no-legend | grep -v manager | grep -q logind-test-user; then echo >&2 "Session of the 'logind-test-user' is already present." exit 1 fi @@ -545,7 +547,7 @@ testcase_session_properties() { trap cleanup_session RETURN create_session - s=$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $1 }') + s=$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $1 }') /usr/lib/systemd/tests/unit-tests/manual/test-session-properties "/org/freedesktop/login1/session/_3${s?}" /dev/tty2 } @@ -561,17 +563,17 @@ testcase_list_users_sessions_seats() { create_session # Activate the session - loginctl activate "$(loginctl --no-legend | grep tty | awk '$3 == "logind-test-user" { print $1 }')" + loginctl activate "$(loginctl --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $1 }')" - session=$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $1 }') + session=$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $1 }') : check that we got a valid session id busctl get-property org.freedesktop.login1 "/org/freedesktop/login1/session/_3${session?}" org.freedesktop.login1.Session Id - assert_eq "$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $2 }')" "$(id -ru logind-test-user)" - seat=$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $4 }') - assert_eq "$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $5 }')" tty2 - assert_eq "$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $6 }')" active - assert_eq "$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $7 }')" no - assert_eq "$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $8 }')" '-' + assert_eq "$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $2 }')" "$(id -ru logind-test-user)" + seat=$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $4 }') + assert_eq "$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $6 }')" user + assert_eq "$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $7 }')" tty2 + assert_eq "$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $8 }')" no + assert_eq "$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $9 }')" '-' loginctl list-seats --no-legend | grep -Fwq "${seat?}" @@ -625,7 +627,7 @@ EOF sleep 5 assert_eq "$(journalctl -b -u systemd-logind.service --since="$ts" --grep "Session \"$id\" of user \"logind-test-user\" is idle, stopping." | wc -l)" 1 - assert_eq "$(loginctl --no-legend | grep tty | grep -c "logind-test-user")" 0 + assert_eq "$(loginctl --no-legend | grep -v manager | grep -c "logind-test-user")" 0 } testcase_ambient_caps() {