tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

xvfb.sh (1172B)


      1 #! /bin/bash -x
      2 
      3 set -x
      4 
      5 fail() {
      6    echo # make sure error message is on a new line
      7    echo "[xvfb.sh:error]" "${@}"
      8    exit 1
      9 }
     10 
     11 cleanup_xvfb() {
     12    # When you call this script with START_VNC or TASKCLUSTER_INTERACTIVE
     13    # we make sure we do not kill xvfb so you do not lose your connection
     14    local xvfb_pid=`pidof Xvfb`
     15    local vnc=${START_VNC:-false}
     16    local interactive=${TASKCLUSTER_INTERACTIVE:-false}
     17    if [ -n "$xvfb_pid" ] && [[ $vnc == false ]] && [[ $interactive == false ]] ; then
     18        kill $xvfb_pid || true
     19    fi
     20 }
     21 
     22 start_xvfb() {
     23    mkdir -p ~/artifacts/xvfb
     24    # Add a handler for SIGUSR1
     25    trap : SIGUSR1
     26    # Start Xvfb with SIGUSR1 set to SIG_IGN; it will then signal its parent when it's ready to accept connections
     27    (trap '' SIGUSR1; exec Xvfb :$2 -nolisten tcp -noreset -screen 0 $1 > ~/artifacts/xvfb/xvfb.log 2>&1) &
     28    xvfb_pid=$!
     29    # Wait for SIGUSR1 (or Xvfb exit in case of error)
     30    set +e
     31    wait $xvfb_pid
     32    wait_result=$?
     33    if [ $wait_result -ne $((128 + $(kill -l SIGUSR1) )) ]; then
     34        fail "Xvfb failed to start" "$(cat ~/artifacts/xvfb/xvfb.log >&2)"
     35    fi
     36    set -e
     37 
     38    export DISPLAY=:$2
     39 }