summaryrefslogtreecommitdiffstats
path: root/sandbox/linux
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-17 19:02:35 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-17 19:02:35 +0000
commit42f558fdef03f1ec2261f554151d8a4d168919e4 (patch)
treea2f2403061c945c8983524036bc73550098de6b7 /sandbox/linux
parentcb8d22b096bf5698bcf58725d6e4d7534e235a0a (diff)
downloadchromium_src-42f558fdef03f1ec2261f554151d8a4d168919e4.zip
chromium_src-42f558fdef03f1ec2261f554151d8a4d168919e4.tar.gz
chromium_src-42f558fdef03f1ec2261f554151d8a4d168919e4.tar.bz2
Implement ScopedFD in terms of ScopedGeneric.
Move to a new file base/files/scoped_file.h. I will also add ScopedFILE to here (currently in file_util.h) later. I think there is a crash in the old code in content/browser/zygote_host/zygote_host_impl_linux.cc that this patch should fix. The old ScopedFD took the address of something in a vector that is being modified. I removed SafeScopedFD from content/common/sandbox_linux/sandbox_linux.cc since base's ScopedFD not CHECKs on close failure (this is a more recent addition). Reland of https://codereview.chromium.org/191673003/ R=agl, viettrungluu Review URL: https://codereview.chromium.org/202113004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257473 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox/linux')
-rw-r--r--sandbox/linux/services/broker_process_unittest.cc9
-rw-r--r--sandbox/linux/services/credentials_unittest.cc9
-rw-r--r--sandbox/linux/services/scoped_process_unittest.cc11
-rw-r--r--sandbox/linux/services/yama.cc8
4 files changed, 18 insertions, 19 deletions
diff --git a/sandbox/linux/services/broker_process_unittest.cc b/sandbox/linux/services/broker_process_unittest.cc
index 771790a..7f1a685 100644
--- a/sandbox/linux/services/broker_process_unittest.cc
+++ b/sandbox/linux/services/broker_process_unittest.cc
@@ -17,6 +17,7 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/file_util.h"
+#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/posix/eintr_wrapper.h"
@@ -24,8 +25,6 @@
#include "sandbox/linux/tests/unit_tests.h"
#include "testing/gtest/include/gtest/gtest.h"
-using file_util::ScopedFD;
-
namespace sandbox {
namespace {
@@ -269,7 +268,7 @@ void TestOpenCpuinfo(bool fast_check_in_client) {
int fd = -1;
fd = open_broker->Open(kFileCpuInfo, O_RDWR);
- ScopedFD fd_closer(&fd);
+ base::ScopedFD fd_closer(fd);
ASSERT_EQ(fd, -EPERM);
// Check we can read /proc/cpuinfo.
@@ -281,7 +280,7 @@ void TestOpenCpuinfo(bool fast_check_in_client) {
// Open cpuinfo via the broker.
int cpuinfo_fd = open_broker->Open(kFileCpuInfo, O_RDONLY);
- ScopedFD cpuinfo_fd_closer(&cpuinfo_fd);
+ base::ScopedFD cpuinfo_fd_closer(cpuinfo_fd);
ASSERT_GE(cpuinfo_fd, 0);
char buf[3];
memset(buf, 0, sizeof(buf));
@@ -290,7 +289,7 @@ void TestOpenCpuinfo(bool fast_check_in_client) {
// Open cpuinfo directly.
int cpuinfo_fd2 = open(kFileCpuInfo, O_RDONLY);
- ScopedFD cpuinfo_fd2_closer(&cpuinfo_fd2);
+ base::ScopedFD cpuinfo_fd2_closer(cpuinfo_fd2);
ASSERT_GE(cpuinfo_fd2, 0);
char buf2[3];
memset(buf2, 1, sizeof(buf2));
diff --git a/sandbox/linux/services/credentials_unittest.cc b/sandbox/linux/services/credentials_unittest.cc
index 9b792aa..a54ed04 100644
--- a/sandbox/linux/services/credentials_unittest.cc
+++ b/sandbox/linux/services/credentials_unittest.cc
@@ -12,13 +12,12 @@
#include <unistd.h>
#include "base/file_util.h"
+#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "sandbox/linux/tests/unit_tests.h"
#include "testing/gtest/include/gtest/gtest.h"
-using file_util::ScopedFD;
-
namespace sandbox {
namespace {
@@ -65,7 +64,7 @@ TEST(Credentials, HasOpenDirectory) {
{
// Have a "/dev" file descriptor around.
int dev_fd = open("/dev", O_RDONLY | O_DIRECTORY);
- ScopedFD dev_fd_closer(&dev_fd);
+ base::ScopedFD dev_fd_closer(dev_fd);
EXPECT_TRUE(creds.HasOpenDirectory(-1));
}
EXPECT_FALSE(creds.HasOpenDirectory(-1));
@@ -75,7 +74,7 @@ TEST(Credentials, HasOpenDirectoryWithFD) {
Credentials creds;
int proc_fd = open("/proc", O_RDONLY | O_DIRECTORY);
- ScopedFD proc_fd_closer(&proc_fd);
+ base::ScopedFD proc_fd_closer(proc_fd);
ASSERT_LE(0, proc_fd);
// Don't pass |proc_fd|, an open directory (proc_fd) should
@@ -87,7 +86,7 @@ TEST(Credentials, HasOpenDirectoryWithFD) {
{
// Have a "/dev" file descriptor around.
int dev_fd = open("/dev", O_RDONLY | O_DIRECTORY);
- ScopedFD dev_fd_closer(&dev_fd);
+ base::ScopedFD dev_fd_closer(dev_fd);
EXPECT_TRUE(creds.HasOpenDirectory(proc_fd));
}
diff --git a/sandbox/linux/services/scoped_process_unittest.cc b/sandbox/linux/services/scoped_process_unittest.cc
index 7ae82bf8..2800bd7 100644
--- a/sandbox/linux/services/scoped_process_unittest.cc
+++ b/sandbox/linux/services/scoped_process_unittest.cc
@@ -13,6 +13,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/file_util.h"
+#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
#include "base/threading/platform_thread.h"
@@ -73,13 +74,13 @@ TEST(ScopedProcess, ScopedProcessSignaled) {
TEST(ScopedProcess, DiesForReal) {
int pipe_fds[2];
ASSERT_EQ(0, pipe(pipe_fds));
- file_util::ScopedFDCloser read_end_closer(pipe_fds);
- file_util::ScopedFDCloser write_end_closer(pipe_fds + 1);
+ base::ScopedFD read_end_closer(pipe_fds[0]);
+ base::ScopedFD write_end_closer(pipe_fds[1]);
{ ScopedProcess process(base::Bind(&DoExit)); }
// Close writing end of the pipe.
- ASSERT_EQ(0, IGNORE_EINTR(close(pipe_fds[1])));
+ write_end_closer.reset();
pipe_fds[1] = -1;
ASSERT_EQ(0, fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK));
@@ -108,8 +109,8 @@ void SleepInMsAndWriteOneByte(int time_to_sleep, int fd) {
TEST(ScopedProcess, SynchronizationWorks) {
int pipe_fds[2];
ASSERT_EQ(0, pipe(pipe_fds));
- file_util::ScopedFDCloser read_end_closer(pipe_fds);
- file_util::ScopedFDCloser write_end_closer(pipe_fds + 1);
+ base::ScopedFD read_end_closer(pipe_fds[0]);
+ base::ScopedFD write_end_closer(pipe_fds[1]);
// Start a process with a closure that takes a little bit to run.
ScopedProcess process(
diff --git a/sandbox/linux/services/yama.cc b/sandbox/linux/services/yama.cc
index efb261c..39ac079 100644
--- a/sandbox/linux/services/yama.cc
+++ b/sandbox/linux/services/yama.cc
@@ -12,6 +12,7 @@
#include "base/basictypes.h"
#include "base/file_util.h"
+#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
@@ -78,18 +79,17 @@ int Yama::GetStatus() {
static const char kPtraceScopePath[] = "/proc/sys/kernel/yama/ptrace_scope";
- int yama_scope = open(kPtraceScopePath, O_RDONLY);
+ base::ScopedFD yama_scope(open(kPtraceScopePath, O_RDONLY));
- if (yama_scope < 0) {
+ if (!yama_scope.is_valid()) {
const int open_errno = errno;
DCHECK(ENOENT == open_errno);
// The status is known, yama is not present.
return STATUS_KNOWN;
}
- file_util::ScopedFDCloser yama_scope_closer(&yama_scope);
char yama_scope_value = 0;
- ssize_t num_read = read(yama_scope, &yama_scope_value, 1);
+ ssize_t num_read = read(yama_scope.get(), &yama_scope_value, 1);
PCHECK(1 == num_read);
switch (yama_scope_value) {