aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil/zenserverprocess.cpp
diff options
context:
space:
mode:
authorLiam Mitchell <[email protected]>2025-07-26 00:01:13 +0000
committerLiam Mitchell <[email protected]>2025-07-26 00:01:13 +0000
commit10f6dc559688a650617b2e74eec039409f3d4687 (patch)
tree551160a329487d4d45cd7aa1c39ece4a4e41bee0 /src/zenutil/zenserverprocess.cpp
parentUpload vcpkg logs as artifacts on failure (diff)
parentFix naming of service handle close guard variable (diff)
downloadzen-10f6dc559688a650617b2e74eec039409f3d4687.tar.xz
zen-10f6dc559688a650617b2e74eec039409f3d4687.zip
Merge branch 'de/zen-service-command' of https://github.ol.epicgames.net/ue-foundation/zen into de/zen-service-command
Diffstat (limited to 'src/zenutil/zenserverprocess.cpp')
-rw-r--r--src/zenutil/zenserverprocess.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/zenutil/zenserverprocess.cpp b/src/zenutil/zenserverprocess.cpp
index b36f11741..0409cb976 100644
--- a/src/zenutil/zenserverprocess.cpp
+++ b/src/zenutil/zenserverprocess.cpp
@@ -167,10 +167,23 @@ ZenServerState::Initialize()
ThrowLastError("Could not map view of Zen server state");
}
#else
- int Fd = shm_open("/UnrealEngineZen", O_RDWR | O_CREAT | O_CLOEXEC, 0666);
+ ZEN_INFO("{}", S_IRUSR | S_IWUSR | S_IXUSR);
+ ZEN_INFO("{}", geteuid());
+ int Fd = shm_open("/UnrealEngineZen", O_RDWR | O_CREAT | O_CLOEXEC, geteuid() == 0 ? 0766 : 0666);
if (Fd < 0)
{
- ThrowLastError("Could not open a shared memory object");
+ // Work around a potential issue if the service user is changed in certain configurations.
+ // If the sysctl 'fs.protected_regular' is set to 1 or 2 (default on many distros),
+ // we will be unable to open an existing shared memory object created by another user using O_CREAT,
+ // even if we have the correct permissions, or are running as root. If we destroy the existing
+ // 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);
+ if (Fd < 0)
+ {
+ ThrowLastError("Could not open a shared memory object");
+ }
}
fchmod(Fd, 0666);
void* hMap = (void*)intptr_t(Fd);