From 7616a8913ab03dec3cad1103b5be2fcc5036bd79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Marczewski?= Date: Mon, 29 Jun 2020 12:20:23 +0200 Subject: [PATCH] Clean up the guid-conf file on domain stop --- qubesadmin/tools/qvm_start_daemon.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/qubesadmin/tools/qvm_start_daemon.py b/qubesadmin/tools/qvm_start_daemon.py index 0a1f6a7..a52bfec 100644 --- a/qubesadmin/tools/qvm_start_daemon.py +++ b/qubesadmin/tools/qvm_start_daemon.py @@ -575,12 +575,29 @@ class DAEMONLauncher: asyncio.ensure_future( self.start_gui_for_stubdomain(vm)) + def on_domain_stopped(self, vm, _event, **_kwargs): + """Handler of 'domain-stopped' event, cleans up""" + self.cleanup_guid(vm.xid) + if vm.virt_mode == 'hvm': + self.cleanup_guid(vm.stubdom_xid) + + def cleanup_guid(self, xid): + """ + Clean up after qubes-guid. Removes the auto-generated configuration + file, if any. + """ + + config_path = self.guid_config_file(xid) + if os.path.exists(config_path): + os.unlink(config_path) + def register_events(self, events): """Register domain startup events in app.events dispatcher""" events.add_handler('domain-spawn', self.on_domain_spawn) events.add_handler('domain-start', self.on_domain_start) events.add_handler('connection-established', self.on_connection_established) + events.add_handler('domain-stopped', self.on_domain_stopped) def x_reader(conn, callback):