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

Unified Diff: base/memory/shared_memory_posix.cc

Issue 197873014: Revert of Implement ScopedFD in terms of ScopedGeneric. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | « base/memory/shared_memory.h ('k') | base/posix/unix_domain_socket_linux_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/shared_memory_posix.cc
diff --git a/base/memory/shared_memory_posix.cc b/base/memory/shared_memory_posix.cc
index 1a90847145b4d688bbd9cfd6ceac510c3da5c4fd..8780c040cc2de72492b5b4e1c1c93456fad1d793 100644
--- a/base/memory/shared_memory_posix.cc
+++ b/base/memory/shared_memory_posix.cc
@@ -30,6 +30,7 @@
#include "third_party/ashmem/ashmem.h"
#endif
+using file_util::ScopedFD;
using file_util::ScopedFILE;
namespace base {
@@ -131,7 +132,8 @@
ScopedFILE fp;
bool fix_size = true;
- ScopedFD readonly_fd;
+ int readonly_fd_storage = -1;
+ ScopedFD readonly_fd(&readonly_fd_storage);
FilePath path;
if (options.name_deprecated == NULL || options.name_deprecated->empty()) {
@@ -143,8 +145,8 @@
if (fp) {
// Also open as readonly so that we can ShareReadOnlyToProcess.
- readonly_fd.reset(HANDLE_EINTR(open(path.value().c_str(), O_RDONLY)));
- if (!readonly_fd.is_valid()) {
+ *readonly_fd = HANDLE_EINTR(open(path.value().c_str(), O_RDONLY));
+ if (*readonly_fd < 0) {
DPLOG(ERROR) << "open(\"" << path.value() << "\", O_RDONLY) failed";
fp.reset();
}
@@ -196,8 +198,8 @@
}
// Also open as readonly so that we can ShareReadOnlyToProcess.
- readonly_fd.reset(HANDLE_EINTR(open(path.value().c_str(), O_RDONLY)));
- if (!readonly_fd.is_valid()) {
+ *readonly_fd = HANDLE_EINTR(open(path.value().c_str(), O_RDONLY));
+ if (*readonly_fd < 0) {
DPLOG(ERROR) << "open(\"" << path.value() << "\", O_RDONLY) failed";
close(fd);
fd = -1;
@@ -263,8 +265,10 @@
const char *mode = read_only ? "r" : "r+";
ScopedFILE fp(base::OpenFile(path, mode));
- ScopedFD readonly_fd(HANDLE_EINTR(open(path.value().c_str(), O_RDONLY)));
- if (!readonly_fd.is_valid()) {
+ int readonly_fd_storage = -1;
+ ScopedFD readonly_fd(&readonly_fd_storage);
+ *readonly_fd = HANDLE_EINTR(open(path.value().c_str(), O_RDONLY));
+ if (*readonly_fd < 0) {
DPLOG(ERROR) << "open(\"" << path.value() << "\", O_RDONLY) failed";
}
return PrepareMapFile(fp.Pass(), readonly_fd.Pass());
@@ -349,7 +353,7 @@
bool SharedMemory::PrepareMapFile(ScopedFILE fp, ScopedFD readonly_fd) {
DCHECK_EQ(-1, mapped_file_);
DCHECK_EQ(-1, readonly_mapped_file_);
- if (fp == NULL || !readonly_fd.is_valid()) return false;
+ if (fp == NULL || *readonly_fd < 0) return false;
// This function theoretically can block on the disk, but realistically
// the temporary files we create will just go into the buffer cache
@@ -360,7 +364,7 @@
struct stat readonly_st = {};
if (fstat(fileno(fp.get()), &st))
NOTREACHED();
- if (fstat(readonly_fd.get(), &readonly_st))
+ if (fstat(*readonly_fd, &readonly_st))
NOTREACHED();
if (st.st_dev != readonly_st.st_dev || st.st_ino != readonly_st.st_ino) {
LOG(ERROR) << "writable and read-only inodes don't match; bailing";
@@ -377,7 +381,7 @@
}
}
inode_ = st.st_ino;
- readonly_mapped_file_ = readonly_fd.release();
+ readonly_mapped_file_ = *readonly_fd.release();
return true;
}
« no previous file with comments | « base/memory/shared_memory.h ('k') | base/posix/unix_domain_socket_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698