Skip to content

Commit

Permalink
Simplify sys-usb udev rules/actions
Browse files Browse the repository at this point in the history
By using a single matching strategy in the udev rules, we can simplify
this down to one rule and one script for attaching export devices, as
the device paths passed to the script for either storage or printer
devices will be at equivalent depths.
  • Loading branch information
rmol committed Dec 9, 2019
1 parent f1076d9 commit 17f4c92
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 25 deletions.
14 changes: 3 additions & 11 deletions dom0/sys-usb.sls
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,10 @@ sd-rc-local-udev-rules:
- require:
- file: sd-rc-local-udev-rules

sd-attach-export-disk:
sd-attach-export-device:
file.managed:
- name: /usr/local/bin/sd-attach-export-disk
- source: salt://sd/sys-usb/sd-attach-export-disk
- user: root
- group: root
- mode: 0555

sd-attach-export-printer:
file.managed:
- name: /usr/local/bin/sd-attach-export-printer
- source: salt://sd/sys-usb/sd-attach-export-printer
- name: /usr/local/bin/sd-attach-export-device
- source: salt://sd/sys-usb/sd-attach-export-device
- user: root
- group: root
- mode: 0555
8 changes: 6 additions & 2 deletions sys-usb/99-sd-export-usb.rules
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
ACTION=="add", SUBSYSTEM=="usb", DRIVER=="usb-storage", RUN+="/usr/local/bin/sd-attach-export-disk"
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701??:*", RUN+="/usr/local/bin/sd-attach-export-printer"
# Class 08 == storage, subclass 06 == SCSI
# Class 07 == printer, subclass 01 == printer
# https://www.usb.org/defined-class-codes
# https://www.usb.org/document-library/mass-storage-class-specification-overview-14
# https://www.usb.org/document-library/printer-device-class-document-11
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0806??:*|*:0701??:*", RUN+="/usr/local/bin/sd-attach-export-device"
6 changes: 6 additions & 0 deletions sys-usb/sd-attach-export-device
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# udev action for attaching USB export devices to sd-export-usb

QDEVNAME="$(basename $DEVPATH)"
echo sys-usb "$QDEVNAME" | qrexec-client-vm sd-export-usb qubes.USBAttach
5 changes: 0 additions & 5 deletions sys-usb/sd-attach-export-disk

This file was deleted.

5 changes: 0 additions & 5 deletions sys-usb/sd-attach-export-printer

This file was deleted.

3 changes: 1 addition & 2 deletions tests/test_sys_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def setUp(self):

def test_files_are_properly_copied(self):
self.assertTrue(self._fileExists("/etc/udev/rules.d/99-sd-export-usb.rules"))
self.assertTrue(self._fileExists("/usr/local/bin/sd-attach-export-disk"))
self.assertTrue(self._fileExists("/usr/local/bin/sd-attach-export-printer"))
self.assertTrue(self._fileExists("/usr/local/bin/sd-attach-export-device"))


def load_tests(loader, tests, pattern):
Expand Down

0 comments on commit 17f4c92

Please sign in to comment.