udev, overwrite existing rules

Viewed 147

when I plug an HID device into my Linux box (OpenSuse 15.3), then the UDEV rules in /usr/lib/udev/rules.d/60-persistent-input.rules seem to apply and it gets a MODE="664".

I'd like to handle several HID devices on my own and not have them handled by the generic rule that already comes with my installations UDEV.

Is there a way to specifically formulate own rules for just some devices (based on VID:PID) so they overwrite the ones that are already in place?

Thanks for any hints, Torsten

1 Answers

systemd-udev has terrible support for .rules, so what you can do depends on your systemd version.

  1. The official way that man udev suggests, supported by all systemd versions: you basically create a rule file under /etc/ directory which has same name as the one you wanted to override. Quoting:

    files with identical filenames replace each other. Files in /etc/ have the highest priority, files in /run/ take precedence over files with the same name under /usr/. This can be used to override a system-supplied rules file with a local file if needed; a symlink in /etc/ with the same name as a rules file in /usr/lib/, pointing to /dev/null, disables the rules file entirely.

    So in your case you have to copy /usr/lib/udev/rules.d/60-persistent-input.rules to /etc/udev/rules.d/60-persistent-input.rules, then you edit lines you're interested in and add your custom handling of ATTRS{idVendor}=="NUMBER1", ATTRS{idProduct}=="NUMBER2". See this answer.

  2. Unofficial way, which I recommend: create a .rules with priority 99 that undoes whatever systemd did. It's the best solution, because the alternative from point 1. means you may get into trouble on a system update, which may change content of the system rules as well as their names, so your overrides would just silently break.

    Well, implementing that is hard: did I mention systemd-udev is broken? Well, here's number of upstream bugs that will be in your way: -= (sometimes or always) doesn't work, the = doesn't work.

    What you can do is create a rule that uses RUN command to undo whatever systemd done, but older systemd versions are prone to race-condition with that. The 250 is known to work though, not sure when exactly they fixed that, so you may have to test that yourself, by using e.g. testcases from the linked bugreport.

Whichever way you chose, detecting VID and PID is done with ATTRS{idVendor}=="VID" and ATTRS{idProduct}=="PID"

Related