ea71a49292
Resolves: #2161260,#2170883,#2178222,#2190226,#2209912,#2211065,#2213521,#2226980,#2230364,#2231845
68 lines
3.2 KiB
Diff
68 lines
3.2 KiB
Diff
From 327f02ddb69c6f908db86e250d240c1036b5c394 Mon Sep 17 00:00:00 2001
|
|
From: Mike Yuan <me@yhndnzj.com>
|
|
Date: Thu, 11 May 2023 13:17:59 +0800
|
|
Subject: [PATCH] loginctl: list-sessions: minor modernization
|
|
|
|
(cherry picked from commit 486f61a8c908d63c47625c352e456d80c88b4687)
|
|
|
|
Related: #2209912
|
|
---
|
|
src/login/loginctl.c | 37 +++++++++++++++++++------------------
|
|
1 file changed, 19 insertions(+), 18 deletions(-)
|
|
|
|
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
|
|
index 8b72ebae57..9c21b97bb5 100644
|
|
--- a/src/login/loginctl.c
|
|
+++ b/src/login/loginctl.c
|
|
@@ -141,9 +141,9 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
|
|
(void) table_set_align_percent(table, TABLE_HEADER_CELL(1), 100);
|
|
|
|
for (;;) {
|
|
- _cleanup_(sd_bus_error_free) sd_bus_error error_tty = SD_BUS_ERROR_NULL;
|
|
- _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply_tty = NULL;
|
|
- const char *id, *user, *seat, *object, *tty = NULL;
|
|
+ _cleanup_(sd_bus_error_free) sd_bus_error error_property = SD_BUS_ERROR_NULL;
|
|
+ _cleanup_free_ char *tty = NULL;
|
|
+ const char *id, *user, *seat, *object;
|
|
uint32_t uid;
|
|
|
|
r = sd_bus_message_read(reply, "(susso)", &id, &uid, &user, &seat, &object);
|
|
@@ -152,21 +152,22 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
|
|
if (r == 0)
|
|
break;
|
|
|
|
- r = sd_bus_get_property(
|
|
- bus,
|
|
- "org.freedesktop.login1",
|
|
- object,
|
|
- "org.freedesktop.login1.Session",
|
|
- "TTY",
|
|
- &error_tty,
|
|
- &reply_tty,
|
|
- "s");
|
|
- if (r < 0)
|
|
- log_warning_errno(r, "Failed to get TTY for session %s: %s", id, bus_error_message(&error_tty, r));
|
|
- else {
|
|
- r = sd_bus_message_read(reply_tty, "s", &tty);
|
|
- if (r < 0)
|
|
- return bus_log_parse_error(r);
|
|
+ r = sd_bus_get_property_string(bus,
|
|
+ "org.freedesktop.login1",
|
|
+ object,
|
|
+ "org.freedesktop.login1.Session",
|
|
+ "TTY",
|
|
+ &error_property,
|
|
+ &tty);
|
|
+ if (r < 0) {
|
|
+ if (sd_bus_error_has_name(&error_property, SD_BUS_ERROR_UNKNOWN_OBJECT))
|
|
+ /* The session is already closed when we're querying the property */
|
|
+ continue;
|
|
+
|
|
+ log_warning_errno(r, "Failed to get TTY for session %s, ignoring: %s",
|
|
+ id, bus_error_message(&error_property, r));
|
|
+
|
|
+ sd_bus_error_free(&error_property);
|
|
}
|
|
|
|
r = table_add_many(table,
|