Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Unified Diff: base/process/process_metrics_linux.cc

Issue 1526253003: Linux: Correctly count the number of open file descriptors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/files/dir_reader_linux.h ('k') | base/process/process_metrics_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_metrics_linux.cc
diff --git a/base/process/process_metrics_linux.cc b/base/process/process_metrics_linux.cc
index 10516a4bdc0bc45af399165a6a9458eb7547181b..4d98772670e4ea045f0d2c731a7d1d89b1fb07f6 100644
--- a/base/process/process_metrics_linux.cc
+++ b/base/process/process_metrics_linux.cc
@@ -12,6 +12,7 @@
#include <unistd.h>
#include <utility>
+#include "base/files/dir_reader_posix.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/process/internal_linux.h"
@@ -291,17 +292,16 @@ int ProcessMetrics::GetOpenFdCount() const {
// Use /proc/<pid>/fd to count the number of entries there.
FilePath fd_path = internal::GetProcPidDir(process_).Append("fd");
- DIR* dir = opendir(fd_path.value().c_str());
- if (!dir) {
- DPLOG(ERROR) << "opendir(" << fd_path.value() << ")";
+ DirReaderPosix dir_reader(fd_path.value().c_str());
+ if (!dir_reader.IsValid())
return -1;
- }
int total_count = 0;
- while (readdir(dir))
- ++total_count;
-
- closedir(dir);
+ for (; dir_reader.Next(); ) {
+ const char* name = dir_reader.name();
+ if (strcmp(name, ".") != 0 && strcmp(name, "..") != 0)
+ ++total_count;
+ }
return total_count;
}
« no previous file with comments | « base/files/dir_reader_linux.h ('k') | base/process/process_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698