From 5477f8c9e211cddd35acb003a84b4c2e9d8b0bc6 Mon Sep 17 00:00:00 2001 From: Piotr Bartman-Szwarc Date: Wed, 21 Aug 2024 00:39:42 +0200 Subject: [PATCH] q-dev: auto-attaching order --- qubesusbproxy/core3ext.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/qubesusbproxy/core3ext.py b/qubesusbproxy/core3ext.py index 9dd07b7..a5b84ba 100644 --- a/qubesusbproxy/core3ext.py +++ b/qubesusbproxy/core3ext.py @@ -523,10 +523,13 @@ async def attach_and_notify(self, vm, assignment): device, {vm: assignment}): return - await self.on_device_attach_usb( - vm, 'device-pre-attach:usb', device, assignment.options) - await vm.fire_event_async( - 'device-attach:usb', device=device, options=assignment.options) + try: + await self.on_device_attach_usb( + vm, 'device-pre-attach:usb', device, assignment.options) + await vm.fire_event_async( + 'device-attach:usb', device=device, options=assignment.options) + except qubes.devices.DeviceAlreadyAttached: + pass @qubes.ext.handler('domain-qdb-change:/qubes-usb-devices') def on_qdb_change(self, vm, event, path): @@ -689,7 +692,9 @@ async def on_device_detach_usb(self, vm, event, port): @qubes.ext.handler('domain-start') async def on_domain_start(self, vm, _event, **_kwargs): # pylint: disable=unused-argument - for assignment in get_assigned_devices(vm.devices['usb']): + # the most specific assignments first + for assignment in reversed(sorted( + get_assigned_devices(vm.devices['usb']))): await self.attach_and_notify(vm, assignment) @qubes.ext.handler('domain-shutdown')