Skip to content

Commit 6826989

Browse files
committed
Merge #13197: util: warn about ignored recursive -includeconf calls
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
2 parents 0264836 + 2352aa9 commit 6826989

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/util.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,14 @@ void ArgsManager::ReadConfigFiles()
790790
includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end());
791791
}
792792

793+
// Remove -includeconf from configuration, so we can warn about recursion
794+
// later
795+
{
796+
LOCK(cs_args);
797+
m_config_args.erase("-includeconf");
798+
m_config_args.erase(std::string("-") + GetChainName() + ".includeconf");
799+
}
800+
793801
for (const std::string& to_include : includeconf) {
794802
fs::ifstream include_config(GetConfigFile(to_include));
795803
if (include_config.good()) {
@@ -799,6 +807,16 @@ void ArgsManager::ReadConfigFiles()
799807
fprintf(stderr, "Failed to include configuration file %s\n", to_include.c_str());
800808
}
801809
}
810+
811+
// Warn about recursive -includeconf
812+
includeconf = GetArgs("-includeconf");
813+
{
814+
std::vector<std::string> includeconf_net(GetArgs(std::string("-") + GetChainName() + ".includeconf"));
815+
includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end());
816+
}
817+
for (const std::string& to_include : includeconf) {
818+
fprintf(stderr, "warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", to_include.c_str());
819+
}
802820
}
803821
}
804822

test/functional/feature_includeconf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ def run_test(self):
5353
self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")
5454
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f:
5555
f.write("includeconf=relative2.conf\n")
56-
5756
self.start_node(0)
5857

5958
subversion = self.nodes[0].getnetworkinfo()["subversion"]
6059
assert subversion.endswith("main; relative)/")
60+
self.stop_node(0, expected_stderr="warning: -includeconf cannot be used from included files; ignoring -includeconf=relative2.conf")
6161

6262
self.log.info("multiple -includeconf args can be used from the base config file. subversion should end with 'main; relative; relative2)/'")
6363
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f:
@@ -66,7 +66,7 @@ def run_test(self):
6666
with open(os.path.join(self.options.tmpdir, "node0", "bitcoin.conf"), "a", encoding='utf8') as f:
6767
f.write("includeconf=relative2.conf\n")
6868

69-
self.restart_node(0)
69+
self.start_node(0)
7070

7171
subversion = self.nodes[0].getnetworkinfo()["subversion"]
7272
assert subversion.endswith("main; relative; relative2)/")

0 commit comments

Comments
 (0)