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