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 |
22 | 22 | |
23 | 23 | # Other libraries |
24 | 24 | import gobject |
25 | | from dbus import SystemBus |
| 25 | from dbus import DBusException, SystemBus |
26 | 26 | from telepathy.client import Connection |
27 | 27 | from telepathy.interfaces import CONN_INTERFACE |
28 | 28 | from telepathy.constants import HANDLE_TYPE_CONTACT |
… |
… |
class LinkLocalPlugin(TelepathyPlugin): |
53 | 53 | def __init__(self, registry, owner): |
54 | 54 | TelepathyPlugin.__init__(self, registry, owner) |
55 | 55 | |
56 | | self._sys_bus = SystemBus() |
57 | 56 | 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 |
61 | 58 | # Glib source ID indicating we have to wait before be allowed to try |
62 | 59 | # to connect |
63 | 60 | 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') |
64 | 71 | |
65 | 72 | def _avahi_owner_cb(self, unique_name): |
66 | 73 | had_avahi = self._have_avahi |
diff --git a/src/psutils.py b/src/psutils.py
index feabefe..6e6b2b6 100644
a
|
b
|
class IP4AddressMonitor(gobject.GObject): |
159 | 159 | self._matches = [] |
160 | 160 | self._addr = None |
161 | 161 | 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: |
166 | 178 | addr, iface = self._get_address_fallback() |
167 | 179 | self._update_address(addr, iface) |
168 | 180 | |