* dbus.service.Object: don't let the user try to export objects on the local
[dbus-python-phuang.git] / test / run-with-tmp-session-bus.sh
blobd03569ffd60ee05f05980da5ae437a6a0efeea04
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="$DBUS_TOP_BUILDDIR"/test/tmp-session-bus.conf
26 unset DBUS_SESSION_BUS_ADDRESS
27 unset DBUS_SESSION_BUS_PID
29 echo "Running dbus-launch --sh-syntax --config-file=$CONFIG_FILE" >&2
30 eval `dbus-launch --sh-syntax --config-file=$CONFIG_FILE`
32 if test -z "$DBUS_SESSION_BUS_PID" ; then
33 die "Failed to launch message bus for introspection generation to run"
36 echo "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2
38 # Execute wrapped script
39 echo "Running: $WRAPPED_SCRIPT $*" >&2
40 "$WRAPPED_SCRIPT" "$@" || die "script \"$WRAPPED_SCRIPT\" failed"
42 kill -TERM "$DBUS_SESSION_BUS_PID" \
43 || die "Message bus vanished! should not have happened" \
44 && echo "Killed daemon $DBUS_SESSION_BUS_PID" >&2
46 sleep 2
48 ## be sure it really died
49 kill -9 $DBUS_SESSION_BUS_PID > /dev/null 2>&1 || true
51 exit 0