From cb7efb157083f5d5290ca4164bbad50b3fbd6f51 Mon Sep 17 00:00:00 2001 From: Matt McCutchen Date: Thu, 23 Apr 2015 21:38:45 -0400 Subject: [PATCH] getDevice: Do not read a dirent after calling closedir. On my Fedora 20 system, closedir apparently frees the dirent, and reading it afterwards returns garbage data. This prevented my dance pad from being detected. --- src/arch/InputHandler/LinuxInputManager.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/arch/InputHandler/LinuxInputManager.cpp b/src/arch/InputHandler/LinuxInputManager.cpp index c224a81002..e657dd58b7 100644 --- a/src/arch/InputHandler/LinuxInputManager.cpp +++ b/src/arch/InputHandler/LinuxInputManager.cpp @@ -13,17 +13,21 @@ RString getDevice(RString inputDir, RString type) { + RString result = ""; DIR* dir = opendir( inputDir.c_str() ); if(dir == NULL) { LOG->Warn("LinuxInputManager: Couldn't open %s: %s.", inputDir.c_str(), strerror(errno) ); return ""; } struct dirent* d; while( ( d = readdir(dir) ) != NULL) - if( strncmp( type.c_str(), d->d_name, type.size() ) == 0) break; + if( strncmp( type.c_str(), d->d_name, type.size() ) == 0) + { + result = RString("/dev/input/") + d->d_name; + break; + } closedir(dir); - if( d == NULL ) return ""; - return RString("/dev/input/") + d->d_name; + return result; } LinuxInputManager::LinuxInputManager()