Bug 107062

Summary: act-user-manager: Find the user's graphical session instead of assuming we are in it
Product: accountsservice Reporter: Iain Lane <iain>
Component: generalAssignee: Matthias Clasen <mclasen>
Status: RESOLVED MOVED QA Contact:
Severity: normal    
Priority: medium CC: iain, marius.vollmer, rstrode, stefw
Version: unspecified   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: act-user-manager: Find the user's graphical session instead of assuming we are in it
act-user-manager: Find the user's graphical session instead of assuming we are in it
daemon which doesn't quit when SIGTERMed

Description Iain Lane 2018-06-28 12:08:08 UTC
See https://wiki.gnome.org/Initiatives/SystemdUser for more details - basically
if programs are started by systemd --user then you can't ask "what session am I
in?" because the answer is "none". Instead it's "what is the display session?".

This patch should be safe to merge immediately & it is a prerequisite for the
systemd --user work.
Comment 1 Iain Lane 2018-06-28 12:08:11 UTC
Created attachment 140379 [details] [review]
act-user-manager: Find the user's graphical session instead of assuming we are in it

If we were started by systemd --user, we won't be in a login session.
Find the user's graphical session by asking logind for it.
Comment 2 Ray Strode [halfline] 2018-06-28 18:56:54 UTC
Comment on attachment 140379 [details] [review]
act-user-manager: Find the user's graphical session instead of assuming we are in it

Review of attachment 140379 [details] [review]:
-----------------------------------------------------------------

::: src/libaccountsservice/act-user-manager.c
@@ +710,5 @@
> +        int saved_errno;
> +
> +        g_return_val_if_fail (session_id != NULL, FALSE);
> +
> +        if ((saved_errno = sd_uid_get_display (getuid (), &local_session_id)) < 0) {

not sure this is right.  What will sd_uid_get_display() return if there's an old closing state session that's only hanging around because of pulseaudio ?  will it skip the closing one or return it ?
Comment 3 Iain Lane 2018-07-02 11:01:41 UTC
Created attachment 140420 [details] [review]
act-user-manager: Find the user's graphical session instead of assuming we are in it

If we were started by systemd --user, we won't be in a login session.
Find the user's graphical session by asking logind for it.
Comment 4 Iain Lane 2018-07-02 11:11:14 UTC
Created attachment 140425 [details]
daemon which doesn't quit when SIGTERMed

Yes, it returns it. Good catch. In the updated patch I added an explicit check to only return {online, active} sessions.

For me pulseaudio does not leave the session hanging, so I'm attaching a .c file (from https://stackoverflow.com/questions/17954432/creating-a-daemon-in-linux plus ignoring SIGTERM) which makes a session stay around in closing forever, to provoke the situation for testing.

I was also concerned that sd_uid_get_display() would still return the 'closing' session, so I tested:

  - Log in with GDM
  - Start this hanging daemon
  - Log out # session is now 'closing' forever, this code returns FALSE
  - Log back in # now you have two sessions, one closing and one active

and it returns the right thing.
Comment 5 GitLab Migration User 2018-08-07 09:33:41 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/accountsservice/accountsservice/issues/42.

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.