Added ability to set config parameters through environment variables#3476
Added ability to set config parameters through environment variables#3476jmcorgan wants to merge 4 commits intobitcoin:masterfrom
Conversation
The environment is parsed for variables starting with BITCOIN_, and the remaining portion of the name becomes the argument name, with the value set to the portion after the = sign, e.g., BITCOIN_DATADIR=FOO is equivalent to -datadir=FOO The environment is parsed before the command line, allowing the command line to take precedence over the environment. There is a whitelist in util.cpp that only allows specified environment variables to be used this way; currently, this is set to just -datadir and -conf. Signed-off-by: Johnathan Corgan <johnathan@corganlabs.com>
There was a problem hiding this comment.
Indentation looks a bit strange here. Are you mixing tabs and spaces? Please use four spaces for indentation.
|
I'm using emacs C++ mode, which defaults to two spaces, then trying to make things match up with what is already there. It didn't work out so well. Regarding the ClearArgs, I'm just replicating what was already there at the start of ParseParameters(). It's true they start out empty, but in the test code it calls ParseParameters multiple times and assumes that the args get cleared in between. I'm happy to make whatever changes you feel are necessary, of course. |
|
Also, there is a backport to 0.8.6 on my branch envconfig-0.8.6. |
Signed-off-by: Johnathan Corgan <johnathan@corganlabs.com>
|
All of Iaanwj's comments should be addressed now. |
|
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/0729a596da7caeda1a0243d3739513d193f5f590 for binaries and test log. |
|
It seems that do not have the strong requirement for this extended feature, since we already have configure file(bitcoin.conf) to do it. Also it make the bitcoin to tangle the OSs environments. Different OS may have some quirks. |
|
This serves several needs that I personally have, to run bitcoind with different conf files and not have to always specify them with -conf=foo on the command line. Instead I set the BITCOIN_CONF=foo environment variable and I can type bitcoind (or bitcoin-cli) repeatedly and it will use that value. Being able to specify alternate datadir locations works the same way. It also allows running common scripts whose parameters can be changed via the environment they are passed, instead of having to point at different conf files. In any case, I'll keep using this locally, and the pull request is offered up to the devs to integrate or not as they see fit. |
|
@emmix How does this "tangle" the OS environment? It reads it only, uses clearly identifiable variable names that you'd never use by accident, and currently only allows two settings ( I can see how this can be useful. Though, to be fair, you can accomplish the same with something like: (sure, an alias won't nest into scripts, but the scripts could pass the environment variable to |
|
'Tangle" which I mean couple with the OS environment. Sorry for my unclarity. Anyway the change takes convenience actually. But type the whole commands and options let you know what you are dong clearly. |
|
This adds more testing work. Especially in the case of the GUI, there are already many sources of configuration options that interact in non-trivial ways and this has resulted in bugs in the past. And as said this can be easily handled from outside the code; either by defining an alias or function for bitcoin-cli with arguments, or by using a script. In general we don't add extra code to the core for what can be handled easily from outside. |
The environment is parsed for variables starting with BITCOIN_, and
the remaining portion of the name becomes the argument name, with
the value set to the portion after the = sign, e.g.,
BITCOIN_DATADIR=FOO is equivalent to -datadir=FOO
The environment is parsed before the command line, allowing the
command line to take precedence over the environment.
There is a whitelist in util.cpp that only allows specified environment
variables to be used this way; currently, this is set to just -datadir
and -conf.
Signed-off-by: Johnathan Corgan johnathan@corganlabs.com