[devtools] make xvfb-run not wait 3s each time (closes #2265710) stable
authorJulien Cristau <julien.cristau@logilab.fr>
Thu, 22 Mar 2012 11:50:43 +0100
branchstable
changeset 8327 4d76492508f3
parent 8319 f6d455b9346f
child 8330 e69832f9b3af
[devtools] make xvfb-run not wait 3s each time (closes #2265710) Ask Xvfb to tell us when it's ready instead of unconditionally waiting 3 seconds. Sync from http://anonscm.debian.org/gitweb/?p=pkg-xorg/xserver/xorg-server.git;a=blob_plain;f=debian/local/xvfb-run;hb=HEAD
devtools/data/xvfb-run.sh
--- a/devtools/data/xvfb-run.sh	Tue Mar 20 18:20:20 2012 +0100
+++ b/devtools/data/xvfb-run.sh	Thu Mar 22 11:50:43 2012 +0100
@@ -1,13 +1,11 @@
 #!/bin/sh
 
-# $Id: xvfb-run 2027 2004-11-16 14:54:16Z branden $
-
 # 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
 # value of the command becomes the return value of this script.
 #
 # If anyone is using this to build a Debian package, make sure the package
-# Build-Depends on xvfb, xbase-clients, and xfonts-base.
+# Build-Depends on xvfb and xauth.
 
 set -e
 
@@ -15,7 +13,6 @@
 SERVERNUM=99
 AUTHFILE=
 ERRORFILE=/dev/null
-STARTWAIT=3
 XVFBARGS="-screen 0 640x480x8"
 LISTENTCP="-nolisten tcp"
 XAUTHPROTO=.
@@ -62,8 +59,6 @@
 -s ARGS   --server-args=ARGS        arguments (other than server number and
                                     "-nolisten tcp") to pass to the Xvfb server
                                     (default: "$XVFBARGS")
--w DELAY  --wait=DELAY              delay in seconds to wait for Xvfb to start
-                                    before running COMMAND (default: $STARTWAIT)
 EOF
 }
 
@@ -93,7 +88,7 @@
         fi
     fi
     if [ -n "$XVFBPID" ]; then
-        kill $XVFBPID
+        kill "$XVFBPID"
     fi
 }
 
@@ -120,7 +115,7 @@
         -l|--listen-tcp) LISTENTCP="" ;;
         -p|--xauth-protocol) XAUTHPROTO="$2"; shift ;;
         -s|--server-args) XVFBARGS="$2"; shift ;;
-        -w|--wait) STARTWAIT="$2"; shift ;;
+        -w|--wait) shift ;;
         --) shift; break ;;
         *) error "internal error; getopt permitted \"$1\" unexpectedly"
            exit 6
@@ -163,10 +158,13 @@
     XAUTHORITY=$AUTHFILE xauth source - << EOF >>"$ERRORFILE" 2>&1
 add :$SERVERNUM $XAUTHPROTO $MCOOKIE
 EOF
-    XAUTHORITY=$AUTHFILE Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP >>"$ERRORFILE" 2>&1 &
+    # handle SIGUSR1 so Xvfb knows to send a signal when it's ready to accept
+    # connections
+    trap : SIGUSR1
+    (trap '' SIGUSR1; XAUTHORITY=$AUTHFILE exec Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP >>"$ERRORFILE" 2>&1) &
     XVFBPID=$!
 
-    sleep "$STARTWAIT"
+    wait || :
     if kill -0 $XVFBPID 2>/dev/null; then
         break
     elif [ -n "$AUTONUM" ]; then
@@ -176,6 +174,7 @@
         continue
     fi
     error "Xvfb failed to start" >&2
+    XVFBPID=
     exit 1
 done