mirror of
https://github.com/systemd/systemd.git
synced 2025-01-12 13:18:14 +03:00
loginctl: list-users: also show state
This commit is contained in:
parent
f44744ff51
commit
bae05711b5
@ -206,13 +206,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;
|
||||
@ -228,16 +230,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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user