diff options
| author | Martin Ridgers <[email protected]> | 2021-12-08 09:04:04 +0100 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2021-12-08 09:04:04 +0100 |
| commit | 1037aa9edc9b88d9c59fdf2d2531ac265b571b3c (patch) | |
| tree | 805f277f60b1eba7de8b78ae209d7464bcedd398 /zenutil/zenserverprocess.cpp | |
| parent | Implement zen/internalfile for POSIX platforms (diff) | |
| parent | Use 'Platform' instead of 'OSFamily' for Horde condition (diff) | |
| download | zen-1037aa9edc9b88d9c59fdf2d2531ac265b571b3c.tar.xz zen-1037aa9edc9b88d9c59fdf2d2531ac265b571b3c.zip | |
Merged main
Diffstat (limited to 'zenutil/zenserverprocess.cpp')
| -rw-r--r-- | zenutil/zenserverprocess.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/zenutil/zenserverprocess.cpp b/zenutil/zenserverprocess.cpp index 417bd74ab..74fbaf180 100644 --- a/zenutil/zenserverprocess.cpp +++ b/zenutil/zenserverprocess.cpp @@ -110,10 +110,19 @@ ZenServerState::Initialize() #if ZEN_PLATFORM_WINDOWS // TODO: there's a small chance of a race here, this logic could be tightened up with a mutex to // ensure only a single process at a time creates the mapping + // TODO: the fallback to Local instead of Global has a flaw where if you start a non-elevated instance + // first then start an elevated instance second you'll have the first instance with a local + // mapping and the second instance with a global mapping. This kind of elevated/non-elevated + // shouldn't be common, but handling for it should be improved in the future. HANDLE hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Global\\ZenMap"); if (hMap == NULL) { + hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Local\\ZenMap"); + } + + if (hMap == NULL) + { // Security attributes to enable any user to access state zenutil::AnyUserSecurityAttributes Attrs; @@ -126,6 +135,16 @@ ZenServerState::Initialize() if (hMap == NULL) { + hMap = CreateFileMapping(INVALID_HANDLE_VALUE, // use paging file + Attrs.Attributes(), // allow anyone to access + PAGE_READWRITE, // read/write access + 0, // maximum object size (high-order DWORD) + m_MaxEntryCount * sizeof(ZenServerEntry), // maximum object size (low-order DWORD) + L"Local\\ZenMap"); // name of mapping object + } + + if (hMap == NULL) + { ThrowLastError("Could not open or create file mapping object for Zen server state"); } } @@ -171,6 +190,11 @@ ZenServerState::InitializeReadOnly() HANDLE hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Global\\ZenMap"); if (hMap == NULL) { + hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Local\\ZenMap"); + } + + if (hMap == NULL) + { return false; } |