diff options
| author | Dan Engelbrecht <[email protected]> | 2023-04-24 12:20:15 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-24 12:20:15 +0200 |
| commit | 3ad70adb6c122b253170567cd0efed854fe10d57 (patch) | |
| tree | cfb6ebfeae29c5b57022416060c7a5174187aa5a /zenserver/zenserver.cpp | |
| parent | 0.2.5-pre3 (diff) | |
| download | zen-3ad70adb6c122b253170567cd0efed854fe10d57.tar.xz zen-3ad70adb6c122b253170567cd0efed854fe10d57.zip | |
check for port conflict before trying to take data dir lock (#253)
* check for port conflict before trying to take data dir lock
* demote data dir conflict to warning (still exist with error code)
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) |