summarylogtreecommitdiffstats
path: root/xvfb-run
diff options
context:
space:
mode:
authorDaniel Bermond2018-10-27 12:13:04 +0000
committerDaniel Bermond2018-10-27 12:56:59 +0000
commit3ce8034dd0ed3cb4b7ce6f9bd7cf6f935494d672 (patch)
treeffcda07a866bf3df7eb10a67fe4edf59c07e806a /xvfb-run
parent39a180236c14a6f728a5e641e876391da25a6994 (diff)
downloadaur-3ce8034dd0ed3cb4b7ce6f9bd7cf6f935494d672.tar.gz
Updated to version 1.20.3
Diffstat (limited to 'xvfb-run')
-rw-r--r--xvfb-run86
1 files changed, 53 insertions, 33 deletions
diff --git a/xvfb-run b/xvfb-run
index 4c2f4e0d3a4..9d088c1c28e 100644
--- a/xvfb-run
+++ b/xvfb-run
@@ -1,6 +1,21 @@
#!/bin/sh
-
-# $Id: xvfb-run 2027 2004-11-16 14:54:16Z branden $
+# --- T2-COPYRIGHT-NOTE-BEGIN ---
+# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
+#
+# T2 SDE: package/.../xorg-server/xvfb-run.sh
+# Copyright (C) 2005 The T2 SDE Project
+# Copyright (C) XXXX - 2005 Debian
+#
+# More information can be found in the files COPYING and README.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License. A copy of the
+# GNU General Public License can be found in the file COPYING.
+# --- T2-COPYRIGHT-NOTE-END ---
+
+# $Id$
+# from: http://necrotic.deadbeast.net/xsf/XFree86/trunk/debian/local/xvfb-run
# This script starts an instance of Xvfb, the "fake" X server, runs a command
# with that server available, and kills the X server when done. The return
@@ -16,7 +31,7 @@ SERVERNUM=99
AUTHFILE=
ERRORFILE=/dev/null
STARTWAIT=3
-XVFBARGS="-screen 0 640x480x8"
+XVFBARGS="-screen 0 640x480x24"
LISTENTCP="-nolisten tcp"
XAUTHPROTO=.
@@ -49,7 +64,10 @@ Usage: $PROGNAME [OPTION ...] COMMAND
Run COMMAND (usually an X client) in a virtual X server environment.
Options:
-a --auto-servernum try to get a free server number, starting at
- --server-num
+ --server-num (deprecated, use --auto-display
+ instead)
+-d --auto-display use the X server to find a display number
+ automatically
-e FILE --error-file=FILE file used to store xauth errors and Xvfb
output (default: $ERRORFILE)
-f FILE --auth-file=FILE file used to store auth cookie
@@ -81,22 +99,9 @@ find_free_servernum() {
echo $i
}
-# Clean up files
-clean_up() {
- if [ -e "$AUTHFILE" ]; then
- XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >>"$ERRORFILE" 2>&1
- fi
- if [ -n "$XVFB_RUN_TMPDIR" ]; then
- if ! rm -r "$XVFB_RUN_TMPDIR"; then
- error "problem while cleaning up temporary directory"
- exit 5
- fi
- fi
-}
-
# Parse the command line.
-ARGS=$(getopt --options +ae:f:hn:lp:s:w: \
- --long auto-servernum,error-file:,auth-file:,help,server-num:,listen-tcp,xauth-protocol:,server-args:,wait: \
+ARGS=$(getopt --options +ade:f:hn:lp:s:w: \
+ --long auto-servernum,error-file:auth-file:,help,server-num:,listen-tcp,xauth-protocol:,server-args:,wait: \
--name "$PROGNAME" -- "$@")
GETOPT_STATUS=$?
@@ -110,6 +115,7 @@ eval set -- "$ARGS"
while :; do
case "$1" in
-a|--auto-servernum) SERVERNUM=$(find_free_servernum) ;;
+ -d|--auto-display) AUTO_DISPLAY=1 ;;
-e|--error-file) ERRORFILE="$2"; shift ;;
-f|--auth-file) AUTHFILE="$2"; shift ;;
-h|--help) SHOWHELP="yes" ;;
@@ -136,34 +142,39 @@ if [ -z "$*" ]; then
exit 2
fi
-if ! which xauth >/dev/null; then
+if ! type xauth >/dev/null; then
error "xauth command not found"
exit 3
fi
-# tidy up after ourselves
-trap clean_up EXIT
-
+# Set up the temp dir for the pid and X authorization file
+XVFB_RUN_TMPDIR="$(mktemp --directory --tmpdir $PROGNAME.XXXXXX)"
# If the user did not specify an X authorization file to use, set up a temporary
# directory to house one.
if [ -z "$AUTHFILE" ]; then
- XVFB_RUN_TMPDIR="$(mktemp -d -t $PROGNAME.XXXXXX)"
- AUTHFILE="$XVFB_RUN_TMPDIR/Xauthority"
+ AUTHFILE=$(mktemp -p "$XVFB_RUN_TMPDIR" Xauthority.XXXXXX)
fi
# Start Xvfb.
MCOOKIE=$(mcookie)
+
+if [ -z "$AUTO_DISPLAY" ]; then
+ # Old style using a pre-computed SERVERNUM
+ XAUTHORITY=$AUTHFILE Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP >>"$ERRORFILE" \
+ 2>&1 &
+ XVFBPID=$!
+else
+ # New style using Xvfb to provide a free display
+ PIDFILE=$(mktemp -p "$XVFB_RUN_TMPDIR" pid.XXXXXX)
+ SERVERNUM=$(XAUTHORITY=$AUTHFILE Xvfb -displayfd 1 $XVFBARGS $LISTENTCP \
+ 2>"$ERRORFILE" & echo $! > $PIDFILE)
+ XVFBPID=$(cat $PIDFILE)
+fi
+sleep "$STARTWAIT"
+
XAUTHORITY=$AUTHFILE xauth source - << EOF >>"$ERRORFILE" 2>&1
add :$SERVERNUM $XAUTHPROTO $MCOOKIE
EOF
-XAUTHORITY=$AUTHFILE Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP >>"$ERRORFILE" \
- 2>&1 &
-XVFBPID=$!
-sleep "$STARTWAIT"
-if ! kill -0 $XVFBPID 2>/dev/null; then
- echo "Xvfb failed to start" >&2
- exit 1
-fi
# Start the command and save its exit status.
set +e
@@ -174,6 +185,15 @@ set -e
# Kill Xvfb now that the command has exited.
kill $XVFBPID
+# Clean up.
+XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >"$ERRORFILE" 2>&1
+if [ -n "$XVFB_RUN_TMPDIR" ]; then
+ if ! rm -r "$XVFB_RUN_TMPDIR"; then
+ error "problem while cleaning up temporary directory"
+ exit 5
+ fi
+fi
+
# Return the executed command's exit status.
exit $RETVAL