runitx Claude Opus 5.5 commited on
Commit
ca53176
·
unverified ·
1 Parent(s): 7b0bd61

with-x11: let the X server pick the display via -displayfd

Browse files

Scanning /tmp/.X11-unix for a free number races when several sessions
start at once (parallel agents each running make test): two can pick
the same display. Xvfb/Xephyr -displayfd allocates atomically.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. t/bin/with-x11 +9 -10
t/bin/with-x11 CHANGED
@@ -18,26 +18,25 @@ set -eu
18
 
19
  size=${X11_SIZE:-1280x800}
20
 
21
- # Pick a free display number
22
- n=90
23
- while [ -e "/tmp/.X11-unix/X$n" ] || [ -e "/tmp/.X$n-lock" ]; do n=$((n + 1)); done
24
- disp=":$n"
25
-
26
  if [ "${VISIBLE:-}" = 1 ]; then
27
  # Xephyr needs the host's (X)Wayland display to draw its window.
28
- Xephyr "$disp" -screen "$size" -title "shutter test session $disp" -no-host-grab -nolisten tcp >/dev/null 2>&1 &
29
  else
30
- Xvfb "$disp" -screen 0 "${size}x24" -nolisten tcp >/dev/null 2>&1 &
31
  fi
32
  xpid=$!
33
- trap 'kill "$xpid" 2>/dev/null || true' EXIT INT TERM
34
 
35
  i=0
36
- until [ -e "/tmp/.X11-unix/X$n" ]; do
37
  i=$((i + 1))
38
- if [ "$i" -gt 100 ]; then echo "with-x11: X server on $disp did not start" >&2; exit 1; fi
39
  sleep 0.1
40
  done
 
41
 
42
  env -u WAYLAND_DISPLAY -u WAYLAND_SOCKET -u XDG_CURRENT_DESKTOP -u DESKTOP_SESSION \
43
  DISPLAY="$disp" GDK_BACKEND=x11 QT_QPA_PLATFORM=xcb XDG_SESSION_TYPE=x11 \
 
18
 
19
  size=${X11_SIZE:-1280x800}
20
 
21
+ # The X server picks a free display itself and reports it via -displayfd,
22
+ # so concurrent runs (e.g. parallel agents) never race for a number.
23
+ dfile=$(mktemp)
 
 
24
  if [ "${VISIBLE:-}" = 1 ]; then
25
  # Xephyr needs the host's (X)Wayland display to draw its window.
26
+ Xephyr -displayfd 3 -screen "$size" -title "shutter test session" -no-host-grab -nolisten tcp 3>"$dfile" >/dev/null 2>&1 &
27
  else
28
+ Xvfb -displayfd 3 -screen 0 "${size}x24" -nolisten tcp 3>"$dfile" >/dev/null 2>&1 &
29
  fi
30
  xpid=$!
31
+ trap 'kill "$xpid" 2>/dev/null || true; rm -f "$dfile"' EXIT INT TERM
32
 
33
  i=0
34
+ until [ -s "$dfile" ]; do
35
  i=$((i + 1))
36
+ if [ "$i" -gt 100 ] || ! kill -0 "$xpid" 2>/dev/null; then echo "with-x11: X server did not start" >&2; exit 1; fi
37
  sleep 0.1
38
  done
39
+ disp=":$(head -n1 "$dfile")"
40
 
41
  env -u WAYLAND_DISPLAY -u WAYLAND_SOCKET -u XDG_CURRENT_DESKTOP -u DESKTOP_SESSION \
42
  DISPLAY="$disp" GDK_BACKEND=x11 QT_QPA_PLATFORM=xcb XDG_SESSION_TYPE=x11 \