Don't fail on DBus connection error or opening log
Especially in offline mode - like during installation, tests etc. QubesOS/qubes-issues#2412
This commit is contained in:
parent
02a0713665
commit
a318d5cea9
@ -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',
|
||||
|
11
qubes/log.py
11
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user