/* Find all .so files and store their names in list */
DIR *dir;
- struct dirent *entry;
struct stat st;
LogDebug("Opening plugins directory");
dir = opendir(m_npsource.c_str());
ThrowMsg(Exceptions::InternalError, "Unable to read plugins directory");
}
std::string tempname;
+ struct dirent entry;
+ struct dirent *result;
+ int return_code;
+ errno = 0;
const std::string ext(".so");
/* Listing directory and checking entries found inside */
- while ((entry = readdir(dir)) != NULL) {
- tempname = m_npsource + "/" + entry->d_name;
+ for (return_code = readdir_r(dir, &entry, &result);
+ result != NULL && return_code == 0;
+ return_code = readdir_r(dir, &entry, &result))
+ {
+ tempname = m_npsource + "/" + entry.d_name;
if (lstat(tempname.c_str(), &st) != 0) {
LogWarning(
"Failed to call \"lstat\" (errno:" << errno
}
/* Directories other than "." and ".." should not be found*/
if (S_ISDIR(st.st_mode)) {
- if (strncmp(entry->d_name, "..", 2) != 0
- && strncmp(entry->d_name, ".", 1) != 0)
+ if (strncmp(entry.d_name, "..", 2) != 0
+ && strncmp(entry.d_name, ".", 1) != 0)
{
LogError("Directory detected instead of plugin file: "
- << entry->d_name);
+ << entry.d_name);
/* Subdirectories inside plugins/ARCH are not supported */
if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
LogError(
}
}
- tempname = std::string(entry->d_name);
+ tempname = std::string(entry.d_name);
/* Check whether file extension is ".so" */
if (tempname.compare(tempname.size() - ext.size(), ext.size(),
ext) == 0)
LogWarning("Non-plugin file found: " << tempname);
}
}
+ if (return_code != 0 || errno != 0) {
+ LogError("readdir_r() failed with " << DPL::GetErrnoString());
+ }
+ errno = 0;
if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
LogError("Failed to close dir: " << m_npsource << " with error: "
<< DPL::GetErrnoString());
/* Copy plugins from widget package into
* .netscape/plugins in widget's target directory */
for (std::list<std::string>::const_iterator it = m_nplugins.begin();
- it != m_nplugins.end(); it++)
+ it != m_nplugins.end(); ++it)
{
LogDebug("Copying plugin file: " << (*it));
source = m_npsource + "/" + (*it);