linuxudev

Proper way to use `udev` rules with `/dev/uhid`


I want to set the group of /dev/uhid on Linux to uhid so that users of that group have rw access without root privileges. Unfortunately rules like KERNEL=="uhid", GROUP="uinput-users", MODE="0660" don't get applied on startup (udev doesn't even know the device), but when I access /dev/uhid once with root access.

Example:

sugar@achilles:~$ udevadm info /dev/uhid
Unknown device "/dev/uhid": No such device
sugar@achilles:~$ sudo ./some/random/program/that/accesses/uhid 
[sudo] password for sugar: 
^C
sugar@achilles:~$ udevadm info /dev/uhid
P: /devices/virtual/misc/uhid
N: uhid
L: 0
E: DEVPATH=/devices/virtual/misc/uhid
E: DEVNAME=/dev/uhid
E: MAJOR=10
E: MINOR=239
E: SUBSYSTEM=misc
sugar@achilles:~$ ls -la /etc/udev/rules.d/90-uinput.rules 
-rw-r--r-- 1 root root 42 Aug 12 22:58 /etc/udev/rules.d/90-uinput.rules
sugar@achilles:~$ cat /etc/udev/rules.d/90-uinput.rules 
KERNEL=="uhid", GROUP="udev", MODE="0660"

(I tried different things but the example above is from here: https://gist.github.com/StuntsPT/cd3ef67a5ac30e168cb6774ea939f55f)

Can somebody tell me why this is and how I can fix it? The only explanation I could come up with is that /dev/uhid is created before udev is "ready".


Solution

  • The problem was that the uhid module is only loaded "on demand", i.e. when accessing the /dev/uhid the first time. The udev rule is applied when loading the module. This can be easily fixed by adding uhid to /etc/module to load the module during boot.