@ -48,6 +48,13 @@ constexpr const int kDefaultMmapLimit = (sizeof(void*) >= 8) ? 1000 : 0;
// Can be set using EnvPosixTestHelper::SetReadOnlyMMapLimit.
// Can be set using EnvPosixTestHelper::SetReadOnlyMMapLimit.
int g_mmap_limit = kDefaultMmapLimit ;
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 ;
constexpr const size_t kWritableFileBufferSize = 65536 ;
Status PosixError ( const std : : string & context , int error_number ) {
Status PosixError ( const std : : string & context , int error_number ) {
@ -168,7 +175,7 @@ class PosixRandomAccessFile final : public RandomAccessFile {
char * scratch ) const override {
char * scratch ) const override {
int fd = fd_ ;
int fd = fd_ ;
if ( ! has_permanent_fd_ ) {
if ( ! has_permanent_fd_ ) {
fd = : : open ( filename_ . c_str ( ) , O_RDONLY ) ;
fd = : : open ( filename_ . c_str ( ) , O_RDONLY | O_FLAGS ) ;
if ( fd < 0 ) {
if ( fd < 0 ) {
return PosixError ( filename_ , errno ) ;
return PosixError ( filename_ , errno ) ;
}
}
@ -343,7 +350,7 @@ class PosixWritableFile final : public WritableFile {
return status ;
return status ;
}
}
int fd = : : open ( dirname_ . c_str ( ) , O_RDONLY ) ;
int fd = : : open ( dirname_ . c_str ( ) , O_RDONLY | O_FLAGS ) ;
if ( fd < 0 ) {
if ( fd < 0 ) {
status = PosixError ( dirname_ , errno ) ;
status = PosixError ( dirname_ , errno ) ;
} else {
} else {
@ -491,7 +498,7 @@ class PosixEnv : public Env {
Status NewSequentialFile ( const std : : string & filename ,
Status NewSequentialFile ( const std : : string & filename ,
SequentialFile * * result ) override {
SequentialFile * * result ) override {
int fd = : : open ( filename . c_str ( ) , O_RDONLY ) ;
int fd = : : open ( filename . c_str ( ) , O_RDONLY | O_FLAGS ) ;
if ( fd < 0 ) {
if ( fd < 0 ) {
* result = nullptr ;
* result = nullptr ;
return PosixError ( filename , errno ) ;
return PosixError ( filename , errno ) ;
@ -504,7 +511,7 @@ class PosixEnv : public Env {
Status NewRandomAccessFile ( const std : : string & filename ,
Status NewRandomAccessFile ( const std : : string & filename ,
RandomAccessFile * * result ) override {
RandomAccessFile * * result ) override {
* result = nullptr ;
* result = nullptr ;
int fd = : : open ( filename . c_str ( ) , O_RDONLY ) ;
int fd = : : open ( filename . c_str ( ) , O_RDONLY | O_FLAGS ) ;
if ( fd < 0 ) {
if ( fd < 0 ) {
return PosixError ( filename , errno ) ;
return PosixError ( filename , errno ) ;
}
}
@ -536,7 +543,9 @@ class PosixEnv : public Env {
Status NewWritableFile ( const std : : string & filename ,
Status NewWritableFile ( const std : : string & filename ,
WritableFile * * result ) override {
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 ) {
if ( fd < 0 ) {
* result = nullptr ;
* result = nullptr ;
return PosixError ( filename , errno ) ;
return PosixError ( filename , errno ) ;
@ -548,7 +557,9 @@ class PosixEnv : public Env {
Status NewAppendableFile ( const std : : string & filename ,
Status NewAppendableFile ( const std : : string & filename ,
WritableFile * * result ) override {
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 ) {
if ( fd < 0 ) {
* result = nullptr ;
* result = nullptr ;
return PosixError ( filename , errno ) ;
return PosixError ( filename , errno ) ;
@ -618,7 +629,7 @@ class PosixEnv : public Env {
Status LockFile ( const std : : string & filename , FileLock * * lock ) override {
Status LockFile ( const std : : string & filename , FileLock * * lock ) override {
* lock = nullptr ;
* 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 ) {
if ( fd < 0 ) {
return PosixError ( filename , errno ) ;
return PosixError ( filename , errno ) ;
}
}
@ -674,7 +685,7 @@ class PosixEnv : public Env {
}
}
Status NewLogger ( const std : : string & filename , Logger * * result ) override {
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 ) {
if ( fp = = nullptr ) {
* result = nullptr ;
* result = nullptr ;
return PosixError ( filename , errno ) ;
return PosixError ( filename , errno ) ;