diff options
author | Andrew Chow <github@achow101.com> | 2023-12-01 12:18:09 -0500 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-12-01 12:24:29 -0500 |
commit | 18bed148af65746dd3a0066fefc5b48f9729c1b6 (patch) | |
tree | 194f00bb5d20458a06f3f36f57537232519edee3 /src | |
parent | 6b3927f79a92a737f32ab32e96c681462da923ef (diff) | |
parent | 7cb9367157eb42ee06bc6fa024522cc14a80138d (diff) |
Merge bitcoin/bitcoin#28784: rpc: keep `.cookie` file if it was not generated
7cb9367157eb42ee06bc6fa024522cc14a80138d rpc: keep .cookie if it was not generated (Roman Zeyde)
Pull request description:
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).
ACKs for top commit:
willcl-ark:
re-ACK 7cb9367157eb42ee06bc6fa024522cc14a80138d
achow101:
ACK 7cb9367157eb42ee06bc6fa024522cc14a80138d
kristapsk:
re-ACK 7cb9367157eb42ee06bc6fa024522cc14a80138d
stickies-v:
ACK 7cb9367157eb42ee06bc6fa024522cc14a80138d
Tree-SHA512: 0960dbc457975b0e0535f3d814824a879d7f85c9f1191537415b3fc253429a316a8e4badde56c8bc139778f132392983cec5fbe03891fb15ff61d3bc3f6e681b
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/request.cpp | 8 |
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)); } |