18
18
# along with this program; if not, write to the Free Software
19
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20
20
# USA.
21
+ import itertools
21
22
import asyncio
23
+ import subprocess
24
+ import sys
25
+
26
+ import gbulb
22
27
23
28
import qubes
24
29
30
+ from typing import Type
31
+
32
+ from qubes .ext .attachment_confirm import confirm_device_attachment
33
+ from qrexec import server
34
+
25
35
26
36
def device_list_change (
27
37
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 ]
29
39
):
30
40
devclass = device_class .__name__ [:- len ('Device' )].lower ()
31
41
@@ -54,6 +64,7 @@ def device_list_change(
54
64
55
65
ext .devices_cache [vm .name ] = current_devices
56
66
67
+ to_attach = {}
57
68
for front_vm in vm .app .domains :
58
69
if not front_vm .is_running ():
59
70
continue
@@ -62,8 +73,35 @@ def device_list_change(
62
73
and assignment .ident in added
63
74
and assignment .ident not in attached
64
75
):
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 ))
67
105
68
106
69
107
def compare_device_cache (vm , devices_cache , current_devices ):
0 commit comments