X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/2ec904370c028570277cb1d88405e7ab68e71f50..7bfa1e069777af48312d509a88e5faff02f930ff:/svc/conntrack.in diff --git a/svc/conntrack.in b/svc/conntrack.in index 5f4cc98d..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 ###-------------------------------------------------------------------------- @@ -457,12 +474,13 @@ def init(): Add the D-Bus monitor here, because we might send commands off immediately, and we want to make sure the server connection is up. """ - T.Coroutine(kickpeers).switch() - dbm = DBusMonitor() - dbm.addmon(NetworkManagerMonitor()) - dbm.addmon(MaemoICdMonitor()) - G.timeout_add_seconds(300, lambda: (netupdown(True, ['interval-timer']) - or True)) + global DBM + T.Coroutine(kickpeers, name = 'kickpeers').switch() + DBM = DBusMonitor() + DBM.addmon(NetworkManagerMonitor()) + DBM.addmon(MaemoICdMonitor()) + G.timeout_add_seconds(30, lambda: (netupdown(True, ['interval-timer']) + or True)) def parse_options(): """