Hi, The shell code that is used in spec files to run "make check" for packages that require an X connection does not work properly. It does not take into account that you need an entry in .Xauthority to connect to the X server, and when the "make check" fails (for example because it can't connect to the X server...) the Xvfb does not get killed, so on a build machine you accumulate ghost Xvfbs.
The debian xvfb package contains a script called "xvfb-run" that runs a given command in a new Xvfb. Unless something goes wrong with the script itself, it returns as exit code the exit code of the command. This script is in itself useful (I use it to run xmms on my jukebox PC), so I propose to add this script to the XFree86-Xvfb package (installed in /usr/bin, for example) and changing things like (from libbonoboui.spec): XDISPLAY=$(i=0; while [ -f /tmp/.X$i-lock ]; do i=$(($i+1)); done; echo $i) /usr/X11R6/bin/Xvfb :$XDISPLAY >& /dev/null & DISPLAY=:$XDISPLAY make check kill $(cat /tmp/.X$XDISPLAY-lock) in specfiles to: xvfb-run make check I attached the script and the manpage, but it is also available from the debian XFree86 patch (1.5M): http://ftp.debian.org/debian/pool/main/x/xfree86/xfree86_4.2.1-8.diff.gz cheers, Christiaan
#!/bin/sh # xvfb-run - run the specified command in a virtual X server # 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. set -e PROGNAME=xvfb-run SERVERNUM=99 AUTHFILE=$(pwd)/.Xauthority ERRORFILE=/dev/null STARTWAIT=3 XVFBARGS="-screen 0 640x480x8" LISTENTCP="-nolisten tcp" XAUTHPROTO=. # display a usage message usage () { cat << EOF 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 -e FILE --error-file=FILE file used to store xauth errors and Xvfb output (defualt: $ERRORFILE) -f FILE --auth-file=FILE file used to store auth cookie (default: ./.Xauthority) -h --help display this usage message and exit -n NUM --server-num=NUM server number to use (default: $SERVERNUM) -l --listen-tcp enable TCP port listening in the X server -p PROTO --xauth-protocol=PROTO X authority protocol name to use (defaults to xauth's default) -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 (default: $STARTWAIT) EOF :; } # find free server number by looking at .X*-lock files in /tmp find_free_servernum() { i=$SERVERNUM while [ -f /tmp/.X$i-lock ]; do i=$(($i + 1)) done echo $i; } # parse 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: \ --name "$PROGNAME" -- "$@") if [ $? -ne 0 ]; then echo "$PROGNAME: error while getting options" >&2 exit 1 fi eval set -- "$ARGS" while :; do case "$1" in -a|--auto-servernum) SERVERNUM=$(find_free_servernum) ;; -e|--error-file) ERRORFILE="$2"; shift ;; -f|--auth-file) AUTHFILE="$2"; shift ;; -h|--help) SHOWHELP="yes" ;; -n|--server-num) SERVERNUM="$2"; shift ;; -l|--listen-tcp) LISTENTCP="" ;; -p|--xauth-protocol) XAUTHPROTO="$2"; shift ;; -s|--server-args) XVFBARGS="$2"; shift ;; -w|--wait) STARTWAIT="$2"; shift ;; --) shift; break ;; *) echo "$PROGNAME: error while parsing option \"$1\"" >&2; USAGE=$(usage); echo "$USAGE" >&2; exit 1 ;; esac shift done if [ "$SHOWHELP" ]; then usage exit 0 fi if [ -z "$*" ]; then echo "$PROGNAME: need a command to run" >&2 exit 2 fi if ! which xauth > /dev/null; then echo "$PROGNAME: xauth command not found; exiting." >&2 exit 3 fi # start Xvfb rm -f $AUTHFILE MCOOKIE=$(mcookie) XAUTHORITY=$AUTHFILE xauth add :$SERVERNUM $XAUTHPROTO $MCOOKIE > $ERRORFILE 2>&1 XAUTHORITY=$AUTHFILE Xvfb :$SERVERNUM $XVFBARGS $LISTENTCP > $ERRORFILE 2>&1 & XVFBPID=$! sleep $STARTWAIT # start the command and save its exit status set +e DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE $@ 2>&1 RETVAL=$? set -e # kill Xvfb now that the command has exited kill $XVFBPID # clean up XAUTHORITY=$AUTHFILE xauth remove :$SERVERNUM > $ERRORFILE 2>&1 rm $AUTHFILE # return the executed command's exit status exit $RETVAL # vim:set ai et sts=4 sw=4 tw=0:
.\" This manpage is copyright (C) 1998,1999,2000,2001,2002 Branden Robinson .\" <[EMAIL PROTECTED]>. .\" .\" This is free software; you may redistribute it and/or modify .\" it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2, .\" or (at your option) any later version. .\" .\" This is distributed in the hope that it will be useful, but .\" WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public License .\" along with the Debian GNU/Linux system; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA .\" 02111-1307 USA .TH xvfb\-run 1 "2002\-10\-24" "Debian Project" .SH NAME xvfb\-run \- run specified X client or command in a virtual X server environment .SH SYNOPSIS .B xvfb\-run [ .I options ] .I command .SH DESCRIPTION .B xvfb\-run is a wrapper for the .BR Xvfb (1x) command which simplifies the task of running commands (typically an X client, or a script containing a list of clients to be run) within a virtual X server environment. .PP .B xvfb\-run sets up an X authority file, writes a cookie to it (see .BR xauth (1x)) and then starts the .B Xvfb X server as a background process. The process ID of .B Xvfb is stored for later use. The specified .I command is then run using the X display corresponding to the .B Xvfb server just started and the X authority file created earlier. .PP When the .I command exits, its status is saved, the .B Xvfb server is killed (using the process ID stored earlier), the X authority cookie removed, and the authority file deleted. .B xvfb\-run then exits with the exit status of .IR command. .PP .B xvfb\-run requires the .B xauth command to function. .SH OPTIONS .TP .B \-a\fR,\fB \-\-auto\-servernum Try to get a free server number, starting at 99, or the argument to .BR \-\-server\-num . .TP .BI \-e\ file \fR,\fB\ \-\-error\-file= file Store output from .B xauth and .B Xvfb in .IR file . If not set, output is sent to .IR /dev/null . .TP .BI \-f\ file \fR,\fB\ \-\-auth\-file= file Store X authentication data in .IR file . By default, a file named .I .Xauthority in the current working directory is used. .TP .B \-h\fR,\fB \-\-help Display a usage message and exit. .TP .BI \-n\ servernumber \fR,\fB\ \-\-server\-num= servernumber Use .I servernumber as the server number (but see the .B \-a\fR,\fB \-\-auto\-servernum option above). This value defaults to 99. .TP .B \-l\fR,\fB \-\-listen\-tcp Enable TCP port listening in the X server. .TP .BI \-p\ protocolname \fR,\fB\ \-\-xauth\-protocol= protocolname Use .I protocolname as the X authority protocol to use. This defaults to \(oq.\(cq, which .B xauth interprets as its own default protocol, which is MIT-MAGIC-COOKIE-1. .TP .BI \-s\ arguments \fR,\fB\ \-\-server\-args= arguments Pass .I arguments to the .B Xvfb server. Be careful to quote any whitespace characters that may occur within .I arguments to prevent them from regarded as separators for .BR xvfb-run 's own arguments. Also, note that specification of \(oq-nolisten tcp\(cq in .I arguments may override the function of .BR xvfb-run 's own .B \-l\fR,\fB \-\-listen\-tcp option, and that specification of the server number (e.g., \(oq:1\(cq) may be ignored because of the way the X server parses its argument list. Use the .B xvfb-run option .BI \-n\ servernumber \fR,\fB\ \-\-server\-num= servernumber to achieve the latter function. Defaults to \(oq\-screen 0 640x480x8\(cq. .TP .BI \-w\ delay \fR,\fB\ \-\-wait= delay Wait .I delay seconds after launching .B Xvfb before attempting to start the specified command. Defaults to 3. '\" .SH ENVIRONMENT '\" None. '\" .SH INPUT FILES '\" None. .SH OUTPUT FILES .TP .I .Xauthority is created (and deleted) in the current working directory to store the X authority cookies used by the .B Xvfb server and client(s) run under it. .PP An error file with a user\-specified name is also created if the .B \-e or .B \-\-error\-file options are specifed; see above. .SH EXIT STATUS .B xvfb\-run uses its exit status as well as output to standard error to communicate diagnostics. .TP 1 The command\-line options could not be processed. .TP 2 No command to run was specified. .TP 3 The .B xauth command is not available. .SH EXAMPLES .TP .B xvfb\-run \-\-auto\-servernum \-\-server\-num=1 xlogo runs the .BR xlogo (1x) demonstration client inside the .B Xvfb X server on the first available server number greater than or equal to 1. .TP .B xvfb\-run \-\-server\-args="-screen 0 1024x768x24" ico -faces runs the .BR ico (1x) demonstration client (and passes it the .B -faces argument) inside the .B Xvfb X server, configured with a root window of 1024 by 768 pixels and a color depth of 24 bits. .PP Note that the demo X clients used in the above examples will not exit on their own, so they will have to be killed before .B xvfb\-run will exit. .SH AUTHOR .B xfvb\-run was written by Branden Robinson and Jeff Licquia for Progeny Linux Systems, Inc., and the Debian Project. .SH "SEE ALSO" .BR Xvfb (1x), .BR xauth (1x)