Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,14 @@ void ArgsManager::ReadConfigFiles()
includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end());
}

// Remove -includeconf from configuration, so we can warn about recursion
// later
{
LOCK(cs_args);
m_config_args.erase("-includeconf");
m_config_args.erase(std::string("-") + GetChainName() + ".includeconf");
}

for (const std::string& to_include : includeconf) {
fs::ifstream include_config(GetConfigFile(to_include));
if (include_config.good()) {
Expand All @@ -799,6 +807,16 @@ void ArgsManager::ReadConfigFiles()
fprintf(stderr, "Failed to include configuration file %s\n", to_include.c_str());
}
}

// Warn about recursive -includeconf
includeconf = GetArgs("-includeconf");
{
std::vector<std::string> includeconf_net(GetArgs(std::string("-") + GetChainName() + ".includeconf"));
includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end());
}
for (const std::string& to_include : includeconf) {
fprintf(stderr, "warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", to_include.c_str());
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_includeconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def run_test(self):
self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f:
f.write("includeconf=relative2.conf\n")

self.start_node(0)

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

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

self.restart_node(0)
self.start_node(0)

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