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

Unified Diff: sandbox/linux/services/proc_util.cc

Issue 938223004: Linux sandbox: better APIs with /proc/ arguments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix invalid proc_fd_ usage. Created 5 years, 10 months 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 | « sandbox/linux/services/proc_util.h ('k') | sandbox/linux/services/proc_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/services/proc_util.cc
diff --git a/sandbox/linux/services/proc_util.cc b/sandbox/linux/services/proc_util.cc
index 13d8842f788b453393f7ca802e2f3c0b6d2110a1..d3f755f9a1d72740757c8336808470aacf4bbe89 100644
--- a/sandbox/linux/services/proc_util.cc
+++ b/sandbox/linux/services/proc_util.cc
@@ -28,12 +28,20 @@ struct DIRCloser {
typedef scoped_ptr<DIR, DIRCloser> ScopedDIR;
+base::ScopedFD OpenDirectory(const char* path) {
+ DCHECK(path);
+ base::ScopedFD directory_fd(
+ HANDLE_EINTR(open(path, O_RDONLY | O_DIRECTORY | O_CLOEXEC)));
+ PCHECK(directory_fd.is_valid());
+ return directory_fd.Pass();
+}
+
} // namespace
int ProcUtil::CountOpenFds(int proc_fd) {
DCHECK_LE(0, proc_fd);
int proc_self_fd = HANDLE_EINTR(
- openat(proc_fd, "self/fd", O_DIRECTORY | O_RDONLY | O_CLOEXEC));
+ openat(proc_fd, "self/fd/", O_DIRECTORY | O_RDONLY | O_CLOEXEC));
PCHECK(0 <= proc_self_fd);
// Ownership of proc_self_fd is transferred here, it must not be closed
@@ -61,24 +69,10 @@ int ProcUtil::CountOpenFds(int proc_fd) {
}
bool ProcUtil::HasOpenDirectory(int proc_fd) {
- int proc_self_fd = -1;
- if (proc_fd >= 0) {
- proc_self_fd = openat(proc_fd, "self/fd", O_DIRECTORY | O_RDONLY);
- } else {
- proc_self_fd = openat(AT_FDCWD, "/proc/self/fd", O_DIRECTORY | O_RDONLY);
- if (proc_self_fd < 0) {
- // If this process has been chrooted (eg into /proc/self/fdinfo) then
- // the new root dir will not have directory listing permissions for us
- // (hence EACCES). And if we do have this permission, then /proc won't
- // exist anyway (hence ENOENT).
- DPCHECK(errno == EACCES || errno == ENOENT)
- << "Unexpected failure when trying to open /proc/self/fd: ("
- << errno << ") " << strerror(errno);
-
- // If not available, guess false.
- return false;
- }
- }
+ DCHECK_LE(0, proc_fd);
+ int proc_self_fd =
+ openat(proc_fd, "self/fd/", O_DIRECTORY | O_RDONLY | O_CLOEXEC);
+
PCHECK(0 <= proc_self_fd);
// Ownership of proc_self_fd is transferred here, it must not be closed
@@ -111,13 +105,15 @@ bool ProcUtil::HasOpenDirectory(int proc_fd) {
return false;
}
+bool ProcUtil::HasOpenDirectory() {
+ base::ScopedFD proc_fd(
+ HANDLE_EINTR(open("/proc/", O_DIRECTORY | O_RDONLY | O_CLOEXEC)));
+ return HasOpenDirectory(proc_fd.get());
+}
+
//static
-base::ScopedFD ProcUtil::OpenProcSelfTask() {
- base::ScopedFD proc_self_task(
- HANDLE_EINTR(
- open("/proc/self/task/", O_RDONLY | O_DIRECTORY | O_CLOEXEC)));
- PCHECK(proc_self_task.is_valid());
- return proc_self_task.Pass();
+base::ScopedFD ProcUtil::OpenProc() {
+ return OpenDirectory("/proc/");
}
} // namespace sandbox
« no previous file with comments | « sandbox/linux/services/proc_util.h ('k') | sandbox/linux/services/proc_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698