New -includeconf argument for including external configuration files#10267
New -includeconf argument for including external configuration files#10267laanwj merged 3 commits intobitcoin:masterfrom
Conversation
1bd0ee1 to
fe8850e
Compare
|
Yeah. Why not. This can be useful.
|
|
Why not making the existing |
|
@jonasschnelli Good point - will switch to @NicolasDorier I think |
fe8850e to
93818ed
Compare
|
Unsquashed history: 1 → 2 → 3⊱1 → 4⊱2 |
|
Concept ACK
Yes, making it relative to the data directory is a good choice. I think we should handle all relative paths in
That was also my first thought, but it may just be confusing as it changes the meaning of the option slightly. It's possible that some setups already use multiple So I'm good with making it an explicit option. Another suggestion for the name would be |
|
Concept ACK. Don't care much about the name, but what about -extraconf ? |
|
From the given suggestions I think
To clarify, you mean that the relative path inside /dir/file.conf should be /dir/, not [bitcoin datadir], right? It will require some lines of code I bet but I think that makes sense too. |
93818ed to
939087f
Compare
|
The with |
Yes, seems good to me too. So it's like C's include "" - I wasn't thinking about relative includes in other includes. |
75a36ca to
5d1e823
Compare
|
To clarify, the code now does what @laanwj suggested. |
Some ideas:
To achieve the latter the option |
|
@laanwj's suggested test method seems sensible. I'm happy to review that or lend a hand implementing it. Feel free to reach me on IRC. |
|
Thanks for the suggestion! I added a test that checks for load order and ensures circular include is guarded against. @jnewbery review would be wonderful :) Edit: If anyone has ideas why travis is failing I'd appreciate it. It works fine on all the machines I test it on locally (mac, linux). |
a3a8f4a to
3499187
Compare
You've made There's already a function that locks in the other order: If those two functions are called in different threads, we'd have a deadlock. There's a CPP_FLAG option that checks lock ordering You can fix this by not locking cs_args recursively. |
2317d90 to
8fb6511
Compare
|
@jnewbery Thanks a lot for the explanation! I should've paid closer attention to locks considering the added recursiveness. 97ee63b fixes this by moving the conditionally-locked code into a new (Also had to tweak tests a tiny bit; 8fb6511.) |
|
I think you've introduced a subtle bug here. If I think you should try to not make ReadConfigFile recursive. For me, it would be acceptable to only allow one level of redirection here (ie the "base" config file can specify |
|
@jnewbery Hm, no the datadir cache is cleared after any recursions happen, which means it is always cleared, just not directly after the config file has been parsed. There are two cases:
As for forbidding multiple levels of recursion, I think the value outweighs the issues personally (and I addressed circular refs I believe), but if people think it's not worth it I'll restrict it to one include. |
8fb6511 to
8069dbf
Compare
|
@kallewoof yes you're right. datadir cache is cleared after all files are read. My mistake. I still don't like the recursion and the fact that there can be multiple levels of imports. It means there are more edge cases and unexpected behaviour. For example, if The new Finally, you've introduced a new crash bug. If If I use an invalid filename for |
8c06988 to
6d56055
Compare
|
I'd prefer to not to have special stderr checking for this test. I have a PR open here: #12755 which adds stderr checking to the test framework. I've also prepared a branch here: https://github.com/bitcoin/bitcoin/compare/master...jnewbery:pr10267.3?expand=1 which rebases this PR on #12755 and adds explicit stderr checking. Would you mind either:
|
jnewbery
left a comment
There was a problem hiding this comment.
Tested ACK 6d5605517b477538f0447d41fe0bc734da27d10c. A couple of nits in the new test code, but nothing that should prevent merge.
@jnewbery Wouldn't it be simpler to fix this in a follow-up PR once #12755 is merged?
Not 100% sure what you mean by 'fix this', but I'm guessing you mean merge this as is and then remove the specific stderr checking code from this test when the generic stderr checking is added in #12755? Sure - that's fine, as long as you don't mind reviewing #12755 for me :)
There was a problem hiding this comment.
nit: PEP8 import ordering please (std library first, then local application imports)
There was a problem hiding this comment.
micronit: all other tests have set_test_params() as the first method. I think that makes more logical sense since that method is called by __init__(). Do you mind doing the same here?
6d56055 to
25b7ab9
Compare
|
@jnewbery Thanks for review! Addressed your nits. |
|
Tested ACK 25b7ab9.
Sorry - I haven't been very clear in my updates. Now that this PR includes stderr testing, it conflicts with #12755. My initial suggestions were to remove the stderr testing from this test, or rebase on top of #12755. But now I think it would make more sense to rebase #12755 on this, since this PR has been around for so long and should almost be ready for merge. I've rebased #12755 on this. As soon as this PR is merged, #12755 will be ready to go in. |
|
I think this is very nearly ready for merge. Are previous reviewers @laanwj, @ajtowns @promag, @ryanofsky, @MarcoFalke @meshcollider, @jonasschnelli able to re-review this? |
|
utACK 25b7ab9
|
|
utACK 25b7ab9. I suggest to add a warning if -includeconf is used in an included file (follow up PR). |
…uration files 25b7ab9 doc: Add release notes for -includeconf (Karl-Johan Alm) 0f0badd test: Test includeconf parameter. (Karl-Johan Alm) 629ff8c -includeconf=<path> support in config handler, for including external configuration files (Karl-Johan Alm) Pull request description: Fixes: #10071. Done: - adds `-includeconf=<path>`, where `<path>` is relative to `datadir` or to the path of the file being read, if in a file - protects against circular includes - updates help docs ~~~Thoughts:~~~ - ~~~I am not sure how to test this in a neat manner. Feedback on this would be nice. Will dig/think though.~~~ Tree-SHA512: cb31f1b2f69fbc0890d264948eb2e501ac05cf12f5e06a5942f9c1539eb15ea8dc3cae817f4073aecb2fcc21d0386747f14f89d990772003a76e2a6d25642553
beee49b [tests] Allow stderr to be tested against specified string (John Newbery) e503671 [Tests] Use LIBC_FATAL_STDERR_=1 in tests (John Newbery) c22ce8a [Tests] Write stdout/stderr to datadir instead of temp file. (John Newbery) Pull request description: **Due to a merge conflict, this is now based on #10267. Please review that PR first!** Subset of #12379 now that parts of that PR have been merged. #12362 was only observed when running the functional tests locally because: - by defatul libc logs to `/dev/tty` instead of stderr - the functional tests only check for substring inclusion in stderr when we're expecting bitcoind to fail. This PR tightens our checking of stderr and will cause tests to fail if there is any unexpected message in stderr: - commit *Write stdout/stderr to datadir instead of temp file* writes stderr to a file in the datadir instead of a temporary file. This helps with debugging in the case of failure. - commit *Use LIBC_FATAL_STDERR=1 in tests* ensures that libc failures are logged to stderr instead of the terminal. commit *Assert that bitcoind stdout is empty on shutdown* asserts that stderr is empty on bitcoind shutdown. Tree-SHA512: 21111030e667b3b686f2a7625c2b625ebcfb6998e1cccb4f3932e8b5d21fb514b19a73ac971595d049343430e9a63155986a7f5648cad55b8f36f3c58b1c7048
|
When working on the locking annotations (see #13126) I noticed that The PR #13126 adds the correct locking. FWIW Travis will catch this type of |
2352aa9 test: Ensure that recursive -includeconf produces appropriate warnings (Karl-Johan Alm) c5bcc7d util: warn about recursive -includeconf arguments in configuration files (Karl-Johan Alm) Pull request description: This is a follow-up PR to #10267, and addresses #10267 (comment). ~~I am adding extra work for @jnewbery in #12755 here -- maybe I should just rebase on top of that, but not sure what the appropriate approach is here.~~ Tree-SHA512: 87f0c32436b70424e33616ffb88d7cb699f90d6a583a10237e224b28fc936d6a9df95536c8c52ee8546b3942da92b2a357e61bf87e00d1462bc10d46d3bee352
| assert subversion.endswith("main; relative)/") | ||
| log_stderr.seek(0) | ||
| stderr = log_stderr.read().decode('utf-8').strip() | ||
| assert_equal(stderr, 'warning: -includeconf cannot be used from commandline; ignoring -includeconf=relative2.conf') |
There was a problem hiding this comment.
nit: should probably be an (init)error, since it is clearly an invalid command line
| ReadConfigStream(include_config); | ||
| LogPrintf("Included configuration file %s\n", to_include.c_str()); | ||
| } else { | ||
| fprintf(stderr, "Failed to include configuration file %s\n", to_include.c_str()); |
Summary: - adds -includeconf=<path>, where <path> is relative to datadir or to the path of the file being read, if in a file - protects against circular includes - updates help docs Backport of core PR10267 https://github.com/bitcoin/bitcoin/pull/10267/files Includes a fix from PR13126 bitcoin/bitcoin#10267 (comment) Completes T541 Progresses towards T652 Test Plan: make check ./test/functional/test_runner.py feature_includeconf Reviewers: #bitcoin_abc, deadalnix, markblundeberg Reviewed By: #bitcoin_abc, markblundeberg Subscribers: markblundeberg Maniphest Tasks: T541 Differential Revision: https://reviews.bitcoinabc.org/D3035
Summary: - adds -includeconf=<path>, where <path> is relative to datadir or to the path of the file being read, if in a file - protects against circular includes - updates help docs Backport of core PR10267 https://github.com/bitcoin/bitcoin/pull/10267/files Includes a fix from PR13126 bitcoin/bitcoin#10267 (comment) Completes T541 Progresses towards T652 Test Plan: make check ./test/functional/test_runner.py feature_includeconf Reviewers: #bitcoin_abc, deadalnix, markblundeberg Reviewed By: #bitcoin_abc, markblundeberg Subscribers: markblundeberg Maniphest Tasks: T541 Differential Revision: https://reviews.bitcoinabc.org/D3035
Summary: 2352aa9 test: Ensure that recursive -includeconf produces appropriate warnings (Karl-Johan Alm) c5bcc7d util: warn about recursive -includeconf arguments in configuration files (Karl-Johan Alm) Pull request description: This is a follow-up PR to #10267, and addresses bitcoin/bitcoin#10267 (comment). ~~I am adding extra work for @jnewbery in #12755 here -- maybe I should just rebase on top of that, but not sure what the appropriate approach is here.~~ Tree-SHA512: 87f0c32436b70424e33616ffb88d7cb699f90d6a583a10237e224b28fc936d6a9df95536c8c52ee8546b3942da92b2a357e61bf87e00d1462bc10d46d3bee352 Backport of Core PR13197 bitcoin/bitcoin#13197 Test Plan: make check test_runner.py Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D4118
Fixes: #10071.
Done:
-includeconf=<path>, where<path>is relative todatadiror to the path of the file being read, if in a file