From 7bfa1e069777af48312d509a88e5faff02f930ff Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 15 May 2010 19:34:56 +0100 Subject: [PATCH] svc/conntrack.in: Better diagnostic equipment for D-Bus reconnection. Send out notifications about the D-Bus connection status. Also, inspect some environment variables and decide which bus to connect to, so that I can have it connect to a special test bus which I can bounce up and down without destroying the world. --- svc/conntrack.in | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/svc/conntrack.in b/svc/conntrack.in index 18e2f730..367d26d4 100644 --- a/svc/conntrack.in +++ b/svc/conntrack.in @@ -388,6 +388,7 @@ class DBusMonitor (object): """ me._mons = [] me._loop = D.mainloop.glib.DBusGMainLoop() + me._state = 'startup' me._reconnect() def addmon(me, mon): @@ -408,6 +409,14 @@ class DBusMonitor (object): If we fail the first time, retry periodically. """ + if me._state == 'startup': + T.aside(SM.notify, 'conntrack', 'dbus-connection', 'startup') + elif me._state == 'connected': + T.aside(SM.notify, 'conntrack', 'dbus-connection', 'lost') + else: + T.aside(SM.notify, 'conntrack', 'dbus-connection', + 'state=%s' % me._state) + me._state == 'reconnecting' me._bus = None if me._try_connect(): G.timeout_add_seconds(5, me._try_connect) @@ -419,13 +428,21 @@ class DBusMonitor (object): If we succeed, attach the monitors. """ try: - bus = D.SystemBus(mainloop = me._loop, private = True) - except D.DBusException: + addr = OS.getenv('TRIPE_CONNTRACK_BUS') + if addr == 'SESSION': + bus = D.SessionBus(mainloop = me._loop, private = True) + elif addr is not None: + bus = D.bus.BusConnection(addr, mainloop = me._loop) + else: + bus = D.SystemBus(mainloop = me._loop, private = True) + for m in me._mons: + m.attach(bus) + except D.DBusException, e: return True me._bus = bus + me._state = 'connected' bus.call_on_disconnection(me._reconnect) - for m in me._mons: - m.attach(bus) + T.aside(SM.notify, 'conntrack', 'dbus-connection', 'connected') return False ###-------------------------------------------------------------------------- -- 2.11.0