From 9a944471007a19460145dc9e4f05183e509f88bb Mon Sep 17 00:00:00 2001 From: Bushstar Date: Thu, 24 Oct 2024 07:57:51 +0100 Subject: [PATCH] Remove ports just before usage. Use network specific folders. --- src/init.cpp | 5 +++-- src/logging.cpp | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index f98e7812c1..d49f36daab 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1053,8 +1053,6 @@ void InitLogging() version_string += " (release build)"; #endif LogPrintf(PACKAGE_NAME " version %s\n", version_string); - // Remove ports.lock on startup in case of an unclean shutdown. - RemovePortUsage(); } namespace { // Variables internal to initialization process only @@ -1829,6 +1827,9 @@ bool AppInitMain(InitInterfaces& interfaces) RegisterZMQRPCCommands(tableRPC); #endif + // Remove ports.lock on startup in case of an unclean shutdown. + RemovePortUsage(); + /* Start the RPC server already. It will be started in "warmup" mode * and not really process calls already (but it will signify connections * that the server is there and will be ready later). Warmup mode will diff --git a/src/logging.cpp b/src/logging.cpp index 61afaa20b0..7b1f63c1ae 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -348,7 +348,7 @@ static std::string GetAutoPortString(const AutoPort type) uint16_t GetPortFromLockFile(const AutoPort type) { - const fs::path lockFilePath = GetDataDir() / "ports.lock"; + const fs::path lockFilePath = GetDataDir(true) / "ports.lock"; const std::string portTypeStr = GetAutoPortString(type); std::ifstream lockFile(lockFilePath); @@ -376,7 +376,7 @@ void SetPortToLockFile(const AutoPort portType, const uint16_t portNumber) return; } - const fs::path lockFilePath = GetDataDir() / "ports.lock"; + const fs::path lockFilePath = GetDataDir(true) / "ports.lock"; std::ofstream lockFile(lockFilePath, std::ios_base::app); if (!lockFile.is_open()) { @@ -389,7 +389,7 @@ void SetPortToLockFile(const AutoPort portType, const uint16_t portNumber) void RemovePortUsage() { - const fs::path lockFilePath = GetDataDir() / "ports.lock"; + const fs::path lockFilePath = GetDataDir(true) / "ports.lock"; // Remove the file. Ignore errors, file might not be present. std::error_code ec;