Skip to content

Commit decc57d

Browse files
committed
Fix handling remove event
Remove event cannot query udev as the device may not be there anymore, so it uses environment provided to the handler. Environment is a dict-like structure, convert udev output to dict earlier to match types. This makes matching a bit cleaner too (although a bit more verbose).
1 parent 9506a92 commit decc57d

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

qubes-rpc/qubes-input-trigger

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def get_args():
3737
def get_service_name(udevreturn, input_dev):
3838
service = None
3939
try:
40-
devpath = [line.split("=", 1)[1] for line in udevreturn.splitlines()
41-
if line.startswith("DEVPATH=")][0]
40+
devpath = udevreturn.get("DEVPATH")
4241
with open(f"/sys/{devpath}/device/capabilities/abs", "r") as f:
4342
abs_string = f.read().strip()
4443
# we care about only the last byte - that's where X,Y axies are
@@ -49,7 +48,7 @@ def get_service_name(udevreturn, input_dev):
4948
('ID_INPUT_TABLET' in udevreturn) or
5049
('ID_INPUT_TOUCHSCREEN' in udevreturn) or
5150
('ID_INPUT_TOUCHPAD' in udevreturn) or
52-
('QEMU_USB_Tablet' in udevreturn)
51+
('QEMU_USB_Tablet' in udevreturn.get("ID_MODEL"))
5352
) and 'ID_INPUT_KEY' not in udevreturn:
5453
service = 'qubes-input-sender-tablet'
5554
# if mouse report absolute events, prefer tablet service
@@ -106,31 +105,37 @@ def handle_event(input_dev, action, dom0):
106105
udevreturn = subprocess.check_output([
107106
"udevadm", "info", "--query=property",
108107
"--name=" + eventFile]).decode()
109-
if 'ID_TYPE=video' in udevreturn:
108+
udevreturn = dict(
109+
item.split("=", 1)
110+
for item in udevreturn.splitlines()
111+
)
112+
if udevreturn.get('ID_TYPE') == 'video':
110113
return
111114
# The ID_SERIAL here corresponds to qemu-emulated tablet
112115
# device for HVM which is static. It allows to attach another
113116
# tablet for example when using KVM for tests. Depending on
114117
# QEMU version, the device may look different. But it will
115118
# always be the first bus, either on 00:04.0 or 00:05.0.
116-
if ('ID_PATH=pci-0000:00:04.0-usb-0:1:1.0' in udevreturn or \
117-
'ID_PATH=pci-0000:00:05.0-usb-0:1:1.0' in udevreturn) and \
118-
'ID_SERIAL=QEMU_QEMU_USB_Tablet_' in udevreturn:
119+
if udevreturn.get('ID_PATH') in (
120+
'pci-0000:00:04.0-usb-0:1:1.0',
121+
'pci-0000:00:05.0-usb-0:1:1.0') and \
122+
udevreturn.get('ID_SERIAL', '').startswith('QEMU_QEMU_USB_Tablet'):
119123
return
120-
if '/devices/virtual/' in udevreturn and dom0:
124+
if udevreturn.get('DEVPATH', '').startswith('/devices/virtual/') and dom0:
121125
return
122126
# exclude qubes virtual input device created by gui agent
123-
if 'TAGS=:qubes-virtual-input-device:' in udevreturn:
127+
if udevreturn.get('TAGS') == ':qubes-virtual-input-device:':
124128
return
125129
# We exclude in sys-usb ID_PATH=acpi-* and ID_PATH=platform-*
126130
# which can correspond to power-switch buttons. By default, HVM
127131
# exposes some so there is no point for adding input devices
128132
# into dom0 from those. This is only pertinent in the case
129133
# of dom0 key devices to sys-gui-gpu
130-
if 'ID_PATH=acpi-' in udevreturn and not dom0:
131-
return
132-
if 'ID_PATH=platform-' in udevreturn and not dom0:
133-
return
134+
if not dom0:
135+
if udevreturn.get('ID_PATH', '').startswith('acpi-'):
136+
return
137+
if udevreturn.get('ID_PATH', '').startswith('platform-'):
138+
return
134139
elif action == "remove":
135140
# on remove action we use information passed through
136141
# env by udev

0 commit comments

Comments
 (0)