21 #if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
23 #include <pthread_np.h>
31 #ifdef _POSIX_C_SOURCE
32 #undef _POSIX_C_SOURCE
35 #define _POSIX_C_SOURCE 200112L
43 #include <sys/resource.h>
49 #pragma warning(disable : 4786)
50 #pragma warning(disable : 4804)
51 #pragma warning(disable : 4805)
52 #pragma warning(disable : 4717)
65 #ifdef HAVE_MALLOPT_ARENA_MAX
84 static std::map<std::string, std::unique_ptr<fsbridge::FileLock>>
90 fs::path pathLockFile = directory / lockfile_name;
103 auto lock = std::make_unique<fsbridge::FileLock>(pathLockFile);
104 if (!lock->TryLock()) {
105 return error(
"Error while attempting to lock directory %s: %s",
116 const std::string &lockfile_name) {
142 constexpr uint64_t min_disk_space = 52428800;
144 uint64_t free_bytes_available = fs::space(dir).available;
145 return free_bytes_available >= min_disk_space + additional_bytes;
148 std::streampos
GetFileSize(
const char *path, std::streamsize max) {
151 return file.gcount();
172 if (strValue.empty()) {
175 return (
atoi(strValue) != 0);
179 return arg.size() > 0 && arg[0] ==
'-' ? arg.substr(1) : arg;
204 const std::string &value) {
207 size_t option_index = key.find(
'.');
208 if (option_index != std::string::npos) {
209 section = key.substr(0, option_index);
210 key.erase(0, option_index + 1);
212 if (key.substr(0, 2) ==
"no") {
216 LogPrintf(
"Warning: parsed potentially confusing double-negative "
237 "Negating of -%s is meaningless and therefore forbidden", key);
247 result = result.parent_path();
250 assert(fs::equivalent(result, path));
262 std::set<std::string> unsuitables;
267 if (m_network.empty()) {
268 return std::set<std::string>{};
273 return std::set<std::string>{};
276 for (
const auto &arg : m_network_only_args) {
279 unsuitables.insert(arg);
287 static const std::set<std::string> available_sections{
292 std::list<SectionInfo> unrecognized = m_config_sections;
293 unrecognized.remove_if([](
const SectionInfo &appeared) {
294 return available_sections.find(appeared.
m_name) !=
295 available_sections.end();
306 size_t is_index = key.find(
'=');
307 if (is_index != std::string::npos) {
308 val = key.substr(is_index + 1);
323 if (key.length() > 1 && key[1] ==
'-') {
330 std::string &
error) {
332 m_settings.command_line_options.clear();
334 for (
int i = 1; i < argc; i++) {
335 std::string key(argv[i]);
342 if (key.substr(0, 5) ==
"-psn_") {
365 if (!
flags || !section.empty()) {
374 m_settings.command_line_options[key].push_back(value);
380 util::FindKey(m_settings.command_line_options,
"includeconf")) {
383 "-includeconf cannot be used from commandline; -includeconf=" +
384 include.get_str() +
"\n";
391 std::optional<unsigned int>
394 for (
const auto &arg_map : m_available_args) {
395 const auto search = arg_map.second.find(
name);
396 if (search != arg_map.second.end()) {
397 return search->second.m_flags;
405 fs::path &path = m_cached_blocks_path;
416 if (!fs::is_directory(path)) {
426 fs::create_directories(path);
427 path = StripRedundantLastElementsOfPath(path);
434 net_specific ? m_cached_network_datadir_path : m_cached_datadir_path;
441 std::string datadir =
GetArg(
"-datadir",
"");
442 if (!datadir.empty()) {
444 if (!fs::is_directory(path)) {
455 if (fs::create_directories(path)) {
457 fs::create_directories(path /
"wallets");
460 path = StripRedundantLastElementsOfPath(path);
468 m_cached_network_datadir_path =
fs::path();
473 std::vector<std::string> result;
475 result.push_back(value.isFalse() ?
"0"
476 : value.isTrue() ?
"1"
491 std::vector<std::string> errors;
494 Join(errors,
"\n- "));
499 Join(errors,
"\n- "));
518 static void SaveErrors(
const std::vector<std::string> errors,
519 std::vector<std::string> *error_out) {
520 for (
const auto &
error : errors) {
522 error_out->emplace_back(
error);
536 m_settings.rw_settings.clear();
537 std::vector<std::string> read_errors;
542 for (
const auto &setting : m_settings.rw_settings) {
544 std::string key = setting.first;
548 LogPrintf(
"Ignoring unknown rw_settings value %s\n", setting.first);
558 throw std::logic_error(
"Attempt to write settings file when dynamic "
559 "settings are disabled.");
563 std::vector<std::string> write_errors;
570 {
strprintf(
"Failed renaming settings file %s to %s\n",
583 const std::string &strDefault)
const {
585 return value.
isNull() ? strDefault
592 int64_t nDefault)
const {
594 return value.
isNull() ? nDefault
603 return value.
isNull() ? fDefault
609 const std::string &strValue) {
627 const std::string &strValue) {
629 m_settings.forced_settings[
SettingName(strArg)] = strValue;
638 const std::vector<std::string> &values) {
642 for (
const std::string &s : values) {
646 m_settings.forced_settings[
SettingName(strArg)] = value;
652 size_t eq_index =
name.find(
'=');
653 if (eq_index == std::string::npos) {
654 eq_index =
name.size();
656 std::string arg_name =
name.substr(0, eq_index);
659 std::map<std::string, Arg> &arg_map = m_available_args[cat];
660 auto ret = arg_map.emplace(
667 m_network_only_args.emplace(arg_name);
672 for (
const std::string &
name : names) {
679 m_settings.forced_settings.erase(
SettingName(strArg));
683 const bool show_debug =
GetBoolArg(
"-help-debug",
false);
685 std::string usage =
"";
687 for (
const auto &arg_map : m_available_args) {
688 switch (arg_map.first) {
746 for (
const auto &arg : arg_map.second) {
749 if (arg.second.m_help_param.empty()) {
752 name = arg.first + arg.second.m_help_param;
767 args.
AddArg(
"-?",
"Print this help message and exit",
false,
777 return std::string(message) + std::string(
"\n\n");
781 const std::string &message) {
782 return std::string(
optIndent,
' ') + std::string(option) +
783 std::string(
"\n") + std::string(
msgIndent,
' ') +
789 const char *pszThread) {
792 GetModuleFileNameA(
nullptr, pszModule,
sizeof(pszModule));
794 const char *pszModule =
"bitcoin";
797 return strprintf(
"EXCEPTION: %s \n%s \n%s in %s \n",
798 typeid(*pex).name(), pex->what(), pszModule,
801 return strprintf(
"UNKNOWN EXCEPTION \n%s in %s \n",
802 pszModule, pszThread);
808 LogPrintf(
"\n\n************************\n%s\n", message);
809 tfm::format(std::cerr,
"\n\n************************\n%s\n", message);
818 return GetSpecialFolderPath(CSIDL_APPDATA) /
"Bitcoin";
821 char *pszHome = getenv(
"HOME");
822 if (pszHome ==
nullptr || strlen(pszHome) == 0) {
829 return pathRet /
"Library/Application Support/Bitcoin";
832 return pathRet /
".bitcoin";
838 std::string datadir =
gArgs.
GetArg(
"-datadir",
"");
839 return datadir.empty() ||
850 std::vector<std::pair<std::string, std::string>> &options,
851 std::list<SectionInfo> §ions) {
853 std::string::size_type pos;
855 while (std::getline(stream, str)) {
856 bool used_hash =
false;
857 if ((pos = str.find(
'#')) != std::string::npos) {
858 str = str.substr(0, pos);
861 const static std::string pattern =
" \t\r\n";
864 if (*str.begin() ==
'[' && *str.rbegin() ==
']') {
865 const std::string section = str.substr(1, str.size() - 2);
866 sections.emplace_back(
SectionInfo{section, filepath, linenr});
868 }
else if (*str.begin() ==
'-') {
870 "parse error on line %i: %s, options in configuration file "
871 "must be specified without leading -",
874 }
else if ((pos = str.find(
'=')) != std::string::npos) {
877 std::string value =
TrimString(str.substr(pos + 1), pattern);
879 name.find(
"rpcpassword") != std::string::npos) {
881 "parse error on line %i, using # in rpcpassword can be "
882 "ambiguous and should be avoided",
886 options.emplace_back(
name, value);
887 if ((pos =
name.rfind(
'.')) != std::string::npos &&
889 sections.emplace_back(
894 if (str.size() >= 2 && str.substr(0, 2) ==
"no") {
896 "option, use %s=1 instead",
908 const std::string &filepath,
910 bool ignore_invalid_keys) {
912 std::vector<std::pair<std::string, std::string>> options;
914 m_config_sections)) {
917 for (
const std::pair<std::string, std::string> &option : options) {
919 std::string key = option.first;
927 m_settings.ro_config[section][key].push_back(value);
929 if (ignore_invalid_keys) {
930 LogPrintf(
"Ignoring unknown configuration value %s\n",
934 option.first.c_str());
943 bool ignore_invalid_keys) {
946 m_settings.ro_config.clear();
947 m_config_sections.clear();
961 bool use_conf_file{
true};
964 if (
auto *includes =
util::FindKey(m_settings.command_line_options,
969 use_conf_file =
false;
974 std::vector<std::string> conf_file_names;
976 auto add_includes = [&](
const std::string &network,
978 size_t num_values = 0;
983 for (
size_t i = std::max(
985 i < values->size(); ++i) {
986 conf_file_names.push_back((*values)[i].get_str());
988 num_values = values->size();
996 const size_t chain_includes = add_includes(chain_id);
997 const size_t default_includes = add_includes({});
999 for (
const std::string &conf_file_name : conf_file_names) {
1002 if (conf_file_stream.good()) {
1004 error, ignore_invalid_keys)) {
1007 LogPrintf(
"Included configuration file %s\n",
1010 error =
"Failed to include configuration file " +
1017 conf_file_names.clear();
1018 add_includes(chain_id, chain_includes);
1019 add_includes({}, default_includes);
1021 if (chain_id_final != chain_id) {
1024 add_includes(chain_id_final);
1026 for (
const std::string &conf_file_name : conf_file_names) {
1028 "warning: -includeconf cannot be used from "
1029 "included files; ignoring -includeconf=%s\n",
1038 error =
strprintf(
"specified data directory \"%s\" does not exist.",
1039 GetArg(
"-datadir",
"").c_str());
1046 auto get_net = [&](
const std::string &arg) {
1052 return value.
isNull() ? false
1057 const bool fRegTest = get_net(
"-regtest");
1058 const bool fTestNet = get_net(
"-testnet");
1059 const bool is_chain_arg_set =
IsArgSet(
"-chain");
1061 if (
int(is_chain_arg_set) +
int(fRegTest) +
int(fTestNet) > 1) {
1062 throw std::runtime_error(
"Invalid combination of -regtest, -testnet "
1063 "and -chain. Can use at most one.");
1076 m_network_only_args.count(arg) == 0;
1086 std::vector<util::SettingsValue>
1094 const std::string &
prefix,
const std::string §ion,
1095 const std::map<std::string, std::vector<util::SettingsValue>> &args)
const {
1096 std::string section_str = section.empty() ?
"" :
"[" + section +
"] ";
1097 for (
const auto &arg : args) {
1098 for (
const auto &value : arg.second) {
1101 std::string value_str =
1112 for (
const auto §ion : m_settings.ro_config) {
1113 logArgsPrefix(
"Config file arg:", section.first, section.second);
1115 for (
const auto &setting : m_settings.rw_settings) {
1116 LogPrintf(
"Setting file arg: %s = %s\n", setting.first,
1117 setting.second.write());
1119 logArgsPrefix(
"Command-line arg:",
"", m_settings.command_line_options);
1124 return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(),
1125 MOVEFILE_REPLACE_EXISTING) != 0;
1127 int rc = std::rename(src.c_str(), dest.c_str());
1139 return fs::create_directories(p);
1140 }
catch (
const fs::filesystem_error &) {
1141 if (!
fs::exists(p) || !fs::is_directory(p)) {
1153 if (fflush(file) != 0) {
1154 LogPrintf(
"%s: fflush failed: %d\n", __func__, errno);
1158 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1159 if (FlushFileBuffers(hFile) == 0) {
1160 LogPrintf(
"%s: FlushFileBuffers failed: %d\n", __func__,
1165 #if defined(HAVE_FDATASYNC)
1167 if (fdatasync(fileno(file)) != 0 && errno != EINVAL) {
1168 LogPrintf(
"%s: fdatasync failed: %d\n", __func__, errno);
1171 #elif defined(MAC_OSX) && defined(F_FULLFSYNC)
1173 if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) {
1174 LogPrintf(
"%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno);
1178 if (fsync(fileno(file)) != 0 && errno != EINVAL) {
1179 LogPrintf(
"%s: fsync failed: %d\n", __func__, errno);
1189 return _chsize(_fileno(file), length) == 0;
1191 return ftruncate(fileno(file), length) == 0;
1204 struct rlimit limitFD;
1205 if (getrlimit(RLIMIT_NOFILE, &limitFD) != -1) {
1206 if (limitFD.rlim_cur < (rlim_t)nMinFD) {
1207 limitFD.rlim_cur = nMinFD;
1208 if (limitFD.rlim_cur > limitFD.rlim_max) {
1209 limitFD.rlim_cur = limitFD.rlim_max;
1211 setrlimit(RLIMIT_NOFILE, &limitFD);
1212 getrlimit(RLIMIT_NOFILE, &limitFD);
1214 return limitFD.rlim_cur;
1229 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1230 LARGE_INTEGER nFileSize;
1231 int64_t nEndPos = (int64_t)offset + length;
1232 nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF;
1233 nFileSize.u.HighPart = nEndPos >> 32;
1234 SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN);
1235 SetEndOfFile(hFile);
1236 #elif defined(MAC_OSX)
1241 fst.fst_flags = F_ALLOCATECONTIG;
1242 fst.fst_posmode = F_PEOFPOSMODE;
1246 fst.fst_length = length;
1247 fst.fst_bytesalloc = 0;
1248 if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
1249 fst.fst_flags = F_ALLOCATEALL;
1250 fcntl(fileno(file), F_PREALLOCATE, &fst);
1252 ftruncate(fileno(file),
static_cast<off_t
>(offset) + length);
1253 #elif defined(HAVE_POSIX_FALLOCATE)
1255 off_t nEndPos = (off_t)offset + length;
1256 posix_fallocate(fileno(file), 0, nEndPos);
1260 static const char buf[65536] = {};
1261 if (fseek(file, offset, SEEK_SET)) {
1264 while (length > 0) {
1265 unsigned int now = 65536;
1270 fwrite(buf, 1, now, file);
1277 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate) {
1280 if (SHGetSpecialFolderPathW(
nullptr, pszPath, nFolder, fCreate)) {
1285 "SHGetSpecialFolderPathW() failed, could not obtain requested path.\n");
1292 std::string escaped = arg;
1294 return "'" + escaped +
"'";
1298 #if defined(HAVE_SYSTEM)
1299 void runCommand(
const std::string &strCommand) {
1300 if (strCommand.empty()) {
1304 int nErr = ::system(strCommand.c_str());
1306 int nErr = ::_wsystem(
1307 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>()
1308 .from_bytes(strCommand)
1312 LogPrintf(
"runCommand error: system(%s) returned %d\n", strCommand,
1319 #ifdef HAVE_MALLOPT_ARENA_MAX
1325 if (
sizeof(
void *) == 4) {
1326 mallopt(M_ARENA_MAX, 1);
1331 #if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && \
1332 !defined(__OpenBSD__)
1336 }
catch (
const std::runtime_error &) {
1337 setenv(
"LC_ALL",
"C.UTF-8", 1);
1339 #elif defined(WIN32)
1341 SetConsoleCP(CP_UTF8);
1342 SetConsoleOutputCP(CP_UTF8);
1348 std::locale loc = fs::path::imbue(std::locale::classic());
1350 fs::path::imbue(loc);
1352 fs::path::imbue(std::locale(loc,
new std::codecvt_utf8_utf16<wchar_t>()));
1360 int ret = WSAStartup(MAKEWORD(2, 2), &wsadata);
1361 if (ret != NO_ERROR || LOBYTE(wsadata.wVersion) != 2 ||
1362 HIBYTE(wsadata.wVersion) != 2) {
1370 return std::thread::hardware_concurrency();
1374 return strPrefix +
strprintf(
_(COPYRIGHT_HOLDERS).translated,
1375 COPYRIGHT_HOLDERS_SUBSTITUTION);
1384 if (path.is_absolute()) {
1393 const static sched_param param{};
1394 const int rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m);
1396 LogPrintf(
"Failed to pthread_setschedparam: %s\n", strerror(rc));
1403 WinCmdLineArgs::WinCmdLineArgs() {
1404 wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
1405 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t> utf8_cvt;
1406 argv =
new char *[argc];
1408 for (
int i = 0; i < argc; i++) {
1409 args[i] = utf8_cvt.to_bytes(wargv[i]);
1410 argv[i] = &*args[i].begin();
1415 WinCmdLineArgs::~WinCmdLineArgs() {
1419 std::pair<int, char **> WinCmdLineArgs::get() {
1420 return std::make_pair(argc, argv);
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
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...
const fs::path & GetBlocksDirPath() const
Get blocks directory path.
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
bool ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
void logArgsPrefix(const std::string &prefix, const std::string §ion, const std::map< std::string, std::vector< util::SettingsValue >> &args) const
bool InitSettings(std::string &error)
Read and update settings file with saved settings.
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr) const
Write settings file.
bool ParseParameters(int argc, const char *const argv[], std::string &error)
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
std::optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
const fs::path & GetDataDirBase() const
Get data directory path.
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
void SelectConfigNetwork(const std::string &network)
Select the network in use.
std::string GetHelpMessage() const
Get the help string.
void ForceSetMultiArg(const std::string &strArg, const std::vector< std::string > &values)
This function is only used for testing purpose so so we should not worry about element uniqueness and...
void ClearPathCache()
Clear cached directory paths.
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
const fs::path & GetDataDir(bool net_specific) const
Get data directory path.
void ClearForcedArg(const std::string &strArg)
Remove a forced arg setting, used only in testing.
std::vector< util::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
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.
void LogArgs() const
Log the config file options and the command line arguments, useful for troubleshooting.
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...
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
util::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
bool ReadConfigStream(std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false)
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
const std::list< SectionInfo > GetUnrecognizedSections() const
Log warnings for unrecognized section names in the config file.
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
static const std::string REGTEST
static const std::string TESTNET
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
const std::string & get_str() const
int64_t get_int64() const
bool push_back(const UniValue &val)
Path class wrapper to prepare application code for transition from boost::filesystem library to std::...
fs::path GetUniquePath(const fs::path &base)
Helper function for getting a unique path.
static path system_complete(const path &p)
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to byte string.
static path PathFromString(const std::string &string)
Convert byte string to path object.
FILE * fopen(const fs::path &p, const char *mode)
fs::path AbsPathJoin(const fs::path &base, const fs::path &path)
Helper function for joining two paths.
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 ReadSettings(const fs::path &path, std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Read settings file.
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 WriteSettings(const fs::path &path, const std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Write settings file.
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
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,...
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.
std::string ToLower(const std::string &str)
Returns the lowercase equivalent of the given string.
int atoi(const std::string &str)
int64_t atoi64(const std::string &str)
void ReplaceAll(std::string &in_out, std::string_view search, std::string_view substitute)
auto Join(const std::vector< T > &list, const BaseType &separator, UnaryOp unary_op) -> decltype(unary_op(list.at(0)))
Join a list of items.
std::string TrimString(const std::string &str, const std::string &pattern=" \f\n\r\t\v")
Accessor for list of settings that skips negated values when iterated over.
size_t negated() const
Number of negated values.
bool last_negated() const
True if the last value is negated.
static Mutex cs_dir_locks
Mutex to protect dir_locks.
bool HelpRequested(const ArgsManager &args)
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
static bool CheckValid(const std::string &key, const util::SettingsValue &val, unsigned int flags, std::string &error)
Check settings value validity according to flags.
fs::path GetDefaultDataDir()
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...
static const int msgIndent
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)
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.
int64_t GetStartupTime()
Server/client environment: argument handling, config file parsing, thread wrappers,...
const char *const BITCOIN_SETTINGS_FILENAME
bool ParseKeyValue(std::string &key, std::string &val)
std::string CopyrightHolders(const std::string &strPrefix)
bool LockDirectory(const fs::path &directory, const std::string lockfile_name, bool probe_only)
static util::SettingsValue InterpretOption(std::string §ion, std::string &key, const std::string &value)
Interpret -nofoo as if the user supplied -foo=0.
void UnlockDirectory(const fs::path &directory, const std::string &lockfile_name)
bool CheckDataDirOption()
static std::string FormatException(const std::exception *pex, const char *pszThread)
bool DirIsWritable(const fs::path &directory)
bool RenameOver(fs::path src, fs::path dest)
std::streampos GetFileSize(const char *path, std::streamsize max)
Get the size of a file by scanning it.
void ScheduleBatchPriority()
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
static const int screenWidth
int RaiseFileDescriptorLimit(int nMinFD)
This function tries to raise the file descriptor limit to the requested number.
void ReleaseDirectoryLocks()
Release all directory locks.
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by Boost's create_directories if the requested directory exists.
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...
fs::path GetConfigFile(const std::string &confPath)
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
static std::string SettingName(const std::string &arg)
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes)
const int64_t nStartupTime
const char *const BITCOIN_CONF_FILENAME
bool TruncateFile(FILE *file, unsigned int length)
static bool InterpretBool(const std::string &strValue)
Interpret a string argument as a boolean.
static const int optIndent
int GetNumCores()
Return the number of cores available on the current system.
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
bool FileCommit(FILE *file)
std::string ShellEscape(const std::string &arg)
bool error(const char *fmt, const Args &...args)
T GetTime()
Return system time (or mocked time, if set)
bilingual_str _(const char *psz)
Translation function.