summaryrefslogtreecommitdiff
path: root/util/env_posix.cc
diff options
context:
space:
mode:
authorVictor Costan <costan@google.com>2019-05-07 14:19:08 -0700
committerVictor Costan <pwnall@chromium.org>2019-05-07 14:20:31 -0700
commit27dc99fb2642cadc87c9aaec82c54a2c725ee0d6 (patch)
treeb85e39ce73691211f70e44a5c2e6ff1a35817958 /util/env_posix.cc
parent9521545b062841409cf66eff0655feff09d9fd82 (diff)
downloadleveldb-27dc99fb2642cadc87c9aaec82c54a2c725ee0d6.tar.gz
Fix EnvPosix tests on Travis CI.
The previous attempt of having EnvPosix use O_CLOEXEC (close-on-exec()) when opening file descriptors added tests that relied on procfs, which is Linux-specific. These tests failed on macOS. Unfortunately, the test failures were not caught due to a (since fixed) error in our Travis CI configuration. This CL re-structures the tests to only rely on POSIX features. Since there is no POSIX-compliant way to get a file name/path out of a file descriptor, this CL breaks up the O_CLOEXEC test into multiple tests, where each Env method that creates an FD gets its own test. This is intended to make it easier to find and fix errors in Env implementations. This CL also fixes the implementation of NewLogger() to use O_CLOEXEC on macOS. The current implementation passes "we" to fopen(), but the macOS standard C library does not implement the "e" flag yet. PiperOrigin-RevId: 247088953
Diffstat (limited to 'util/env_posix.cc')
-rw-r--r--util/env_posix.cc10
1 files changed, 9 insertions, 1 deletions
diff --git a/util/env_posix.cc b/util/env_posix.cc
index cd0508b..0cfb069 100644
--- a/util/env_posix.cc
+++ b/util/env_posix.cc
@@ -683,8 +683,16 @@ class PosixEnv : public Env {
}
Status NewLogger(const std::string& filename, Logger** result) override {
- std::FILE* fp = std::fopen(filename.c_str(), "we");
+ int fd = ::open(filename.c_str(),
+ O_APPEND | O_WRONLY | O_CREAT | kOpenBaseFlags, 0644);
+ if (fd < 0) {
+ *result = nullptr;
+ return PosixError(filename, errno);
+ }
+
+ std::FILE* fp = ::fdopen(fd, "w");
if (fp == nullptr) {
+ ::close(fd);
*result = nullptr;
return PosixError(filename, errno);
} else {