1 ################################################################################
3 # xvfb.cygclass - for building packages which require a running X server
5 # Part of cygport - Cygwin packaging application
6 # Copyright (C) 2006-2020 Cygport authors
7 # Provided by the Cygwin project <https://cygwin.com/>
9 # cygport is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # cygport is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with cygport. If not, see <https://www.gnu.org/licenses/>.
22 ################################################################################
24 #****h* Cygclasses/xvfb.cygclass
28 # Some packages require a running X server while building; if one is already
29 # running, that usually suffices, but checking that one is present, and
30 # starting one if not, is complicated to do in an automated fashion.
32 # This cygclass provides a function which handles checking for, and
33 # if necessary, launching a temporary X session.
36 #****C* xvfb.cygclass/xvfb_run
38 # xvfb_run COMMAND [ARGUMENTS...]
40 # Runs the given COMMAND (binary, script, or shell function), with
41 # optional ARGUMENTS, which requires an X session to complete.
43 # If several consecutive commands require an X session, then they can be
44 # wrapped in a single custom function which can then be passed to xvfb_run,
46 # mycommand() { for f in *; do foo; bar; done ; }
53 # dbus, gamin, xmodmap, xorg-server
57 local xvfb_display xvfb_pid dbus_pid gamin_pid
58 local xvfb_sock dbus_sock gamin_sock
60 check_prog_req Xorg xorg-server
61 check_prog_req xmodmap # relatively safe dep, required by xinit
63 if defined DISPLAY && xmodmap -display $DISPLAY &> /dev/null
69 if [ ! -e /tmp/.X11-unix/X${n} -a ! -e /tmp/.X${n}-lock ]
72 Xorg $xvfb_display -config cygport-xvfb.conf -nolisten tcp -noreset &> /dev/null &
74 xvfb_sock="/tmp/.X${n}-lock /tmp/.X11-unix/X${n}"
75 if xmodmap -display $xvfb_display &> /dev/null
77 export DISPLAY=${xvfb_display}
81 /bin/kill $xvfb_pid &> /dev/null || true
82 /bin/kill -s KILL $xvfb_pid &> /dev/null || true
89 # avoid the most common fork failures
92 if [ x"$(ps | grep gam_server)" = x ]
94 export GAM_CLIENT_ID="cygport"
95 /usr/libexec/gam_server --notimeout $GAM_CLIENT_ID &
97 gamin_sock="/tmp/fam-$(id -un)/fam-"$GAM_CLIENT_ID
101 # what doesn't require a D-Bus session nowadays?
102 if ! defined DBUS_SESSION_BUS_ADDRESS
104 eval `dbus-launch --sh-syntax`
105 dbus_pid=$DBUS_SESSION_BUS_PID
106 dbus_sock=$(echo $DBUS_SESSION_BUS_ADDRESS | sed -e 's/.*path=\(.*\),.*/\1/')
113 /bin/kill $xvfb_pid $dbus_pid $gamin_pid &> /dev/null || true
114 /bin/kill -s KILL $xvfb_pid $dbus_pid $gamin_pid &> /dev/null || true
115 rm -f $xvfb_sock $dbus_sock $gamin_sock