diff options
| author | Stefan Boberg <[email protected]> | 2024-11-14 13:12:52 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-11-14 13:12:52 +0100 |
| commit | 24b1719f60ce7d6b3538474f7ab131c55c7a987f (patch) | |
| tree | 6fc8d9dc28cafaf91e4d59da26706e77025f0c51 /src/zenutil/zenserverprocess.cpp | |
| parent | Self-hosted dashboard: Searchable oplog and links between oplog entry depende... (diff) | |
| download | zen-24b1719f60ce7d6b3538474f7ab131c55c7a987f.tar.xz zen-24b1719f60ce7d6b3538474f7ab131c55c7a987f.zip | |
fixed some issues with ZenServerInstance::SpawnServer (#218)
* previously it would assign a child identifier twice in some cases, which would lead to confusing log output
* added pid as context in debug logging when launching a process
Diffstat (limited to 'src/zenutil/zenserverprocess.cpp')
| -rw-r--r-- | src/zenutil/zenserverprocess.cpp | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/src/zenutil/zenserverprocess.cpp b/src/zenutil/zenserverprocess.cpp index 4003cef48..214737425 100644 --- a/src/zenutil/zenserverprocess.cpp +++ b/src/zenutil/zenserverprocess.cpp @@ -673,26 +673,39 @@ ZenServerInstance::Shutdown() return -1; } +int +ZenServerInstance::AssignName() +{ + const int ChildId = ++ChildIdCounter; + + ExtendableStringBuilder<32> LogId; + LogId << "Zen" << ChildId; + m_Name = LogId.ToString(); + + return ChildId; +} + void ZenServerInstance::SpawnServer(std::string_view ServerArgs, bool OpenConsole, int WaitTimeoutMs) { ZEN_ASSERT(!m_Process.IsValid()); // Only spawn once - const int ChildId = ++ChildIdCounter; + const int ChildId = AssignName(); + + SpawnServerInternal(ChildId, ServerArgs, OpenConsole, WaitTimeoutMs); +} + +void +ZenServerInstance::SpawnServerInternal(int ChildId, std::string_view ServerArgs, bool OpenConsole, int WaitTimeoutMs) +{ + const bool IsTest = m_Env.IsTestEnvironment(); ExtendableStringBuilder<32> ChildEventName; ChildEventName << "Zen_Child_" << ChildId; NamedEvent ChildEvent{ChildEventName}; - ExtendableStringBuilder<32> LogId; - LogId << "Zen" << ChildId; - m_Name = LogId.ToString(); - ExtendableStringBuilder<512> CommandLine; CommandLine << "zenserver" ZEN_EXE_SUFFIX_LITERAL; // see CreateProc() call for actual binary path - - const bool IsTest = m_Env.IsTestEnvironment(); - CommandLine << " --child-id " << ChildEventName; if (!ServerArgs.empty()) @@ -702,7 +715,7 @@ ZenServerInstance::SpawnServer(std::string_view ServerArgs, bool OpenConsole, in std::filesystem::path CurrentDirectory = std::filesystem::current_path(); - ZEN_DEBUG("Spawning server '{}'", LogId); + ZEN_DEBUG("Spawning server '{}'", m_Name); uint32_t CreationFlags = 0; if (OpenConsole) @@ -738,7 +751,7 @@ ZenServerInstance::SpawnServer(std::string_view ServerArgs, bool OpenConsole, in ThrowLastError("Server spawn failed"); } - ZEN_DEBUG("Server '{}' spawned OK", LogId); + ZEN_DEBUG("Server '{}' spawned OK (pid:{})", m_Name, GetProcessId(ChildPid)); m_Process.Initialize(ChildPid); @@ -768,14 +781,9 @@ ZenServerInstance::SpawnServer(int BasePort, std::string_view AdditionalServerAr ZEN_ASSERT(!m_Process.IsValid()); // Only spawn once const int MyPid = zen::GetCurrentProcessId(); - const int ChildId = ++ChildIdCounter; - - ExtendableStringBuilder<32> LogId; - LogId << "Zen" << ChildId; - m_Name = LogId.ToString(); + const int ChildId = AssignName(); ExtendableStringBuilder<512> CommandLine; - CommandLine << "zenserver" ZEN_EXE_SUFFIX_LITERAL; // see CreateProc() call for actual binary path const bool IsTest = m_Env.IsTestEnvironment(); @@ -823,7 +831,7 @@ ZenServerInstance::SpawnServer(int BasePort, std::string_view AdditionalServerAr CommandLine << " " << AdditionalServerArgs; } - SpawnServer(CommandLine, !IsTest, WaitTimeoutMs); + SpawnServerInternal(ChildId, CommandLine, !IsTest, WaitTimeoutMs); } void |