]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_mon: use readdir() as readdir_r() is deprecated 11047/head
authorKefu Chai <kchai@redhat.com>
Mon, 12 Sep 2016 03:56:09 +0000 (11:56 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 12 Sep 2016 03:56:11 +0000 (11:56 +0800)
see https://lwn.net/Articles/696469/, readdir_r() is deprecated by glibc
since 2.24. so let's use readdir() instead.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/ceph_mon.cc

index 68b6e371e69460fc2707b48cbf2223c775e48b86..5755827f3ad14a22da1b88961237209bc6ed9b9c 100644 (file)
@@ -137,25 +137,20 @@ int check_mon_data_empty()
     cerr << "opendir(" << mon_data << ") " << cpp_strerror(errno) << std::endl;
     return -errno;
   }
-  char buf[offsetof(struct dirent, d_name) + PATH_MAX + 1];
-
   int code = 0;
-  struct dirent *de;
+  struct dirent *de = nullptr;
   errno = 0;
-  while (!::readdir_r(dir, reinterpret_cast<struct dirent*>(buf), &de)) {
-    if (!de) {
-      if (errno) {
-       cerr << "readdir(" << mon_data << ") " << cpp_strerror(errno) << std::endl;
-       code = -errno;
-      }
-      break;
-    }
+  while ((de = ::readdir(dir))) {
     if (string(".") != de->d_name &&
        string("..") != de->d_name) {
       code = -ENOTEMPTY;
       break;
     }
   }
+  if (!de && errno) {
+    cerr << "readdir(" << mon_data << ") " << cpp_strerror(errno) << std::endl;
+    code = -errno;
+  }
 
   ::closedir(dir);