Improved robustness of Linux joystick init.

This commit is contained in:
Camilla Berglund 2015-01-06 19:22:19 +01:00
parent 0e3cb945e8
commit 6c7509c942

View File

@ -192,12 +192,13 @@ int _glfwInitJoysticks(void)
#if defined(__linux__) #if defined(__linux__)
const char* dirname = "/dev/input"; const char* dirname = "/dev/input";
DIR* dir; DIR* dir;
struct dirent* entry;
_glfw.linux_js.inotify = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); _glfw.linux_js.inotify = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
if (_glfw.linux_js.inotify == -1) if (_glfw.linux_js.inotify == -1)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, "Linux: Failed to initialize inotify"); _glfwInputError(GLFW_PLATFORM_ERROR,
"Linux: Failed to initialize inotify: %s",
strerror(errno));
return GL_FALSE; return GL_FALSE;
} }
@ -210,8 +211,10 @@ int _glfwInitJoysticks(void)
if (_glfw.linux_js.watch == -1) if (_glfw.linux_js.watch == -1)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Linux: Failed to add watch to %s", dirname); "Linux: Failed to watch for joystick connections in %s: %s",
return GL_FALSE; dirname,
strerror(errno));
// Continue without device connection notifications
} }
if (regcomp(&_glfw.linux_js.regex, "^js[0-9]\\+$", 0) != 0) if (regcomp(&_glfw.linux_js.regex, "^js[0-9]\\+$", 0) != 0)
@ -221,11 +224,9 @@ int _glfwInitJoysticks(void)
} }
dir = opendir(dirname); dir = opendir(dirname);
if (!dir) if (dir)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, "Linux: Failed to open %s", dirname); struct dirent* entry;
return GL_FALSE;
}
while ((entry = readdir(dir))) while ((entry = readdir(dir)))
{ {
@ -240,6 +241,16 @@ int _glfwInitJoysticks(void)
} }
closedir(dir); closedir(dir);
}
else
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Linux: Failed to open joystick device directory %s: %s",
dirname,
strerror(errno));
// Continue with no joysticks detected
}
#endif // __linux__ #endif // __linux__
return GL_TRUE; return GL_TRUE;