Skip to content

Commit

Permalink
Remove ports just before usage. Use network specific folders. (#3102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar authored Oct 24, 2024
1 parent 9ee5876 commit a2c4958
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand All @@ -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;
Expand Down

0 comments on commit a2c4958

Please sign in to comment.