]> git.0d.be Git - empathy.git/blob - tools/with-session-bus.sh
Updated Oriya Translation
[empathy.git] / tools / with-session-bus.sh
1 #!/bin/sh
2 # with-session-bus.sh - run a program with a temporary D-Bus session daemon
3 #
4 # The canonical location of this program is the telepathy-glib tools/
5 # directory, please synchronize any changes with that copy.
6 #
7 # Copyright (C) 2007-2008 Collabora Ltd. <http://www.collabora.co.uk/>
8 #
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.
12
13 set -e
14
15 me=with-session-bus
16
17 dbus_daemon_args="--print-address=5 --print-pid=6 --fork"
18
19 usage ()
20 {
21   echo "usage: $me [options] -- program [program_options]" >&2
22   echo "Requires write access to the current directory." >&2
23   echo "" >&2
24   echo "If \$WITH_SESSION_BUS_FORK_DBUS_MONITOR is set, fork dbus-monitor" >&2
25   echo "with the arguments in \$WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT." >&2
26   echo "The output of dbus-monitor is saved in $me-<pid>.dbus-monitor-logs" >&2
27   exit 2
28 }
29
30 while test "z$1" != "z--"; do
31   case "$1" in
32   --session)
33     dbus_daemon_args="$dbus_daemon_args --session"
34     shift
35     ;;
36   --config-file=*)
37     # FIXME: assumes config file doesn't contain any special characters
38     dbus_daemon_args="$dbus_daemon_args $1"
39     shift
40     ;;
41   *)
42     usage
43     ;;
44   esac
45 done
46 shift
47 if test "z$1" = "z"; then usage; fi
48
49 exec 5> $me-$$.address
50 exec 6> $me-$$.pid
51
52 cleanup ()
53 {
54   pid=`head -n1 $me-$$.pid`
55   if test -n "$pid" ; then
56     echo "Killing temporary bus daemon: $pid" >&2
57     kill -INT "$pid"
58   fi
59   rm -f $me-$$.address
60   rm -f $me-$$.pid
61 }
62
63 trap cleanup INT HUP TERM
64 dbus-daemon $dbus_daemon_args
65
66 { echo -n "Temporary bus daemon is "; cat $me-$$.address; } >&2
67 { echo -n "Temporary bus daemon PID is "; head -n1 $me-$$.pid; } >&2
68
69 e=0
70 DBUS_SESSION_BUS_ADDRESS="`cat $me-$$.address`"
71 export DBUS_SESSION_BUS_ADDRESS
72
73 if [ -n "$WITH_SESSION_BUS_FORK_DBUS_MONITOR" ] ; then
74   echo -n "Forking dbus-monitor $WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT" >&2
75   dbus-monitor $WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT \
76         &> $me-$$.dbus-monitor-logs &
77 fi
78
79 "$@" || e=$?
80
81 trap - INT HUP TERM
82 cleanup
83
84 exit $e