Help me understand this udev/uinput behaviour

Hi there!!

For context i’m a bit outside of my comfort zone on the pocket reform as I’ve haven’t had a linux personal machine for ages…
I’m actively trying to learn more!!!

So I need correct permissions for /dev/uinput, for use by kanata (a very fancy software-level kb remapper) to work.

I added a udev rule that enforces the right chmod and group.

When booting, the chmod and group are not applied, although the /dev/uinput file exists (as in I see with ls -l). Then if I sudo modprobe uinput, the correct chmod/group are applied, I can start kanata (as a normal user) fine after that

I don’t understand why this other approach also works:

  • sudo chmod and chown on /dev/uinput, then start kanata (as a normal user) then it works fine as well! As a side effect I then see the uinput module loaded!! How does kanata manage to load the module?? Modprobe seems to be restricted to root only, I don’t think that software would somehow itself load the module…

I guess it’s something to do with magically loading the module upon accessing the file? (You’d obviously need the right permissions) Could people point me to where this is configured? Name of the tool/feature etc. I’m curious to know more

Thanks a lot!!

The kernel itself does the autoloading here.
uinput.ko at build-time sets this modalias: char-major-10-233.

When the kernel’s drivers/char/misc.c sees you are going to open subdevice type 233, it will autoload that alias, in turn loading uinput.ko.

Maybe you can match on some earlier event in udev to set up the permissions.

2 Likes

Something like

KERNEL=="event[0-9]*", ACTION=="add", SUBSYSTEM=="input", ENV{ID_INPUT_KEYBOARD}=="1", ENV{ID_MODEL}=="Pocket_Reform_Input", OWNER="my_username"

should do.

EDIT: for me it is always a bit of trying until it works, the command udevadm info --query=property --name=/dev/input/by-id/my_keyboard give you the keys and values to write the rule. Also wikis like the arch or gentoo distros are usually a good source of information.