2 # Helper functions to start your own D-Bus session.
4 # Refactored from with-session-bush.sh (from telepathy-glib).
6 # The canonical location of this program is the telepathy-glib tools/
7 # directory, please synchronize any changes with that copy.
9 # Copyright (C) 2007-2008,2011 Collabora Ltd. <http://www.collabora.co.uk/>
11 # Copying and distribution of this file, with or without modification,
12 # are permitted in any medium without royalty provided the copyright
13 # notice and this notice are preserved.
16 dbus_daemon_args="--print-address=5 --print-pid=6 --fork"
18 dbus_me=with-session-bus
24 # verbose: 0 for off and 1 for on
27 exec 5> $dbus_me-$$.address
28 exec 6> $dbus_me-$$.pid
34 echo "usage: $me [options] -- program [program_options]" >&2
35 echo "Requires write access to the current directory." >&2
37 echo "If \$WITH_SESSION_BUS_FORK_DBUS_MONITOR is set, fork dbus-monitor" >&2
38 echo "with the arguments in \$WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT." >&2
39 echo "The output of dbus-monitor is saved in $me-<pid>.dbus-monitor-logs" >&2
44 while test "z$1" != "z--"; do
48 dbus_sleep="${sleep#--sleep=}"
52 dbus_with_session="--session"
56 # FIXME: assumes config file doesn't contain any special characters
68 local args="$dbus_daemon_args $dbus_with_session $dbus_config_file "
70 if [ $dbus_verbose -gt 0 ] ; then
71 echo -n "dbus args $args "
77 if [ $dbus_verbose -gt 0 ] ; then
78 echo -n "Temporary bus daemon is "; cat $dbus_me-$$.address;
83 if [ $dbus_verbose -gt 0 ] ; then
84 echo -n "Temporary bus daemon PID is "; head -n1 $dbus_me-$$.pid;
88 DBUS_SESSION_BUS_ADDRESS="`cat $dbus_me-$$.address`"
89 export DBUS_SESSION_BUS_ADDRESS
91 if [ -n "$WITH_SESSION_BUS_FORK_DBUS_MONITOR" ] ; then
92 if [ $dbus_verbose -gt 0 ] ; then
93 echo -n "Forking dbus-monitor " \
94 "$WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT" >&2
96 dbus-monitor $WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT \
97 > $dbus_me-$$.dbus-monitor-logs 2>&1 &
102 # This should be called for INT, HUP and TERM signals
105 pid=`head -n1 $dbus_me-$$.pid`
106 if test -n "$pid" ; then
107 if [ $dbus_verbose -gt 0 ] ; then
108 echo "Killing temporary bus daemon: $pid" >&2
112 rm -f $dbus_me-$$.address
113 rm -f $dbus_me-$$.pid