From bb08478eff76d53f6969cb3d21431ff12630b1f7 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Tue, 09 Mar 2010 10:03:43 +0000 Subject: fail gracefully if system DBus unreachable (#1401) System bus (DBus) is only required for optional features (NetworkManager and Avahi support), so fail gracefully (but output errors to logs) if it is unreachable. This aids testing Sugar inside chroots. Tested: - inside chroot (no system bus): Jabber: neighbourhood shows buddies, Salut: neighbourhood empty (expected - Salut requires Avahi) - on XO-1 (regular session, no NM): Jabber+Salut: neighbourhood shows buddies - on XO-1 (regular session, NM): Jabber+Salut: neighbourhood shows buddies Signed-off-by: Sascha Silbe --- diff --git a/src/linklocal_plugin.py b/src/linklocal_plugin.py index eb44ca5..051797e 100644 --- a/src/linklocal_plugin.py +++ b/src/linklocal_plugin.py @@ -22,7 +22,7 @@ from itertools import izip # Other libraries import gobject -from dbus import SystemBus +from dbus import DBusException, SystemBus from telepathy.client import Connection from telepathy.interfaces import CONN_INTERFACE from telepathy.constants import HANDLE_TYPE_CONTACT @@ -53,14 +53,21 @@ class LinkLocalPlugin(TelepathyPlugin): def __init__(self, registry, owner): TelepathyPlugin.__init__(self, registry, owner) - self._sys_bus = SystemBus() self._have_avahi = False - self._watch = self._sys_bus.watch_name_owner('org.freedesktop.Avahi', - self._avahi_owner_cb) - + self._watch = None # Glib source ID indicating we have to wait before be allowed to try # to connect self._have_to_wait_id = 0 + self._find_avahi() + + def _find_avahi(self): + try: + sys_bus = SystemBus() + self._watch = sys_bus.watch_name_owner('org.freedesktop.Avahi', + self._avahi_owner_cb) + + except DBusException: + _logger.exception('Error connecting to Avahi') def _avahi_owner_cb(self, unique_name): had_avahi = self._have_avahi diff --git a/src/psutils.py b/src/psutils.py index feabefe..6e6b2b6 100644 --- a/src/psutils.py +++ b/src/psutils.py @@ -159,10 +159,22 @@ class IP4AddressMonitor(gobject.GObject): self._matches = [] self._addr = None self._nm_iface = None - self._sys_bus = dbus.SystemBus() - self._watch = self._sys_bus.watch_name_owner(_NM_SERVICE, - self._nm_owner_cb) - if not self._sys_bus.name_has_owner(_NM_SERVICE): + self._sys_bus = None + self._watch = None + self._find_network_manager() + + def _find_network_manager(self): + found = False + try: + self._sys_bus = dbus.SystemBus() + self._watch = self._sys_bus.watch_name_owner(_NM_SERVICE, + self._nm_owner_cb) + found = self._sys_bus.name_has_owner(_NM_SERVICE) + + except DBusException: + _logger.exception('Error connecting to NetworkManager') + + if not found: addr, iface = self._get_address_fallback() self._update_address(addr, iface) -- cgit v0.9.1