Merge pull request #30958 from YHNdnzj/loginctl-list-session-more-info
loginctl: show more info in list-sessions (ListSessionsEx())
This commit is contained in:
+8
-5
@@ -50,7 +50,8 @@
|
||||
<varlistentry>
|
||||
<term><command>list-sessions</command></term>
|
||||
|
||||
<listitem><para>List current sessions.</para></listitem>
|
||||
<listitem><para>List current sessions. The JSON format output can be toggled using <option>--json=</option>
|
||||
or <option>-j</option> option.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
@@ -145,8 +146,8 @@
|
||||
<varlistentry>
|
||||
<term><command>list-users</command></term>
|
||||
|
||||
<listitem><para>List currently logged in users.
|
||||
</para></listitem>
|
||||
<listitem><para>List currently logged in users. The JSON format output can be toggled using
|
||||
<option>--json=</option> or <option>-j</option> option.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
@@ -225,8 +226,8 @@
|
||||
<varlistentry>
|
||||
<term><command>list-seats</command></term>
|
||||
|
||||
<listitem><para>List currently available seats on the local
|
||||
system.</para></listitem>
|
||||
<listitem><para>List currently available seats on the local system. The JSON format output can be
|
||||
toggled using <option>--json=</option> or <option>-j</option> option.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
@@ -411,6 +412,8 @@
|
||||
|
||||
<xi:include href="standard-options.xml" xpointer="no-pager" />
|
||||
<xi:include href="standard-options.xml" xpointer="no-legend" />
|
||||
<xi:include href="standard-options.xml" xpointer="json" />
|
||||
<xi:include href="standard-options.xml" xpointer="j" />
|
||||
<xi:include href="standard-options.xml" xpointer="help" />
|
||||
<xi:include href="standard-options.xml" xpointer="version" />
|
||||
</variablelist>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
|
||||
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
|
||||
|
||||
<variablelist
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
|
||||
<variablelist>
|
||||
<varlistentry id='help'>
|
||||
<term><option>-h</option></term>
|
||||
<term><option>--help</option></term>
|
||||
@@ -31,16 +29,6 @@
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry id='no-pager-255'>
|
||||
<term><option>--no-pager</option></term>
|
||||
|
||||
<listitem>
|
||||
<para>Do not pipe output into a pager.</para>
|
||||
|
||||
<xi:include href="version-info.xml" xpointer="v255"/>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry id='no-ask-password'>
|
||||
<term><option>--no-ask-password</option></term>
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
<xi:include href="version-info.xml" xpointer="v215"/></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<xi:include href="standard-options.xml" xpointer="no-pager-255"/>
|
||||
<xi:include href="standard-options.xml" xpointer="no-pager"/>
|
||||
<xi:include href="standard-options.xml" xpointer="help" />
|
||||
<xi:include href="standard-options.xml" xpointer="version" />
|
||||
</variablelist>
|
||||
|
||||
@@ -42,9 +42,9 @@ _loginctl () {
|
||||
|
||||
local -A OPTS=(
|
||||
[STANDALONE]='--all -a --help -h --no-pager --version
|
||||
--no-legend --no-ask-password -l --full --value'
|
||||
--no-legend --no-ask-password -l --full --value -j'
|
||||
[ARG]='--host -H --kill-whom --property -p --signal -s -M --machine
|
||||
-n --lines -o --output -P'
|
||||
-n --lines -o --output -P --json'
|
||||
)
|
||||
|
||||
if __contains_word "$prev" ${OPTS[ARG]}; then
|
||||
@@ -68,6 +68,9 @@ _loginctl () {
|
||||
--output|-o)
|
||||
comps=$( loginctl --output=help 2>/dev/null )
|
||||
;;
|
||||
--json)
|
||||
comps=$( loginctl --json=help 2>/dev/null )
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
|
||||
return 0
|
||||
|
||||
+141
-52
@@ -44,6 +44,7 @@ static BusPrintPropertyFlags arg_print_flags = 0;
|
||||
static bool arg_full = false;
|
||||
static PagerFlags arg_pager_flags = 0;
|
||||
static bool arg_legend = true;
|
||||
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
static const char *arg_kill_whom = NULL;
|
||||
static int arg_signal = SIGTERM;
|
||||
static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
|
||||
@@ -113,80 +114,115 @@ static OutputFlags get_output_flags(void) {
|
||||
colors_enabled() * OUTPUT_COLOR;
|
||||
}
|
||||
|
||||
static int show_table(Table *table, const char *word) {
|
||||
static int list_table_print(Table *table, const char *type) {
|
||||
int r;
|
||||
|
||||
assert(table);
|
||||
assert(word);
|
||||
assert(type);
|
||||
|
||||
if (!table_isempty(table) || OUTPUT_MODE_IS_JSON(arg_output)) {
|
||||
r = table_set_sort(table, (size_t) 0);
|
||||
if (r < 0)
|
||||
return table_log_sort_error(r);
|
||||
r = table_set_sort(table, (size_t) 0);
|
||||
if (r < 0)
|
||||
return table_log_sort_error(r);
|
||||
|
||||
table_set_header(table, arg_legend);
|
||||
|
||||
if (OUTPUT_MODE_IS_JSON(arg_output))
|
||||
r = table_print_json(table, NULL, output_mode_to_json_format_flags(arg_output) | JSON_FORMAT_COLOR_AUTO);
|
||||
else
|
||||
r = table_print(table, NULL);
|
||||
if (r < 0)
|
||||
return table_log_print_error(r);
|
||||
}
|
||||
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (arg_legend) {
|
||||
if (table_isempty(table))
|
||||
printf("No %s.\n", word);
|
||||
printf("No %s.\n", type);
|
||||
else
|
||||
printf("\n%zu %s listed.\n", table_get_rows(table) - 1, word);
|
||||
printf("\n%zu %s listed.\n", table_get_rows(table) - 1, type);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int list_sessions(int argc, char *argv[], void *userdata) {
|
||||
static int list_sessions_table_add(Table *table, sd_bus_message *reply) {
|
||||
int r;
|
||||
|
||||
assert(table);
|
||||
assert(reply);
|
||||
|
||||
r = sd_bus_message_enter_container(reply, 'a', "(sussussbto)");
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
for (;;) {
|
||||
const char *session_id, *user, *seat, *class, *tty;
|
||||
uint32_t uid, leader_pid;
|
||||
int idle;
|
||||
uint64_t idle_timestamp_monotonic;
|
||||
|
||||
r = sd_bus_message_read(reply, "(sussussbto)",
|
||||
&session_id,
|
||||
&uid,
|
||||
&user,
|
||||
&seat,
|
||||
&leader_pid,
|
||||
&class,
|
||||
&tty,
|
||||
&idle,
|
||||
&idle_timestamp_monotonic,
|
||||
/* object = */ NULL);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
if (r == 0)
|
||||
break;
|
||||
|
||||
r = table_add_many(table,
|
||||
TABLE_STRING, session_id,
|
||||
TABLE_UID, (uid_t) uid,
|
||||
TABLE_STRING, user,
|
||||
TABLE_STRING, empty_to_null(seat),
|
||||
TABLE_PID, (pid_t) leader_pid,
|
||||
TABLE_STRING, class,
|
||||
TABLE_STRING, empty_to_null(tty),
|
||||
TABLE_BOOLEAN, idle);
|
||||
if (r < 0)
|
||||
return table_log_add_error(r);
|
||||
|
||||
if (idle)
|
||||
r = table_add_cell(table, NULL, TABLE_TIMESTAMP_RELATIVE_MONOTONIC, &idle_timestamp_monotonic);
|
||||
else
|
||||
r = table_add_cell(table, NULL, TABLE_EMPTY, NULL);
|
||||
if (r < 0)
|
||||
return table_log_add_error(r);
|
||||
}
|
||||
|
||||
r = sd_bus_message_exit_container(reply);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int list_sessions_table_add_fallback(Table *table, sd_bus_message *reply, sd_bus *bus) {
|
||||
|
||||
static const struct bus_properties_map map[] = {
|
||||
{ "Leader", "u", NULL, offsetof(SessionStatusInfo, leader) },
|
||||
{ "Class", "s", NULL, offsetof(SessionStatusInfo, class) },
|
||||
{ "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) },
|
||||
{},
|
||||
};
|
||||
|
||||
_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;
|
||||
sd_bus *bus = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
|
||||
assert(argv);
|
||||
|
||||
pager_open(arg_pager_flags);
|
||||
|
||||
r = bus_call_method(bus, bus_login_mgr, "ListSessions", &error, &reply, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to list sessions: %s", bus_error_message(&error, r));
|
||||
assert(table);
|
||||
assert(reply);
|
||||
assert(bus);
|
||||
|
||||
r = sd_bus_message_enter_container(reply, 'a', "(susso)");
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
table = table_new("session", "uid", "user", "seat", "tty", "state", "idle", "since");
|
||||
if (!table)
|
||||
return log_oom();
|
||||
|
||||
/* Right-align the first two fields (since they are numeric) */
|
||||
(void) table_set_align_percent(table, TABLE_HEADER_CELL(0), 100);
|
||||
(void) table_set_align_percent(table, TABLE_HEADER_CELL(1), 100);
|
||||
|
||||
(void) table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
|
||||
|
||||
for (;;) {
|
||||
_cleanup_(sd_bus_error_free) sd_bus_error e = SD_BUS_ERROR_NULL;
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
||||
const char *id, *user, *seat, *object;
|
||||
uint32_t uid;
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
||||
SessionStatusInfo i = {};
|
||||
|
||||
r = sd_bus_message_read(reply, "(susso)", &id, &uid, &user, &seat, &object);
|
||||
@@ -209,8 +245,9 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
|
||||
TABLE_UID, (uid_t) uid,
|
||||
TABLE_STRING, user,
|
||||
TABLE_STRING, empty_to_null(seat),
|
||||
TABLE_PID, i.leader,
|
||||
TABLE_STRING, i.class,
|
||||
TABLE_STRING, empty_to_null(i.tty),
|
||||
TABLE_STRING, i.state,
|
||||
TABLE_BOOLEAN, i.idle_hint);
|
||||
if (r < 0)
|
||||
return table_log_add_error(r);
|
||||
@@ -227,7 +264,49 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
return show_table(table, "sessions");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int list_sessions(int argc, char *argv[], void *userdata) {
|
||||
sd_bus *bus = ASSERT_PTR(userdata);
|
||||
_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;
|
||||
bool use_ex = true;
|
||||
int r;
|
||||
|
||||
assert(argv);
|
||||
|
||||
r = bus_call_method(bus, bus_login_mgr, "ListSessionsEx", &error, &reply, NULL);
|
||||
if (r < 0) {
|
||||
if (sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_METHOD)) {
|
||||
sd_bus_error_free(&error);
|
||||
|
||||
use_ex = false;
|
||||
r = bus_call_method(bus, bus_login_mgr, "ListSessions", &error, &reply, NULL);
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to list sessions: %s", bus_error_message(&error, r));
|
||||
}
|
||||
|
||||
table = table_new("session", "uid", "user", "seat", "leader", "class", "tty", "idle", "since");
|
||||
if (!table)
|
||||
return log_oom();
|
||||
|
||||
/* Right-align the first two fields (since they are numeric) */
|
||||
(void) table_set_align_percent(table, TABLE_HEADER_CELL(0), 100);
|
||||
(void) table_set_align_percent(table, TABLE_HEADER_CELL(1), 100);
|
||||
|
||||
(void) table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
|
||||
|
||||
if (use_ex)
|
||||
r = list_sessions_table_add(table, reply);
|
||||
else
|
||||
r = list_sessions_table_add_fallback(table, reply, bus);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return list_table_print(table, "sessions");
|
||||
}
|
||||
|
||||
static int list_users(int argc, char *argv[], void *userdata) {
|
||||
@@ -246,8 +325,6 @@ static int list_users(int argc, char *argv[], void *userdata) {
|
||||
|
||||
assert(argv);
|
||||
|
||||
pager_open(arg_pager_flags);
|
||||
|
||||
r = bus_call_method(bus, bus_login_mgr, "ListUsers", &error, &reply, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to list users: %s", bus_error_message(&error, r));
|
||||
@@ -305,7 +382,7 @@ static int list_users(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
return show_table(table, "users");
|
||||
return list_table_print(table, "users");
|
||||
}
|
||||
|
||||
static int list_seats(int argc, char *argv[], void *userdata) {
|
||||
@@ -317,8 +394,6 @@ static int list_seats(int argc, char *argv[], void *userdata) {
|
||||
|
||||
assert(argv);
|
||||
|
||||
pager_open(arg_pager_flags);
|
||||
|
||||
r = bus_call_method(bus, bus_login_mgr, "ListSeats", &error, &reply, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to list seats: %s", bus_error_message(&error, r));
|
||||
@@ -351,7 +426,7 @@ static int list_seats(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
return show_table(table, "seats");
|
||||
return list_table_print(table, "seats");
|
||||
}
|
||||
|
||||
static int show_unit_cgroup(
|
||||
@@ -1464,6 +1539,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
ARG_VALUE,
|
||||
ARG_NO_PAGER,
|
||||
ARG_NO_LEGEND,
|
||||
ARG_JSON,
|
||||
ARG_KILL_WHOM,
|
||||
ARG_NO_ASK_PASSWORD,
|
||||
};
|
||||
@@ -1477,6 +1553,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
{ "full", no_argument, NULL, 'l' },
|
||||
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
|
||||
{ "no-legend", no_argument, NULL, ARG_NO_LEGEND },
|
||||
{ "json", required_argument, NULL, ARG_JSON },
|
||||
{ "kill-whom", required_argument, NULL, ARG_KILL_WHOM },
|
||||
{ "signal", required_argument, NULL, 's' },
|
||||
{ "host", required_argument, NULL, 'H' },
|
||||
@@ -1492,7 +1569,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
assert(argc >= 0);
|
||||
assert(argv);
|
||||
|
||||
while ((c = getopt_long(argc, argv, "hp:P:als:H:M:n:o:", options, NULL)) >= 0)
|
||||
while ((c = getopt_long(argc, argv, "hp:P:als:H:M:n:o:j", options, NULL)) >= 0)
|
||||
|
||||
switch (c) {
|
||||
|
||||
@@ -1546,7 +1623,19 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
if (arg_output < 0)
|
||||
return log_error_errno(arg_output, "Unknown output '%s'.", optarg);
|
||||
|
||||
if (OUTPUT_MODE_IS_JSON(arg_output))
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
|
||||
arg_legend = false;
|
||||
break;
|
||||
|
||||
case ARG_JSON:
|
||||
r = parse_json_argument(optarg, &arg_json_format_flags);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))
|
||||
arg_legend = false;
|
||||
|
||||
break;
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
+19
-17
@@ -258,7 +258,7 @@ cleanup_session() (
|
||||
|
||||
systemctl stop getty@tty2.service
|
||||
|
||||
for s in $(loginctl --no-legend list-sessions | grep tty | awk '$3 == "logind-test-user" { print $1 }'); do
|
||||
for s in $(loginctl --no-legend list-sessions | grep -v manager | awk '$3 == "logind-test-user" { print $1 }'); do
|
||||
echo "INFO: stopping session $s"
|
||||
loginctl terminate-session "$s"
|
||||
done
|
||||
@@ -308,18 +308,18 @@ check_session() (
|
||||
|
||||
local seat session leader_pid
|
||||
|
||||
if [[ $(loginctl --no-legend | grep tty | grep -c "logind-test-user") != 1 ]]; then
|
||||
if [[ $(loginctl --no-legend | grep -v manager | grep -c "logind-test-user") != 1 ]]; then
|
||||
echo "no session or multiple sessions for logind-test-user." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
seat=$(loginctl --no-legend | grep tty | grep 'logind-test-user *seat' | awk '{ print $4 }')
|
||||
seat=$(loginctl --no-legend | grep -v manager | grep 'logind-test-user *seat' | awk '{ print $4 }')
|
||||
if [[ -z "$seat" ]]; then
|
||||
echo "no seat found for user logind-test-user" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
session=$(loginctl --no-legend | grep tty | awk '$3 == "logind-test-user" { print $1 }')
|
||||
session=$(loginctl --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $1 }')
|
||||
if [[ -z "$session" ]]; then
|
||||
echo "no session found for user logind-test-user" >&2
|
||||
return 1
|
||||
@@ -364,7 +364,7 @@ EOF
|
||||
check_session && break
|
||||
done
|
||||
check_session
|
||||
assert_eq "$(loginctl --no-legend | grep tty | awk '$3=="logind-test-user" { print $5 }')" "tty2"
|
||||
assert_eq "$(loginctl --no-legend | grep -v manager | awk '$3=="logind-test-user" { print $7 }')" "tty2"
|
||||
}
|
||||
|
||||
testcase_sanity_check() {
|
||||
@@ -382,6 +382,8 @@ testcase_sanity_check() {
|
||||
# the seat/session autodetection work-ish
|
||||
systemd-run --user --pipe --wait -M "logind-test-user@.host" bash -eux <<\EOF
|
||||
loginctl list-sessions
|
||||
loginctl list-sessions -j
|
||||
loginctl list-sessions --json=short
|
||||
loginctl session-status
|
||||
loginctl show-session
|
||||
loginctl show-session -P DelayInhibited
|
||||
@@ -455,7 +457,7 @@ EOF
|
||||
udevadm info "$dev"
|
||||
|
||||
# trigger logind and activate session
|
||||
loginctl activate "$(loginctl --no-legend | grep tty | awk '$3 == "logind-test-user" { print $1 }')"
|
||||
loginctl activate "$(loginctl --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $1 }')"
|
||||
|
||||
# check ACL
|
||||
sleep 1
|
||||
@@ -496,7 +498,7 @@ testcase_lock_idle_action() {
|
||||
return
|
||||
fi
|
||||
|
||||
if loginctl --no-legend | grep tty | grep -q logind-test-user; then
|
||||
if loginctl --no-legend | grep -v manager | grep -q logind-test-user; then
|
||||
echo >&2 "Session of the 'logind-test-user' is already present."
|
||||
exit 1
|
||||
fi
|
||||
@@ -545,7 +547,7 @@ testcase_session_properties() {
|
||||
trap cleanup_session RETURN
|
||||
create_session
|
||||
|
||||
s=$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $1 }')
|
||||
s=$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $1 }')
|
||||
/usr/lib/systemd/tests/unit-tests/manual/test-session-properties "/org/freedesktop/login1/session/_3${s?}" /dev/tty2
|
||||
}
|
||||
|
||||
@@ -561,17 +563,17 @@ testcase_list_users_sessions_seats() {
|
||||
create_session
|
||||
|
||||
# Activate the session
|
||||
loginctl activate "$(loginctl --no-legend | grep tty | awk '$3 == "logind-test-user" { print $1 }')"
|
||||
loginctl activate "$(loginctl --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $1 }')"
|
||||
|
||||
session=$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $1 }')
|
||||
session=$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $1 }')
|
||||
: check that we got a valid session id
|
||||
busctl get-property org.freedesktop.login1 "/org/freedesktop/login1/session/_3${session?}" org.freedesktop.login1.Session Id
|
||||
assert_eq "$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $2 }')" "$(id -ru logind-test-user)"
|
||||
seat=$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $4 }')
|
||||
assert_eq "$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $5 }')" tty2
|
||||
assert_eq "$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $6 }')" active
|
||||
assert_eq "$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $7 }')" no
|
||||
assert_eq "$(loginctl list-sessions --no-legend | grep tty | awk '$3 == "logind-test-user" { print $8 }')" '-'
|
||||
assert_eq "$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $2 }')" "$(id -ru logind-test-user)"
|
||||
seat=$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $4 }')
|
||||
assert_eq "$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $6 }')" user
|
||||
assert_eq "$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $7 }')" tty2
|
||||
assert_eq "$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $8 }')" no
|
||||
assert_eq "$(loginctl list-sessions --no-legend | grep -v manager | awk '$3 == "logind-test-user" { print $9 }')" '-'
|
||||
|
||||
loginctl list-seats --no-legend | grep -Fwq "${seat?}"
|
||||
|
||||
@@ -625,7 +627,7 @@ EOF
|
||||
sleep 5
|
||||
|
||||
assert_eq "$(journalctl -b -u systemd-logind.service --since="$ts" --grep "Session \"$id\" of user \"logind-test-user\" is idle, stopping." | wc -l)" 1
|
||||
assert_eq "$(loginctl --no-legend | grep tty | grep -c "logind-test-user")" 0
|
||||
assert_eq "$(loginctl --no-legend | grep -v manager | grep -c "logind-test-user")" 0
|
||||
}
|
||||
|
||||
testcase_ambient_caps() {
|
||||
|
||||
Reference in New Issue
Block a user