[Nut-upsdev] nut + usb + udev with kernel 2.6.22
Gilad Arnold
arnold at cs.berkeley.edu
Fri Sep 28 23:22:00 UTC 2007
Hi all,
Here's a brief history of my adventure: I purchased a CyberPower 685 AVR
and decided to connect it through USB to my Gentoo linux machine running
kernel 2.6.22. While the device was detected properly and added to
/dev, it was added with the wrong permissions (gid was set to 'usb'
instead of 'nut', as it was expected to be according to the rules under
/etc/udev/rules.d/70-nut-usbups.rules). Worse, it was improperly setup
only during udev coldplug, whereas hotplugging worked fine. Finally,
when I recompiled the kernel without CONFIG_USB_DEVICE_CLASS (which is
marked DEPRECATED as of 2.6.22), it constantly added the device with the
wrong gid.
After spending many hours, I managed to find a hint to the solution: the
default udev rules that are installed with nut assume that, as far as
the kernel event, SUBSYSTEM needs to be 'usb_device'. Nonetheless, this
is only the case with kernels up to 2.6.21, or newer kernels compiled
with CONFIG_USB_DEVICE_CLASS. (Also, I suspect that with the latter,
SUBSYSTEM is set to 'usb_device' only when hotplugging, which will
explain my weird situation above.) However, with the recent kernel the
SUBSYSTEM is set to 'usb', but udev default rules
(/etc/udev/rules.d/50-udev.rules) set the variable ENV{DEVTYPE} to be
'usb_device'; this is in fact explicitly stated as a comment in
50-udev.rules.
The proposed fix is therefore: proper matching happens if either
ENV{DEVTYPE} is set to 'usb_device' and SUBSYSTEM is 'usb' (i.e. new
kernel without CONFIG_USB_DEVICE_CLASS, or a coldplug event), or if
SUBSYSTEM value is 'usb_device' (i.e. old kernel, or new kernel with
CONFIG_USB_DEVICE_CLASS, in a hotplug event). I believe this is better
than working around permissions in other ways, and solves the problem in
a safe manner. A patch to the rules file is attached.
Please advise if this solution makes sense, and whether it can be
incorporated into the standard distribution of nut.
(Note: I'm not subscribed to nut-upsdev, so please reply-all)
Many thanks.
Gilad
-------------- next part --------------
--- 70-nut-usbups.rules 2007-09-20 17:24:41.000000000 -0700
+++ 71-nut-usbups-gilad-20070926.rules 2007-09-28 16:16:18.000000000 -0700
@@ -1,7 +1,10 @@
# udev rules for the NUT USB drivers
-SUBSYSTEM!="usb_device", GOTO="nut-usbups_rules_end"
ACTION!="add", GOTO="nut-usbups_rules_end"
+SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", GOTO="nut-usbups_rules_no-device-class"
+SUBSYSTEM!="usb_device", GOTO="nut-usbups_rules_end"
+
+LABEL="nut-usbups_rules_no-device-class"
# MGE UPS SYSTEMS - usbhid-ups
SYSFS{idVendor}=="0463", SYSFS{idProduct}=="ffff", MODE="664", GROUP="nut"
More information about the Nut-upsdev
mailing list