bugfix: Fix incorrect debug.log config file path

Currently debug.log will show the wrong bitcoin.conf config file path when
bitcoind is invoked without -conf or -datadir arguments, and there's a default
bitcoin.conf file which specifies another datadir= location. When this happens,
the debug.log will include an incorrect "Config file:" line referring to a
bitcoin.conf file in the other datadir, instead of the referring to the actual
configuration file in the default datadir which was parsed.

The bad log print was reported and originally fixed in
https://github.com/bitcoin/bitcoin/pull/27303 by
Matthew Zipkin <pinheadmz@gmail.com>

This PR takes a slightly different approach to fixing the bug, trying to avoid
future bugs by not allowing the GetConfigFilePath function to be called before
the the configuration is parsed, and deleting GetConfigFile function which
could be confused with GetConfigFilePath. It also includes a test for the bug
which the original fix did not have.

Co-authored-by: Matthew Zipkin <pinheadmz@gmail.com>
This commit is contained in:
Ryan Ofsky
2023-03-27 10:17:57 -04:00
parent 3746f00be1
commit eefe56967b
6 changed files with 45 additions and 9 deletions

View File

@@ -714,7 +714,8 @@ bool CheckDataDirOption(const ArgsManager& args)
fs::path ArgsManager::GetConfigFilePath() const
{
return GetConfigFile(*this, GetPathArg("-conf", BITCOIN_CONF_FILENAME));
LOCK(cs_args);
return *Assert(m_config_path);
}
std::string ArgsManager::GetChainName() const