aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/bip32.cpp2
-rw-r--r--src/util/bip32.h2
-rw-r--r--src/util/error.cpp2
-rw-r--r--src/util/error.h2
-rw-r--r--src/util/fees.cpp2
-rw-r--r--src/util/fees.h2
-rw-r--r--src/util/moneystr.cpp6
-rw-r--r--src/util/moneystr.h2
-rw-r--r--src/util/rbf.cpp2
-rw-r--r--src/util/rbf.h2
-rw-r--r--src/util/settings.cpp29
-rw-r--r--src/util/settings.h11
-rw-r--r--src/util/spanparsing.cpp2
-rw-r--r--src/util/spanparsing.h2
-rw-r--r--src/util/strencodings.cpp17
-rw-r--r--src/util/strencodings.h2
-rw-r--r--src/util/string.h21
-rw-r--r--src/util/system.cpp94
-rw-r--r--src/util/system.h33
-rw-r--r--src/util/threadnames.cpp2
-rw-r--r--src/util/threadnames.h2
-rw-r--r--src/util/url.cpp2
-rw-r--r--src/util/url.h2
23 files changed, 150 insertions, 93 deletions
diff --git a/src/util/bip32.cpp b/src/util/bip32.cpp
index 6f176dd5ec..571c6ec5e1 100644
--- a/src/util/bip32.cpp
+++ b/src/util/bip32.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2019 The Bitcoin Core developers
+// Copyright (c) 2019-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/bip32.h b/src/util/bip32.h
index 7e58b79f38..c93940e4eb 100644
--- a/src/util/bip32.h
+++ b/src/util/bip32.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2019 The Bitcoin Core developers
+// Copyright (c) 2019-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/error.cpp b/src/util/error.cpp
index aa44ed3e3a..72a6e87cde 100644
--- a/src/util/error.cpp
+++ b/src/util/error.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2010-2018 The Bitcoin Core developers
+// Copyright (c) 2010-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/error.h b/src/util/error.h
index f540b0020d..61af88ddea 100644
--- a/src/util/error.h
+++ b/src/util/error.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010-2018 The Bitcoin Core developers
+// Copyright (c) 2010-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/fees.cpp b/src/util/fees.cpp
index 41149888d7..b335bfa666 100644
--- a/src/util/fees.cpp
+++ b/src/util/fees.cpp
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2018 The Bitcoin Core developers
+// Copyright (c) 2009-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/fees.h b/src/util/fees.h
index fc355ce9c2..a930c8935a 100644
--- a/src/util/fees.h
+++ b/src/util/fees.h
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2018 The Bitcoin Core developers
+// Copyright (c) 2009-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_UTIL_FEES_H
diff --git a/src/util/moneystr.cpp b/src/util/moneystr.cpp
index ba5a12e58c..2797f450ca 100644
--- a/src/util/moneystr.cpp
+++ b/src/util/moneystr.cpp
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2018 The Bitcoin Core developers
+// Copyright (c) 2009-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -7,6 +7,7 @@
#include <tinyformat.h>
#include <util/strencodings.h>
+#include <util/string.h>
std::string FormatMoney(const CAmount& n)
{
@@ -32,6 +33,9 @@ std::string FormatMoney(const CAmount& n)
bool ParseMoney(const std::string& str, CAmount& nRet)
{
+ if (!ValidAsCString(str)) {
+ return false;
+ }
return ParseMoney(str.c_str(), nRet);
}
diff --git a/src/util/moneystr.h b/src/util/moneystr.h
index 4d0218911a..027c7e2e53 100644
--- a/src/util/moneystr.h
+++ b/src/util/moneystr.h
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2018 The Bitcoin Core developers
+// Copyright (c) 2009-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/rbf.cpp b/src/util/rbf.cpp
index d520a9606d..ef536bdcad 100644
--- a/src/util/rbf.cpp
+++ b/src/util/rbf.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018 The Bitcoin Core developers
+// Copyright (c) 2016-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/rbf.h b/src/util/rbf.h
index d3ef110628..6a20b37de5 100644
--- a/src/util/rbf.h
+++ b/src/util/rbf.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018 The Bitcoin Core developers
+// Copyright (c) 2016-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/settings.cpp b/src/util/settings.cpp
index af75fef310..e4979df755 100644
--- a/src/util/settings.cpp
+++ b/src/util/settings.cpp
@@ -56,6 +56,7 @@ SettingsValue GetSetting(const Settings& settings,
bool get_chain_name)
{
SettingsValue result;
+ bool done = false; // Done merging any more settings sources.
MergeSettings(settings, section, name, [&](SettingsSpan span, Source source) {
// Weird behavior preserved for backwards compatibility: Apply negated
// setting even if non-negated setting would be ignored. A negated
@@ -68,7 +69,9 @@ SettingsValue GetSetting(const Settings& settings,
// precedence over early settings, but for backwards compatibility in
// the config file the precedence is reversed for all settings except
// chain name settings.
- const bool reverse_precedence = (source == Source::CONFIG_FILE_NETWORK_SECTION || source == Source::CONFIG_FILE_DEFAULT_SECTION) && !get_chain_name;
+ const bool reverse_precedence =
+ (source == Source::CONFIG_FILE_NETWORK_SECTION || source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
+ !get_chain_name;
// Weird behavior preserved for backwards compatibility: Negated
// -regtest and -testnet arguments which you would expect to override
@@ -77,19 +80,23 @@ SettingsValue GetSetting(const Settings& settings,
// negated values, or at least warn they are ignored.
const bool skip_negated_command_line = get_chain_name;
+ if (done) return;
+
// Ignore settings in default config section if requested.
- if (ignore_default_section_config && source == Source::CONFIG_FILE_DEFAULT_SECTION && !never_ignore_negated_setting) return;
+ if (ignore_default_section_config && source == Source::CONFIG_FILE_DEFAULT_SECTION &&
+ !never_ignore_negated_setting) {
+ return;
+ }
// Skip negated command line settings.
if (skip_negated_command_line && span.last_negated()) return;
- // Stick with highest priority value, keeping result if already set.
- if (!result.isNull()) return;
-
if (!span.empty()) {
result = reverse_precedence ? span.begin()[0] : span.end()[-1];
+ done = true;
} else if (span.last_negated()) {
result = false;
+ done = true;
}
});
return result;
@@ -101,7 +108,7 @@ std::vector<SettingsValue> GetSettingsList(const Settings& settings,
bool ignore_default_section_config)
{
std::vector<SettingsValue> result;
- bool result_complete = false;
+ bool done = false; // Done merging any more settings sources.
bool prev_negated_empty = false;
MergeSettings(settings, section, name, [&](SettingsSpan span, Source source) {
// Weird behavior preserved for backwards compatibility: Apply config
@@ -111,14 +118,16 @@ std::vector<SettingsValue> GetSettingsList(const Settings& settings,
// value is followed by non-negated value, in which case config file
// settings will be brought back from the dead (but earlier command
// line settings will still be ignored).
- const bool add_zombie_config_values = (source == Source::CONFIG_FILE_NETWORK_SECTION || source == Source::CONFIG_FILE_DEFAULT_SECTION) && !prev_negated_empty;
+ const bool add_zombie_config_values =
+ (source == Source::CONFIG_FILE_NETWORK_SECTION || source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
+ !prev_negated_empty;
// Ignore settings in default config section if requested.
if (ignore_default_section_config && source == Source::CONFIG_FILE_DEFAULT_SECTION) return;
// Add new settings to the result if isn't already complete, or if the
// values are zombies.
- if (!result_complete || add_zombie_config_values) {
+ if (!done || add_zombie_config_values) {
for (const auto& value : span) {
if (value.isArray()) {
result.insert(result.end(), value.getValues().begin(), value.getValues().end());
@@ -129,8 +138,8 @@ std::vector<SettingsValue> GetSettingsList(const Settings& settings,
}
// If a setting was negated, or if a setting was forced, set
- // result_complete to true to ignore any later lower priority settings.
- result_complete |= span.negated() > 0 || source == Source::FORCED;
+ // done to true to ignore any later lower priority settings.
+ done |= span.negated() > 0 || source == Source::FORCED;
// Update the negated and empty state used for the zombie values check.
prev_negated_empty |= span.last_negated() && result.empty();
diff --git a/src/util/settings.h b/src/util/settings.h
index 17832e4d2c..9ca581109d 100644
--- a/src/util/settings.h
+++ b/src/util/settings.h
@@ -43,11 +43,18 @@ struct Settings {
//! [section] keywords)
//! @param get_chain_name - enable special backwards compatible behavior
//! for GetChainName
-SettingsValue GetSetting(const Settings& settings, const std::string& section, const std::string& name, bool ignore_default_section_config, bool get_chain_name);
+SettingsValue GetSetting(const Settings& settings,
+ const std::string& section,
+ const std::string& name,
+ bool ignore_default_section_config,
+ bool get_chain_name);
//! Get combined setting value similar to GetSetting(), except if setting was
//! specified multiple times, return a list of all the values specified.
-std::vector<SettingsValue> GetSettingsList(const Settings& settings, const std::string& section, const std::string& name, bool ignore_default_section_config);
+std::vector<SettingsValue> GetSettingsList(const Settings& settings,
+ const std::string& section,
+ const std::string& name,
+ bool ignore_default_section_config);
//! Return true if a setting is set in the default config file section, and not
//! overridden by a higher priority command-line or network section value.
diff --git a/src/util/spanparsing.cpp b/src/util/spanparsing.cpp
index 0c8575399a..0f68254f2c 100644
--- a/src/util/spanparsing.cpp
+++ b/src/util/spanparsing.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2018 The Bitcoin Core developers
+// Copyright (c) 2018-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/spanparsing.h b/src/util/spanparsing.h
index 63f54758bd..fa2e698e6d 100644
--- a/src/util/spanparsing.h
+++ b/src/util/spanparsing.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2018 The Bitcoin Core developers
+// Copyright (c) 2018-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp
index 46042f5634..eec1a52e95 100644
--- a/src/util/strencodings.cpp
+++ b/src/util/strencodings.cpp
@@ -1,9 +1,10 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2018 The Bitcoin Core developers
+// Copyright (c) 2009-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <util/strencodings.h>
+#include <util/string.h>
#include <tinyformat.h>
@@ -190,6 +191,12 @@ std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid)
std::string DecodeBase64(const std::string& str, bool* pf_invalid)
{
+ if (!ValidAsCString(str)) {
+ if (pf_invalid) {
+ *pf_invalid = true;
+ }
+ return {};
+ }
std::vector<unsigned char> vchRet = DecodeBase64(str.c_str(), pf_invalid);
return std::string((const char*)vchRet.data(), vchRet.size());
}
@@ -259,6 +266,12 @@ std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid)
std::string DecodeBase32(const std::string& str, bool* pf_invalid)
{
+ if (!ValidAsCString(str)) {
+ if (pf_invalid) {
+ *pf_invalid = true;
+ }
+ return {};
+ }
std::vector<unsigned char> vchRet = DecodeBase32(str.c_str(), pf_invalid);
return std::string((const char*)vchRet.data(), vchRet.size());
}
@@ -269,7 +282,7 @@ NODISCARD static bool ParsePrechecks(const std::string& str)
return false;
if (str.size() >= 1 && (IsSpace(str[0]) || IsSpace(str[str.size()-1]))) // No padding allowed
return false;
- if (str.size() != strlen(str.c_str())) // No embedded NUL characters allowed
+ if (!ValidAsCString(str)) // No embedded NUL characters allowed
return false;
return true;
}
diff --git a/src/util/strencodings.h b/src/util/strencodings.h
index e35b2ab857..ccc4edac12 100644
--- a/src/util/strencodings.h
+++ b/src/util/strencodings.h
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2018 The Bitcoin Core developers
+// Copyright (c) 2009-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/string.h b/src/util/string.h
index 76a83a4949..3db8fc8b98 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -5,9 +5,22 @@
#ifndef BITCOIN_UTIL_STRING_H
#define BITCOIN_UTIL_STRING_H
+#include <attributes.h>
+
+#include <cstring>
#include <string>
#include <vector>
+NODISCARD inline std::string TrimString(const std::string& str, const std::string& pattern = " \f\n\r\t\v")
+{
+ std::string::size_type front = str.find_first_not_of(pattern);
+ if (front == std::string::npos) {
+ return std::string();
+ }
+ std::string::size_type end = str.find_last_not_of(pattern);
+ return str.substr(front, end - front + 1);
+}
+
/**
* Join a list of items
*
@@ -31,4 +44,12 @@ inline std::string Join(const std::vector<std::string>& list, const std::string&
return Join(list, separator, [](const std::string& i) { return i; });
}
+/**
+ * Check if a string does not contain any embedded NUL (\0) characters
+ */
+NODISCARD inline bool ValidAsCString(const std::string& str) noexcept
+{
+ return str.size() == strlen(str.c_str());
+}
+
#endif // BITCOIN_UTIL_STRENCODINGS_H
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 2a2ae6fdf5..8d1efc170a 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -7,6 +7,7 @@
#include <chainparamsbase.h>
#include <util/strencodings.h>
+#include <util/string.h>
#include <util/translation.h>
@@ -63,6 +64,7 @@
#endif
#include <thread>
+#include <typeinfo>
#include <univalue.h>
// Application startup time (used for uptime calculation)
@@ -167,23 +169,6 @@ static std::string SettingName(const std::string& arg)
return arg.size() > 0 && arg[0] == '-' ? arg.substr(1) : arg;
}
-/** Internal helper functions for ArgsManager */
-class ArgsManagerHelper {
-public:
- /** Determine whether to use config settings in the default section,
- * See also comments around ArgsManager::ArgsManager() below. */
- static inline bool UseDefaultSection(const ArgsManager& am, const std::string& arg) EXCLUSIVE_LOCKS_REQUIRED(am.cs_args)
- {
- return (am.m_network == CBaseChainParams::MAIN || am.m_network_only_args.count(arg) == 0);
- }
-
- static util::SettingsValue Get(const ArgsManager& am, const std::string& arg)
- {
- LOCK(am.cs_args);
- return GetSetting(am.m_settings, am.m_network, SettingName(arg), !UseDefaultSection(am, arg), /* get_chain_name= */ false);
- }
-};
-
/**
* Interpret -nofoo as if the user supplied -foo=0.
*
@@ -326,9 +311,9 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
key.erase(0, 1);
std::string section;
util::SettingsValue value = InterpretOption(section, key, val);
- const unsigned int flags = FlagsOfKnownArg(key);
+ Optional<unsigned int> flags = GetArgFlags('-' + key);
if (flags) {
- if (!CheckValid(key, value, flags, error)) {
+ if (!CheckValid(key, value, *flags, error)) {
return false;
}
// Weird behavior preserved for backwards compatibility: command
@@ -344,7 +329,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
}
}
- // we do not allow -includeconf from command line, so we clear it here
+ // we do not allow -includeconf from command line
bool success = true;
if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
for (const auto& include : util::SettingsSpan(*includes)) {
@@ -355,25 +340,22 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
return success;
}
-unsigned int ArgsManager::FlagsOfKnownArg(const std::string& key) const
+Optional<unsigned int> ArgsManager::GetArgFlags(const std::string& name) const
{
LOCK(cs_args);
for (const auto& arg_map : m_available_args) {
- const auto search = arg_map.second.find('-' + key);
+ const auto search = arg_map.second.find(name);
if (search != arg_map.second.end()) {
return search->second.m_flags;
}
}
- return ArgsManager::NONE;
+ return nullopt;
}
std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
{
- LOCK(cs_args);
- bool ignore_default_section_config = !ArgsManagerHelper::UseDefaultSection(*this, strArg);
std::vector<std::string> result;
- for (const util::SettingsValue& value :
- util::GetSettingsList(m_settings, m_network, SettingName(strArg), ignore_default_section_config)) {
+ for (const util::SettingsValue& value : GetSettingsList(strArg)) {
result.push_back(value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str());
}
return result;
@@ -381,29 +363,29 @@ std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
bool ArgsManager::IsArgSet(const std::string& strArg) const
{
- return !ArgsManagerHelper::Get(*this, strArg).isNull();
+ return !GetSetting(strArg).isNull();
}
bool ArgsManager::IsArgNegated(const std::string& strArg) const
{
- return ArgsManagerHelper::Get(*this, strArg).isFalse();
+ return GetSetting(strArg).isFalse();
}
std::string ArgsManager::GetArg(const std::string& strArg, const std::string& strDefault) const
{
- const util::SettingsValue value = ArgsManagerHelper::Get(*this, strArg);
+ const util::SettingsValue value = GetSetting(strArg);
return value.isNull() ? strDefault : value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str();
}
int64_t ArgsManager::GetArg(const std::string& strArg, int64_t nDefault) const
{
- const util::SettingsValue value = ArgsManagerHelper::Get(*this, strArg);
+ const util::SettingsValue value = GetSetting(strArg);
return value.isNull() ? nDefault : value.isFalse() ? 0 : value.isTrue() ? 1 : value.isNum() ? value.get_int64() : atoi64(value.get_str());
}
bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const
{
- const util::SettingsValue value = ArgsManagerHelper::Get(*this, strArg);
+ const util::SettingsValue value = GetSetting(strArg);
return value.isNull() ? fDefault : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
}
@@ -679,16 +661,6 @@ fs::path GetConfigFile(const std::string& confPath)
return AbsPathForConfigVal(fs::path(confPath), false);
}
-static std::string TrimString(const std::string& str, const std::string& pattern)
-{
- std::string::size_type front = str.find_first_not_of(pattern);
- if (front == std::string::npos) {
- return std::string();
- }
- std::string::size_type end = str.find_last_not_of(pattern);
- return str.substr(front, end - front + 1);
-}
-
static bool GetConfigOptions(std::istream& stream, const std::string& filepath, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::list<SectionInfo>& sections)
{
std::string str, prefix;
@@ -745,9 +717,9 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
std::string section;
std::string key = option.first;
util::SettingsValue value = InterpretOption(section, key, option.second);
- const unsigned int flags = FlagsOfKnownArg(key);
+ Optional<unsigned int> flags = GetArgFlags('-' + key);
if (flags) {
- if (!CheckValid(key, value, flags, error)) {
+ if (!CheckValid(key, value, *flags, error)) {
return false;
}
m_settings.ro_config[section][key].push_back(value);
@@ -780,7 +752,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
return false;
}
// `-includeconf` cannot be included in the command line arguments except
- // as `-noincludeconf` (which indicates that no conf file should be used).
+ // as `-noincludeconf` (which indicates that no included conf file should be used).
bool use_conf_file{true};
{
LOCK(cs_args);
@@ -854,9 +826,9 @@ std::string ArgsManager::GetChainName() const
{
auto get_net = [&](const std::string& arg) {
LOCK(cs_args);
- util::SettingsValue value = GetSetting(m_settings, /* section= */ "", SettingName(arg),
- /* ignore_default_section_config= */ false,
- /* get_chain_name= */ true);
+ util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg),
+ /* ignore_default_section_config= */ false,
+ /* get_chain_name= */ true);
return value.isNull() ? false : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
};
@@ -874,6 +846,24 @@ std::string ArgsManager::GetChainName() const
return GetArg("-chain", CBaseChainParams::MAIN);
}
+bool ArgsManager::UseDefaultSection(const std::string& arg) const
+{
+ return m_network == CBaseChainParams::MAIN || m_network_only_args.count(arg) == 0;
+}
+
+util::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
+{
+ LOCK(cs_args);
+ return util::GetSetting(
+ m_settings, m_network, SettingName(arg), !UseDefaultSection(arg), /* get_chain_name= */ false);
+}
+
+std::vector<util::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const
+{
+ LOCK(cs_args);
+ return util::GetSettingsList(m_settings, m_network, SettingName(arg), !UseDefaultSection(arg));
+}
+
bool RenameOver(fs::path src, fs::path dest)
{
#ifdef WIN32
@@ -1126,17 +1116,13 @@ fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific)
return fs::absolute(path, GetDataDir(net_specific));
}
-int ScheduleBatchPriority()
+void ScheduleBatchPriority()
{
#ifdef SCHED_BATCH
const static sched_param param{};
- if (int ret = pthread_setschedparam(pthread_self(), SCHED_BATCH, &param)) {
+ if (pthread_setschedparam(pthread_self(), SCHED_BATCH, &param) != 0) {
LogPrintf("Failed to pthread_setschedparam: %s\n", strerror(errno));
- return ret;
}
- return 0;
-#else
- return 1;
#endif
}
diff --git a/src/util/system.h b/src/util/system.h
index e0b6371dc9..394adb9555 100644
--- a/src/util/system.h
+++ b/src/util/system.h
@@ -19,6 +19,7 @@
#include <compat/assumptions.h>
#include <fs.h>
#include <logging.h>
+#include <optional.h>
#include <sync.h>
#include <tinyformat.h>
#include <util/memory.h>
@@ -132,7 +133,6 @@ class ArgsManager
{
public:
enum Flags {
- NONE = 0x00,
// Boolean options can accept negation syntax -noOPTION or -noOPTION=1
ALLOW_BOOL = 0x01,
ALLOW_INT = 0x02,
@@ -148,8 +148,6 @@ public:
};
protected:
- friend class ArgsManagerHelper;
-
struct Arg
{
std::string m_help_param;
@@ -166,6 +164,27 @@ protected:
NODISCARD bool ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys = false);
+ /**
+ * Returns true if settings values from the default section should be used,
+ * depending on the current network and whether the setting is
+ * network-specific.
+ */
+ bool UseDefaultSection(const std::string& arg) const EXCLUSIVE_LOCKS_REQUIRED(cs_args);
+
+ /**
+ * Get setting value.
+ *
+ * Result will be null if setting was unset, true if "-setting" argument was passed
+ * false if "-nosetting" argument was passed, and a string if a "-setting=value"
+ * argument was passed.
+ */
+ util::SettingsValue GetSetting(const std::string& arg) const;
+
+ /**
+ * Get list of setting values.
+ */
+ std::vector<util::SettingsValue> GetSettingsList(const std::string& arg) const;
+
public:
ArgsManager();
@@ -296,9 +315,9 @@ public:
/**
* Return Flags for known arg.
- * Return ArgsManager::NONE for unknown arg.
+ * Return nullopt for unknown arg.
*/
- unsigned int FlagsOfKnownArg(const std::string& key) const;
+ Optional<unsigned int> GetArgFlags(const std::string& name) const;
};
extern ArgsManager gArgs;
@@ -367,10 +386,8 @@ std::string CopyrightHolders(const std::string& strPrefix);
* On platforms that support it, tell the kernel the calling thread is
* CPU-intensive and non-interactive. See SCHED_BATCH in sched(7) for details.
*
- * @return The return value of sched_setschedule(), or 1 on systems without
- * sched_setschedule().
*/
-int ScheduleBatchPriority();
+void ScheduleBatchPriority();
namespace util {
diff --git a/src/util/threadnames.cpp b/src/util/threadnames.cpp
index 20df403a66..764fffabd7 100644
--- a/src/util/threadnames.cpp
+++ b/src/util/threadnames.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2018 The Bitcoin Core developers
+// Copyright (c) 2018-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/threadnames.h b/src/util/threadnames.h
index 69a1b55bfe..64b2689cf1 100644
--- a/src/util/threadnames.h
+++ b/src/util/threadnames.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2018 The Bitcoin Core developers
+// Copyright (c) 2018-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/url.cpp b/src/util/url.cpp
index 49eacbf2d0..e42d93bce8 100644
--- a/src/util/url.cpp
+++ b/src/util/url.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2015-2018 The Bitcoin Core developers
+// Copyright (c) 2015-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
diff --git a/src/util/url.h b/src/util/url.h
index 3d7315a338..e9ea2ab765 100644
--- a/src/util/url.h
+++ b/src/util/url.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2015-2018 The Bitcoin Core developers
+// Copyright (c) 2015-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.