Add more CLOEXEC-like things.
From missed call sites found during/after code review.
This commit is contained in:
parent
1f02cd30e2
commit
69fb852ee0
|
@ -154,7 +154,7 @@ public:
|
|||
ACTOR static Future<Void> async_fsync_parent( std::string filename ) {
|
||||
std::string folder = parentDirectory( filename );
|
||||
TraceEvent("FSyncParentDir").detail("Folder", folder).detail("File", filename);
|
||||
state int folderFD = ::open( folder.c_str(), O_DIRECTORY, 0 );
|
||||
state int folderFD = ::open( folder.c_str(), O_DIRECTORY | O_CLOEXEC, 0 );
|
||||
if (folderFD<0)
|
||||
throw io_error();
|
||||
try {
|
||||
|
|
|
@ -515,7 +515,7 @@ private:
|
|||
: h(h), diskParameters(diskParameters), delayOnWrite(delayOnWrite), filename(filename), actualFilename(actualFilename), dbgId(g_random->randomUniqueID()), flags(flags) {}
|
||||
|
||||
static int flagConversion( int flags ) {
|
||||
int outFlags = O_BINARY;
|
||||
int outFlags = O_BINARY | O_CLOEXEC;
|
||||
if( flags&OPEN_READWRITE ) outFlags |= O_RDWR;
|
||||
if( flags&OPEN_CREATE ) outFlags |= O_CREAT;
|
||||
if( flags&OPEN_READONLY ) outFlags |= O_RDONLY;
|
||||
|
|
|
@ -483,7 +483,7 @@ bool checkHighMemory(int64_t threshold, bool* error) {
|
|||
#if defined(__linux__) && defined(USE_GPERFTOOLS) && !defined(VALGRIND)
|
||||
*error = false;
|
||||
uint64_t page_size = sysconf(_SC_PAGESIZE);
|
||||
int fd = open("/proc/self/statm", O_RDONLY);
|
||||
int fd = open("/proc/self/statm", O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
TraceEvent("OpenStatmFileFailure");
|
||||
*error = true;
|
||||
|
|
|
@ -1606,7 +1606,7 @@ int getRandomSeed() {
|
|||
}
|
||||
} while (randomSeed == 0 && retryCount < FLOW_KNOBS->RANDOMSEED_RETRY_LIMIT); // randomSeed cannot be 0 since we use mersenne twister in DeterministicRandom. Get a new one if randomSeed is 0.
|
||||
#else
|
||||
int devRandom = open("/dev/urandom", O_RDONLY);
|
||||
int devRandom = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
||||
do {
|
||||
retryCount++;
|
||||
if (read(devRandom, &randomSeed, sizeof(randomSeed)) != sizeof(randomSeed) ) {
|
||||
|
@ -1659,13 +1659,21 @@ void renameFile( std::string const& fromPath, std::string const& toPath ) {
|
|||
throw io_error();
|
||||
}
|
||||
|
||||
#if defined(__linux__)
|
||||
#define FOPEN_CLOEXEC_MODE "e"
|
||||
#elif defined(_WIN32)
|
||||
#define FOPEN_CLOEXEC_MODE "N"
|
||||
#else
|
||||
#define FOPEN_CLOEXEC_MODE ""
|
||||
#endif
|
||||
|
||||
void atomicReplace( std::string const& path, std::string const& content, bool textmode ) {
|
||||
FILE* f = 0;
|
||||
try {
|
||||
INJECT_FAULT( io_error, "atomicReplace" );
|
||||
|
||||
std::string tempfilename = joinPath(parentDirectory(path), g_random->randomUniqueID().toString() + ".tmp");
|
||||
f = textmode ? fopen( tempfilename.c_str(), "wt" ) : fopen(tempfilename.c_str(), "wb");
|
||||
f = textmode ? fopen( tempfilename.c_str(), "wt" FOPEN_CLOEXEC_MODE ) : fopen( tempfilename.c_str(), "wb" FOPEN_CLOEXEC_MODE );
|
||||
if(!f)
|
||||
throw io_error();
|
||||
#ifdef _WIN32
|
||||
|
@ -2206,7 +2214,7 @@ void deprioritizeThread() {
|
|||
}
|
||||
|
||||
bool fileExists(std::string const& filename) {
|
||||
FILE* f = fopen(filename.c_str(), "rb");
|
||||
FILE* f = fopen(filename.c_str(), "rb" FOPEN_CLOEXEC_MODE );
|
||||
if (!f) return false;
|
||||
fclose(f);
|
||||
return true;
|
||||
|
@ -2245,7 +2253,7 @@ int64_t fileSize(std::string const& filename) {
|
|||
|
||||
std::string readFileBytes( std::string const& filename, int maxSize ) {
|
||||
std::string s;
|
||||
FILE* f = fopen(filename.c_str(), "rb");
|
||||
FILE* f = fopen(filename.c_str(), "rb" FOPEN_CLOEXEC_MODE);
|
||||
if (!f) throw file_not_readable();
|
||||
try {
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
@ -2265,7 +2273,7 @@ std::string readFileBytes( std::string const& filename, int maxSize ) {
|
|||
}
|
||||
|
||||
void writeFileBytes(std::string const& filename, const uint8_t* data, size_t count) {
|
||||
FILE* f = fopen(filename.c_str(), "wb");
|
||||
FILE* f = fopen(filename.c_str(), "wb" FOPEN_CLOEXEC_MODE);
|
||||
if (!f)
|
||||
{
|
||||
TraceEvent(SevError, "WriteFileBytes").detail("Filename", filename).GetLastError();
|
||||
|
|
Loading…
Reference in New Issue