From e95ef5f61d4e41c17f0e251dd3434f19316c6963 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Ouellet Date: Sun, 29 Jul 2018 22:37:31 -0400 Subject: [PATCH] Add domain-paused/-unpaused events Needed for event-driven domains-tray UI updating and anti-GUI-DoS usability improvements. Catches errors from event handlers to protect libvirt, and logs to main qubesd logger singleton (by default meaning systemd journal). --- qubes/app.py | 10 ++++++++++ qubes/vm/qubesvm.py | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/qubes/app.py b/qubes/app.py index a9e967e1..da668c51 100644 --- a/qubes/app.py +++ b/qubes/app.py @@ -1251,6 +1251,16 @@ class Qubes(qubes.PropertyHolder): if event == libvirt.VIR_DOMAIN_EVENT_STOPPED: vm.on_libvirt_domain_stopped() + elif event == libvirt.VIR_DOMAIN_EVENT_SUSPENDED: + try: + vm.fire_event('domain-paused') + except Exception: # pylint: disable=broad-except + self.log.exception('Uncaught exception from domain-paused handler for domain %s', vm.name) + elif event == libvirt.VIR_DOMAIN_EVENT_RESUMED: + try: + vm.fire_event('domain-unpaused') + except Exception: # pylint: disable=broad-except + self.log.exception('Uncaught exception from domain-unpaused handler for domain %s', vm.name) @qubes.events.handler('domain-pre-delete') def on_domain_pre_deleted(self, event, vm): diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 39713255..5c8f5843 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -187,6 +187,21 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): :param event: Event name (``'domain-start'``) *other arguments are as in :py:meth:`start`* + + .. event:: domain-paused (subject, event) + + Fired when the domain has been paused. + + :param subject: Event emitter (the qube object) + :param event: Event name (``'domain-paused'``) + + .. event:: domain-unpaused (subject, event) + + Fired when the domain has been unpaused. + + :param subject: Event emitter (the qube object) + :param event: Event name (``'domain-unpaused'``) + .. event:: domain-stopped (subject, event) Fired when domain has been stopped.