mirror of
https://github.com/systemd/systemd
synced 2024-10-15 04:24:19 +00:00
logind-dbus: introduce ListSessionsEx() call
As per https://github.com/systemd/systemd/pull/30884#discussion_r1448938737
This commit is contained in:
parent
7fbdd8c323
commit
b3cb952c03
|
@ -53,6 +53,7 @@ node /org/freedesktop/login1 {
|
|||
GetSeat(in s seat_id,
|
||||
out o object_path);
|
||||
ListSessions(out a(susso) sessions);
|
||||
ListSessionsEx(out a(sussussbto) sessions);
|
||||
ListUsers(out a(uso) users);
|
||||
ListSeats(out a(so) seats);
|
||||
ListInhibitors(out a(ssssuu) inhibitors);
|
||||
|
@ -315,6 +316,8 @@ node /org/freedesktop/login1 {
|
|||
|
||||
<variablelist class="dbus-method" generated="True" extra-ref="ListSessions()"/>
|
||||
|
||||
<variablelist class="dbus-method" generated="True" extra-ref="ListSessionsEx()"/>
|
||||
|
||||
<variablelist class="dbus-method" generated="True" extra-ref="ListUsers()"/>
|
||||
|
||||
<variablelist class="dbus-method" generated="True" extra-ref="ListSeats()"/>
|
||||
|
@ -549,8 +552,17 @@ node /org/freedesktop/login1 {
|
|||
is any.</para>
|
||||
|
||||
<para><function>ListSessions()</function> returns an array of all current sessions. The structures in
|
||||
the array consist of the following fields: session id, user id, user name, seat id, session object
|
||||
path. If a session does not have a seat attached, the seat id field will be an empty string.</para>
|
||||
the array consist of the following fields: <varname>session id</varname>, <varname>user id</varname>,
|
||||
<varname>user name</varname>, <varname>seat id</varname>, and <varname>session object path</varname>.
|
||||
If a session does not have a seat attached, the seat id field will be an empty string.</para>
|
||||
|
||||
<para><function>ListSessionsEx()</function> returns an array of all current sessions with more metadata
|
||||
than <function>ListSessions()</function>. The structures in the array consist of the following fields:
|
||||
<varname>session id</varname>, <varname>user id</varname>, <varname>user name</varname>,
|
||||
<varname>seat id</varname>, <varname>leader pid</varname>, <varname>session class</varname>,
|
||||
<varname>tty name</varname>, <varname>idle hint</varname>, <varname>idle hint monotonic timestamp</varname>,
|
||||
and <varname>session object path</varname>. <varname>tty</varname> and <varname>seat id</varname> fields
|
||||
could be empty, if the session has no associated tty or session has no seat attached, respectively.</para>
|
||||
|
||||
<para><function>ListUsers()</function> returns an array of all currently logged in users. The
|
||||
structures in the array consist of the following fields: user id, user name, user object path.</para>
|
||||
|
@ -1559,8 +1571,9 @@ node /org/freedesktop/login1/session/1 {
|
|||
<para><function>PrepareForShutdownWithMetadata</function> and
|
||||
<function>CreateSessionWithPIDFD()</function> were added in version 255.</para>
|
||||
<para><function>Sleep()</function>,
|
||||
<function>CanSleep()</function>, and
|
||||
<varname>SleepOperation</varname> were added in version 256.</para>
|
||||
<function>CanSleep()</function>,
|
||||
<varname>SleepOperation</varname>, and
|
||||
<function>ListSessionsEx()</function> were added in version 256.</para>
|
||||
</refsect2>
|
||||
<refsect2>
|
||||
<title>Session Objects</title>
|
||||
|
|
|
@ -591,6 +591,60 @@ static int method_list_sessions(sd_bus_message *message, void *userdata, sd_bus_
|
|||
return sd_bus_send(NULL, reply, NULL);
|
||||
}
|
||||
|
||||
static int method_list_sessions_ex(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
Manager *m = ASSERT_PTR(userdata);
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
||||
int r;
|
||||
|
||||
assert(message);
|
||||
|
||||
r = sd_bus_message_new_method_return(message, &reply);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_open_container(reply, 'a', "(sussussbto)");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
Session *s;
|
||||
HASHMAP_FOREACH(s, m->sessions) {
|
||||
_cleanup_free_ char *path = NULL;
|
||||
dual_timestamp idle_ts;
|
||||
bool idle;
|
||||
|
||||
assert(s->user);
|
||||
|
||||
path = session_bus_path(s);
|
||||
if (!path)
|
||||
return -ENOMEM;
|
||||
|
||||
r = session_get_idle_hint(s, &idle_ts);
|
||||
if (r < 0)
|
||||
return r;
|
||||
idle = r > 0;
|
||||
|
||||
r = sd_bus_message_append(reply, "(sussussbto)",
|
||||
s->id,
|
||||
(uint32_t) s->user->user_record->uid,
|
||||
s->user->user_record->user_name,
|
||||
s->seat ? s->seat->id : "",
|
||||
(uint32_t) s->leader.pid,
|
||||
session_class_to_string(s->class),
|
||||
s->tty,
|
||||
idle,
|
||||
idle_ts.monotonic,
|
||||
path);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_bus_message_close_container(reply);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return sd_bus_send(NULL, reply, NULL);
|
||||
}
|
||||
|
||||
static int method_list_users(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
||||
Manager *m = ASSERT_PTR(userdata);
|
||||
|
@ -3636,6 +3690,11 @@ static const sd_bus_vtable manager_vtable[] = {
|
|||
SD_BUS_RESULT("a(susso)", sessions),
|
||||
method_list_sessions,
|
||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD_WITH_ARGS("ListSessionsEx",
|
||||
SD_BUS_NO_ARGS,
|
||||
SD_BUS_RESULT("a(sussussbto)", sessions),
|
||||
method_list_sessions_ex,
|
||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD_WITH_ARGS("ListUsers",
|
||||
SD_BUS_NO_ARGS,
|
||||
SD_BUS_RESULT("a(uso)", users),
|
||||
|
|
|
@ -62,6 +62,10 @@
|
|||
send_interface="org.freedesktop.login1.Manager"
|
||||
send_member="ListSessions"/>
|
||||
|
||||
<allow send_destination="org.freedesktop.login1"
|
||||
send_interface="org.freedesktop.login1.Manager"
|
||||
send_member="ListSessionsEx"/>
|
||||
|
||||
<allow send_destination="org.freedesktop.login1"
|
||||
send_interface="org.freedesktop.login1.Manager"
|
||||
send_member="ListUsers"/>
|
||||
|
|
Loading…
Reference in a new issue