Skip to content

Fix device watch errors and race-conditions#901

Merged
hpccc53 merged 9 commits intoxremap:masterfrom
hpccc53:device_watch_problem
Apr 20, 2026
Merged

Fix device watch errors and race-conditions#901
hpccc53 merged 9 commits intoxremap:masterfrom
hpccc53:device_watch_problem

Conversation

@hpccc53
Copy link
Copy Markdown
Contributor

@hpccc53 hpccc53 commented Apr 20, 2026

Device watching had some problems with both race-condititions and sensitivity to the expectable unpredictable batching and duplicate file events.

The important commits:

  • Ignore irrelevant device events
    • Ignore file events for devices that are already grabbed, those would cause EBUSY when trying to regrab a device.
    • Ignore multiple file events for the same device in same batch.
  • Only remove a single device, when events can't be fetched.
    • Instead of ungrabbing all devices, when it's detected one is removed. Only that specific device is removed. This fixes the case where two devices are removed, and it's tried to regrab the second removed device. It's better to react on the information that is certain instead of regrabbing all devices.
  • Fix race from InputDevice::try_from() to device.grab()
    • There is no way to atomically grab a device. When reading /dev/input folder, anything can happen in the time until device.grab() is called. The only solution is therefore to squash ENODEV errors when grabbing. Note that InputDevice::try_from() already squashes all errors.

Problems that still remain

evdev prints an error message, if the device can't be ungrabbed, even though the device is gone, and ungrab is not needed. I have made a PR that is still open.

The error message is "Failed to ungrab device: No such device (os error 19)"

@hpccc53 hpccc53 merged commit 101c9fb into xremap:master Apr 20, 2026
21 checks passed
@hpccc53 hpccc53 deleted the device_watch_problem branch April 20, 2026 12:46
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