diff options
Diffstat (limited to 'zenserver/zenserver.cpp')
| -rw-r--r-- | zenserver/zenserver.cpp | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index f4fd130b1..443bb627e 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -947,6 +947,34 @@ ZenEntryPoint::Run() try { // Mutual exclusion and synchronization + ZenServerState ServerState; + ServerState.Initialize(); + ServerState.Sweep(); + + ZenServerState::ZenServerEntry* Entry = ServerState.Lookup(ServerOptions.BasePort); + + if (Entry) + { + if (ServerOptions.OwnerPid) + { + ConsoleLog().info( + "Looks like there is already a process listening to this port {} (pid: {}), attaching owner pid {} to running instance", + ServerOptions.BasePort, + Entry->Pid, + ServerOptions.OwnerPid); + + Entry->AddSponsorProcess(ServerOptions.OwnerPid); + + std::exit(0); + } + else + { + ConsoleLog().warn("Exiting since there is already a process listening to port {} (pid: {})", + ServerOptions.BasePort, + Entry->Pid); + std::exit(1); + } + } std::error_code Ec; @@ -965,7 +993,7 @@ ZenEntryPoint::Run() if (Ec) { - ConsoleLog().error("ERROR: Unable to grab lock at '{}' (error: '{}')", LockFilePath, Ec.message()); + ConsoleLog().warn("ERROR: Unable to grab lock at '{}' (error: '{}')", LockFilePath, Ec.message()); std::exit(99); } @@ -992,29 +1020,6 @@ ZenEntryPoint::Run() ZEN_INFO(ZEN_APP_NAME " - starting on port {}, version '{}'", ServerOptions.BasePort, ZEN_CFG_VERSION_BUILD_STRING_FULL); - ZenServerState ServerState; - ServerState.Initialize(); - ServerState.Sweep(); - - ZenServerState::ZenServerEntry* Entry = ServerState.Lookup(ServerOptions.BasePort); - - if (Entry) - { - if (ServerOptions.OwnerPid) - { - ZEN_WARN("Looks like there is already a process listening to this port {} (pid: {})", ServerOptions.BasePort, Entry->Pid); - - Entry->AddSponsorProcess(ServerOptions.OwnerPid); - - std::exit(0); - } - else - { - ZEN_WARN("Exiting since there is already a process listening to port {} (pid: {})", ServerOptions.BasePort, Entry->Pid); - std::exit(1); - } - } - Entry = ServerState.Register(ServerOptions.BasePort); if (ServerOptions.OwnerPid) |