From c5bcc7dbe9af7f4124e7c78159fe36eae3a304d4 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Wed, 9 May 2018 16:49:59 +0900 Subject: [PATCH 1/2] util: warn about recursive -includeconf arguments in configuration files Since -includeconf cannot be used recursively, the user would not see feedback that an -includeconf in an -includeconf'd file was silently ignored. --- src/util.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/util.cpp b/src/util.cpp index 7dd6884f758..6a2b2c1ed4c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -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()) { @@ -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 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()); + } } } From 2352aa9f3681fbcfb89a1910d9c5529dac9ca2e9 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Wed, 9 May 2018 16:50:02 +0900 Subject: [PATCH 2/2] test: Ensure that recursive -includeconf produces appropriate warnings --- test/functional/feature_includeconf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional/feature_includeconf.py b/test/functional/feature_includeconf.py index 1ead2fcb024..9ccb89af434 100755 --- a/test/functional/feature_includeconf.py +++ b/test/functional/feature_includeconf.py @@ -53,11 +53,11 @@ class IncludeConfTest(BitcoinTestFramework): 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: @@ -66,7 +66,7 @@ class IncludeConfTest(BitcoinTestFramework): 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)/")