Skip to content

server: detect graphical sessions under systemd --user compositors - #558

Open
TheSkyentist wants to merge 3 commits into
linux-credentials:mainfrom
TheSkyentist:fix/graphical-session-detection
Open

server: detect graphical sessions under systemd --user compositors#558
TheSkyentist wants to merge 3 commits into
linux-credentials:mainfrom
TheSkyentist:fix/graphical-session-detection

Conversation

@TheSkyentist

@TheSkyentist TheSkyentist commented Aug 24, 2026

Copy link
Copy Markdown

Fixes #557

Fix

SessionType::detect now falls back past logind, in order:

  1. The peer's own /proc/<pid>/environ, since compositors export WAYLAND_DISPLAY/DISPLAY to the clients they spawn. This is often blocked by Yama's ptrace_scope (default 1 on many distros), since the daemon is never an ancestor of its D-Bus peers.
  2. The systemd --user manager's own exported environment, which compositors following this integration model populate on startup (e.g. via dbus-update-activation-environment) and which isreadable live over D-Bus with no ptrace_scope restriction. This is coarser, since it is session-wide rather than peer-specific, so it is only used once logind gives no answer at all for the peer.

Each step is only consulted if the previous one could not place the peer in a session at all, so a definite non-graphical answer from logind (e.g. a real tty/SSH login) is still trusted as-is.

Testing

Reproduced and confirmed fixed on Arch Linux with niri run as a systemd --user service and ly as greeter. Added unit tests for from_environ. cargo test, cargo clippy --all-targets clean.

Add two fallbacks to SessionType detection, used only when logind
can't place the peer in a session at all: reading the peer's own
/proc/<pid>/environ for WAYLAND_DISPLAY/DISPLAY, and, since that is
commonly blocked by Yama's ptrace_scope, falling back further to the
systemd --user manager's own exported environment, which compositors
following this integration model populate on startup and which is
readable over D-Bus without needing ptrace access.
Comment thread server/src/session.rs Outdated
Comment thread server/src/session.rs Outdated
Comment thread server/src/session.rs Outdated
@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown

📊 Code Coverage Report

Metric Value
Current PR Coverage 83.36%
Main Branch Coverage 83.53%
Coverage Change 📉 -0.17%

Coverage report generated by cargo-tarpaulin

Extract the WAYLAND_DISPLAY/DISPLAY lookup shared by from_environ
and from_systemd_user_environment into from_display_vars, add unit
tests for it, drop the unneeded allocation, and make both helpers
private since only detect() is used externally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Secret Service falls back to the CLI prompter under compositors run as a systemd --user service

2 participants