Add a test case for the various options to get_args_list.
[dbus-python-phuang.git] / tools / run-with-tmp-session-bus.sh
blob0ebf228a3e8ece0b556ba72c9f14060598ed537e
1 #! /bin/bash
3 SCRIPTNAME=$0
4 WRAPPED_SCRIPT=$1
5 shift
7 function die()
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
13 echo $SCRIPTNAME: $* >&2
14 exit 1
17 if test -z "$DBUS_TOP_BUILDDIR" ; then
18 die "Must set DBUS_TOP_BUILDDIR"
21 ## convenient to be able to ctrl+C without leaking the message bus process
22 trap 'die "Received SIGINT"' SIGINT
24 CONFIG_FILE=./run-with-tmp-session-bus.conf
25 SERVICE_DIR="`pwd`/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
29 ## create a configuration file based on the standard session.conf
30 cat tools/session.conf | \
31 sed -e 's/<servicedir>.*$/<servicedir>'$ESCAPED_SERVICE_DIR'<\/servicedir>/g' | \
32 sed -e 's/<include.*$//g' \
33 > $CONFIG_FILE
35 echo "Created configuration file $CONFIG_FILE" >&2
37 export PATH=$DBUS_TOP_BUILDDIR/bus:$PATH
38 ## the libtool script found by the path search should already do this, but
39 export LD_LIBRARY_PATH=$DBUS_TOP_BUILDDIR/dbus/.libs:$LD_LIBRARY_PATH
41 unset DBUS_SESSION_BUS_ADDRESS
42 unset DBUS_SESSION_BUS_PID
44 #export DBUS_VERBOSE=1
45 echo "Running dbus-launch --sh-syntax --config-file=$CONFIG_FILE" >&2
46 eval `dbus-launch --sh-syntax --config-file=$CONFIG_FILE`
48 if test -z "$DBUS_SESSION_BUS_PID" ; then
49 die "Failed to launch message bus for introspection generation to run"
52 echo "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2
54 # Execute wrapped script
55 echo "Running $WRAPPED_SCRIPT $@" >&2
56 $WRAPPED_SCRIPT "$@" || die "script \"$WRAPPED_SCRIPT\" failed"
58 kill -TERM $DBUS_SESSION_BUS_PID || die "Message bus vanished! should not have happened" && echo "Killed daemon $DBUS_SESSION_BUS_PID" >&2
60 sleep 2
62 ## be sure it really died
63 kill -9 $DBUS_SESSION_BUS_PID > /dev/null 2>&1 || true
65 exit 0