Don't try to distribute COPYING.AFL-2.1 and COPYING.GPL-2, which we no longer have...
[dbus-python-phuang.git] / test / run-with-tmp-session-bus.sh
blobe767f2d7264f335b7c7fa16c64523d0010335056
1 #! /bin/bash
3 # Copyright (C) 2003-2005 Red Hat Inc. <http://www.redhat.com/>
4 # Copyright (C) 2005 Colin Walters
5 # Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
7 # Permission is hereby granted, free of charge, to any person
8 # obtaining a copy of this software and associated documentation
9 # files (the "Software"), to deal in the Software without
10 # restriction, including without limitation the rights to use, copy,
11 # modify, merge, publish, distribute, sublicense, and/or sell copies
12 # of the Software, and to permit persons to whom the Software is
13 # furnished to do so, subject to the following conditions:
15 # The above copyright notice and this permission notice shall be
16 # included in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 # DEALINGS IN THE SOFTWARE.
27 SCRIPTNAME=$0
28 WRAPPED_SCRIPT=$1
29 shift
31 function die()
33 if ! test -z "$DBUS_SESSION_BUS_PID" ; then
34 echo "killing message bus $DBUS_SESSION_BUS_PID" >&2
35 kill -9 "$DBUS_SESSION_BUS_PID"
37 echo "$SCRIPTNAME: $*" >&2
38 exit 1
41 if test -z "$DBUS_TOP_BUILDDIR" ; then
42 die "Must set DBUS_TOP_BUILDDIR"
45 ## convenient to be able to ctrl+C without leaking the message bus process
46 trap 'die "Received SIGINT"' SIGINT
48 CONFIG_FILE="$DBUS_TOP_BUILDDIR"/test/tmp-session-bus.conf
50 unset DBUS_SESSION_BUS_ADDRESS
51 unset DBUS_SESSION_BUS_PID
53 echo "Running dbus-launch --sh-syntax --config-file=$CONFIG_FILE" >&2
54 eval `dbus-launch --sh-syntax --config-file=$CONFIG_FILE`
56 if test -z "$DBUS_SESSION_BUS_PID" ; then
57 die "Failed to launch message bus for introspection generation to run"
60 echo "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2
62 # Execute wrapped script
63 echo "Running: $WRAPPED_SCRIPT $*" >&2
64 "$WRAPPED_SCRIPT" "$@" || die "script \"$WRAPPED_SCRIPT\" failed"
66 kill -TERM "$DBUS_SESSION_BUS_PID" \
67 || die "Message bus vanished! should not have happened" \
68 && echo "Killed daemon $DBUS_SESSION_BUS_PID" >&2
70 sleep 2
72 ## be sure it really died
73 kill -9 $DBUS_SESSION_BUS_PID > /dev/null 2>&1 || true
75 exit 0