Skip to content

(RHEL-20757) Fixlets for StopIdleSessionSec= logic regarding greeter and background sessions #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions man/logind.conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,11 @@
<term><varname>StopIdleSessionSec=</varname></term>

<listitem><para>Specifies a timeout in seconds, or a time span value after which
<filename>systemd-logind</filename> checks the idle state of all sessions. Every session that is idle for
longer then the timeout will be stopped. Defaults to <literal>infinity</literal>
(<filename>systemd-logind</filename> is not checking the idle state of sessions). For details about the syntax
of time spans, see
<filename>systemd-logind</filename> checks the idle state of all sessions. Every session that is idle
for longer than the timeout will be stopped. Note that this option doesn't apply to
<literal>greeter</literal> or <literal>lock-screen</literal> sessions. Defaults to
<literal>infinity</literal> (<filename>systemd-logind</filename> is not checking the idle state
of sessions). For details about the syntax of time spans, see
<citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
</para></listitem>
</varlistentry>
Expand Down
28 changes: 15 additions & 13 deletions src/login/logind-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ static int session_setup_stop_on_idle_timer(Session *s) {

assert(s);

if (s->manager->stop_idle_session_usec == USEC_INFINITY)
if (s->manager->stop_idle_session_usec == USEC_INFINITY || IN_SET(s->class, SESSION_GREETER, SESSION_LOCK_SCREEN))
return 0;

r = sd_event_add_time_relative(
Expand Down Expand Up @@ -1029,19 +1029,21 @@ int session_get_idle_hint(Session *s, dual_timestamp *t) {
return s->idle_hint;
}

/* For sessions with an explicitly configured tty, let's check its atime */
if (s->tty) {
r = get_tty_atime(s->tty, &atime);
if (r >= 0)
goto found_atime;
}
if (s->type == SESSION_TTY) {
/* For sessions with an explicitly configured tty, let's check its atime */
if (s->tty) {
r = get_tty_atime(s->tty, &atime);
if (r >= 0)
goto found_atime;
}

/* For sessions with a leader but no explicitly configured tty, let's check the controlling tty of
* the leader */
if (pid_is_valid(s->leader)) {
r = get_process_ctty_atime(s->leader, &atime);
if (r >= 0)
goto found_atime;
/* For sessions with a leader but no explicitly configured tty, let's check the controlling tty of
* the leader */
if (pid_is_valid(s->leader)) {
r = get_process_ctty_atime(s->leader, &atime);
if (r >= 0)
goto found_atime;
}
}

if (t)
Expand Down
2 changes: 1 addition & 1 deletion src/login/logind.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ static int manager_dispatch_idle_action(sd_event_source *s, uint64_t t, void *us
m->event,
&m->idle_action_event_source,
CLOCK_MONOTONIC,
elapse, USEC_PER_SEC*30,
elapse, MIN(USEC_PER_SEC*30, m->idle_action_usec), /* accuracy of 30s, but don't have an accuracy lower than the idle action timeout */
manager_dispatch_idle_action, m);
if (r < 0)
return log_error_errno(r, "Failed to add idle event source: %m");
Expand Down