tools/qvm-start-gui: do not crash on qubesd restart

Do not crash if qubesd restart exactly the moment event handler was
called.
Event listener properly handle qubesd restarts (reconnects), but exists
if any handler raise an exception. Avoid this by logging such exceptions
but not propagating them.
This commit is contained in:
Marek Marczykowski-Górecki 2018-07-14 01:49:55 +02:00
parent a481490d60
commit 72a2fd646d
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -30,6 +30,7 @@ import xcffib.xproto # pylint: disable=unused-import
import daemon.pidfile import daemon.pidfile
import qubesadmin import qubesadmin
import qubesadmin.exc
import qubesadmin.tools import qubesadmin.tools
import qubesadmin.vm import qubesadmin.vm
have_events = False have_events = False
@ -306,17 +307,24 @@ class GUILauncher(object):
def on_domain_spawn(self, vm, _event, **kwargs): def on_domain_spawn(self, vm, _event, **kwargs):
'''Handler of 'domain-spawn' event, starts GUI daemon for stubdomain''' '''Handler of 'domain-spawn' event, starts GUI daemon for stubdomain'''
try:
if not vm.features.check_with_template('gui', True): if not vm.features.check_with_template('gui', True):
return return
if vm.virt_mode == 'hvm' and kwargs.get('start_guid', 'True') == 'True': if vm.virt_mode == 'hvm' and \
kwargs.get('start_guid', 'True') == 'True':
asyncio.ensure_future(self.start_gui_for_stubdomain(vm)) asyncio.ensure_future(self.start_gui_for_stubdomain(vm))
except qubesadmin.exc.QubesException as e:
vm.log.warning('Failed to start GUI for %s: %s', vm.name, str(e))
def on_domain_start(self, vm, _event, **kwargs): def on_domain_start(self, vm, _event, **kwargs):
'''Handler of 'domain-start' event, starts GUI daemon for actual VM''' '''Handler of 'domain-start' event, starts GUI daemon for actual VM'''
try:
if not vm.features.check_with_template('gui', True): if not vm.features.check_with_template('gui', True):
return return
if kwargs.get('start_guid', 'True') == 'True': if kwargs.get('start_guid', 'True') == 'True':
asyncio.ensure_future(self.start_gui_for_vm(vm)) asyncio.ensure_future(self.start_gui_for_vm(vm))
except qubesadmin.exc.QubesException as e:
vm.log.warning('Failed to start GUI for %s: %s', vm.name, str(e))
def on_connection_established(self, _subject, _event, **_kwargs): def on_connection_established(self, _subject, _event, **_kwargs):
'''Handler of 'connection-established' event, used to launch GUI '''Handler of 'connection-established' event, used to launch GUI