systemd/0295-loginctl-list-users-also-show-state.patch
Jan Macku ea71a49292 systemd-252-18
Resolves: #2161260,#2170883,#2178222,#2190226,#2209912,#2211065,#2213521,#2226980,#2230364,#2231845
2023-08-22 13:24:53 +02:00

78 lines
3.6 KiB
Diff

From 5c1e6fb6440f86d59720d2d3673eb81c9255c5e8 Mon Sep 17 00:00:00 2001
From: Mike Yuan <me@yhndnzj.com>
Date: Thu, 11 May 2023 13:05:39 +0800
Subject: [PATCH] loginctl: list-users: also show state
(cherry picked from commit bae05711b5d06f330423f69d4d6500c907b8d322)
Related: #2209912
---
src/login/loginctl.c | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 4dbfa0db44..8b72ebae57 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -205,13 +205,15 @@ static int list_users(int argc, char *argv[], void *userdata) {
if (r < 0)
return bus_log_parse_error(r);
- table = table_new("uid", "user", "linger");
+ table = table_new("uid", "user", "linger", "state");
if (!table)
return log_oom();
(void) table_set_align_percent(table, TABLE_HEADER_CELL(0), 100);
for (;;) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error_property = SD_BUS_ERROR_NULL;
+ _cleanup_free_ char *state = NULL;
const char *user, *object;
uint32_t uid;
int linger;
@@ -227,16 +229,39 @@ static int list_users(int argc, char *argv[], void *userdata) {
object,
"org.freedesktop.login1.User",
"Linger",
- &error,
+ &error_property,
'b',
&linger);
- if (r < 0)
- return log_error_errno(r, "Failed to get linger status: %s", bus_error_message(&error, r));
+ if (r < 0) {
+ if (sd_bus_error_has_name(&error_property, SD_BUS_ERROR_UNKNOWN_OBJECT))
+ /* The user logged out when we're querying the property */
+ continue;
+
+ return log_error_errno(r, "Failed to get linger status for user %s: %s",
+ user, bus_error_message(&error_property, r));
+ }
+
+ r = sd_bus_get_property_string(bus,
+ "org.freedesktop.login1",
+ object,
+ "org.freedesktop.login1.User",
+ "State",
+ &error_property,
+ &state);
+ if (r < 0) {
+ if (sd_bus_error_has_name(&error_property, SD_BUS_ERROR_UNKNOWN_OBJECT))
+ /* The user logged out when we're querying the property */
+ continue;
+
+ return log_error_errno(r, "Failed to get state for user %s: %s",
+ user, bus_error_message(&error_property, r));
+ }
r = table_add_many(table,
TABLE_UID, (uid_t) uid,
TABLE_STRING, user,
- TABLE_BOOLEAN, linger);
+ TABLE_BOOLEAN, linger,
+ TABLE_STRING, state);
if (r < 0)
return table_log_add_error(r);
}