atagen

monolith

public
Star0
Watch0

Commit 28e12a7e36cd

tarball

atagen <boss@atagen.co>2026-10-17 05:11 UTC

1 file changed+8-2
monolith: treat X display locks held by unrelated processes as stale

The lock only records a pid, so once a killed monolith's pid was reused the display number stayed taken until reboot.
Modified file: crates/monolith/src/xwayland.rs+8 additions−2 deletions
@@ -59,8 +59,7 @@ fn claim() -> Option<(u32, Vec<UnixListener>)> {
5959 let owner = std::fs::read_to_string(&lock)
6060 .ok()
6161 .and_then(|s| s.trim().parse::<u32>().ok());
62- let stale = owner
63- .is_some_and(|pid| !std::path::Path::new(&format!("/proc/{pid}")).exists());
62+ let stale = owner.is_some_and(|pid| !holds_display(pid));
6463 if !stale || std::fs::remove_file(&lock).is_err() {
6564 continue;
6665 }
@@ -405,3 +404,10 @@ pub fn logged<E: std::fmt::Display>(what: &str, result: Result<(), E>) {
405404 tracing::debug!("X11 {what} failed: {e}");
406405 }
407406 }
407+
408+/// Whether `pid` is alive and could own an X display lock. A SIGKILLed
409+/// monolith leaves its lock behind, and its pid may since belong to anything.
410+fn holds_display(pid: u32) -> bool {
411+ std::fs::read_to_string(format!("/proc/{pid}/comm"))
412+ .is_ok_and(|comm| comm.starts_with('X') || comm.trim() == "monolith")
413+}