aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Zeyde <me@romanzey.de>2023-11-03 16:34:42 +0200
committerAntoine Poinsot <darosior@protonmail.com>2024-02-28 11:19:27 +0100
commit1e956439eb86de7a455560c349370684f4e54561 (patch)
tree8f5dfc7e9cbc4c1ddd409256719e960c5a23b696 /src
parenta4690485d145bef4e4dc9688291aa956a246fd47 (diff)
rpc: keep .cookie if it was not generated
Otherwise, starting bitcoind twice may cause the `.cookie` file generated by the first instance to be deleted by the second instance shutdown (after failing to obtain a lock). Github-Pull: bitcoin/bitcoin#28784 Rebased-From: 7cb9367157eb42ee06bc6fa024522cc14a80138d
Diffstat (limited to 'src')
-rw-r--r--src/rpc/request.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/rpc/request.cpp b/src/rpc/request.cpp
index 4c67da8b70..b7acd62ee3 100644
--- a/src/rpc/request.cpp
+++ b/src/rpc/request.cpp
@@ -80,6 +80,8 @@ static fs::path GetAuthCookieFile(bool temp=false)
return AbsPathForConfigVal(gArgs, arg);
}
+static bool g_generated_cookie = false;
+
bool GenerateAuthCookie(std::string *cookie_out)
{
const size_t COOKIE_SIZE = 32;
@@ -105,6 +107,7 @@ bool GenerateAuthCookie(std::string *cookie_out)
LogPrintf("Unable to rename cookie authentication file %s to %s\n", fs::PathToString(filepath_tmp), fs::PathToString(filepath));
return false;
}
+ g_generated_cookie = true;
LogPrintf("Generated RPC authentication cookie %s\n", fs::PathToString(filepath));
if (cookie_out)
@@ -131,7 +134,10 @@ bool GetAuthCookie(std::string *cookie_out)
void DeleteAuthCookie()
{
try {
- fs::remove(GetAuthCookieFile());
+ if (g_generated_cookie) {
+ // Delete the cookie file if it was generated by this process
+ fs::remove(GetAuthCookieFile());
+ }
} catch (const fs::filesystem_error& e) {
LogPrintf("%s: Unable to remove random auth cookie file: %s\n", __func__, fsbridge::get_filesystem_error_message(e));
}