diff --git a/src/util/system.cpp b/src/util/system.cpp --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -445,12 +445,11 @@ if (it != m_override_args.end()) { if (it->second.size() > 0) { for (const auto &ic : it->second) { - fprintf(stderr, - "warning: -includeconf cannot be used from " - "commandline; ignoring -includeconf=%s\n", - ic.c_str()); + error += "-includeconf cannot be used from commandline; " + "-includeconf=" + + ic + "\n"; } - m_override_args.erase(it); + return false; } } return true; @@ -933,13 +932,14 @@ emptyIncludeConf = m_override_args.count("-includeconf") == 0; } if (emptyIncludeConf) { + std::string chain_id = GetChainName(); std::vector includeconf(GetArgs("-includeconf")); { // We haven't set m_network yet (that happens in // SelectParams()), so manually check for network.includeconf // args. - std::vector includeconf_net(GetArgs( - std::string("-") + GetChainName() + ".includeconf")); + std::vector includeconf_net( + GetArgs(std::string("-") + chain_id + ".includeconf")); includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end()); } @@ -949,7 +949,7 @@ { LOCK(cs_args); m_config_args.erase("-includeconf"); - m_config_args.erase(std::string("-") + GetChainName() + + m_config_args.erase(std::string("-") + chain_id + ".includeconf"); } @@ -963,18 +963,29 @@ LogPrintf("Included configuration file %s\n", to_include.c_str()); } else { - fprintf(stderr, "Failed to include configuration file %s\n", - to_include.c_str()); + error = + "Failed to include configuration file " + to_include; + return false; } } // Warn about recursive -includeconf includeconf = GetArgs("-includeconf"); { - std::vector includeconf_net(GetArgs( - std::string("-") + GetChainName() + ".includeconf")); + std::vector includeconf_net( + GetArgs(std::string("-") + chain_id + ".includeconf")); includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end()); + std::string chain_id_final = GetChainName(); + if (chain_id_final != chain_id) { + // Also warn about recursive includeconf for the chain that + // was specified in one of the includeconfs + includeconf_net = GetArgs(std::string("-") + + chain_id_final + ".includeconf"); + includeconf.insert(includeconf.end(), + includeconf_net.begin(), + includeconf_net.end()); + } } for (const std::string &to_include : includeconf) { fprintf(stderr, diff --git a/test/functional/feature_includeconf.py b/test/functional/feature_includeconf.py --- a/test/functional/feature_includeconf.py +++ b/test/functional/feature_includeconf.py @@ -43,16 +43,10 @@ subversion = self.nodes[0].getnetworkinfo()["subversion"] assert subversion.endswith("main; relative)/") - self.log.info( - "-includeconf cannot be used as command-line arg. subversion should still end with 'main; relative)/'") + self.log.info("-includeconf cannot be used as command-line arg") self.stop_node(0) - - self.start_node(0, extra_args=["-includeconf=relative2.conf"]) - - subversion = self.nodes[0].getnetworkinfo()["subversion"] - assert subversion.endswith("main; relative)/") - self.stop_node( - 0, expected_stderr="warning: -includeconf cannot be used from commandline; ignoring -includeconf=relative2.conf") + self.nodes[0].assert_start_raises_init_error(extra_args=["-includeconf=relative2.conf"], + expected_msg="Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf=relative2.conf") self.log.info( "-includeconf cannot be used recursively. subversion should end with 'main; relative)/'") @@ -65,9 +59,21 @@ self.stop_node( 0, expected_stderr="warning: -includeconf cannot be used from included files; ignoring -includeconf=relative2.conf") + self.log.info("-includeconf cannot contain invalid arg") + with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f: + f.write("foo=bar\n") + self.nodes[0].assert_start_raises_init_error( + expected_msg="Error reading configuration file: Invalid configuration value foo") + + self.log.info("-includeconf cannot be invalid path") + os.remove(os.path.join(self.options.tmpdir, "node0", "relative.conf")) + self.nodes[0].assert_start_raises_init_error( + expected_msg="Error reading configuration file: Failed to include configuration file relative.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: + # Restore initial file contents f.write("uacomment=relative\n") with open(os.path.join(self.options.tmpdir, "node0", "bitcoin.conf"), "a", encoding='utf8') as f: