From a397195d3fd14b3e94026bce684e6b5f392f5015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 9 Aug 2017 12:04:38 +0200 Subject: [PATCH] Linux: Make joystick init always fail silently Related to #833. --- README.md | 1 + src/linux_joystick.c | 39 +++++++++++++-------------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 260818c8..62dc98bd 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,7 @@ information on what to include when reporting a bug. - [Linux] Moved to evdev for joystick input (#906,#1005) - [Linux] Bugfix: Event processing did not detect joystick disconnection (#932) - [Linux] Bugfix: The joystick device path could be truncated (#1025) +- [Linux] Bugfix: `glfwInit` would fail if inotify creation failed (#833) - [Cocoa] Added support for Vulkan window surface creation via [MoltenVK](https://moltengl.com/moltenvk/) (#870) - [Cocoa] Added support for loading a `MainMenu.nib` when available diff --git a/src/linux_joystick.c b/src/linux_joystick.c index a16f208c..3283d1ea 100644 --- a/src/linux_joystick.c +++ b/src/linux_joystick.c @@ -266,28 +266,17 @@ GLFWbool _glfwInitJoysticksLinux(void) const char* dirname = "/dev/input"; _glfw.linjs.inotify = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); - if (_glfw.linjs.inotify == -1) + if (_glfw.linjs.inotify > 0) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Linux: Failed to initialize inotify: %s", - strerror(errno)); - return GLFW_FALSE; + // HACK: Register for IN_ATTRIB to get notified when udev is done + // This works well in practice but the true way is libudev + + _glfw.linjs.watch = inotify_add_watch(_glfw.linjs.inotify, + dirname, + IN_CREATE | IN_ATTRIB | IN_DELETE); } - // HACK: Register for IN_ATTRIB as well to get notified when udev is done - // This works well in practice but the true way is libudev - - _glfw.linjs.watch = inotify_add_watch(_glfw.linjs.inotify, - dirname, - IN_CREATE | IN_ATTRIB | IN_DELETE); - if (_glfw.linjs.watch == -1) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Linux: Failed to watch for joystick connections in %s: %s", - dirname, - strerror(errno)); - // Continue without device connection notifications - } + // Continue without device connection notifications if inotify fails if (regcomp(&_glfw.linjs.regex, "^event[0-9]\\+$", 0) != 0) { @@ -318,13 +307,8 @@ GLFWbool _glfwInitJoysticksLinux(void) closedir(dir); } else - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Linux: Failed to open joystick device directory %s: %s", - dirname, - strerror(errno)); - // Continue with no joysticks detected - } + + // Continue with no joysticks if enumeration fails qsort(_glfw.joysticks, count, sizeof(_GLFWjoystick), compareJoysticks); return GLFW_TRUE; @@ -359,6 +343,9 @@ void _glfwDetectJoystickConnectionLinux(void) ssize_t offset = 0; char buffer[16384]; + if (_glfw.linjs.inotify <= 0) + return; + const ssize_t size = read(_glfw.linjs.inotify, buffer, sizeof(buffer)); while (size > offset)