author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Thu, 06 Feb 2014 19:04:03 +0100 | |
changeset 9584 | 8209bede1a4b |
parent 8884 | e750e5abd1c7 |
permissions | -rwxr-xr-x |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
1 |
#!/bin/sh |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
2 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
3 |
# This script starts an instance of Xvfb, the "fake" X server, runs a command |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
4 |
# with that server available, and kills the X server when done. The return |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
5 |
# value of the command becomes the return value of this script. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
6 |
# |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
7 |
# If anyone is using this to build a Debian package, make sure the package |
8327
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
8 |
# Build-Depends on xvfb and xauth. |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
9 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
10 |
set -e |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
11 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
12 |
PROGNAME=xvfb-run |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
13 |
SERVERNUM=99 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
14 |
AUTHFILE= |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
15 |
ERRORFILE=/dev/null |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
16 |
XVFBARGS="-screen 0 640x480x8" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
17 |
LISTENTCP="-nolisten tcp" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
18 |
XAUTHPROTO=. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
19 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
20 |
# Query the terminal to establish a default number of columns to use for |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
21 |
# displaying messages to the user. This is used only as a fallback in the event |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
22 |
# the COLUMNS variable is not set. ($COLUMNS can react to SIGWINCH while the |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
23 |
# script is running, and this cannot, only being calculated once.) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
24 |
DEFCOLUMNS=$(stty size 2>/dev/null | awk '{print $2}') || true |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
25 |
if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" >/dev/null 2>&1; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
26 |
DEFCOLUMNS=80 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
27 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
28 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
29 |
# Display a message, wrapping lines at the terminal width. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
30 |
message () { |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
31 |
echo "$PROGNAME: $*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
32 |
} |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
33 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
34 |
# Display an error message. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
35 |
error () { |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
36 |
message "error: $*" >&2 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
37 |
} |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
38 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
39 |
# Display a usage message. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
40 |
usage () { |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
41 |
if [ -n "$*" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
42 |
message "usage error: $*" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
43 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
44 |
cat <<EOF |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
45 |
Usage: $PROGNAME [OPTION ...] COMMAND |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
46 |
Run COMMAND (usually an X client) in a virtual X server environment. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
47 |
Options: |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
48 |
-a --auto-servernum try to get a free server number, starting at |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
49 |
--server-num |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
50 |
-e FILE --error-file=FILE file used to store xauth errors and Xvfb |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
51 |
output (default: $ERRORFILE) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
52 |
-f FILE --auth-file=FILE file used to store auth cookie |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
53 |
(default: ./.Xauthority) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
54 |
-h --help display this usage message and exit |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
55 |
-n NUM --server-num=NUM server number to use (default: $SERVERNUM) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
56 |
-l --listen-tcp enable TCP port listening in the X server |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
57 |
-p PROTO --xauth-protocol=PROTO X authority protocol name to use |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
58 |
(default: xauth command's default) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
59 |
-s ARGS --server-args=ARGS arguments (other than server number and |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
60 |
"-nolisten tcp") to pass to the Xvfb server |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
61 |
(default: "$XVFBARGS") |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
62 |
EOF |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
63 |
} |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
64 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
65 |
# Find a free server number by looking at .X*-lock files in /tmp. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
66 |
find_free_servernum() { |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
67 |
# Sadly, the "local" keyword is not POSIX. Leave the next line commented in |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
68 |
# the hope Debian Policy eventually changes to allow it in /bin/sh scripts |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
69 |
# anyway. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
70 |
#local i |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
71 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
72 |
i=$SERVERNUM |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
73 |
while [ -f /tmp/.X$i-lock ]; do |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
74 |
i=$(($i + 1)) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
75 |
done |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
76 |
echo $i |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
77 |
} |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
78 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
79 |
# Clean up files |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
80 |
clean_up() { |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
81 |
if [ -e "$AUTHFILE" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
82 |
XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >>"$ERRORFILE" 2>&1 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
83 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
84 |
if [ -n "$XVFB_RUN_TMPDIR" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
85 |
if ! rm -r "$XVFB_RUN_TMPDIR"; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
86 |
error "problem while cleaning up temporary directory" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
87 |
exit 5 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
88 |
fi |
8884
e750e5abd1c7
[devtools] protect xvfb-run.sh against clean_up being called twice
Julien Cristau <julien.cristau@logilab.fr>
parents:
8758
diff
changeset
|
89 |
XVFB_RUN_TMPDIR= |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
90 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
91 |
if [ -n "$XVFBPID" ]; then |
8327
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
92 |
kill "$XVFBPID" |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
93 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
94 |
} |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
95 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
96 |
# Parse the command line. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
97 |
ARGS=$(getopt --options +ae:f:hn:lp:s:w: \ |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
98 |
--long auto-servernum,error-file:,auth-file:,help,server-num:,listen-tcp,xauth-protocol:,server-args:,wait: \ |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
99 |
--name "$PROGNAME" -- "$@") |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
100 |
GETOPT_STATUS=$? |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
101 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
102 |
if [ $GETOPT_STATUS -ne 0 ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
103 |
error "internal error; getopt exited with status $GETOPT_STATUS" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
104 |
exit 6 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
105 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
106 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
107 |
eval set -- "$ARGS" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
108 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
109 |
while :; do |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
110 |
case "$1" in |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
111 |
-a|--auto-servernum) SERVERNUM=$(find_free_servernum); AUTONUM="yes" ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
112 |
-e|--error-file) ERRORFILE="$2"; shift ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
113 |
-f|--auth-file) AUTHFILE="$2"; shift ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
114 |
-h|--help) SHOWHELP="yes" ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
115 |
-n|--server-num) SERVERNUM="$2"; shift ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
116 |
-l|--listen-tcp) LISTENTCP="" ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
117 |
-p|--xauth-protocol) XAUTHPROTO="$2"; shift ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
118 |
-s|--server-args) XVFBARGS="$2"; shift ;; |
8327
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
119 |
-w|--wait) shift ;; |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
120 |
--) shift; break ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
121 |
*) error "internal error; getopt permitted \"$1\" unexpectedly" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
122 |
exit 6 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
123 |
;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
124 |
esac |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
125 |
shift |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
126 |
done |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
127 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
128 |
if [ "$SHOWHELP" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
129 |
usage |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
130 |
exit 0 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
131 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
132 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
133 |
if [ -z "$*" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
134 |
usage "need a command to run" >&2 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
135 |
exit 2 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
136 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
137 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
138 |
if ! which xauth >/dev/null; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
139 |
error "xauth command not found" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
140 |
exit 3 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
141 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
142 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
143 |
# tidy up after ourselves |
8758
3a0d91237e2c
[devtools] fix a couple issues with xvfb-run
Julien Cristau <julien.cristau@logilab.fr>
parents:
8339
diff
changeset
|
144 |
trap clean_up EXIT TERM |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
145 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
146 |
# If the user did not specify an X authorization file to use, set up a temporary |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
147 |
# directory to house one. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
148 |
if [ -z "$AUTHFILE" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
149 |
XVFB_RUN_TMPDIR="$(mktemp -d -t $PROGNAME.XXXXXX)" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
150 |
# Create empty file to avoid xauth warning |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
151 |
AUTHFILE=$(tempfile -n "$XVFB_RUN_TMPDIR/Xauthority") |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
152 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
153 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
154 |
# Start Xvfb. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
155 |
MCOOKIE=$(mcookie) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
156 |
tries=10 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
157 |
while [ $tries -gt 0 ]; do |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
158 |
tries=$(( $tries - 1 )) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
159 |
XAUTHORITY=$AUTHFILE xauth source - << EOF >>"$ERRORFILE" 2>&1 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
160 |
add :$SERVERNUM $XAUTHPROTO $MCOOKIE |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
161 |
EOF |
8327
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
162 |
# handle SIGUSR1 so Xvfb knows to send a signal when it's ready to accept |
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
163 |
# connections |
8339
63348ead09fb
[devtools] fix bashism in xvfb-run.sh
Julien Cristau <julien.cristau@logilab.fr>
parents:
8327
diff
changeset
|
164 |
trap : USR1 |
63348ead09fb
[devtools] fix bashism in xvfb-run.sh
Julien Cristau <julien.cristau@logilab.fr>
parents:
8327
diff
changeset
|
165 |
(trap '' USR1; XAUTHORITY=$AUTHFILE exec Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP >>"$ERRORFILE" 2>&1) & |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
166 |
XVFBPID=$! |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
167 |
|
8327
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
168 |
wait || : |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
169 |
if kill -0 $XVFBPID 2>/dev/null; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
170 |
break |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
171 |
elif [ -n "$AUTONUM" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
172 |
# The display is in use so try another one (if '-a' was specified). |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
173 |
SERVERNUM=$((SERVERNUM + 1)) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
174 |
SERVERNUM=$(find_free_servernum) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
175 |
continue |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
176 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
177 |
error "Xvfb failed to start" >&2 |
8327
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
178 |
XVFBPID= |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
179 |
exit 1 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
180 |
done |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
181 |
|
8758
3a0d91237e2c
[devtools] fix a couple issues with xvfb-run
Julien Cristau <julien.cristau@logilab.fr>
parents:
8339
diff
changeset
|
182 |
# Start the command |
3a0d91237e2c
[devtools] fix a couple issues with xvfb-run
Julien Cristau <julien.cristau@logilab.fr>
parents:
8339
diff
changeset
|
183 |
DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" 2>&1 & |
3a0d91237e2c
[devtools] fix a couple issues with xvfb-run
Julien Cristau <julien.cristau@logilab.fr>
parents:
8339
diff
changeset
|
184 |
wait $! |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
185 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
186 |
# vim:set ai et sts=4 sw=4 tw=80: |