@ -605,6 +605,12 @@ class PosixEnv : public Env {
exit ( 1 ) ;
exit ( 1 ) ;
}
}
void SetFD_CLOEXEC ( int fd , const EnvOptions * options ) {
if ( ( options = = nullptr | | options - > IsFDCloseOnExec ( ) ) & & fd > 0 ) {
fcntl ( fd , F_SETFD , fcntl ( fd , F_GETFD ) | FD_CLOEXEC ) ;
}
}
virtual Status NewSequentialFile ( const std : : string & fname ,
virtual Status NewSequentialFile ( const std : : string & fname ,
unique_ptr < SequentialFile > * result ,
unique_ptr < SequentialFile > * result ,
const EnvOptions & options ) {
const EnvOptions & options ) {
@ -614,6 +620,8 @@ class PosixEnv : public Env {
* result = nullptr ;
* result = nullptr ;
return IOError ( fname , errno ) ;
return IOError ( fname , errno ) ;
} else {
} else {
int fd = fileno ( f ) ;
SetFD_CLOEXEC ( fd , & options ) ;
result - > reset ( new PosixSequentialFile ( fname , f , options ) ) ;
result - > reset ( new PosixSequentialFile ( fname , f , options ) ) ;
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}
@ -625,6 +633,7 @@ class PosixEnv : public Env {
result - > reset ( ) ;
result - > reset ( ) ;
Status s ;
Status s ;
int fd = open ( fname . c_str ( ) , O_RDONLY ) ;
int fd = open ( fname . c_str ( ) , O_RDONLY ) ;
SetFD_CLOEXEC ( fd , & options ) ;
if ( fd < 0 ) {
if ( fd < 0 ) {
s = IOError ( fname , errno ) ;
s = IOError ( fname , errno ) ;
} else if ( options . UseMmapReads ( ) & & sizeof ( void * ) > = 8 ) {
} else if ( options . UseMmapReads ( ) & & sizeof ( void * ) > = 8 ) {
@ -657,6 +666,7 @@ class PosixEnv : public Env {
if ( fd < 0 ) {
if ( fd < 0 ) {
s = IOError ( fname , errno ) ;
s = IOError ( fname , errno ) ;
} else {
} else {
SetFD_CLOEXEC ( fd , & options ) ;
if ( options . UseMmapWrites ( ) ) {
if ( options . UseMmapWrites ( ) ) {
if ( ! checkedDiskForMmap_ ) {
if ( ! checkedDiskForMmap_ ) {
// this will be executed once in the program's lifetime.
// this will be executed once in the program's lifetime.
@ -772,6 +782,7 @@ class PosixEnv : public Env {
result = IOError ( " lock " + fname , errno ) ;
result = IOError ( " lock " + fname , errno ) ;
close ( fd ) ;
close ( fd ) ;
} else {
} else {
SetFD_CLOEXEC ( fd , nullptr ) ;
PosixFileLock * my_lock = new PosixFileLock ;
PosixFileLock * my_lock = new PosixFileLock ;
my_lock - > fd_ = fd ;
my_lock - > fd_ = fd ;
my_lock - > filename = fname ;
my_lock - > filename = fname ;
@ -823,6 +834,8 @@ class PosixEnv : public Env {
result - > reset ( ) ;
result - > reset ( ) ;
return IOError ( fname , errno ) ;
return IOError ( fname , errno ) ;
} else {
} else {
int fd = fileno ( f ) ;
SetFD_CLOEXEC ( fd , nullptr ) ;
result - > reset ( new PosixLogger ( f , & PosixEnv : : gettid ) ) ;
result - > reset ( new PosixLogger ( f , & PosixEnv : : gettid ) ) ;
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}