loginctl: show session idle status in list-sessions
This commit is contained in:
+21
-10
@@ -73,6 +73,8 @@ typedef struct SessionStatusInfo {
|
||||
const char *state;
|
||||
const char *scope;
|
||||
const char *desktop;
|
||||
bool idle_hint;
|
||||
dual_timestamp idle_hint_timestamp;
|
||||
} SessionStatusInfo;
|
||||
|
||||
static OutputFlags get_output_flags(void) {
|
||||
@@ -138,8 +140,10 @@ static int show_table(Table *table, const char *word) {
|
||||
static int list_sessions(int argc, char *argv[], void *userdata) {
|
||||
|
||||
static const struct bus_properties_map map[] = {
|
||||
{ "State", "s", NULL, offsetof(SessionStatusInfo, state) },
|
||||
{ "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) },
|
||||
{},
|
||||
};
|
||||
|
||||
@@ -161,7 +165,7 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
table = table_new("session", "uid", "user", "seat", "tty", "state");
|
||||
table = table_new("session", "uid", "user", "seat", "tty", "state", "idle", "since");
|
||||
if (!table)
|
||||
return log_oom();
|
||||
|
||||
@@ -184,12 +188,11 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
|
||||
|
||||
r = bus_map_all_properties(bus, "org.freedesktop.login1", object, map, BUS_MAP_BOOLEAN_AS_BOOL, &e, &m, &i);
|
||||
if (r < 0) {
|
||||
if (sd_bus_error_has_name(&e, SD_BUS_ERROR_UNKNOWN_OBJECT))
|
||||
/* The session is already closed when we're querying the property */
|
||||
continue;
|
||||
|
||||
log_warning_errno(r, "Failed to get properties of session %s, ignoring: %s",
|
||||
id, bus_error_message(&e, r));
|
||||
log_full_errno(sd_bus_error_has_name(&e, SD_BUS_ERROR_UNKNOWN_OBJECT) ? LOG_DEBUG : LOG_WARNING,
|
||||
r,
|
||||
"Failed to get properties of session %s, ignoring: %s",
|
||||
id, bus_error_message(&e, r));
|
||||
continue;
|
||||
}
|
||||
|
||||
r = table_add_many(table,
|
||||
@@ -198,7 +201,15 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
|
||||
TABLE_STRING, user,
|
||||
TABLE_STRING, seat,
|
||||
TABLE_STRING, strna(i.tty),
|
||||
TABLE_STRING, i.state);
|
||||
TABLE_STRING, i.state,
|
||||
TABLE_BOOLEAN, i.idle_hint);
|
||||
if (r < 0)
|
||||
return table_log_add_error(r);
|
||||
|
||||
if (i.idle_hint)
|
||||
r = table_add_cell(table, NULL, TABLE_TIMESTAMP_RELATIVE, &i.idle_hint_timestamp.monotonic);
|
||||
else
|
||||
r = table_add_cell(table, NULL, TABLE_EMPTY, NULL);
|
||||
if (r < 0)
|
||||
return table_log_add_error(r);
|
||||
}
|
||||
|
||||
@@ -543,6 +543,8 @@ testcase_list_users_sessions_seats() {
|
||||
seat=$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $4 }')
|
||||
assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $5 }')" tty2
|
||||
assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $6 }')" active
|
||||
assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $7 }')" no
|
||||
assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $8 }')" ''
|
||||
|
||||
loginctl list-seats --no-legend | grep -Fwq "${seat?}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user