-
Notifications
You must be signed in to change notification settings - Fork 4
/
xvfb-run-safe
executable file
·28 lines (25 loc) · 977 Bytes
/
xvfb-run-safe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
#
# cf https://stackoverflow.com/a/30336424/143305
# plus one change as noted below
# allow settings to be updated via environment
### make CRAN happy and avoid $HOME
## : "${xvfb_lockdir:=$HOME/.xvfb-locks}"
### feel free to revert in local installations
: "${xvfb_lockdir:=/tmp/.xvfb-locks-$USER}"
: "${xvfb_display_min:=99}"
: "${xvfb_display_max:=599}"
# assuming only one user will use this, let's put the locks in our own home directory
# avoids vulnerability to symlink attacks.
mkdir -p -- "$xvfb_lockdir" || exit
i=$xvfb_display_min # minimum display number
while (( i < xvfb_display_max )); do
if [ -f "/tmp/.X$i-lock" ]; then # still avoid an obvious open display
(( ++i )); continue
fi
exec 5>"$xvfb_lockdir/$i" || continue # open a lockfile
if flock -x -n 5; then # try to lock it
exec xvfb-run --server-num="$i" "$@" || exit # if locked, run xvfb-run
fi
(( i++ ))
done