Ticket #1401: 1401.patch

File 1401.patch, 3.3 KB (added by sascha_silbe, 14 years ago)

fail gracefully if system DBus unreachable

  • src/linklocal_plugin.py

    From: Sascha Silbe <sascha@silbe.org>
    Subject: [PATCH] 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 <sascha@silbe.org>
    
    ---
     src/linklocal_plugin.py |   17 ++++++++++++-----
     src/psutils.py          |   20 ++++++++++++++++----
     2 files changed, 28 insertions(+), 9 deletions(-)
    
    diff --git a/src/linklocal_plugin.py b/src/linklocal_plugin.py
    index eb44ca5..051797e 100644
    a b from itertools import izip 
    2222
    2323# Other libraries
    2424import gobject
    25 from dbus import SystemBus
     25from dbus import DBusException, SystemBus
    2626from telepathy.client import Connection
    2727from telepathy.interfaces import CONN_INTERFACE
    2828from telepathy.constants import HANDLE_TYPE_CONTACT
    class LinkLocalPlugin(TelepathyPlugin): 
    5353    def __init__(self, registry, owner):
    5454        TelepathyPlugin.__init__(self, registry, owner)
    5555
    56         self._sys_bus = SystemBus()
    5756        self._have_avahi = False
    58         self._watch = self._sys_bus.watch_name_owner('org.freedesktop.Avahi',
    59                                                      self._avahi_owner_cb)
    60 
     57        self._watch = None
    6158        # Glib source ID indicating we have to wait before be allowed to try
    6259        # to connect
    6360        self._have_to_wait_id = 0
     61        self._find_avahi()
     62
     63    def _find_avahi(self):
     64        try:
     65            sys_bus = SystemBus()
     66            self._watch = sys_bus.watch_name_owner('org.freedesktop.Avahi',
     67                self._avahi_owner_cb)
     68
     69        except DBusException:
     70            _logger.exception('Error connecting to Avahi')
    6471
    6572    def _avahi_owner_cb(self, unique_name):
    6673        had_avahi = self._have_avahi
  • src/psutils.py

    diff --git a/src/psutils.py b/src/psutils.py
    index feabefe..6e6b2b6 100644
    a b class IP4AddressMonitor(gobject.GObject): 
    159159        self._matches = []
    160160        self._addr = None
    161161        self._nm_iface = None
    162         self._sys_bus = dbus.SystemBus()
    163         self._watch = self._sys_bus.watch_name_owner(_NM_SERVICE,
    164                                                      self._nm_owner_cb)
    165         if not self._sys_bus.name_has_owner(_NM_SERVICE):
     162        self._sys_bus = None
     163        self._watch = None
     164        self._find_network_manager()
     165
     166    def _find_network_manager(self):
     167        found = False
     168        try:
     169            self._sys_bus = dbus.SystemBus()
     170            self._watch = self._sys_bus.watch_name_owner(_NM_SERVICE,
     171                self._nm_owner_cb)
     172            found = self._sys_bus.name_has_owner(_NM_SERVICE)
     173
     174        except DBusException:
     175            _logger.exception('Error connecting to NetworkManager')
     176
     177        if not found:
    166178            addr, iface = self._get_address_fallback()
    167179            self._update_address(addr, iface)
    168180