bitcoind: process -help/-version before touching the datadir - #341
Open
kwsantiago wants to merge 1 commit into
Open
bitcoind: process -help/-version before touching the datadir#341kwsantiago wants to merge 1 commit into
kwsantiago wants to merge 1 commit into
Conversation
luke-jr
reviewed
Jul 25, 2026
kwsantiago
force-pushed
the
fix-bitcoind-help-version-datadir
branch
from
July 25, 2026 13:36
b8832a9 to
51e7235
Compare
Ari4ka
approved these changes
Jul 25, 2026
kwsantiago
force-pushed
the
fix-bitcoind-help-version-datadir
branch
from
July 25, 2026 15:05
51e7235 to
0bed563
Compare
Author
|
Rebased onto v29.0 as a daggy fix and force-pushed. |
pdath
approved these changes
Jul 28, 2026
pdath
left a comment
There was a problem hiding this comment.
ACK 0bed563.
I reviewed the changes to src/bitcoind.cpp, and found them to be simple, low risk, and as described.
Code Rabbit reviewed the change and found no issues.
I tested using the following commands on Ubuntu 24.04 running on ARMv8-A (64-bit) and gcc to verify the the original issue #304 is resolved.
git clone https://github.com/bitcoinknots/bitcoin.git pr341
cd pr341
git fetch origin pull/341/head:pr341
git switch pr341
cmake -B build -DCMAKE_BUILD_TYPE=Release
nice cmake --build build --target bitcoind -j $(nproc)
chmod 444 ~/.bitcoin
./contrib/devtools/gen-bitcoin-conf.sh
And then verified that the following file was created and contained the expected content:
./share/examples/bitcoin.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #329, where @luke-jr asked about the comment in
ProcessInitCommands()claiming help and version are processed "before taking care about datadir", when in factParseArgs()callscommon::InitConfig()first.InitConfig()creates the datadir and itswallets/subdirectory, statsbitcoin.conf, and writessettings.json. Sobitcoind --helpandbitcoind --versionboth create$HOME/.bitcoin, and fail outright if it exists but is not traversable (issue #304).Move the
InitConfig()call afterProcessInitCommands(), so the comment becomes true. This is the orderingbitcoin-clialready uses:ParseParameters(), then help/version, then config.Testing
Built with clang and compared against a pre-patch build of the same tree.
bitcoin-cli$HOME,--version/--help.bitcoin/,wallets/,settings.jsonchmod 444 ~/.bitcoin,--version/--help(#304)Permission denied, exit 1--help/--versionoutput--help foo(loose token)bitcoin.conf, normal startup-datadir=/nonexistent, normal startupBecause the config file is no longer read before help/version, three things change, all of them matching
bitcoin-cli's existing behavior:bitcoin-clihelp-debug=1inbitcoin.conf,--help-conf=/nonexistent.conf -version-datadir=/nonexistent -version/-help-help-debugon the command line still works, and both-confand-datadirare still validated on a normal startup.feature_help.py,feature_config_args.py,feature_settings.pyandfeature_init.pypass.