fix(linux): bound the xrandr call in the wayland primary-display lookup (#15802)

`try_xrandr_primary` runs a bare `Command::new("xrandr").output()`. Its two
siblings in the same file, `try_kscreen_primary` and the gdbus one, both go through
`run_with_timeout(.., COMMAND_TIMEOUT)`, and the comment above that helper says why:
these commands are known to hang. xrandr is the one left bare.

It matters because of where it runs. `get_primary_monitor` is called from
`get_displays` with the process-wide `DISPLAYS` guard held, and on a Wayland host
the caller can be the service, which has no DISPLAY and no session bus. An X client
that blocks there blocks every consumer of the display list behind the same lock.

No behaviour change when xrandr answers: same command, same parsing, one second of
patience.
This commit is contained in:
Mariano Abad
2026-08-09 07:04:54 -03:00
committed by GitHub
parent 11190fa54e
commit 2915076642

View File

@@ -76,7 +76,9 @@ fn run_with_timeout(
// 2. The distro may not have xrandr installed by default.
// 3. xrandr may not report "primary" in its output. eg. openSUSE Leap 15.6 KDE Plasma.
fn try_xrandr_primary() -> Option<String> {
let output = Command::new("xrandr").output().ok()?;
// Bounded like its two siblings below: this runs inside the held `DISPLAYS` guard, and from a
// service with no DISPLAY and no session bus, where an X client can block indefinitely.
let output = run_with_timeout("xrandr", &[], COMMAND_TIMEOUT, "xrandr")?;
if !output.status.success() {
return None;
}