Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
interfaces: fix udev tagging for hooks #4144
Conversation
zyga
added some commits
Nov 3, 2017
This was referenced Nov 3, 2017
zyga
requested review from
pedronis,
stolowski and
mvo5
Nov 3, 2017
codecov-io
commented
Nov 3, 2017
•
Codecov Report
@@ Coverage Diff @@
## master #4144 +/- ##
=========================================
Coverage ? 75.71%
=========================================
Files ? 437
Lines ? 37856
Branches ? 0
=========================================
Hits ? 28663
Misses ? 7192
Partials ? 2001
Continue to review full report at Codecov.
|
stolowski
reviewed
Nov 6, 2017
Looks good, much better than the old code. Just two minor comments.
| - spec.AddSnippet(snippet) | ||
| - } | ||
| + for _, rule := range iface.connectedPlugUDev { | ||
| + spec.TagDevice(rule) |
| + spec.TagDevice(fmt.Sprintf(`SUBSYSTEM=="hidraw", KERNEL=="%s"`, strings.TrimPrefix(path, "/dev/"))) | ||
| + } else { | ||
| + spec.TagDevice(fmt.Sprintf(`IMPORT{builtin}="usb_id" | ||
| +SUBSYSTEM=="hidraw", SUBSYSTEMS=="usb", ATTRS{idVendor}=="%04x", ATTRS{idProduct}=="%04x"`, usbVendor, usbProduct)) |
stolowski
Nov 6, 2017
Contributor
I'm not totally sure it's more readable than calling udevUsbDeviceSnippet helper here to be honest. Anyway, not biggie but if you decide not to use udevUsbDeviceSnippet, then perhaps udevUsbDeviceSnippet can be removed from utils?
jdstrand
Nov 7, 2017
Contributor
I agree, either use udevUsbDeviceSnippet where you can or remove it from utils.go.
| + iface := &ifacetest.TestInterface{ | ||
| + InterfaceName: "test", | ||
| + UDevConnectedPlugCallback: func(spec *udev.Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error { | ||
| + spec.TagDevice(`kernel="voodoo"`) |
stolowski
Nov 6, 2017
Contributor
Could you please extend this test to have call spec.TagDevice twice?
jdstrand
requested changes
Nov 7, 2017
I blackbox tested this by connecting all the (non-gadget) interfaces and found that the udev tagging rules are fine. On the one hand, the sorting of the rules is nice since the left hand side (non-TAG) part is sorted, but on the other hand, the TAGs are not grouped by command. I think it would be good to group by snap command and then by rule (eg, each command is in a stanza with stanzas separated by new lines). While this sounds cosmetic, it helps with debugging and for making policy audits easier.
| + spec.TagDevice(fmt.Sprintf(`SUBSYSTEM=="hidraw", KERNEL=="%s"`, strings.TrimPrefix(path, "/dev/"))) | ||
| + } else { | ||
| + spec.TagDevice(fmt.Sprintf(`IMPORT{builtin}="usb_id" | ||
| +SUBSYSTEM=="hidraw", SUBSYSTEMS=="usb", ATTRS{idVendor}=="%04x", ATTRS{idProduct}=="%04x"`, usbVendor, usbProduct)) |
stolowski
Nov 6, 2017
Contributor
I'm not totally sure it's more readable than calling udevUsbDeviceSnippet helper here to be honest. Anyway, not biggie but if you decide not to use udevUsbDeviceSnippet, then perhaps udevUsbDeviceSnippet can be removed from utils?
jdstrand
Nov 7, 2017
Contributor
I agree, either use udevUsbDeviceSnippet where you can or remove it from utils.go.
| + */ | ||
| + spec.TagDevice(`KERNEL=="tty[A-Z]*[0-9]*|cdc-wdm[0-9]*"`) | ||
| + spec.TagDevice(`KERNEL=="tun"`) | ||
| + spec.TagDevice(`KERNEL=="tun[0-9]*"`) |
jdstrand
Nov 7, 2017
Contributor
Oh, this tun[0-9]* tag is actually an error. I realize this PR didn't introduce this, but we should fix it. See #4031
zyga
added some commits
Nov 8, 2017
|
The udev rules cannot contain trailing comments:
This is not allowed. I'll update the PR after lunch. |
zyga
added some commits
Nov 8, 2017
jdstrand
approved these changes
Nov 8, 2017
Since you fixed the ofono issue and added the comment commit, I'm going to mark this as approved. I do think that it would be nice to group by command, but we didn't have that before so I don't think it should be a blocker for this PR.
|
Just for the record, this does contain the formatting changes that were requested. Jamie just didn't see it when he made that comment above. We discussed this on IRC yesterday. |
zyga
and others
added some commits
Nov 10, 2017
|
@zyga are the comments in #4146 (review) addressed here? |
zyga
and others
added some commits
Nov 10, 2017
|
@pedronis yes (now) |
zyga commentedNov 3, 2017
•
Edited 2 times
-
zyga
Nov 8, 2017
-
zyga
Nov 8, 2017
This branch aims to fix udev tagging to support hooks in addition to apps that
were added earlier.
There are three main patches here:
spec.TagDevicemethod toudev.Specification, this automatically tagsboth apps and hooks
TagDevice, with exception of some specialuses of
AddSnippetTagDevice, with some trivial changes to howthat is defined.
The only remaining uses of
spec.AddSnippetare special-cases that add largechunk of arbitrary udev code that is not specifically aiming to tag a device.
This passes local unit testing, no testing was done on any hardware.
Base on initial feedback I also included changes to format udev rules
differently. They are now preceded by the snapd interface name (as a comment).
The order of entries is also different, now being sorted by TAG += if one
exists (this allows us to see everything affecting particular command easily)
Signed-off-by: Zygmunt Krynicki zygmunt.krynicki@canonical.com