Skip to content

keventd: fix dangling and misnamed /dev/input/by-id links - #516

Open
vazub wants to merge 1 commit into
finit-project:masterfrom
vazub:symlink-fix
Open

vazub wants to merge 1 commit into
finit-project:masterfrom
vazub:symlink-fix

Conversation

@vazub

@vazub vazub commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

With keventd handling input devices, every rule-created /dev/input/by-id/usb-* link was broken, and the names were missing the USB interface number:

usb-X-event-kbd     -> ../../event17    # resolves to /dev/event17, which does not exist
usb-X-if-event-kbd                      # should be ...-if02-event-kbd
usb-X-event-if                          # should be ...-event-if01

Two independent bugs were causing this, fixed with this combined PR.

Issue 1

symlink_add() built the target as one ../ per / in the link name followed by the basename of the node. That is only right for nodes directly in /dev (disk/by-id/x -> ../../sda). For SYMLINK+="input/by-id/..." and the node /dev/input/event17 it gave ../../event17. Any rule-created link to a node in a subdirectory (input/, dri/, snd/, ...) was dangling.

The target is now computed relative to the link's directory. Nodes directly in /dev come out exactly as before. A path that does not fit the buffer is reported instead of truncated.

Issue 2

The installed 60-persistent-input.rules builds the name with

ATTRS{bInterfaceNumber}=="?*", ...
    SYMLINK+="input/by-id/...-if$attr{bInterfaceNumber}-event-..."

In udev, $attr{} and %s{} read the attribute from the event device and, if it has none, from the parent selected by a preceding KERNELS/SUBSYSTEMS/DRIVERS/ATTRS == key. Here match_parent_chain() found the USB interface but discarded it, and subst_value() only looked at the event device, so the number expanded to nothing.

The syspath of the matched parent is now remembered and used as a fallback. It is cleared at the start of every rule and again after the rule has been applied, so it cannot leak into the next rule or into the deferred RUN+= expansion.

Testing

Device Before After
interface 02, keyboard usb-X-if-event-kbd usb-X-if02-event-kbd
interface 01, no class usb-X-event-if usb-X-event-if01
interface 00, mouse usb-X-event-mouse unchanged

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant