mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-16 13:01:19 +02:00
Merge bitcoin/bitcoin#28784: rpc: keep .cookie file if it was not generated
7cb9367157rpc: 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-ACK7cb9367157achow101: ACK7cb9367157kristapsk: re-ACK7cb9367157stickies-v: ACK7cb9367157Tree-SHA512: 0960dbc457975b0e0535f3d814824a879d7f85c9f1191537415b3fc253429a316a8e4badde56c8bc139778f132392983cec5fbe03891fb15ff61d3bc3f6e681b
This commit is contained in:
parent
956797f24a
commit
cb5c59e8a5
2 changed files with 9 additions and 2 deletions
|
|
@ -78,6 +78,8 @@ static fs::path GetAuthCookieFile(bool temp=false)
|
|||
return AbsPathForConfigVal(fs::PathFromString(arg));
|
||||
}
|
||||
|
||||
static bool g_generated_cookie = false;
|
||||
|
||||
bool GenerateAuthCookie(std::string *cookie_out)
|
||||
{
|
||||
const size_t COOKIE_SIZE = 32;
|
||||
|
|
@ -103,6 +105,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)
|
||||
|
|
@ -168,7 +171,10 @@ bool GetMainchainAuthCookie(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));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue