From 638dbf6143b42cb8f7277fbef8b44f7b6753ab39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 22 May 2021 13:01:12 +0200 Subject: [PATCH] Fix gui-daemon cleanup The cleanup requires XID of the domain, but when it's shut off already, it's too late to retrieve it. Cache value retrieved when the domain was still running (either domain-start event, or program startup). --- qubesadmin/tools/qvm_start_daemon.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/qubesadmin/tools/qvm_start_daemon.py b/qubesadmin/tools/qvm_start_daemon.py index 8f77111..9a3a552 100644 --- a/qubesadmin/tools/qvm_start_daemon.py +++ b/qubesadmin/tools/qvm_start_daemon.py @@ -326,6 +326,10 @@ class DAEMONLauncher: self.vm_names = vm_names self.kde = kde + # cache XID values when the VM was still running - + # for cleanup purpose + self.xid_cache = {} + async def send_monitor_layout(self, vm, layout=None, startup=False): """Send monitor layout to a given VM @@ -607,6 +611,8 @@ class DAEMONLauncher: if not self.is_watched(vm): return + self.xid_cache[vm.name] = vm.xid, vm.stubdom_xid + try: if getattr(vm, 'guivm', None) == vm.app.local_name and \ vm.features.check_with_template('gui', True) and \ @@ -641,6 +647,7 @@ class DAEMONLauncher: asyncio.ensure_future( self.start_gui(vm, monitor_layout=monitor_layout)) asyncio.ensure_future(self.start_audio(vm)) + self.xid_cache[vm.name] = vm.xid, vm.stubdom_xid elif power_state == 'Transient': # it is still starting, we'll get 'domain-start' # event when fully started @@ -654,9 +661,16 @@ class DAEMONLauncher: if not self.is_watched(vm): return - self.cleanup_guid(vm.xid) - if vm.virt_mode == 'hvm': - self.cleanup_guid(vm.stubdom_xid) + # read XID from cache, as stopped domain reports it already as -1 + try: + xid, stubdom_xid = self.xid_cache[vm.name] + del self.xid_cache[vm.name] + except KeyError: + return + if xid != -1: + self.cleanup_guid(xid) + if stubdom_xid != -1: + self.cleanup_guid(stubdom_xid) def cleanup_guid(self, xid): """