Bug 90818 - logind: Save the user’s state when a session enters SESSION_ACTIVE
Summary: logind: Save the user’s state when a session enters SESSION_ACTIVE
Status: RESOLVED FIXED
Alias: None
Product: systemd
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: All All
: medium normal
Assignee: systemd-bugs
QA Contact: systemd-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-02 13:24 UTC by Philip Withnall
Modified: 2015-06-04 15:26 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
logind: Save the user’s state when a session enters SESSION_ACTIVE (1.70 KB, patch)
2015-06-02 13:24 UTC, Philip Withnall
Details | Splinter Review

Description Philip Withnall 2015-06-02 13:24:46 UTC
Patch coming to fix login’s STATE tracking for users to be correct when starting a new session on a VT switch. This is important for PolicyKit decisions about whether the user is active or online, as it affects the return value of sd_uid_get_state().

See the commit message for full details.

See also: bug #90769, bug #67728, bug #76358.

---

The incorrect behaviour can be tested by:
 1. In an X11 terminal, `cat /run/systemd/users/$uid` gives SESSIONS=1 STATE=active.
 2. Switch VT, log in, `cat /run/systemd/users/$uid` gives SESSIONS="c2 1" STATE=online.
 3. Switch back to X11 and cat again, gives SESSIONS="c2 1" STATE=active.
 4. Switch back to VT and cat again, gives SESSIONS="c2 1" STATE=active.

With some debugging logging added to logind, it seems that when switching to the VT (step #2 above):
 A. Session 1 is switched from SESSION_ACTIVE to SESSION_ONLINE because of the VT change.
 B. A new session (c2) is created, with initial state SESSION_OPENING.
 C. user_save() is called, which takes the maximum state of sessions 1 and c2, which is SESSION_ONLINE.
 D. user_save() is not called again after session c2 switches from SESSION_OPENING to SESSION_ACTIVE.
Comment 1 Philip Withnall 2015-06-02 13:24:48 UTC
Created attachment 116244 [details] [review]
logind: Save the user’s state when a session enters SESSION_ACTIVE

When (for example) switching from X11 to a new VT and logging in there,
creating a new session, the user state file (/run/systemd/users/$uid) is
not updated after the session becomes active. The latest time it is
saved is when the session is in SESSION_OPENING.

This results in a /run/systemd/users/$uid file which contains
STATE=online for the current user on the current active VT, which is
obviously wrong.

As functions like sd_uid_get_state() use this file to get the user’s
state, this could result in things like PolicyKit making incorrect
decisions about the user’s state. (See
https://bugs.freedesktop.org/show_bug.cgi?id=76358.)

Fix this by re-saving the state for a session’s user after completing
the state_job for that session.
Comment 2 David Herrmann 2015-06-04 14:59:06 UTC
Applied, thanks!
Comment 3 Philip Withnall 2015-06-04 15:26:04 UTC
(In reply to David Herrmann from comment #2)
> Applied, thanks!

(For posterity, the review is on https://github.com/systemd/systemd/pull/58.)


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.