aboutsummaryrefslogtreecommitdiffstats
path: root/tools/with-session-bus.sh
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2008-04-11 21:11:22 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-04-11 21:11:22 +0800
commit92236b5ccc020a1e1062fbf8305a1bd8d2afb932 (patch)
treeb53508d522d164cd53f132743c00c3fe9d2f9ec5 /tools/with-session-bus.sh
parentffb2b1feee9bb01c821f6de64d6011c1bc6e01b1 (diff)
downloadgsoc2013-empathy-92236b5ccc020a1e1062fbf8305a1bd8d2afb932.tar
gsoc2013-empathy-92236b5ccc020a1e1062fbf8305a1bd8d2afb932.tar.gz
gsoc2013-empathy-92236b5ccc020a1e1062fbf8305a1bd8d2afb932.tar.bz2
gsoc2013-empathy-92236b5ccc020a1e1062fbf8305a1bd8d2afb932.tar.lz
gsoc2013-empathy-92236b5ccc020a1e1062fbf8305a1bd8d2afb932.tar.xz
gsoc2013-empathy-92236b5ccc020a1e1062fbf8305a1bd8d2afb932.tar.zst
gsoc2013-empathy-92236b5ccc020a1e1062fbf8305a1bd8d2afb932.zip
Update tools from tp-glib 0.7.6
svn path=/trunk/; revision=915
Diffstat (limited to 'tools/with-session-bus.sh')
-rw-r--r--tools/with-session-bus.sh73
1 files changed, 73 insertions, 0 deletions
diff --git a/tools/with-session-bus.sh b/tools/with-session-bus.sh
new file mode 100644
index 000000000..26d9f248a
--- /dev/null
+++ b/tools/with-session-bus.sh
@@ -0,0 +1,73 @@
+#!/bin/sh
+# with-session-bus.sh - run a program with a temporary D-Bus session daemon
+#
+# The canonical location of this program is the telepathy-glib tools/
+# directory, please synchronize any changes with that copy.
+#
+# Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+
+set -e
+
+me=with-session-bus
+
+dbus_daemon_args="--print-address=5 --print-pid=6 --fork"
+
+usage ()
+{
+ echo "usage: $me [options] -- program [program_options]" >&2
+ echo "Requires write access to the current directory." >&2
+ exit 2
+}
+
+while test "z$1" != "z--"; do
+ case "$1" in
+ --session)
+ dbus_daemon_args="$dbus_daemon_args --session"
+ shift
+ ;;
+ --config-file=*)
+ # FIXME: assumes config file doesn't contain any special characters
+ dbus_daemon_args="$dbus_daemon_args $1"
+ shift
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+shift
+if test "z$1" = "z"; then usage; fi
+
+exec 5> $me-$$.address
+exec 6> $me-$$.pid
+
+cleanup ()
+{
+ pid=`head -n1 $me-$$.pid`
+ if test -n "$pid" ; then
+ echo "Killing temporary bus daemon: $pid" >&2
+ kill -INT "$pid"
+ fi
+ rm -f $me-$$.address
+ rm -f $me-$$.pid
+}
+
+trap cleanup INT HUP TERM
+dbus-daemon $dbus_daemon_args
+
+{ echo -n "Temporary bus daemon is "; cat $me-$$.address; } >&2
+{ echo -n "Temporary bus daemon PID is "; head -n1 $me-$$.pid; } >&2
+
+e=0
+DBUS_SESSION_BUS_ADDRESS="`cat $me-$$.address`"
+export DBUS_SESSION_BUS_ADDRESS
+"$@" || e=$?
+
+trap - INT HUP TERM
+cleanup
+
+exit $e