From ee80a9d43cfedd41e91a825a0733eaf6cc59b26a Mon Sep 17 00:00:00 2001 From: Christian Linke Date: Mon, 2 Sep 2013 13:37:37 +0200 Subject: Handle cases where readdir() does not return the file type readdir() does not guarantee that the d_type member is set on all file systems. This resulted in plugins not being loaded on some platforms as regular files were not detected. Signed-off-by: Christian Linke --- AudioManagerDaemon/src/CAmCommandSender.cpp | 17 +++++++++++++++++ AudioManagerDaemon/src/CAmRoutingSender.cpp | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/AudioManagerDaemon/src/CAmCommandSender.cpp b/AudioManagerDaemon/src/CAmCommandSender.cpp index a03e5a8..bb49c19 100644 --- a/AudioManagerDaemon/src/CAmCommandSender.cpp +++ b/AudioManagerDaemon/src/CAmCommandSender.cpp @@ -21,8 +21,12 @@ #include "CAmCommandSender.h" #include +#include +#include +#include #include #include +#include #include "CAmCommandReceiver.h" #include "TAmPluginTemplate.h" #include "shared/CAmDltWrapper.h" @@ -72,10 +76,23 @@ CAmCommandSender::CAmCommandSender(const std::vector& listOfPluginD { unsigned char entryType = itemInDirectory->d_type; std::string entryName = itemInDirectory->d_name; + std::string fullName = *dirIter + "/" + entryName; bool regularFile = (entryType == DT_REG || entryType == DT_LNK); bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); + // Handle cases where readdir() could not determine the file type + if (entryType == DT_UNKNOWN) { + struct stat buf; + + if (stat(fullName.c_str(), &buf)) { + logInfo(__PRETTY_FUNCTION__,"Failed to stat file: ", entryName, errno); + continue; + } + + regularFile = S_ISREG(buf.st_mode); + } + if (regularFile && sharedLibExtension) { std::string name(directoryName); diff --git a/AudioManagerDaemon/src/CAmRoutingSender.cpp b/AudioManagerDaemon/src/CAmRoutingSender.cpp index 590f6df..5f7f03a 100644 --- a/AudioManagerDaemon/src/CAmRoutingSender.cpp +++ b/AudioManagerDaemon/src/CAmRoutingSender.cpp @@ -22,6 +22,9 @@ #include "CAmRoutingSender.h" #include #include +#include +#include +#include #include #include #include @@ -71,10 +74,23 @@ CAmRoutingSender::CAmRoutingSender(const std::vector& listOfPluginD { unsigned char entryType = itemInDirectory->d_type; std::string entryName = itemInDirectory->d_name; + std::string fullName = *dirIter + "/" + entryName; bool regularFile = (entryType == DT_REG || entryType == DT_LNK); bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); + // Handle cases where readdir() could not determine the file type + if (entryType == DT_UNKNOWN) { + struct stat buf; + + if (stat(fullName.c_str(), &buf)) { + logInfo(__PRETTY_FUNCTION__,"Failed to stat file: ", entryName, errno); + continue; + } + + regularFile = S_ISREG(buf.st_mode); + } + if (regularFile && sharedLibExtension) { logInfo("RoutingSender::RoutingSender adding file: ", entryName); -- cgit v1.2.1