diff options
| author | Liam Mitchell <[email protected]> | 2025-08-22 16:12:38 -0700 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-08-22 16:12:38 -0700 |
| commit | 207c4a32612891711d9d69466b6dfc653428bb07 (patch) | |
| tree | d4b8de42a91ee3327b14fc0aa66c92bc3de46555 /src/zencore | |
| parent | 5.6.18-pre0 (diff) | |
| parent | Move windows service utilities to zenutil and fix clang-format errors (diff) | |
| download | zen-207c4a32612891711d9d69466b6dfc653428bb07.tar.xz zen-207c4a32612891711d9d69466b6dfc653428bb07.zip | |
Merge pull request #139 from ue-foundation/de/zen-service-command
zen service command
Diffstat (limited to 'src/zencore')
| -rw-r--r-- | src/zencore/filesystem.cpp | 2 | ||||
| -rw-r--r-- | src/zencore/include/zencore/memory/fmalloc.h | 2 | ||||
| -rw-r--r-- | src/zencore/include/zencore/process.h | 5 | ||||
| -rw-r--r-- | src/zencore/memory/mallocmimalloc.cpp | 2 | ||||
| -rw-r--r-- | src/zencore/process.cpp | 27 | ||||
| -rw-r--r-- | src/zencore/thread.cpp | 2 |
6 files changed, 35 insertions, 5 deletions
diff --git a/src/zencore/filesystem.cpp b/src/zencore/filesystem.cpp index 46337ffc8..8327838c9 100644 --- a/src/zencore/filesystem.cpp +++ b/src/zencore/filesystem.cpp @@ -900,6 +900,8 @@ CopyFile(const std::filesystem::path& FromPath, const std::filesystem::path& ToP size_t FileSizeBytes = Stat.st_size; + fchown(ToFd, Stat.st_uid, Stat.st_gid); + // Copy impl const size_t BufferSize = Min(FileSizeBytes, 64u << 10); void* Buffer = malloc(BufferSize); diff --git a/src/zencore/include/zencore/memory/fmalloc.h b/src/zencore/include/zencore/memory/fmalloc.h index aeb05b651..5b476429e 100644 --- a/src/zencore/include/zencore/memory/fmalloc.h +++ b/src/zencore/include/zencore/memory/fmalloc.h @@ -2,6 +2,8 @@ #pragma once +#include <cstddef> + #include <zenbase/zenbase.h> namespace zen { diff --git a/src/zencore/include/zencore/process.h b/src/zencore/include/zencore/process.h index d3e1de703..98d352db6 100644 --- a/src/zencore/include/zencore/process.h +++ b/src/zencore/include/zencore/process.h @@ -51,6 +51,7 @@ struct CreateProcOptions Flag_NewConsole = 1 << 0, Flag_Elevated = 1 << 1, Flag_Unelevated = 1 << 2, + Flag_NoConsole = 1 << 3, }; const std::filesystem::path* WorkingDirectory = nullptr; @@ -100,6 +101,10 @@ int GetProcessId(CreateProcResult ProcId); std::filesystem::path GetProcessExecutablePath(int Pid, std::error_code& OutEc); std::error_code FindProcess(const std::filesystem::path& ExecutableImage, ProcessHandle& OutHandle, bool IncludeSelf = true); +#if ZEN_PLATFORM_LINUX +void IgnoreChildSignals(); +#endif + void process_forcelink(); // internal } // namespace zen diff --git a/src/zencore/memory/mallocmimalloc.cpp b/src/zencore/memory/mallocmimalloc.cpp index 1919af3bf..1f9aff404 100644 --- a/src/zencore/memory/mallocmimalloc.cpp +++ b/src/zencore/memory/mallocmimalloc.cpp @@ -1,5 +1,7 @@ // Copyright Epic Games, Inc. All Rights Reserved. +#include <cstring> + #include <zencore/intmath.h> #include <zencore/memory/align.h> #include <zencore/memory/mallocmimalloc.h> diff --git a/src/zencore/process.cpp b/src/zencore/process.cpp index fcbe657cb..0b25d14f4 100644 --- a/src/zencore/process.cpp +++ b/src/zencore/process.cpp @@ -24,7 +24,6 @@ # include <sys/sem.h> # include <sys/stat.h> # include <sys/syscall.h> -# include <sys/sysctl.h> # include <sys/wait.h> # include <time.h> # include <unistd.h> @@ -32,6 +31,8 @@ #if ZEN_PLATFORM_MAC # include <libproc.h> +# include <sys/types.h> +# include <sys/sysctl.h> #endif ZEN_THIRD_PARTY_INCLUDES_START @@ -41,7 +42,9 @@ ZEN_THIRD_PARTY_INCLUDES_END namespace zen { #if ZEN_PLATFORM_LINUX -const bool bNoZombieChildren = []() { +void +IgnoreChildSignals() +{ // When a child process exits it is put into a zombie state until the parent // collects its result. This doesn't fit the Windows-like model that Zen uses // where there is a less strict familial model and no zombification. Ignoring @@ -52,8 +55,7 @@ const bool bNoZombieChildren = []() { sigemptyset(&Action.sa_mask); Action.sa_handler = SIG_IGN; sigaction(SIGCHLD, &Action, nullptr); - return true; -}(); +} static char GetPidStatus(int Pid, std::error_code& OutEc) @@ -443,6 +445,10 @@ CreateProcNormal(const std::filesystem::path& Executable, std::string_view Comma { CreationFlags |= CREATE_NEW_CONSOLE; } + if (Options.Flags & CreateProcOptions::Flag_NoConsole) + { + CreationFlags |= CREATE_NO_WINDOW; + } const wchar_t* WorkingDir = nullptr; if (Options.WorkingDirectory != nullptr) @@ -588,6 +594,10 @@ CreateProcUnelevated(const std::filesystem::path& Executable, std::string_view C { CreateProcFlags |= CREATE_NEW_CONSOLE; } + if (Options.Flags & CreateProcOptions::Flag_NoConsole) + { + CreateProcFlags |= CREATE_NO_WINDOW; + } ExtendableWideStringBuilder<256> CommandLineZ; CommandLineZ << CommandLine; @@ -798,6 +808,11 @@ IsProcessRunning(int pid, std::error_code& OutEc) { return false; } + if (Error == ERROR_ACCESS_DENIED) + { + // Process is running under other user probably, assume it is running + return true; + } OutEc = MakeErrorCode(Error); return false; } @@ -840,6 +855,10 @@ IsProcessRunning(int pid, std::error_code& OutEc) { return false; } + else if (Error == EPERM) + { + return true; // Running under a user we don't have access to, assume it is live + } else { OutEc = MakeErrorCode(Error); diff --git a/src/zencore/thread.cpp b/src/zencore/thread.cpp index 0d5ad6091..b8ec85a4a 100644 --- a/src/zencore/thread.cpp +++ b/src/zencore/thread.cpp @@ -485,7 +485,7 @@ NamedMutex::Create(std::string_view MutexName) ExtendableStringBuilder<64> Name; Name << "/tmp/" << MutexName; - int Inner = open(Name.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0666); + int Inner = open(Name.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, geteuid() == 0 ? 0766 : 0666); if (Inner < 0) { return false; |