[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: xvfb-run side-effects



On Wed, Sep 18, 2002 at 11:44:59AM -0400, Maitland Bottoms wrote:
> Branden Robinson writes:
> 
>  > Here you go.  The tool and its manpage are attached.
> 
> OK, Thank you.
> 
> I use the updated xvfb-run script in the VTK 4.0-1 package.
> I had to modify it for my task.
> 
> What cleared up most of the problems was using a depth of 24. However,
> resolution and depth do not appear to be settable from the command
> line. That feature may be useful.

Okay.  Do you like this version better?  (Attached.)

-- 
G. Branden Robinson                |
Debian GNU/Linux                   |      Ignorantia judicis est calamitas
branden@debian.org                 |      innocentis.
http://people.debian.org/~branden/ |
#!/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=2 ;;
        -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
.\" <branden@debian.org>.
.\"
.\" 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\-09\-19" "Debian GNU/Linux"
.SH NAME
xvfb\-run \- run specified X client or command in a virtual X server environment
.SH SYNOPSIS
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, \-\-auto\-servernum
Try to get a free server number, starting at 99, or the argument to
.BR \-\-server\-num .
.TP
.BI \-e\  file ,\ \-\-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 ,\ \-\-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, \-\-help
Display a usage message and exit.
.TP
.BI \-n\  servernumber ,\ \-\-server\-num= servernumber
Use
.I servernumber
as the server number (but see the
.B \-a, \-\-auto\-servernum
option above).  This value defaults to 99.
.TP
.B \-l, \-\-listen\-tcp
Enable TCP port listening in the X server.
.TP
.BI \-p\  protocolname ,\ \-\-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 ,\ \-\-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, \-\-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 ,\ \-\-server\-num= servernumber
to achieve the latter function.  Defaults to \(oq\-screen 0 640x480x8\(cq.
.TP
.BI \-w\  delay ,\ \-\-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 pixes 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)

Attachment: pgp8kBNQH0ZOC.pgp
Description: PGP signature


Reply to: