| 885 | } |
| 886 | |
| 887 | bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) |
| 888 | { |
| 889 | { |
| 890 | LOCK(cs_args); |
| 891 | m_config_args.clear(); |
| 892 | } |
| 893 | |
| 894 | const std::string confPath = GetArg("-conf", BITCOIN_CONF_FILENAME); |
| 895 | fs::ifstream stream(GetConfigFile(confPath)); |
| 896 | |
| 897 | // ok to not have a config file |
| 898 | if (stream.good()) { |
| 899 | if (!ReadConfigStream(stream, error, ignore_invalid_keys)) { |
| 900 | return false; |
| 901 | } |
| 902 | // if there is an -includeconf in the override args, but it is empty, that means the user |
| 903 | // passed '-noincludeconf' on the command line, in which case we should not include anything |
| 904 | if (m_override_args.count("-includeconf") == 0) { |
| 905 | std::string chain_id = GetChainName(); |
| 906 | std::vector<std::string> includeconf(GetArgs("-includeconf")); |
| 907 | { |
| 908 | // We haven't set m_network yet (that happens in SelectParams()), so manually check |
| 909 | // for network.includeconf args. |
| 910 | std::vector<std::string> includeconf_net(GetArgs(std::string("-") + chain_id + ".includeconf")); |
| 911 | includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end()); |
| 912 | } |
| 913 | |
| 914 | // Remove -includeconf from configuration, so we can warn about recursion |
| 915 | // later |
| 916 | { |
| 917 | LOCK(cs_args); |
| 918 | m_config_args.erase("-includeconf"); |
| 919 | m_config_args.erase(std::string("-") + chain_id + ".includeconf"); |
| 920 | } |
| 921 | |
| 922 | for (const std::string& to_include : includeconf) { |
| 923 | fs::ifstream include_config(GetConfigFile(to_include)); |
| 924 | if (include_config.good()) { |
| 925 | if (!ReadConfigStream(include_config, error, ignore_invalid_keys)) { |
| 926 | return false; |
| 927 | } |
| 928 | LogPrintf("Included configuration file %s\n", to_include.c_str()); |
| 929 | } else { |
| 930 | error = "Failed to include configuration file " + to_include; |
| 931 | return false; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | // Warn about recursive -includeconf |
| 936 | includeconf = GetArgs("-includeconf"); |
| 937 | { |
| 938 | std::vector<std::string> includeconf_net(GetArgs(std::string("-") + chain_id + ".includeconf")); |
| 939 | includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end()); |
| 940 | std::string chain_id_final = GetChainName(); |
| 941 | if (chain_id_final != chain_id) { |
| 942 | // Also warn about recursive includeconf for the chain that was specified in one of the includeconfs |
| 943 | includeconf_net = GetArgs(std::string("-") + chain_id_final + ".includeconf"); |
| 944 | includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end()); |
no test coverage detected