diff --git a/qubes/ext/qubesmanager.py b/qubes/ext/qubesmanager.py index 9b002d99..e22b30a5 100644 --- a/qubes/ext/qubesmanager.py +++ b/qubes/ext/qubesmanager.py @@ -36,12 +36,19 @@ import qubes.ext class QubesManager(qubes.ext.Extension): def __init__(self, *args, **kwargs): super(QubesManager, self).__init__(*args, **kwargs) - self._system_bus = dbus.SystemBus() + try: + self._system_bus = dbus.SystemBus() + except dbus.exceptions.DBusException: + # we can't access Qubes() object here to check for offline mode, + # so lets assume it is this case... + self._system_bus = None # pylint: disable=no-self-use,unused-argument,too-few-public-methods @qubes.ext.handler('status:error') def on_status_error(self, vm, event, status, message): + if self._system_bus is None: + return try: qubes_manager = self._system_bus.get_object( 'org.qubesos.QubesManager', @@ -54,6 +61,8 @@ class QubesManager(qubes.ext.Extension): @qubes.ext.handler('status:no-error') def on_status_no_error(self, vm, event, status, message): + if self._system_bus is None: + return try: qubes_manager = self._system_bus.get_object( 'org.qubesos.QubesManager', diff --git a/qubes/log.py b/qubes/log.py index 858086db..1a92b360 100644 --- a/qubes/log.py +++ b/qubes/log.py @@ -99,7 +99,16 @@ def enable(): handler_console.setFormatter(formatter_console) logging.root.addHandler(handler_console) - handler_log = logging.FileHandler('log', 'a', encoding='utf-8') + if os.path.exists('/var/log/qubes'): + log_path = '/var/log/qubes/qubes.log' + else: + # for tests, travis etc + log_path = '/tmp/qubes.log' + old_umask = os.umask(0o007) + try: + handler_log = logging.FileHandler(log_path, 'a', encoding='utf-8') + finally: + os.umask(old_umask) handler_log.setFormatter(formatter_log) logging.root.addHandler(handler_log)