You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
5.1 KiB
104 lines
5.1 KiB
From 837b3a3ba22efd133c8b39e142994405cc1aa322 Mon Sep 17 00:00:00 2001
|
|
From: Mike Yuan <me@yhndnzj.com>
|
|
Date: Tue, 23 May 2023 18:27:05 +0800
|
|
Subject: [PATCH] loginctl: list-users: use bus_map_all_properties
|
|
|
|
(cherry picked from commit 8b0da9971afabd47e2e0b72be82dc37c06caabee)
|
|
|
|
Related: #2209912
|
|
---
|
|
src/login/loginctl.c | 58 ++++++++++++++++++--------------------------
|
|
1 file changed, 24 insertions(+), 34 deletions(-)
|
|
|
|
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
|
|
index 598acf766d..98bb87bd87 100644
|
|
--- a/src/login/loginctl.c
|
|
+++ b/src/login/loginctl.c
|
|
@@ -254,6 +254,13 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
|
|
}
|
|
|
|
static int list_users(int argc, char *argv[], void *userdata) {
|
|
+
|
|
+ static const struct bus_properties_map property_map[] = {
|
|
+ { "Linger", "b", NULL, offsetof(UserStatusInfo, linger) },
|
|
+ { "State", "s", NULL, offsetof(UserStatusInfo, state) },
|
|
+ {},
|
|
+ };
|
|
+
|
|
_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;
|
|
@@ -280,10 +287,10 @@ static int list_users(int argc, char *argv[], void *userdata) {
|
|
|
|
for (;;) {
|
|
_cleanup_(sd_bus_error_free) sd_bus_error error_property = SD_BUS_ERROR_NULL;
|
|
- _cleanup_free_ char *state = NULL;
|
|
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply_property = NULL;
|
|
+ _cleanup_(user_status_info_done) UserStatusInfo info = {};
|
|
const char *user, *object;
|
|
uint32_t uid;
|
|
- int linger;
|
|
|
|
r = sd_bus_message_read(reply, "(uso)", &uid, &user, &object);
|
|
if (r < 0)
|
|
@@ -291,44 +298,27 @@ static int list_users(int argc, char *argv[], void *userdata) {
|
|
if (r == 0)
|
|
break;
|
|
|
|
- r = sd_bus_get_property_trivial(bus,
|
|
- "org.freedesktop.login1",
|
|
- object,
|
|
- "org.freedesktop.login1.User",
|
|
- "Linger",
|
|
- &error_property,
|
|
- 'b',
|
|
- &linger);
|
|
+ r = bus_map_all_properties(bus,
|
|
+ "org.freedesktop.login1",
|
|
+ object,
|
|
+ property_map,
|
|
+ BUS_MAP_BOOLEAN_AS_BOOL,
|
|
+ &error_property,
|
|
+ &reply_property,
|
|
+ &info);
|
|
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));
|
|
+ log_full_errno(sd_bus_error_has_name(&error_property, SD_BUS_ERROR_UNKNOWN_OBJECT) ? LOG_DEBUG : LOG_WARNING,
|
|
+ r,
|
|
+ "Failed to get properties of user %s, ignoring: %s",
|
|
+ user, bus_error_message(&error_property, r));
|
|
+ continue;
|
|
}
|
|
|
|
r = table_add_many(table,
|
|
TABLE_UID, (uid_t) uid,
|
|
TABLE_STRING, user,
|
|
- TABLE_BOOLEAN, linger,
|
|
- TABLE_STRING, state);
|
|
+ TABLE_BOOLEAN, info.linger,
|
|
+ TABLE_STRING, info.state);
|
|
if (r < 0)
|
|
return table_log_add_error(r);
|
|
}
|