Skip to content

Commit

Permalink
q-dev: fix detaching
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 14, 2024
1 parent 487b8d6 commit 82b116d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions qubesusbproxy/core3ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ def on_domain_init_load(self, vm, event):

async def attach_and_notify(self, vm, assignment):
# bypass DeviceCollection logic preventing double attach
identity = assignment.device_id
for device in assignment.devices:
if not assignment.matches(device):
print(
Expand Down Expand Up @@ -567,7 +566,6 @@ def on_device_get_usb(self, vm, event, port_id):
if not vm.is_running():
return

print(port_id, file=sys.stderr)
if vm.untrusted_qdb.list(
'/qubes-usb-devices/' + port_id.replace('.', '_')):
yield USBDevice(vm, port_id)
Expand Down Expand Up @@ -676,14 +674,14 @@ async def on_device_detach_usb(self, vm, event, port):

# update the cache before the call, to avoid sending duplicated events
# (one on qubesdb watch and the other by the caller of this method)
backend = attached
self.devices_cache[backend][attached.port_id] = None
backend = attached.backend_domain
self.devices_cache[backend.name][attached.port_id] = None

try:
await backend.backend_domain.run_service_for_stdio(
await backend.run_service_for_stdio(
'qubes.USBDetach',
user='root',
input='{}\n'.format(backend.port_id).encode())
input='{}\n'.format(attached.port_id).encode())
except subprocess.CalledProcessError as e:
# TODO: sanitize and include stdout
raise QubesUSBException('Device detach failed')
Expand Down

0 comments on commit 82b116d

Please sign in to comment.