]> granicus.if.org Git - icinga2/commitdiff
Fix incorrect usage of readdir_r
authorJan Andres <jan.andres@berenberg.de>
Mon, 4 Aug 2014 06:46:14 +0000 (08:46 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 4 Aug 2014 06:49:04 +0000 (08:49 +0200)
refs #6821

Signed-off-by: Gunnar Beutner <gunnar.beutner@netways.de>
lib/base/utility.cpp

index dfb31808ace7e691b92688d419c7b49175934928..aa804414a39a3c1350ccab9cb6536150cff7d4f9 100644 (file)
@@ -545,13 +545,15 @@ bool Utility::GlobRecursive(const String& path, const String& pattern, const boo
                    << boost::errinfo_file_name(path));
 
        while (dirp) {
-               dirent ent, *pent;
+               dirent *pent;
 
-               if (readdir_r(dirp, &ent, &pent) < 0) {
+               errno = 0;
+               pent = readdir(dirp);
+               if (!pent && errno != 0) {
                        closedir(dirp);
 
                        BOOST_THROW_EXCEPTION(posix_error()
-                           << boost::errinfo_api_function("readdir_r")
+                           << boost::errinfo_api_function("readdir")
                            << boost::errinfo_errno(errno)
                            << boost::errinfo_file_name(path));
                }
@@ -559,10 +561,10 @@ bool Utility::GlobRecursive(const String& path, const String& pattern, const boo
                if (!pent)
                        break;
 
-               if (strcmp(ent.d_name, ".") == 0 || strcmp(ent.d_name, "..") == 0)
+               if (strcmp(pent->d_name, ".") == 0 || strcmp(pent->d_name, "..") == 0)
                        continue;
 
-               String cpath = path + "/" + ent.d_name;
+               String cpath = path + "/" + pent->d_name;
 
                struct stat statbuf;
 
@@ -572,7 +574,7 @@ bool Utility::GlobRecursive(const String& path, const String& pattern, const boo
                if (S_ISDIR(statbuf.st_mode))
                        alldirs.push_back(cpath);
 
-               if (!Utility::Match(pattern, ent.d_name))
+               if (!Utility::Match(pattern, pent->d_name))
                        continue;
 
                if (S_ISDIR(statbuf.st_mode) && (type & GlobDirectory))