Skip to content

Commit f80b8b7

Browse files
committed
q-dev: update utils.py
1 parent 4876f2a commit f80b8b7

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

qubesusbproxy/utils.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ def device_list_change(
8686
if len(frontends) > 1:
8787
# unique
8888
device = tuple(frontends.values())[0].device
89-
target_name = confirm_device_attachment(device, frontends)
89+
target_name = asyncio.ensure_future(
90+
confirm_device_attachment(device, frontends)).result()
9091
for front in frontends:
9192
if front.name == target_name:
9293
target = front
@@ -140,17 +141,22 @@ def compare_device_cache(vm, devices_cache, current_devices):
140141
return added, attached, detached, removed
141142

142143

143-
def confirm_device_attachment(device, frontends) -> str:
144+
async def confirm_device_attachment(device, frontends) -> str:
144145
try:
146+
front_names = [f.name for f in frontends.keys()]
145147
# pylint: disable=consider-using-with
146-
proc = subprocess.Popen(
147-
["attach-confirm", device.backend_domain.name,
148-
device.port_id, device.description,
149-
*[f.name for f in frontends.keys()]],
150-
stdout=subprocess.PIPE, stderr=subprocess.PIPE
148+
# vm names are safe to just join by spaces
149+
proc = await asyncio.create_subprocess_shell(
150+
" ".join(["attach-confirm", device.backend_domain.name,
151+
device.port_id, "'" + device.description + "'",
152+
*front_names]),
153+
stdout=asyncio.subprocess.PIPE
151154
)
152-
(target_name, _) = proc.communicate()
153-
return target_name.decode()
155+
(target_name, _) = await proc.communicate()
156+
target_name = target_name.decode()
157+
if target_name in front_names:
158+
return target_name
159+
return ""
154160
except Exception as exc:
155161
print("attach-confirm", exc, file=sys.stderr)
156162
return ""

0 commit comments

Comments
 (0)