aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2022-02-21 12:42:42 +0100
committerMartin Ridgers <[email protected]>2022-02-21 12:42:42 +0100
commitcea930e12929859608c102a378c01c209b523688 (patch)
tree1fc44e5cf629529aa9f0c6e413cc8efc9236d6a9
parentValue propagation fix - Read/Write ValueAPI as CompressedBinary type when wri... (diff)
downloadzen-cea930e12929859608c102a378c01c209b523688.tar.xz
zen-cea930e12929859608c102a378c01c209b523688.zip
Marked a few file descriptors to be closed on execute (POSIX)
-rw-r--r--zen/internalfile.cpp2
-rw-r--r--zencore/thread.cpp4
-rw-r--r--zenstore/basicfile.cpp4
-rw-r--r--zenstore/filecas.cpp2
-rw-r--r--zenutil/zenserverprocess.cpp4
5 files changed, 8 insertions, 8 deletions
diff --git a/zen/internalfile.cpp b/zen/internalfile.cpp
index 804375ce2..8f1ca5c03 100644
--- a/zen/internalfile.cpp
+++ b/zen/internalfile.cpp
@@ -179,7 +179,7 @@ InternalFile::OpenWrite(std::filesystem::path FileName, bool IsCreate)
HRESULT hRes = m_File.Create(FileName.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, dwCreationDisposition);
Success = SUCCEEDED(hRes);
#else
- int OpenFlags = O_RDWR;
+ int OpenFlags = O_RDWR | O_CLOEXEC;
OpenFlags |= IsCreate ? O_CREAT | O_TRUNC : 0;
int Fd = open(FileName.c_str(), OpenFlags, 0666);
diff --git a/zencore/thread.cpp b/zencore/thread.cpp
index 33ea3e95d..313f253f1 100644
--- a/zencore/thread.cpp
+++ b/zencore/thread.cpp
@@ -270,7 +270,7 @@ NamedEvent::NamedEvent(std::string_view EventName)
ExtendableStringBuilder<64> EventPath;
EventPath << "/tmp/" << EventName;
- int Fd = open(EventPath.c_str(), O_RDWR | O_CREAT, 0666);
+ int Fd = open(EventPath.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0666);
if (Fd < 0)
{
ThrowLastError(fmt::format("Failed to create '{}' for named event", EventPath));
@@ -489,7 +489,7 @@ NamedMutex::Exists(std::string_view MutexName)
Name << "/tmp/" << MutexName;
bool bExists = false;
- int Fd = open(Name.c_str(), O_RDWR, 0666);
+ int Fd = open(Name.c_str(), O_RDWR | O_CLOEXEC, 0666);
if (Fd >= 0)
{
if (flock(Fd, LOCK_EX | LOCK_NB) == 0)
diff --git a/zenstore/basicfile.cpp b/zenstore/basicfile.cpp
index dcd9a8575..038d83493 100644
--- a/zenstore/basicfile.cpp
+++ b/zenstore/basicfile.cpp
@@ -72,7 +72,7 @@ BasicFile::Open(std::filesystem::path FileName, bool IsCreate, std::error_code&
return;
}
#else
- int OpenFlags = O_RDWR;
+ int OpenFlags = O_RDWR | O_CLOEXEC;
OpenFlags |= IsCreate ? O_CREAT | O_TRUNC : 0;
int Fd = open(FileName.c_str(), OpenFlags, 0666);
@@ -366,7 +366,7 @@ LockFile::Create(std::filesystem::path FileName, CbObject Payload, std::error_co
return;
}
#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
- int Fd = open(FileName.c_str(), O_RDWR | O_CREAT, 0666);
+ int Fd = open(FileName.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0666);
if (Fd < 0)
{
Ec = zen::MakeErrorCodeFromLastError();
diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp
index 6c137e128..f2f4465cc 100644
--- a/zenstore/filecas.cpp
+++ b/zenstore/filecas.cpp
@@ -388,7 +388,7 @@ FileCasStrategy::InsertChunk(const void* const ChunkData, const size_t ChunkSize
}
#else
// Attempt to exclusively create the file.
- auto InternalCreateFile = [&] { return open(Name.ShardedPath.c_str(), O_WRONLY | O_CREAT | O_EXCL, 0666); };
+ auto InternalCreateFile = [&] { return open(Name.ShardedPath.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0666); };
int Fd = InternalCreateFile();
if (Fd < 0)
{
diff --git a/zenutil/zenserverprocess.cpp b/zenutil/zenserverprocess.cpp
index 531b3c68a..08ebb21b0 100644
--- a/zenutil/zenserverprocess.cpp
+++ b/zenutil/zenserverprocess.cpp
@@ -159,7 +159,7 @@ ZenServerState::Initialize()
ThrowLastError("Could not map view of Zen server state");
}
#else
- int Fd = shm_open("/UnrealEngineZen", O_RDWR | O_CREAT, 0666);
+ int Fd = shm_open("/UnrealEngineZen", O_RDWR | O_CREAT | O_CLOEXEC, 0666);
if (Fd < 0)
{
ThrowLastError("Could not open a shared memory object");
@@ -209,7 +209,7 @@ ZenServerState::InitializeReadOnly()
ThrowLastError("Could not map view of Zen server state");
}
#else
- int Fd = shm_open("/UnrealEngineZen", O_RDONLY, 0666);
+ int Fd = shm_open("/UnrealEngineZen", O_RDONLY | O_CLOEXEC, 0666);
if (Fd < 0)
{
return false;