commit d9579e983f5a196e7ed155035c0e8283c4f9f904 Author: Thomas Woerner Date: Mon Aug 15 11:51:32 2016 +0200 firewall.client: Generate new DBUS_ERROR if SystemBus can not be aquired This happens for example in change roots. The SystemBus() call in slip.dbus fails and also the dbus.SystemBus() call. New error code: DBUS_ERROR diff --git a/src/firewall/client.py b/src/firewall/client.py index 177a74e..5875df2 100644 --- a/src/firewall/client.py +++ b/src/firewall/client.py @@ -2207,8 +2207,13 @@ class FirewallClient(object): self.bus = slip.dbus.SystemBus() self.bus.default_timeout = None except Exception: - print("Not using slip") - self.bus = dbus.SystemBus() + try: + self.bus = dbus.SystemBus() + except dbus.exceptions.DBusException as e: + raise FirewallError(errors.DBUS_ERROR, + e.get_dbus_message()) + else: + print("Not using slip.dbus") else: self.bus = bus diff --git a/src/firewall/errors.py b/src/firewall/errors.py index d939864..34d1d18 100644 --- a/src/firewall/errors.py +++ b/src/firewall/errors.py @@ -44,6 +44,7 @@ IPSET_WITH_TIMEOUT = 32 BUILTIN_IPSET = 33 ALREADY_SET = 34 MISSING_IMPORT = 35 +DBUS_ERROR = 36 INVALID_ACTION = 100 INVALID_SERVICE = 101 commit 937eb926a1ec6f09a3ff825296927e9964232204 Author: Thomas Woerner Date: Mon Aug 15 11:55:19 2016 +0200 firewall-cmd, firewallctl: Gracefully fail if SystemBus can not be aquired diff --git a/src/firewall-cmd b/src/firewall-cmd index 3cf3059..75513c7 100755 --- a/src/firewall-cmd +++ b/src/firewall-cmd @@ -911,7 +911,13 @@ if a.help: sys.exit(0) zone = a.zone -fw = FirewallClient() + +try: + fw = FirewallClient() +except FirewallError as msg: + code = FirewallError.get_code(str(msg)) + cmd.print_and_exit("Error: %s" % msg, code) + fw.setExceptionHandler(cmd.exception_handler) if fw.connected == False: if a.state: commit 63f4f46180d5fe26a68ef6517d2f612fb74a3254 Author: Thomas Woerner Date: Mon Aug 15 11:57:06 2016 +0200 firewall.core.fw_nm: Ignore NetworkManager if NM.Client connect fails This happens for example in change roots. diff --git a/src/firewall/core/fw_nm.py b/src/firewall/core/fw_nm.py index 5f8c8f8..c958e9a 100644 --- a/src/firewall/core/fw_nm.py +++ b/src/firewall/core/fw_nm.py @@ -27,6 +27,7 @@ __all__ = [ "check_nm_imported", "nm_is_imported", "nm_get_bus_name", "nm_get_dbus_interface" ] import gi +from gi.repository import GLib try: gi.require_version('NM', '1.0') except ValueError: @@ -35,8 +36,7 @@ else: try: from gi.repository import NM _nm_imported = True - except (ImportError, ValueError): - NetworkManager = None + except (ImportError, ValueError, GLib.Error): _nm_imported = False from firewall import errors