Bug 1857969

Summary: After login, the "loginctl show-session" command does not show the associated display information
Product: Red Hat Enterprise Linux 8 Reporter: Carlos Santos <casantos>
Component: systemdAssignee: David Tardon <dtardon>
Status: CLOSED ERRATA QA Contact: Frantisek Sumsal <fsumsal>
Severity: high Docs Contact:
Priority: high    
Version: 8.2CC: alanm, amike, brclark, dtardon, hdegoede, joe, jwright, mkolbas, systemd-maint-list
Target Milestone: rcKeywords: FutureFeature, Triaged
Target Release: 8.0Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: systemd-239-61.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2100340 2105959 (view as bug list) Environment:
Last Closed: 2022-11-08 10:49:17 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2100340, 2173632    

Description Carlos Santos 2020-07-16 19:29:26 UTC
Description of problem:

When a user logs in via gdm on RHEL- the /run/systemd/sessions/<n> created via
systemd-logind does not contain the DISPLAY information and loginctl can't
show it.

It is also impossible to use sd_session_get_display() to get the display
information programatically.

Version-Release number of selected component (if applicable):

# rpm -q gdm systemd
gdm-3.28.3-29.el8.x86_64
systemd-239-30.el8_2.x86_64

How reproducible:

Always

Steps to Reproduce:

1. Log in as an ordinary user

2. List the existing sessions

   # loginctl list-sessions
   SESSION   UID USER     SEAT  TTY 
        18     0 root               
        25 22174 casantos seat0 tty2
        c3    42 gdm      seat0 tty1

3. Show the user session information

   # loginctl show-session 25

Actual results:

   Id=25
   User=22174
   Name=casantos
   Timestamp=Thu 2020-07-16 16:16:42 -03
   TimestampMonotonic=21677574113
   VTNr=2
   Seat=seat0
   TTY=tty2
   Remote=no
   Service=gdm-password
   Scope=session-25.scope
   Leader=43159
   Audit=25
   Type=wayland
   Class=user
   Active=yes
   State=active
   IdleHint=no
   IdleSinceHint=0
   IdleSinceHintMonotonic=0
   LockedHint=no

Expected results:

   Should show a line containing "Display=:0"

Additional info:

   # cat /run/systemd/sessions/25
   # This is private data. Do not parse.
   UID=22174
   USER=casantos
   ACTIVE=1
   STATE=active
   REMOTE=0
   TYPE=wayland
   CLASS=user
   SCOPE=session-25.scope
   FIFO=/run/systemd/sessions/25.ref
   SEAT=seat0
   TTY=tty2
   SERVICE=gdm-password
   VTNR=2
   LEADER=43159
   AUDIT=25
   REALTIME=1594927002204542
   MONOTONIC=21677574113
   CONTROLLER=:1.2362
   DEVICES=13:65 13:64 13:67 226:0 13:66 13:69 

Disabling Wayland does not make any difference.

It would be good to find a workaround, since there is a customer case in which
the user needs to find the associated display of running sessions by means of
sd_session_get_display().

Comment 1 Carlos Santos 2020-07-16 19:34:06 UTC
The display information is shown correctly in RHEL 7.8, so the current behavior
should be considered is a regression.

Comment 2 Ray Strode [halfline] 2020-08-11 19:40:02 UTC
This is because, in RHEL 8, the X server (or wayland display server) is started as part of the user session instead of as root before the session starts.  loginctl gets passed it's information at the time the session is created.  There's no way we can know the display at that point.

Fixing this requires adding api to logind to allow the session controller to update the display variable after the session is created.

As far as workarounds goes, i'm not sure...  The user could install an autostart file in /etc/xdg/autostart that does omsething like:

[Desktop Entry]
Name=Record Display To Runtime Dir
Exec=sh -c 'echo $DISPLAY > $XDG_RUNTIME_DIR/display'

and then look at /run/user/1000/display to find the session display.

Of course it's better to run things within the session instead of trying to connect to the session from the outside, anyway.

Moving to systemd. If they ack adding the proposed logind API, then I'll add the bits needed in GDM.

Comment 5 Joe Doss 2022-06-14 23:31:14 UTC
I think a workaround could be using sd_session_get_seat()? pam_systemd seems to set $XDG_SEAT based off of $DISPLAY if it is not set. I am not sure what systemd-logind bases SEAT on however. 

https://www.freedesktop.org/software/systemd/man/pam_systemd.html#%24XDG_SEAT

I am trying to figure out what $DISPLAY users have as well on Fedora 36 using Bash. Here are some things I came up with if the seat number lines up with display.

Find X11 env and look for XDG_SEAT:
# DISPLAY=":$(cat /proc/$(pgrep Xorg)/environ | tr '\0' '\n'| grep ^XDG_SEAT|sed -e "s/^XDG_SEAT=seat//")"
# echo $DISPLAY
:0

Use loginctl:
# DISPLAY=":$(loginctl --no-legend list-sessions|grep seat|awk '{print $4}'|sed -e "s/^seat//")"
# echo $DISPLAY
:0

Both of these examples need a for loop or something for multi-sessions. Anyways, I think sd_session_get_seat() could be a workaround here.

Comment 7 Plumber Bot 2022-07-11 08:01:19 UTC
fix merged to github master branch -> https://github.com/redhat-plumbers/systemd-rhel8/pull/296

Comment 12 errata-xmlrpc 2022-11-08 10:49:17 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (systemd bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:7727