Skip to content

Commit 58ae845

Browse files
committed
q-dev: attachment confirmation PoC
1 parent 458c1c1 commit 58ae845

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

qubes/ext/utils.py

+41-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,24 @@
1818
# along with this program; if not, write to the Free Software
1919
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
2020
# USA.
21+
import itertools
2122
import asyncio
23+
import subprocess
24+
import sys
25+
26+
import gbulb
2227

2328
import qubes
2429

30+
from typing import Type
31+
32+
from qubes.ext.attachment_confirm import confirm_device_attachment
33+
from qrexec import server
34+
2535

2636
def device_list_change(
2737
ext: qubes.ext.Extension, current_devices,
28-
vm, path, device_class: qubes.device_protocol.DeviceInfo
38+
vm, path, device_class: Type[qubes.device_protocol.DeviceInfo]
2939
):
3040
devclass = device_class.__name__[:-len('Device')].lower()
3141

@@ -54,6 +64,7 @@ def device_list_change(
5464

5565
ext.devices_cache[vm.name] = current_devices
5666

67+
to_attach = {}
5768
for front_vm in vm.app.domains:
5869
if not front_vm.is_running():
5970
continue
@@ -62,8 +73,35 @@ def device_list_change(
6273
and assignment.ident in added
6374
and assignment.ident not in attached
6475
):
65-
asyncio.ensure_future(ext.attach_and_notify(
66-
front_vm, assignment.device, assignment.options))
76+
frontends = to_attach.get(assignment.ident, {})
77+
frontends[front_vm] = assignment
78+
to_attach[assignment.ident] = frontends
79+
80+
for ident, frontends in to_attach.items():
81+
if len(frontends) > 1:
82+
guivm = 'dom0' # TODO
83+
84+
assignment = tuple(frontends.values())[0]
85+
86+
proc = subprocess.Popen(
87+
["/home/user/devel/test.py", guivm,
88+
assignment.backend_domain.name, assignment.ident,
89+
*[f.name for f in frontends.keys()]],
90+
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
91+
(target_name, _) = proc.communicate()
92+
target_name = target_name.decode()
93+
for front in frontends:
94+
if front.name == target_name:
95+
target = front
96+
break
97+
else:
98+
print("Something really goes bad :/", file=sys.stderr)
99+
return
100+
else:
101+
target = tuple(frontends.keys())[0]
102+
assignment = frontends[target]
103+
asyncio.ensure_future(ext.attach_and_notify(
104+
target, assignment.device, assignment.options))
67105

68106

69107
def compare_device_cache(vm, devices_cache, current_devices):

qubes/vm/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ def _qdb_watch_reader(self, loop):
426426
if watched_path == path or (
427427
watched_path.endswith('/') and
428428
path.startswith(watched_path)):
429-
self.fire_event('domain-qdb-change:' + watched_path,
430-
path=path)
429+
self.fire_event(
430+
'domain-qdb-change:' + watched_path, path=path)
431431
except qubesdb.DisconnectedError:
432432
loop.remove_reader(self._qdb_connection_watch.watch_fd())
433433
self._qdb_connection_watch.close()

0 commit comments

Comments
 (0)