aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/zenserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenserver/zenserver.cpp')
-rw-r--r--src/zenserver/zenserver.cpp78
1 files changed, 45 insertions, 33 deletions
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index 1cd8ed846..fe6a5a572 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -631,6 +631,10 @@ ZenServerMain::Run()
uint32_t AttachSponsorProcessRetriesLeft = 3;
ZenServerState::ZenServerEntry* Entry = ServerState.Lookup(m_ServerOptions.BasePort);
+ // NOTE: ZEN_CONSOLE_WARN/INFO is used in this block and the lock file block below
+ // (instead of ZEN_WARN/INFO) because InitializeLogging() has not been called yet at
+ // this point. ZEN_WARN/INFO would silently discard messages before the logging system
+ // is initialized.
while (Entry)
{
if (m_ServerOptions.OwnerPid)
@@ -640,27 +644,29 @@ ZenServerMain::Run()
{
if (Ec)
{
- ZEN_WARN(ZEN_APP_NAME
- " exiting, sponsor owner pid {} can not be checked for running state, reason: '{}'. Will not add sponsor "
- "to process "
- "listening to port {} (pid: {})",
- m_ServerOptions.OwnerPid,
- Ec.message(),
- m_ServerOptions.BasePort,
- Entry->Pid.load());
+ ZEN_CONSOLE_WARN(
+ ZEN_APP_NAME
+ " exiting, sponsor owner pid {} can not be checked for running state, reason: '{}'. Will not add sponsor "
+ "to process "
+ "listening to port {} (pid: {})",
+ m_ServerOptions.OwnerPid,
+ Ec.message(),
+ m_ServerOptions.BasePort,
+ Entry->Pid.load());
}
else
{
- ZEN_WARN(ZEN_APP_NAME
- " exiting, sponsor owner pid {} is no longer running, will not add sponsor to process listening to port "
- "{} (pid: {})",
- m_ServerOptions.OwnerPid,
- m_ServerOptions.BasePort,
- Entry->Pid.load());
+ ZEN_CONSOLE_WARN(
+ ZEN_APP_NAME
+ " exiting, sponsor owner pid {} is no longer running, will not add sponsor to process listening to port "
+ "{} (pid: {})",
+ m_ServerOptions.OwnerPid,
+ m_ServerOptions.BasePort,
+ Entry->Pid.load());
}
std::exit(1);
}
- ZEN_INFO(
+ ZEN_CONSOLE_INFO(
"Looks like there is already a process listening to this port {} (pid: {}), attaching owner pid {} to running instance",
m_ServerOptions.BasePort,
Entry->Pid.load(),
@@ -678,18 +684,18 @@ ZenServerMain::Run()
}
else
{
- ZEN_WARN(ZEN_APP_NAME " exiting, failed to add sponsor owner pid {} to process listening to port {} (pid: {})",
- m_ServerOptions.OwnerPid,
- m_ServerOptions.BasePort,
- Entry->Pid.load());
+ ZEN_CONSOLE_WARN(ZEN_APP_NAME " exiting, failed to add sponsor owner pid {} to process listening to port {} (pid: {})",
+ m_ServerOptions.OwnerPid,
+ m_ServerOptions.BasePort,
+ Entry->Pid.load());
std::exit(1);
}
}
else
{
- ZEN_WARN(ZEN_APP_NAME " exiting, there is already a process listening to port {} (pid: {})",
- m_ServerOptions.BasePort,
- Entry->Pid.load());
+ ZEN_CONSOLE_WARN(ZEN_APP_NAME " exiting, there is already a process listening to port {} (pid: {})",
+ m_ServerOptions.BasePort,
+ Entry->Pid.load());
std::exit(1);
}
}
@@ -702,19 +708,19 @@ ZenServerMain::Run()
if (Ec)
{
- ZEN_INFO(ZEN_APP_NAME " unable to grab lock at '{}' (reason: '{}'), retrying", LockFilePath, Ec.message());
+ ZEN_CONSOLE_INFO(ZEN_APP_NAME " unable to grab lock at '{}' (reason: '{}'), retrying", LockFilePath, Ec.message());
Sleep(100);
m_LockFile.Create(LockFilePath, MakeLockData(false), Ec);
if (Ec)
{
- ZEN_INFO(ZEN_APP_NAME " unable to grab lock at '{}' (reason: '{}'), retrying", LockFilePath, Ec.message());
+ ZEN_CONSOLE_INFO(ZEN_APP_NAME " unable to grab lock at '{}' (reason: '{}'), retrying", LockFilePath, Ec.message());
Sleep(500);
m_LockFile.Create(LockFilePath, MakeLockData(false), Ec);
if (Ec)
{
- ZEN_WARN(ZEN_APP_NAME " exiting, unable to grab lock at '{}' (reason: '{}')", LockFilePath, Ec.message());
+ ZEN_CONSOLE_WARN(ZEN_APP_NAME " exiting, unable to grab lock at '{}' (reason: '{}')", LockFilePath, Ec.message());
std::exit(99);
}
}
@@ -736,6 +742,12 @@ ZenServerMain::Run()
Entry = ServerState.Register(m_ServerOptions.BasePort);
+ if (!Entry)
+ {
+ throw std::runtime_error(
+ fmt::format("Failed to register server on port {} in shared state (all slots occupied)", m_ServerOptions.BasePort));
+ }
+
// Publish per-instance extended info (e.g. UDS path) via a small shared memory
// section keyed by SessionId so clients can discover it during Snapshot() enumeration.
{
@@ -762,22 +774,22 @@ ZenServerMain::Run()
}
catch (const AssertException& AssertEx)
{
- ZEN_CRITICAL(ZEN_APP_NAME " caught assert exception in main for process {}: {}",
- zen::GetCurrentProcessId(),
- AssertEx.FullDescription());
+ ZEN_CONSOLE_CRITICAL(ZEN_APP_NAME " caught assert exception in main for process {}: {}",
+ zen::GetCurrentProcessId(),
+ AssertEx.FullDescription());
RequestApplicationExit(1);
}
catch (const std::system_error& e)
{
- ZEN_CRITICAL(ZEN_APP_NAME " caught system error exception in main for process {}: {} ({})",
- zen::GetCurrentProcessId(),
- e.what(),
- e.code().value());
+ ZEN_CONSOLE_CRITICAL(ZEN_APP_NAME " caught system error exception in main for process {}: {} ({})",
+ zen::GetCurrentProcessId(),
+ e.what(),
+ e.code().value());
RequestApplicationExit(1);
}
catch (const std::exception& e)
{
- ZEN_CRITICAL(ZEN_APP_NAME " caught exception in main for process {}: {}", zen::GetCurrentProcessId(), e.what());
+ ZEN_CONSOLE_CRITICAL(ZEN_APP_NAME " caught exception in main for process {}: {}", zen::GetCurrentProcessId(), e.what());
RequestApplicationExit(1);
}