Home | History | Annotate | Download | only in tools
      1 #! /bin/sh
      2 
      3 SCRIPTNAME=$0
      4 WRAPPED_SCRIPT=$1
      5 shift
      6 
      7 die() 
      8 {
      9     if ! test -z "$DBUS_SESSION_BUS_PID" ; then
     10         echo "killing message bus "$DBUS_SESSION_BUS_PID >&2
     11         kill -9 $DBUS_SESSION_BUS_PID
     12     fi
     13     echo $SCRIPTNAME: $* >&2
     14     exit 1
     15 }
     16 
     17 if test -z "$DBUS_TOP_BUILDDIR" ; then
     18     die "Must set DBUS_TOP_BUILDDIR"
     19 fi
     20 
     21 ## convenient to be able to ctrl+C without leaking the message bus process
     22 trap 'die "Received SIGINT"' INT
     23 
     24 CONFIG_FILE=./run-with-tmp-session-bus.conf
     25 SERVICE_DIR="$DBUS_TOP_BUILDDIR/test/data/valid-service-files"
     26 ESCAPED_SERVICE_DIR=`echo $SERVICE_DIR | sed -e 's/\//\\\\\\//g'`
     27 echo "escaped service dir is: $ESCAPED_SERVICE_DIR" >&2
     28 
     29 ## create a configuration file based on the standard session.conf
     30 cat $DBUS_TOP_BUILDDIR/bus/session.conf |  \
     31     sed -e 's/<standard_session_servicedirs.*$/<servicedir>'$ESCAPED_SERVICE_DIR'<\/servicedir>/g' |  \
     32     sed -e 's/<include.*$//g'                \
     33   > $CONFIG_FILE
     34 
     35 echo "Created configuration file $CONFIG_FILE" >&2
     36 
     37 if ! test -e "$DBUS_TOP_BUILDDIR"/bus/dbus-daemon ; then
     38     die "$DBUS_TOP_BUILDDIR/bus/dbus-daemon does not exist"
     39 fi
     40 
     41 export PATH="$DBUS_TOP_BUILDDIR"/bus:$PATH
     42 ## the libtool script found by the path search should already do this, but
     43 export LD_LIBRARY_PATH=$DBUS_TOP_BUILDDIR/dbus/.libs:$LD_LIBRARY_PATH
     44 
     45 unset DBUS_SESSION_BUS_ADDRESS
     46 unset DBUS_SESSION_BUS_PID
     47 
     48 echo "Running $DBUS_TOP_BUILDDIR/tools/dbus-launch --sh-syntax --config-file=$CONFIG_FILE" >&2
     49 
     50 export DBUS_USE_TEST_BINARY=1 
     51 eval `$DBUS_TOP_BUILDDIR/tools/dbus-launch --sh-syntax --config-file=$CONFIG_FILE`
     52 
     53 if test -z "$DBUS_SESSION_BUS_PID" ; then
     54     die "Failed to launch message bus for test script to run"
     55 fi
     56 
     57 echo "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2
     58 
     59 # Execute wrapped script
     60 echo "Running $WRAPPED_SCRIPT $@" >&2
     61 $WRAPPED_SCRIPT "$@" || die "script \"$WRAPPED_SCRIPT\" failed"
     62 
     63 kill -TERM $DBUS_SESSION_BUS_PID || die "Message bus vanished! should not have happened" && echo "Killed daemon $DBUS_SESSION_BUS_PID" >&2
     64 
     65 sleep 2
     66 
     67 ## be sure it really died 
     68 kill -9 $DBUS_SESSION_BUS_PID > /dev/null 2>&1 || true
     69 
     70 exit 0
     71