9 #ifdef HAVE_BOOST_PROCESS 10 #include <boost/process.hpp> 11 #endif // HAVE_BOOST_PROCESS 19 #if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) 21 #include <pthread_np.h> 28 #ifdef _POSIX_C_SOURCE 29 #undef _POSIX_C_SOURCE 32 #define _POSIX_C_SOURCE 200112L 40 #include <sys/resource.h> 46 #pragma warning(disable:4786) 47 #pragma warning(disable:4804) 48 #pragma warning(disable:4805) 49 #pragma warning(disable:4717) 62 #ifdef HAVE_MALLOPT_ARENA_MAX 66 #include <boost/algorithm/string/replace.hpp> 86 static std::map<std::string, std::unique_ptr<fsbridge::FileLock>> dir_locks
GUARDED_BY(cs_dir_locks);
88 bool LockDirectory(
const fs::path& directory,
const std::string lockfile_name,
bool probe_only)
91 fs::path pathLockFile = directory / lockfile_name;
94 if (dir_locks.count(pathLockFile.string())) {
100 if (file) fclose(file);
101 auto lock = MakeUnique<fsbridge::FileLock>(pathLockFile);
102 if (!lock->TryLock()) {
103 return error(
"Error while attempting to lock directory %s: %s", directory.string(), lock->GetReason());
107 dir_locks.emplace(pathLockFile.string(), std::move(lock));
115 dir_locks.erase((directory / lockfile_name).
string());
126 fs::path tmpFile = directory / fs::unique_path();
129 if (!file)
return false;
139 constexpr uint64_t min_disk_space = 52428800;
141 uint64_t free_bytes_available = fs::space(dir).available;
142 return free_bytes_available >= min_disk_space + additional_bytes;
145 std::streampos
GetFileSize(
const char* path, std::streamsize max) {
148 return file.gcount();
170 if (strValue.empty())
172 return (
atoi(strValue) != 0);
177 return arg.size() > 0 && arg[0] ==
'-' ? arg.substr(1) : arg;
203 size_t option_index = key.find(
'.');
204 if (option_index != std::string::npos) {
205 section = key.substr(0, option_index);
206 key.erase(0, option_index + 1);
208 if (key.substr(0, 2) ==
"no") {
212 LogPrintf(
"Warning: parsed potentially confusing double-negative -%s=%s\n", key, value);
230 error =
strprintf(
"Negating of -%s is meaningless and therefore forbidden", key);
244 std::set<std::string> unsuitables;
249 if (m_network.empty())
return std::set<std::string> {};
254 for (
const auto& arg : m_network_only_args) {
256 unsuitables.insert(arg);
265 static const std::set<std::string> available_sections{
273 std::list<SectionInfo> unrecognized = m_config_sections;
274 unrecognized.remove_if([](
const SectionInfo& appeared){
return available_sections.find(appeared.
m_name) != available_sections.end(); });
287 m_settings.command_line_options.clear();
289 for (
int i = 1; i < argc; i++) {
290 std::string key(argv[i]);
297 if (key.substr(0, 5) ==
"-psn_")
continue;
300 if (key ==
"-")
break;
302 size_t is_index = key.find(
'=');
303 if (is_index != std::string::npos) {
304 val = key.substr(is_index + 1);
317 if (key.length() > 1 && key[1] ==
'-')
329 if (!flags || !section.empty()) {
330 error =
strprintf(
"Invalid parameter %s", argv[i]);
334 if (!
CheckValid(key, value, *flags, error))
return false;
336 m_settings.command_line_options[key].push_back(value);
341 if (
auto* includes =
util::FindKey(m_settings.command_line_options,
"includeconf")) {
343 error +=
"-includeconf cannot be used from commandline; -includeconf=" + include.get_str() +
"\n";
353 for (
const auto& arg_map : m_available_args) {
354 const auto search = arg_map.second.find(name);
355 if (search != arg_map.second.end()) {
356 return search->second.m_flags;
364 std::vector<std::string> result;
366 result.push_back(value.isFalse() ?
"0" : value.isTrue() ?
"1" : value.get_str());
382 std::vector<std::string> errors;
384 error =
strprintf(
"Failed loading settings file:\n- %s\n",
Join(errors,
"\n- "));
388 error =
strprintf(
"Failed saving settings file:\n- %s\n",
Join(errors,
"\n- "));
401 *filepath = fs::absolute(temp ? settings +
".tmp" : settings,
GetDataDir(
true));
406 static void SaveErrors(
const std::vector<std::string> errors, std::vector<std::string>* error_out)
408 for (
const auto&
error : errors) {
410 error_out->emplace_back(
error);
425 m_settings.rw_settings.clear();
426 std::vector<std::string> read_errors;
431 for (
const auto& setting : m_settings.rw_settings) {
433 std::string key = setting.first;
436 LogPrintf(
"Ignoring unknown rw_settings value %s\n", setting.first);
444 fs::path path, path_tmp;
446 throw std::logic_error(
"Attempt to write settings file when dynamic settings are disabled.");
450 std::vector<std::string> write_errors;
456 SaveErrors({
strprintf(
"Failed renaming settings file %s to %s\n", path_tmp.string(), path.string())}, errors);
504 m_settings.forced_settings[
SettingName(strArg)] = strValue;
510 size_t eq_index = name.find(
'=');
511 if (eq_index == std::string::npos) {
512 eq_index = name.size();
514 std::string arg_name = name.substr(0, eq_index);
517 std::map<std::string, Arg>& arg_map = m_available_args[cat];
518 auto ret = arg_map.emplace(arg_name,
Arg{name.substr(eq_index, name.size() - eq_index), help, flags});
522 m_network_only_args.emplace(arg_name);
528 for (
const std::string&
name : names) {
535 const bool show_debug =
GetBoolArg(
"-help-debug",
false);
537 std::string usage =
"";
539 for (
const auto& arg_map : m_available_args) {
540 switch(arg_map.first) {
566 if (show_debug) usage +=
HelpMessageGroup(
"Wallet debugging/testing options:");
587 for (
const auto& arg : arg_map.second) {
590 if (arg.second.m_help_param.empty()) {
593 name = arg.first + arg.second.m_help_param;
618 return std::string(message) + std::string(
"\n\n");
621 std::string
HelpMessageOpt(
const std::string &option,
const std::string &message) {
622 return std::string(
optIndent,
' ') + std::string(option) +
623 std::string(
"\n") + std::string(
msgIndent,
' ') +
632 GetModuleFileNameA(
nullptr, pszModule,
sizeof(pszModule));
634 const char* pszModule =
"bitcoin";
638 "EXCEPTION: %s \n%s \n%s in %s \n",
typeid(*pex).name(), pex->what(), pszModule, pszThread);
641 "UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread);
647 LogPrintf(
"\n\n************************\n%s\n", message);
648 tfm::format(std::cerr,
"\n\n************************\n%s\n", message);
658 return GetSpecialFolderPath(CSIDL_APPDATA) /
"Bitcoin";
661 char* pszHome = getenv(
"HOME");
662 if (pszHome ==
nullptr || strlen(pszHome) == 0)
663 pathRet = fs::path(
"/");
665 pathRet = fs::path(pszHome);
668 return pathRet /
"Library/Application Support/Bitcoin";
671 return pathRet /
".bitcoin";
677 fs::path StripRedundantLastElementsOfPath(
const fs::path& path)
680 while (result.filename().string() ==
".") {
681 result = result.parent_path();
684 assert(fs::equivalent(result, path));
701 if (!path.empty())
return path;
704 path = fs::system_complete(gArgs.
GetArg(
"-blocksdir",
""));
705 if (!fs::is_directory(path)) {
715 fs::create_directories(path);
716 path = StripRedundantLastElementsOfPath(path);
727 if (!path.empty())
return path;
729 std::string datadir = gArgs.
GetArg(
"-datadir",
"");
730 if (!datadir.empty()) {
731 path = fs::system_complete(datadir);
732 if (!fs::is_directory(path)) {
742 if (fs::create_directories(path)) {
744 fs::create_directories(path /
"wallets");
747 path = StripRedundantLastElementsOfPath(path);
753 std::string datadir = gArgs.
GetArg(
"-datadir",
"");
754 return datadir.empty() || fs::is_directory(fs::system_complete(datadir));
771 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)
774 std::string::size_type pos;
776 while (std::getline(stream, str)) {
777 bool used_hash =
false;
778 if ((pos = str.find(
'#')) != std::string::npos) {
779 str = str.substr(0, pos);
782 const static std::string pattern =
" \t\r\n";
785 if (*str.begin() ==
'[' && *str.rbegin() ==
']') {
786 const std::string section = str.substr(1, str.size() - 2);
787 sections.emplace_back(
SectionInfo{section, filepath, linenr});
788 prefix = section +
'.';
789 }
else if (*str.begin() ==
'-') {
790 error =
strprintf(
"parse error on line %i: %s, options in configuration file must be specified without leading -", linenr, str);
792 }
else if ((pos = str.find(
'=')) != std::string::npos) {
793 std::string
name = prefix +
TrimString(str.substr(0, pos), pattern);
794 std::string value =
TrimString(str.substr(pos + 1), pattern);
795 if (used_hash && name.find(
"rpcpassword") != std::string::npos) {
796 error =
strprintf(
"parse error on line %i, using # in rpcpassword can be ambiguous and should be avoided", linenr);
799 options.emplace_back(name, value);
800 if ((pos = name.rfind(
'.')) != std::string::npos && prefix.length() <= pos) {
801 sections.emplace_back(
SectionInfo{name.substr(0, pos), filepath, linenr});
804 error =
strprintf(
"parse error on line %i: %s", linenr, str);
805 if (str.size() >= 2 && str.substr(0, 2) ==
"no") {
806 error +=
strprintf(
", if you intended to specify a negated option, use %s=1 instead", str);
819 std::vector<std::pair<std::string, std::string>> options;
820 if (!
GetConfigOptions(stream, filepath, error, options, m_config_sections)) {
823 for (
const std::pair<std::string, std::string>& option : options) {
825 std::string key = option.first;
832 m_settings.ro_config[section][key].push_back(value);
834 if (ignore_invalid_keys) {
835 LogPrintf(
"Ignoring unknown configuration value %s\n", option.first);
837 error =
strprintf(
"Invalid configuration value %s", option.first);
849 m_settings.ro_config.clear();
850 m_config_sections.clear();
863 bool use_conf_file{
true};
866 if (
auto* includes =
util::FindKey(m_settings.command_line_options,
"includeconf")) {
869 use_conf_file =
false;
874 std::vector<std::string> conf_file_names;
876 auto add_includes = [&](
const std::string& network,
size_t skip = 0) {
877 size_t num_values = 0;
879 if (
auto* section =
util::FindKey(m_settings.ro_config, network)) {
882 conf_file_names.push_back((*values)[i].get_str());
884 num_values = values->size();
892 const size_t chain_includes = add_includes(chain_id);
893 const size_t default_includes = add_includes({});
895 for (
const std::string& conf_file_name : conf_file_names) {
897 if (conf_file_stream.good()) {
898 if (!
ReadConfigStream(conf_file_stream, conf_file_name, error, ignore_invalid_keys)) {
901 LogPrintf(
"Included configuration file %s\n", conf_file_name);
903 error =
"Failed to include configuration file " + conf_file_name;
909 conf_file_names.clear();
910 add_includes(chain_id, chain_includes);
911 add_includes({}, default_includes);
913 if (chain_id_final != chain_id) {
915 add_includes(chain_id_final);
917 for (
const std::string& conf_file_name : conf_file_names) {
918 tfm::format(std::cerr,
"warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", conf_file_name);
926 error =
strprintf(
"specified data directory \"%s\" does not exist.",
GetArg(
"-datadir",
""));
934 auto get_net = [&](
const std::string& arg) {
942 const bool fRegTest = get_net(
"-regtest");
943 const bool fSigNet = get_net(
"-signet");
944 const bool fTestNet = get_net(
"-testnet");
945 const bool is_chain_arg_set =
IsArgSet(
"-chain");
947 if ((
int)is_chain_arg_set + (
int)fRegTest + (
int)fSigNet + (
int)fTestNet > 1) {
948 throw std::runtime_error(
"Invalid combination of -regtest, -signet, -testnet and -chain. Can use at most one.");
980 const std::string&
prefix,
981 const std::string& section,
982 const std::map<std::string, std::vector<util::SettingsValue>>& args)
const 984 std::string section_str = section.empty() ?
"" :
"[" + section +
"] ";
985 for (
const auto& arg : args) {
986 for (
const auto& value : arg.second) {
989 std::string value_str = (*flags &
SENSITIVE) ?
"****" : value.write();
990 LogPrintf(
"%s %s%s=%s\n", prefix, section_str, arg.first, value_str);
999 for (
const auto& section : m_settings.ro_config) {
1000 logArgsPrefix(
"Config file arg:", section.first, section.second);
1002 for (
const auto& setting : m_settings.rw_settings) {
1003 LogPrintf(
"Setting file arg: %s = %s\n", setting.first, setting.second.write());
1005 logArgsPrefix(
"Command-line arg:",
"", m_settings.command_line_options);
1011 return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(),
1012 MOVEFILE_REPLACE_EXISTING) != 0;
1014 int rc = std::rename(src.string().c_str(), dest.string().c_str());
1028 return fs::create_directories(p);
1029 }
catch (
const fs::filesystem_error&) {
1030 if (!fs::exists(p) || !fs::is_directory(p))
1040 if (fflush(file) != 0) {
1041 LogPrintf(
"%s: fflush failed: %d\n", __func__, errno);
1045 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1046 if (FlushFileBuffers(hFile) == 0) {
1047 LogPrintf(
"%s: FlushFileBuffers failed: %d\n", __func__, GetLastError());
1050 #elif defined(MAC_OSX) && defined(F_FULLFSYNC) 1051 if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) {
1052 LogPrintf(
"%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno);
1055 #elif HAVE_FDATASYNC 1056 if (fdatasync(fileno(file)) != 0 && errno != EINVAL) {
1057 LogPrintf(
"%s: fdatasync failed: %d\n", __func__, errno);
1061 if (fsync(fileno(file)) != 0 && errno != EINVAL) {
1062 LogPrintf(
"%s: fsync failed: %d\n", __func__, errno);
1074 fsync(fileno(file));
1082 return _chsize(_fileno(file), length) == 0;
1084 return ftruncate(fileno(file), length) == 0;
1096 struct rlimit limitFD;
1097 if (getrlimit(RLIMIT_NOFILE, &limitFD) != -1) {
1098 if (limitFD.rlim_cur < (rlim_t)nMinFD) {
1099 limitFD.rlim_cur = nMinFD;
1100 if (limitFD.rlim_cur > limitFD.rlim_max)
1101 limitFD.rlim_cur = limitFD.rlim_max;
1102 setrlimit(RLIMIT_NOFILE, &limitFD);
1103 getrlimit(RLIMIT_NOFILE, &limitFD);
1105 return limitFD.rlim_cur;
1118 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1119 LARGE_INTEGER nFileSize;
1120 int64_t nEndPos = (int64_t)offset + length;
1121 nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF;
1122 nFileSize.u.HighPart = nEndPos >> 32;
1123 SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN);
1124 SetEndOfFile(hFile);
1125 #elif defined(MAC_OSX) 1130 fst.fst_flags = F_ALLOCATECONTIG;
1131 fst.fst_posmode = F_PEOFPOSMODE;
1133 fst.fst_length = length;
1134 fst.fst_bytesalloc = 0;
1135 if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
1136 fst.fst_flags = F_ALLOCATEALL;
1137 fcntl(fileno(file), F_PREALLOCATE, &fst);
1139 ftruncate(fileno(file), static_cast<off_t>(offset) + length);
1141 #if defined(HAVE_POSIX_FALLOCATE) 1143 off_t nEndPos = (off_t)offset + length;
1144 if (0 == posix_fallocate(fileno(file), 0, nEndPos))
return;
1148 static const char buf[65536] = {};
1149 if (fseek(file, offset, SEEK_SET)) {
1152 while (length > 0) {
1153 unsigned int now = 65536;
1156 fwrite(buf, 1, now, file);
1163 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate)
1167 if(SHGetSpecialFolderPathW(
nullptr, pszPath, nFolder, fCreate))
1169 return fs::path(pszPath);
1172 LogPrintf(
"SHGetSpecialFolderPathW() failed, could not obtain requested path.\n");
1173 return fs::path(
"");
1180 std::string escaped = arg;
1181 boost::replace_all(escaped,
"'",
"'\"'\"'");
1182 return "'" + escaped +
"'";
1187 void runCommand(
const std::string& strCommand)
1189 if (strCommand.empty())
return;
1191 int nErr = ::system(strCommand.c_str());
1193 int nErr = ::_wsystem(std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>().from_bytes(strCommand).c_str());
1196 LogPrintf(
"runCommand error: system(%s) returned %d\n", strCommand, nErr);
1200 #ifdef HAVE_BOOST_PROCESS 1203 namespace bp = boost::process;
1206 bp::opstream stdin_stream;
1207 bp::ipstream stdout_stream;
1208 bp::ipstream stderr_stream;
1214 bp::std_out > stdout_stream,
1215 bp::std_err > stderr_stream,
1216 bp::std_in < stdin_stream
1218 if (!str_std_in.empty()) {
1219 stdin_stream << str_std_in << std::endl;
1221 stdin_stream.pipe().close();
1225 std::getline(stdout_stream, result);
1226 std::getline(stderr_stream, error);
1229 const int n_error = c.exit_code();
1230 if (n_error)
throw std::runtime_error(
strprintf(
"RunCommandParseJSON error: process(%s) returned %d: %s\n", str_command, n_error, error));
1231 if (!result_json.
read(result))
throw std::runtime_error(
"Unable to parse JSON: " + result);
1235 #endif // HAVE_BOOST_PROCESS 1239 #ifdef HAVE_MALLOPT_ARENA_MAX 1245 if (
sizeof(
void*) == 4) {
1246 mallopt(M_ARENA_MAX, 1);
1251 #if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) 1254 }
catch (
const std::runtime_error&) {
1255 setenv(
"LC_ALL",
"C.UTF-8", 1);
1257 #elif defined(WIN32) 1259 SetConsoleCP(CP_UTF8);
1260 SetConsoleOutputCP(CP_UTF8);
1266 std::locale loc = fs::path::imbue(std::locale::classic());
1268 fs::path::imbue(loc);
1270 fs::path::imbue(std::locale(loc,
new std::codecvt_utf8_utf16<wchar_t>()));
1279 int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
1280 if (ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
1288 return std::thread::hardware_concurrency();
1294 std::string strCopyrightHolders = strPrefix + copyright_devs;
1297 if (copyright_devs.find(
"Bitcoin Core") == std::string::npos) {
1298 strCopyrightHolders +=
"\n" + strPrefix +
"The Bitcoin Core developers";
1300 return strCopyrightHolders;
1311 if (path.is_absolute()) {
1314 return fs::absolute(path,
GetDataDir(net_specific));
1320 const static sched_param param{};
1321 const int rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m);
1323 LogPrintf(
"Failed to pthread_setschedparam: %s\n", strerror(rc));
1330 WinCmdLineArgs::WinCmdLineArgs()
1332 wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
1333 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t> utf8_cvt;
1334 argv =
new char*[argc];
1336 for (
int i = 0; i < argc; i++) {
1337 args[i] = utf8_cvt.to_bytes(wargv[i]);
1338 argv[i] = &*args[i].begin();
1343 WinCmdLineArgs::~WinCmdLineArgs()
1348 std::pair<int, char**> WinCmdLineArgs::get()
1350 return std::make_pair(argc, argv);
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
static const int optIndent
#define COPYRIGHT_HOLDERS_SUBSTITUTION
#define COPYRIGHT_HOLDERS
bool OnlyHasDefaultSectionSetting(const Settings &settings, const std::string §ion, const std::string &name)
Return true if a setting is set in the default config file section, and not overridden by a higher pr...
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
std::string FormatParagraph(const std::string &in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line...
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
const std::chrono::seconds now
std::string ToLower(const std::string &str)
Returns the lowercase equivalent of the given string.
const char *const BITCOIN_SETTINGS_FILENAME
bool GetSettingsPath(fs::path *filepath=nullptr, bool temp=false) const
Get settings file path, or return false if read-write settings were disabled with -nosettings...
bool DirIsWritable(const fs::path &directory)
FILE * fopen(const fs::path &p, const char *mode)
size_t negated() const
Number of negated values.
fs::path GetDefaultDataDir()
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
static const int msgIndent
static const std::string REGTEST
static std::map< std::string, std::unique_ptr< fsbridge::FileLock > > dir_locks GUARDED_BY(cs_dir_locks)
A map that contains all the currently held directory locks.
int GetNumCores()
Return the number of cores available on the current system.
auto Join(const std::vector< T > &list, const BaseType &separator, UnaryOp unary_op) -> decltype(unary_op(list.at(0)))
Join a list of items.
bool read(const char *raw, size_t len)
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
SettingsValue GetSetting(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config, bool get_chain_name)
Get settings value from combined sources: forced settings, command line arguments, runtime read-write settings, and the read-only config file.
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by Boost's create_directories if the requested directory exists...
static std::string SettingName(const std::string &arg)
bool last_negated() const
True if the last value is negated.
static bool InterpretBool(const std::string &strValue)
Interpret a string argument as a boolean.
std::string CopyrightHolders(const std::string &strPrefix)
void SelectConfigNetwork(const std::string &network)
Select the network in use.
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr) const
Write settings file.
bool ReadConfigStream(std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false)
static void LogPrintf(const char *fmt, const Args &... args)
util::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
const std::string & get_str() const
static auto & nullopt
Substitute for C++17 std::nullopt DEPRECATED use std::nullopt in new code.
bool ParseParameters(int argc, const char *const argv[], std::string &error)
const fs::path & GetBlocksDir()
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
void ReleaseDirectoryLocks()
Release all directory locks.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
int64_t get_int64() const
void ClearDatadirCache()
Tests only.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes)
Optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
const char *const BITCOIN_CONF_FILENAME
static RecursiveMutex csPathCached
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
const std::string & DataDir() const
std::string TrimString(const std::string &str, const std::string &pattern=" \\\)
std::string GetHelpMessage() const
Get the help string.
static const std::string MAIN
Chain name strings.
bool CheckDataDirOption()
std::vector< SettingsValue > GetSettingsList(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config)
Get combined setting value similar to GetSetting(), except if setting was specified multiple times...
bool WriteSettings(const fs::path &path, const std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Write settings file.
bool LockDirectory(const fs::path &directory, const std::string lockfile_name, bool probe_only)
bool ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
bilingual_str _(const char *psz)
Translation function.
int atoi(const std::string &str)
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
bool HelpRequested(const ArgsManager &args)
const fs::path & GetDataDir(bool fNetSpecific)
static util::SettingsValue InterpretOption(std::string §ion, std::string &key, const std::string &value)
Interpret -nofoo as if the user supplied -foo=0.
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
void logArgsPrefix(const std::string &prefix, const std::string §ion, const std::map< std::string, std::vector< util::SettingsValue >> &args) const
fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific)
Most paths passed as configuration arguments are treated as relative to the datadir if they are not a...
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length)
this function tries to make a particular range of a file allocated (corresponding to disk space) it i...
int64_t atoi64(const std::string &str)
bool RenameOver(fs::path src, fs::path dest)
std::string ShellEscape(const std::string &arg)
Accessor for list of settings that skips negated values when iterated over.
static Mutex cs_dir_locks
Mutex to protect dir_locks.
static fs::path g_blocks_path_cache_net_specific
bool InitSettings(std::string &error)
Read and update settings file with saved settings.
static const int screenWidth
bool TruncateFile(FILE *file, unsigned int length)
fs::path GetConfigFile(const std::string &confPath)
void UnlockDirectory(const fs::path &directory, const std::string &lockfile_name)
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
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 > §ions)
static void SaveErrors(const std::vector< std::string > errors, std::vector< std::string > *error_out)
void LogArgs() const
Log the config file options and the command line arguments, useful for troubleshooting.
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
static fs::path pathCachedNetSpecific
static const std::string TESTNET
std::streampos GetFileSize(const char *path, std::streamsize max)
Get the size of a file by scanning it.
UniValue RunCommandParseJSON(const std::string &str_command, const std::string &str_std_in)
Execute a command which returns JSON, and parse the result.
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
const std::list< SectionInfo > GetUnrecognizedSections() const
Log warnings for unrecognized section names in the config file.
static fs::path pathCached
void ScheduleBatchPriority()
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
const int64_t nStartupTime
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
int64_t GetTime()
Return system time (or mocked time, if set)
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
std::vector< util::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
static std::string FormatException(const std::exception *pex, const char *pszThread)
const std::set< std::string > GetUnsuitableSectionOnlyArgs() const
Log warnings for options in m_section_only_args when they are specified in the default section but no...
bool error(const char *fmt, const Args &... args)
static const std::string SIGNET
static bool CheckValid(const std::string &key, const util::SettingsValue &val, unsigned int flags, std::string &error)
Check settings value validity according to flags.
std::optional< T > Optional
Substitute for C++17 std::optional DEPRECATED use std::optional in new code.
bool UseDefaultSection(const std::string &arg) const EXCLUSIVE_LOCKS_REQUIRED(cs_args)
Returns true if settings values from the default section should be used, depending on the current net...
bool ReadSettings(const fs::path &path, std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Read settings file.