[Release] wrt-installer_0.1.9
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_plugins_copy.cpp
index 1b6d02e..bf295ea 100644 (file)
@@ -85,7 +85,6 @@ void TaskPluginsCopy::StepFindPlugins()
 
     /* 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());
@@ -94,10 +93,17 @@ void TaskPluginsCopy::StepFindPlugins()
         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
@@ -107,11 +113,11 @@ void TaskPluginsCopy::StepFindPlugins()
         }
         /* 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(
@@ -127,7 +133,7 @@ void TaskPluginsCopy::StepFindPlugins()
             }
         }
 
-        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)
@@ -140,6 +146,10 @@ void TaskPluginsCopy::StepFindPlugins()
             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());
@@ -171,7 +181,7 @@ void TaskPluginsCopy::StepCopyPlugins()
     /* 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);