build: remove -enumtypes rules
[empathy-mirror.git] / tools / with-session-bus.sh
blobcfedb5b9d6d6fc60b6fc5b37ffcfbc6b730e0be0
1 #!/bin/sh
2 # with-session-bus.sh - run a program with a temporary D-Bus session daemon
4 # The canonical location of this program is the telepathy-glib tools/
5 # directory, please synchronize any changes with that copy.
7 # Copyright (C) 2007-2008 Collabora Ltd. <http://www.collabora.co.uk/>
9 # Copying and distribution of this file, with or without modification,
10 # are permitted in any medium without royalty provided the copyright
11 # notice and this notice are preserved.
13 set -e
15 me=with-session-bus
17 dbus_daemon_args="--print-address=5 --print-pid=6 --fork"
18 sleep=0
20 usage ()
22 echo "usage: $me [options] -- program [program_options]" >&2
23 echo "Requires write access to the current directory." >&2
24 echo "" >&2
25 echo "If \$WITH_SESSION_BUS_FORK_DBUS_MONITOR is set, fork dbus-monitor" >&2
26 echo "with the arguments in \$WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT." >&2
27 echo "The output of dbus-monitor is saved in $me-<pid>.dbus-monitor-logs" >&2
28 exit 2
31 while test "z$1" != "z--"; do
32 case "$1" in
33 --sleep=*)
34 sleep="$1"
35 sleep="${sleep#--sleep=}"
36 shift
38 --session)
39 dbus_daemon_args="$dbus_daemon_args --session"
40 shift
42 --config-file=*)
43 # FIXME: assumes config file doesn't contain any special characters
44 dbus_daemon_args="$dbus_daemon_args $1"
45 shift
48 usage
50 esac
51 done
52 shift
53 if test "z$1" = "z"; then usage; fi
55 exec 5> $me-$$.address
56 exec 6> $me-$$.pid
58 cleanup ()
60 pid=`head -n1 $me-$$.pid`
61 if test -n "$pid" ; then
62 if [ -n "$VERBOSE_TESTS" ]; then
63 echo "Killing temporary bus daemon: $pid" >&2
65 kill -INT "$pid"
67 rm -f $me-$$.address
68 rm -f $me-$$.pid
71 trap cleanup INT HUP TERM
72 dbus-daemon $dbus_daemon_args
74 if [ -n "$VERBOSE_TESTS" ]; then
75 { echo -n "Temporary bus daemon is "; cat $me-$$.address; } >&2
76 { echo -n "Temporary bus daemon PID is "; head -n1 $me-$$.pid; } >&2
79 e=0
80 DBUS_SESSION_BUS_ADDRESS="`cat $me-$$.address`"
81 export DBUS_SESSION_BUS_ADDRESS
83 if [ -n "$WITH_SESSION_BUS_FORK_DBUS_MONITOR" ] ; then
84 echo -n "Forking dbus-monitor $WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT" >&2
85 dbus-monitor $WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT \
86 > $me-$$.dbus-monitor-logs 2>&1 &
89 "$@" || e=$?
91 if test $sleep != 0; then
92 sleep $sleep
95 trap - INT HUP TERM
96 cleanup
98 exit $e