Skip to content

Commit

Permalink
q-dev: auto-attaching order
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 14, 2024
1 parent 82b116d commit 5477f8c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions qubesusbproxy/core3ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 5477f8c

Please sign in to comment.