Index: sandbox/linux/services/proc_util.cc |
diff --git a/sandbox/linux/services/proc_util.cc b/sandbox/linux/services/proc_util.cc |
index b6d58de56489f7f0a92984ee079c623c7cdfabc6..73f8daa5c0eedb9bd354eb564220fac3af006c49 100644 |
--- a/sandbox/linux/services/proc_util.cc |
+++ b/sandbox/linux/services/proc_util.cc |
@@ -51,15 +51,13 @@ int ProcUtil::CountOpenFds(int proc_fd) { |
CHECK(dir); |
int count = 0; |
- struct dirent e; |
- struct dirent* de; |
- while (!readdir_r(dir.get(), &e, &de) && de) { |
- if (strcmp(e.d_name, ".") == 0 || strcmp(e.d_name, "..") == 0) { |
+ for (struct dirent* e = readdir(dir.get()); e; e = readdir(dir.get())) { |
Jorge Lucangeli Obes
2016/10/19 15:50:16
Are these calls to readdir guaranteed to not race
dcheng
2016/10/19 22:11:39
My understanding (and the condition on which I LGT
|
+ if (strcmp(e->d_name, ".") == 0 || strcmp(e->d_name, "..") == 0) { |
continue; |
} |
int fd_num; |
- CHECK(base::StringToInt(e.d_name, &fd_num)); |
+ CHECK(base::StringToInt(e->d_name, &fd_num)); |
if (fd_num == proc_fd || fd_num == proc_self_fd) { |
continue; |
} |
@@ -81,22 +79,20 @@ bool ProcUtil::HasOpenDirectory(int proc_fd) { |
ScopedDIR dir(fdopendir(proc_self_fd)); |
CHECK(dir); |
- struct dirent e; |
- struct dirent* de; |
- while (!readdir_r(dir.get(), &e, &de) && de) { |
- if (strcmp(e.d_name, ".") == 0 || strcmp(e.d_name, "..") == 0) { |
+ for (struct dirent *e = readdir(dir.get()); e; e = readdir(dir.get())) { |
+ if (strcmp(e->d_name, ".") == 0 || strcmp(e->d_name, "..") == 0) { |
continue; |
} |
int fd_num; |
- CHECK(base::StringToInt(e.d_name, &fd_num)); |
+ CHECK(base::StringToInt(e->d_name, &fd_num)); |
if (fd_num == proc_fd || fd_num == proc_self_fd) { |
continue; |
} |
struct stat s; |
// It's OK to use proc_self_fd here, fstatat won't modify it. |
- CHECK(fstatat(proc_self_fd, e.d_name, &s, 0) == 0); |
+ CHECK(fstatat(proc_self_fd, e->d_name, &s, 0) == 0); |
if (S_ISDIR(s.st_mode)) { |
return true; |
} |