aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil/zenserverprocess.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenutil/zenserverprocess.cpp')
-rw-r--r--src/zenutil/zenserverprocess.cpp42
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