diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/zencore/filesystem.cpp | 3 | ||||
| -rw-r--r-- | src/zenutil/zenserverprocess.cpp | 14 |
2 files changed, 11 insertions, 6 deletions
diff --git a/src/zencore/filesystem.cpp b/src/zencore/filesystem.cpp index 70d0f32b3..debe51cc9 100644 --- a/src/zencore/filesystem.cpp +++ b/src/zencore/filesystem.cpp @@ -3462,11 +3462,12 @@ public: ZEN_UNUSED(SystemGlobal); std::string InstanceMapName = fmt::format("/{}", Name); - ScopedFd FdGuard(shm_open(InstanceMapName.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0666)); + ScopedFd FdGuard(shm_open(InstanceMapName.c_str(), O_RDWR | O_CREAT, 0666)); if (!FdGuard) { return {}; } + fcntl(FdGuard.Fd, F_SETFD, FD_CLOEXEC); fchmod(FdGuard.Fd, 0666); int Result = ftruncate(FdGuard.Fd, Size); diff --git a/src/zenutil/zenserverprocess.cpp b/src/zenutil/zenserverprocess.cpp index 9a282a848..20208e136 100644 --- a/src/zenutil/zenserverprocess.cpp +++ b/src/zenutil/zenserverprocess.cpp @@ -181,7 +181,7 @@ ZenServerState::Initialize() ThrowLastError("Could not map view of Zen server state"); } #else - int Fd = shm_open("/UnrealEngineZen", O_RDWR | O_CREAT | O_CLOEXEC, geteuid() == 0 ? 0766 : 0666); + int Fd = shm_open("/UnrealEngineZen", O_RDWR | O_CREAT, geteuid() == 0 ? 0766 : 0666); if (Fd < 0) { // Work around a potential issue if the service user is changed in certain configurations. @@ -191,12 +191,13 @@ ZenServerState::Initialize() // shared memory object and retry, we'll be able to get past shm_open() so long as we have // the appropriate permissions to create the shared memory object. shm_unlink("/UnrealEngineZen"); - Fd = shm_open("/UnrealEngineZen", O_RDWR | O_CREAT | O_CLOEXEC, geteuid() == 0 ? 0766 : 0666); + Fd = shm_open("/UnrealEngineZen", O_RDWR | O_CREAT, geteuid() == 0 ? 0766 : 0666); if (Fd < 0) { ThrowLastError("Could not open a shared memory object"); } } + fcntl(FdGuard.Fd, F_SETFD, FD_CLOEXEC); fchmod(Fd, 0666); void* hMap = (void*)intptr_t(Fd); @@ -244,11 +245,12 @@ ZenServerState::InitializeReadOnly() ThrowLastError("Could not map view of Zen server state"); } #else - int Fd = shm_open("/UnrealEngineZen", O_RDONLY | O_CLOEXEC, 0666); + int Fd = shm_open("/UnrealEngineZen", O_RDONLY, 0666); if (Fd < 0) { return false; } + fcntl(Fd, F_SETFD, FD_CLOEXEC); void* hMap = (void*)intptr_t(Fd); void* pBuf = mmap(nullptr, MapSize, PROT_READ, MAP_SHARED, Fd, 0); @@ -651,11 +653,12 @@ ZenServerInstanceInfo::Create(const Oid& SessionId, const InstanceInfoData& Data ThrowLastError("Could not map instance info shared memory"); } #else - int Fd = shm_open(Name.c_str(), O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0666); + int Fd = shm_open(Name.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0666); if (Fd < 0) { ThrowLastError("Could not create instance info shared memory"); } + fcntl(FdGuard.Fd, F_SETFD, FD_CLOEXEC); fchmod(Fd, 0666); if (ftruncate(Fd, kInstanceInfoSize) < 0) @@ -718,11 +721,12 @@ ZenServerInstanceInfo::OpenReadOnly(const Oid& SessionId) return false; } #else - int Fd = shm_open(Name.c_str(), O_RDONLY | O_CLOEXEC, 0666); + int Fd = shm_open(Name.c_str(), O_RDONLY, 0666); if (Fd < 0) { return false; } + fcntl(FdGuard.Fd, F_SETFD, FD_CLOEXEC); void* pBuf = mmap(nullptr, kInstanceInfoSize, PROT_READ, MAP_SHARED, Fd, 0); if (pBuf == MAP_FAILED) |