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.
This commit is contained in:
Matt McCutchen
2015-04-23 21:38:45 -04:00
parent 68fdb2cc0b
commit cb7efb1570
+7 -3
View File
@@ -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()