From f3722e2c7e27131be8395dedc9fcbb6a73cda80d Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Mon, 21 Feb 2022 12:53:47 +0100 Subject: Explicitly set access permissions so we're not affected by process' umask --- zenstore/basicfile.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'zenstore/basicfile.cpp') diff --git a/zenstore/basicfile.cpp b/zenstore/basicfile.cpp index 038d83493..1b6080379 100644 --- a/zenstore/basicfile.cpp +++ b/zenstore/basicfile.cpp @@ -75,12 +75,16 @@ BasicFile::Open(std::filesystem::path FileName, bool IsCreate, std::error_code& int OpenFlags = O_RDWR | O_CLOEXEC; OpenFlags |= IsCreate ? O_CREAT | O_TRUNC : 0; - int Fd = open(FileName.c_str(), OpenFlags, 0666); + int Fd = open(FileName.c_str(), OpenFlags); if (Fd < 0) { Ec = zen::MakeErrorCodeFromLastError(); return; } + if (IsCreate) + { + fchmod(Fd, 0666); + } void* FileHandle = (void*)(uintptr_t(Fd)); #endif @@ -366,12 +370,13 @@ 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 | O_CLOEXEC, 0666); + int Fd = open(FileName.c_str(), O_RDWR | O_CREAT | O_CLOEXEC); if (Fd < 0) { Ec = zen::MakeErrorCodeFromLastError(); return; } + fchmod(Fd, 0666); int LockRet = flock(Fd, LOCK_EX | LOCK_NB); if (LockRet < 0) -- cgit v1.2.3