internal/gamepad: don't fail when inotify is unavailable on Linux

The inotify limits are per user, so another program can exhaust them and
make InotifyInit1 or InotifyAddWatch fail. That aborted RunGame with
"gamepad: InotifyAddWatch failed: no space left on device" even though
inotify is only used to detect hotplugged gamepads. GLFW ignores these
errors, so do the same and keep the gamepads found by the initial scan.

Closes #3304
This commit is contained in:
dualfroz committed 2026-09-11 23:26:34 +02:00
1 parent e2e4627cf0
commit f892849eeb
3 files changed
+96 -13

No files matched your search

+14 -13
View File
@@ -65,26 +65,27 @@ func (g *nativeGamepadsImpl) init(gamepads *gamepads) (err error) {
return nil
}
inotify, err := unix.InotifyInit1(unix.IN_NONBLOCK | unix.IN_CLOEXEC)
if err != nil {
return fmt.Errorf("gamepad: InotifyInit1 failed: %w", err)
// Another program of the same user can exhaust the inotify limits (#3304). That only costs
// hotplug detection, so it is not fatal here, and GLFW ignores the same errors.
if inotify, err := unix.InotifyInit1(unix.IN_NONBLOCK | unix.IN_CLOEXEC); err == nil {
g.inotifyPlus1 = inotify + 1
// Register for IN_ATTRIB to get notified when udev is done.
// This works well in practice but the true way is libudev.
if watch, err := unix.InotifyAddWatch(g.inotifyPlus1-1, dirName, unix.IN_CREATE|unix.IN_ATTRIB|unix.IN_DELETE); err == nil {
g.watch = watch
} else {
_ = unix.Close(g.inotifyPlus1 - 1)
g.inotifyPlus1 = 0
}
}
g.inotifyPlus1 = inotify + 1
defer func() {
if err != nil {
if err != nil && g.inotifyPlus1 != 0 {
_ = unix.Close(g.inotifyPlus1 - 1)
g.inotifyPlus1 = 0
}
}()
// Register for IN_ATTRIB to get notified when udev is done.
// This works well in practice but the true way is libudev.
watch, err := unix.InotifyAddWatch(g.inotifyPlus1-1, dirName, unix.IN_CREATE|unix.IN_ATTRIB|unix.IN_DELETE)
if err != nil {
return fmt.Errorf("gamepad: InotifyAddWatch failed: %w", err)
}
g.watch = watch
ents, err := os.ReadDir(dirName)
if err != nil {
return fmt.Errorf("gamepad: ReadDir(%s) failed: %w", dirName, err)