summaryrefslogtreecommitdiff
path: root/util/env_posix.cc
diff options
context:
space:
mode:
Diffstat (limited to 'util/env_posix.cc')
-rw-r--r--util/env_posix.cc27
1 files changed, 19 insertions, 8 deletions
diff --git a/util/env_posix.cc b/util/env_posix.cc
index 362adb3..7a0f04d 100644
--- a/util/env_posix.cc
+++ b/util/env_posix.cc
@@ -48,6 +48,13 @@ constexpr const int kDefaultMmapLimit = (sizeof(void*) >= 8) ? 1000 : 0;
// Can be set using EnvPosixTestHelper::SetReadOnlyMMapLimit.
int g_mmap_limit = kDefaultMmapLimit;
+// Common flags defined for all posix open operations
+#if defined(HAVE_O_CLOEXEC)
+constexpr const int O_FLAGS = O_CLOEXEC;
+#else
+constexpr const int O_FLAGS = 0;
+#endif // defined(HAVE_O_CLOEXEC)
+
constexpr const size_t kWritableFileBufferSize = 65536;
Status PosixError(const std::string& context, int error_number) {
@@ -168,7 +175,7 @@ class PosixRandomAccessFile final : public RandomAccessFile {
char* scratch) const override {
int fd = fd_;
if (!has_permanent_fd_) {
- fd = ::open(filename_.c_str(), O_RDONLY);
+ fd = ::open(filename_.c_str(), O_RDONLY | O_FLAGS);
if (fd < 0) {
return PosixError(filename_, errno);
}
@@ -343,7 +350,7 @@ class PosixWritableFile final : public WritableFile {
return status;
}
- int fd = ::open(dirname_.c_str(), O_RDONLY);
+ int fd = ::open(dirname_.c_str(), O_RDONLY | O_FLAGS);
if (fd < 0) {
status = PosixError(dirname_, errno);
} else {
@@ -491,7 +498,7 @@ class PosixEnv : public Env {
Status NewSequentialFile(const std::string& filename,
SequentialFile** result) override {
- int fd = ::open(filename.c_str(), O_RDONLY);
+ int fd = ::open(filename.c_str(), O_RDONLY | O_FLAGS);
if (fd < 0) {
*result = nullptr;
return PosixError(filename, errno);
@@ -504,7 +511,7 @@ class PosixEnv : public Env {
Status NewRandomAccessFile(const std::string& filename,
RandomAccessFile** result) override {
*result = nullptr;
- int fd = ::open(filename.c_str(), O_RDONLY);
+ int fd = ::open(filename.c_str(), O_RDONLY | O_FLAGS);
if (fd < 0) {
return PosixError(filename, errno);
}
@@ -536,7 +543,9 @@ class PosixEnv : public Env {
Status NewWritableFile(const std::string& filename,
WritableFile** result) override {
- int fd = ::open(filename.c_str(), O_TRUNC | O_WRONLY | O_CREAT, 0644);
+ int fd = ::open(filename.c_str(),
+ O_TRUNC | O_WRONLY | O_CREAT | O_FLAGS,
+ 0644);
if (fd < 0) {
*result = nullptr;
return PosixError(filename, errno);
@@ -548,7 +557,9 @@ class PosixEnv : public Env {
Status NewAppendableFile(const std::string& filename,
WritableFile** result) override {
- int fd = ::open(filename.c_str(), O_APPEND | O_WRONLY | O_CREAT, 0644);
+ int fd = ::open(filename.c_str(),
+ O_APPEND | O_WRONLY | O_CREAT | O_FLAGS,
+ 0644);
if (fd < 0) {
*result = nullptr;
return PosixError(filename, errno);
@@ -618,7 +629,7 @@ class PosixEnv : public Env {
Status LockFile(const std::string& filename, FileLock** lock) override {
*lock = nullptr;
- int fd = ::open(filename.c_str(), O_RDWR | O_CREAT, 0644);
+ int fd = ::open(filename.c_str(), O_RDWR | O_CREAT | O_FLAGS, 0644);
if (fd < 0) {
return PosixError(filename, errno);
}
@@ -674,7 +685,7 @@ class PosixEnv : public Env {
}
Status NewLogger(const std::string& filename, Logger** result) override {
- std::FILE* fp = std::fopen(filename.c_str(), "w");
+ std::FILE* fp = std::fopen(filename.c_str(), "we");
if (fp == nullptr) {
*result = nullptr;
return PosixError(filename, errno);