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>
52 #ifdef HAVE_MALLOPT_ARENA_MAX
63 #include <system_error>
87 fs::path pathLockFile = directory / lockfile_name;
96 if (file) fclose(file);
97 auto lock = std::make_unique<fsbridge::FileLock>(pathLockFile);
98 if (!lock->TryLock()) {
99 return error(
"Error while attempting to lock directory %s: %s",
fs::PathToString(directory), lock->GetReason());
125 if (!file)
return false;
135 constexpr uint64_t min_disk_space = 52428800;
137 uint64_t free_bytes_available = fs::space(dir).available;
138 return free_bytes_available >= min_disk_space + additional_bytes;
141 std::streampos
GetFileSize(
const char* path, std::streamsize max) {
142 std::ifstream file{path, std::ios::binary};
144 return file.gcount();
164 if (strValue.empty())
166 return (LocaleIndependentAtoi<int>(strValue) != 0);
171 return arg.size() > 0 && arg[0] ==
'-' ? arg.substr(1) : arg;
192 size_t option_index = key.find(
'.');
193 if (option_index != std::string::npos) {
194 result.
section = key.substr(0, option_index);
195 key.erase(0, option_index + 1);
197 if (key.substr(0, 2) ==
"no") {
222 error =
strprintf(
"Negating of -%s is meaningless and therefore forbidden", key.
name);
227 LogPrintf(
"Warning: parsed potentially confusing double-negative -%s=%s\n", key.
name, *value);
233 error =
strprintf(
"Can not set -%s with no value. Please specify value with -%s=value.", key.
name, key.
name);
236 return value ? *value :
"";
247 std::set<std::string> unsuitables;
252 if (m_network.empty())
return std::set<std::string> {};
257 for (
const auto& arg : m_network_only_args) {
259 unsuitables.insert(arg);
268 static const std::set<std::string> available_sections{
276 std::list<SectionInfo> unrecognized = m_config_sections;
277 unrecognized.remove_if([](
const SectionInfo& appeared){
return available_sections.find(appeared.
m_name) != available_sections.end(); });
290 m_settings.command_line_options.clear();
292 for (
int i = 1; i < argc; i++) {
293 std::string key(argv[i]);
300 if (key.substr(0, 5) ==
"-psn_")
continue;
303 if (key ==
"-")
break;
304 std::optional<std::string> val;
305 size_t is_index = key.find(
'=');
306 if (is_index != std::string::npos) {
307 val = key.substr(is_index + 1);
317 if (!m_accept_any_command &&
m_command.empty()) {
334 if (key.length() > 1 && key[1] ==
'-')
351 if (!value)
return false;
353 m_settings.command_line_options[keyinfo.
name].push_back(*value);
357 if (
auto* includes =
util::FindKey(m_settings.command_line_options,
"includeconf")) {
361 error =
"-includeconf cannot be used from commandline; -includeconf=" +
values.begin()->write();
371 for (
const auto& arg_map : m_available_args) {
372 const auto search = arg_map.second.find(
name);
373 if (search != arg_map.second.end()) {
374 return search->second.m_flags;
383 std::string path_str =
GetArg(arg,
"");
384 if (path_str.empty())
return default_value;
387 return result.has_filename() ? result : result.parent_path();
393 fs::path& path = m_cached_blocks_path;
397 if (!path.empty())
return path;
401 if (!fs::is_directory(path)) {
418 fs::path& path = net_specific ? m_cached_network_datadir_path : m_cached_datadir_path;
421 if (!path.empty())
return path;
424 if (!datadir.empty()) {
426 if (!fs::is_directory(path)) {
434 if (net_specific && !
BaseParams().DataDir().empty()) {
446 m_cached_network_datadir_path =
fs::path();
459 if (!m_accept_any_command) {
461 ret.command = *(it++);
465 ret.args.push_back(*(it++));
472 std::vector<std::string> result;
474 result.push_back(value.isFalse() ?
"0" : value.isTrue() ?
"1" : value.get_str());
487 if (settings.empty()) {
499 static void SaveErrors(
const std::vector<std::string> errors, std::vector<std::string>* error_out)
501 for (
const auto&
error : errors) {
503 error_out->emplace_back(
error);
518 m_settings.rw_settings.clear();
519 std::vector<std::string> read_errors;
524 for (
const auto& setting : m_settings.rw_settings) {
527 LogPrintf(
"Ignoring unknown rw_settings value %s\n", setting.first);
537 throw std::logic_error(
"Attempt to write settings file when dynamic settings are disabled.");
541 std::vector<std::string> write_errors;
567 return GetArg(strArg).value_or(strDefault);
578 if (value.
isNull())
return std::nullopt;
579 if (value.
isFalse())
return "0";
580 if (value.
isTrue())
return "1";
592 return GetIntArg(strArg).value_or(nDefault);
603 if (value.
isNull())
return std::nullopt;
605 if (value.
isTrue())
return 1;
607 return LocaleIndependentAtoi<int64_t>(value.
get_str());
628 if (value.
isNull())
return std::nullopt;
657 m_settings.forced_settings[
SettingName(strArg)] = strValue;
662 Assert(
cmd.find(
'=') == std::string::npos);
666 m_accept_any_command =
false;
677 size_t eq_index =
name.find(
'=');
678 if (eq_index == std::string::npos) {
679 eq_index =
name.size();
681 std::string arg_name =
name.substr(0, eq_index);
684 std::map<std::string, Arg>& arg_map = m_available_args[cat];
689 m_network_only_args.emplace(arg_name);
695 for (
const std::string&
name : names) {
702 const bool show_debug =
GetBoolArg(
"-help-debug",
false);
706 for (
const auto& arg_map : m_available_args) {
707 switch(arg_map.first) {
733 if (show_debug) usage +=
HelpMessageGroup(
"Wallet debugging/testing options:");
754 for (
const auto& arg : arg_map.second) {
757 if (arg.second.m_help_param.empty()) {
760 name = arg.first + arg.second.m_help_param;
785 return std::string(message) + std::string(
"\n\n");
788 std::string
HelpMessageOpt(
const std::string &option,
const std::string &message) {
789 return std::string(
optIndent,
' ') + std::string(option) +
790 std::string(
"\n") + std::string(
msgIndent,
' ') +
802 return GetSpecialFolderPath(CSIDL_APPDATA) /
"Bitcoin";
805 char* pszHome = getenv(
"HOME");
806 if (pszHome ==
nullptr || strlen(pszHome) == 0)
812 return pathRet /
"Library/Application Support/Bitcoin";
815 return pathRet /
".bitcoin";
823 return datadir.empty() || fs::is_directory(
fs::absolute(datadir));
831 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)
834 std::string::size_type pos;
836 while (std::getline(stream, str)) {
837 bool used_hash =
false;
838 if ((pos = str.find(
'#')) != std::string::npos) {
839 str = str.substr(0, pos);
842 const static std::string pattern =
" \t\r\n";
845 if (*str.begin() ==
'[' && *str.rbegin() ==
']') {
846 const std::string section = str.substr(1, str.size() - 2);
847 sections.emplace_back(
SectionInfo{section, filepath, linenr});
849 }
else if (*str.begin() ==
'-') {
850 error =
strprintf(
"parse error on line %i: %s, options in configuration file must be specified without leading -", linenr, str);
852 }
else if ((pos = str.find(
'=')) != std::string::npos) {
854 std::string_view value =
TrimStringView(std::string_view{str}.substr(pos + 1), pattern);
855 if (used_hash &&
name.find(
"rpcpassword") != std::string::npos) {
856 error =
strprintf(
"parse error on line %i, using # in rpcpassword can be ambiguous and should be avoided", linenr);
859 options.emplace_back(
name, value);
860 if ((pos =
name.rfind(
'.')) != std::string::npos &&
prefix.length() <= pos) {
861 sections.emplace_back(
SectionInfo{
name.substr(0, pos), filepath, linenr});
865 if (str.size() >= 2 && str.substr(0, 2) ==
"no") {
866 error +=
strprintf(
", if you intended to specify a negated option, use %s=1 instead", str);
877 if (key.
name ==
"conf") {
878 error =
"conf cannot be set in the configuration file; use includeconf= if you want to include additional config files";
881 if (key.
name ==
"reindex") {
884 LogPrintf(
"Warning: reindex=1 is set in the configuration file, which will significantly slow down startup. Consider removing or commenting out this option for better performance, unless there is currently a condition which makes rebuilding the indexes necessary\n");
893 std::vector<std::pair<std::string, std::string>> options;
897 for (
const std::pair<std::string, std::string>& option : options) {
906 m_settings.ro_config[key.
section][key.
name].push_back(*value);
908 if (ignore_invalid_keys) {
909 LogPrintf(
"Ignoring unknown configuration value %s\n", option.first);
911 error =
strprintf(
"Invalid configuration value %s", option.first);
928 m_settings.ro_config.clear();
929 m_config_sections.clear();
933 std::ifstream stream{conf_path};
936 if (
IsArgSet(
"-conf") && !stream.good()) {
947 bool use_conf_file{
true};
950 if (
auto* includes =
util::FindKey(m_settings.command_line_options,
"includeconf")) {
953 use_conf_file =
false;
958 std::vector<std::string> conf_file_names;
960 auto add_includes = [&](
const std::string& network,
size_t skip = 0) {
961 size_t num_values = 0;
963 if (
auto* section =
util::FindKey(m_settings.ro_config, network)) {
966 conf_file_names.push_back((*
values)[i].get_str());
968 num_values =
values->size();
976 const size_t chain_includes = add_includes(chain_id);
977 const size_t default_includes = add_includes({});
979 for (
const std::string& conf_file_name : conf_file_names) {
981 if (conf_file_stream.good()) {
985 LogPrintf(
"Included configuration file %s\n", conf_file_name);
987 error =
"Failed to include configuration file " + conf_file_name;
993 conf_file_names.clear();
994 add_includes(chain_id, chain_includes);
995 add_includes({}, default_includes);
997 if (chain_id_final != chain_id) {
999 add_includes(chain_id_final);
1001 for (
const std::string& conf_file_name : conf_file_names) {
1002 tfm::format(std::cerr,
"warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", conf_file_name);
1018 auto get_net = [&](
const std::string& arg) {
1027 const bool fRegTest = get_net(
"-regtest");
1028 const bool fSigNet = get_net(
"-signet");
1029 const bool fTestNet = get_net(
"-testnet");
1030 const bool is_chain_arg_set =
IsArgSet(
"-chain");
1032 if ((
int)is_chain_arg_set + (
int)fRegTest + (
int)fSigNet + (
int)fTestNet > 1) {
1033 throw std::runtime_error(
"Invalid combination of -regtest, -signet, -testnet and -chain. Can use at most one.");
1066 const std::string&
prefix,
1067 const std::string& section,
1068 const std::map<std::string, std::vector<util::SettingsValue>>&
args)
const
1070 std::string section_str = section.empty() ?
"" :
"[" + section +
"] ";
1071 for (
const auto& arg :
args) {
1072 for (
const auto& value : arg.second) {
1075 std::string value_str = (*
flags &
SENSITIVE) ?
"****" : value.write();
1085 for (
const auto& section : m_settings.ro_config) {
1086 logArgsPrefix(
"Config file arg:", section.first, section.second);
1088 for (
const auto& setting : m_settings.rw_settings) {
1089 LogPrintf(
"Setting file arg: %s = %s\n", setting.first, setting.second.write());
1091 logArgsPrefix(
"Command-line arg:",
"", m_settings.command_line_options);
1103 return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(),
1104 MOVEFILE_REPLACE_EXISTING) != 0;
1106 std::error_code
error;
1107 fs::rename(src, dest,
error);
1122 }
catch (
const fs::filesystem_error&) {
1133 if (fflush(file) != 0) {
1134 LogPrintf(
"%s: fflush failed: %d\n", __func__, errno);
1138 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1139 if (FlushFileBuffers(hFile) == 0) {
1140 LogPrintf(
"%s: FlushFileBuffers failed: %d\n", __func__, GetLastError());
1143 #elif defined(MAC_OSX) && defined(F_FULLFSYNC)
1144 if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) {
1145 LogPrintf(
"%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno);
1148 #elif HAVE_FDATASYNC
1149 if (fdatasync(fileno(file)) != 0 && errno != EINVAL) {
1150 LogPrintf(
"%s: fdatasync failed: %d\n", __func__, errno);
1154 if (fsync(fileno(file)) != 0 && errno != EINVAL) {
1155 LogPrintf(
"%s: fsync failed: %d\n", __func__, errno);
1167 fsync(fileno(file));
1175 return _chsize(_fileno(file), length) == 0;
1177 return ftruncate(fileno(file), length) == 0;
1189 struct rlimit limitFD;
1190 if (getrlimit(RLIMIT_NOFILE, &limitFD) != -1) {
1191 if (limitFD.rlim_cur < (rlim_t)nMinFD) {
1192 limitFD.rlim_cur = nMinFD;
1193 if (limitFD.rlim_cur > limitFD.rlim_max)
1194 limitFD.rlim_cur = limitFD.rlim_max;
1195 setrlimit(RLIMIT_NOFILE, &limitFD);
1196 getrlimit(RLIMIT_NOFILE, &limitFD);
1198 return limitFD.rlim_cur;
1211 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1212 LARGE_INTEGER nFileSize;
1213 int64_t nEndPos = (int64_t)offset + length;
1214 nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF;
1215 nFileSize.u.HighPart = nEndPos >> 32;
1216 SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN);
1217 SetEndOfFile(hFile);
1218 #elif defined(MAC_OSX)
1223 fst.fst_flags = F_ALLOCATECONTIG;
1224 fst.fst_posmode = F_PEOFPOSMODE;
1226 fst.fst_length = length;
1227 fst.fst_bytesalloc = 0;
1228 if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
1229 fst.fst_flags = F_ALLOCATEALL;
1230 fcntl(fileno(file), F_PREALLOCATE, &fst);
1232 ftruncate(fileno(file),
static_cast<off_t
>(offset) + length);
1234 #if defined(HAVE_POSIX_FALLOCATE)
1236 off_t nEndPos = (off_t)offset + length;
1237 if (0 == posix_fallocate(fileno(file), 0, nEndPos))
return;
1241 static const char buf[65536] = {};
1242 if (fseek(file, offset, SEEK_SET)) {
1245 while (length > 0) {
1246 unsigned int now = 65536;
1249 fwrite(buf, 1, now, file);
1256 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate)
1260 if(SHGetSpecialFolderPathW(
nullptr, pszPath, nFolder, fCreate))
1265 LogPrintf(
"SHGetSpecialFolderPathW() failed, could not obtain requested path.\n");
1273 std::string escaped = arg;
1275 return "'" + escaped +
"'";
1280 void runCommand(
const std::string& strCommand)
1282 if (strCommand.empty())
return;
1284 int nErr = ::system(strCommand.c_str());
1286 int nErr = ::_wsystem(std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>().from_bytes(strCommand).c_str());
1289 LogPrintf(
"runCommand error: system(%s) returned %d\n", strCommand, nErr);
1296 #ifdef HAVE_MALLOPT_ARENA_MAX
1302 if (
sizeof(
void*) == 4) {
1303 mallopt(M_ARENA_MAX, 1);
1308 #if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
1311 }
catch (
const std::runtime_error&) {
1312 setenv(
"LC_ALL",
"C.UTF-8", 1);
1314 #elif defined(WIN32)
1316 SetConsoleCP(CP_UTF8);
1317 SetConsoleOutputCP(CP_UTF8);
1321 constexpr mode_t private_umask = 0077;
1322 umask(private_umask);
1331 int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
1332 if (
ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
1340 return std::thread::hardware_concurrency();
1351 if (path.is_absolute()) {
1360 const static sched_param param{};
1361 const int rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m);
1370 WinCmdLineArgs::WinCmdLineArgs()
1372 wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
1373 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t> utf8_cvt;
1374 argv =
new char*[argc];
1376 for (
int i = 0; i < argc; i++) {
1377 args[i] = utf8_cvt.to_bytes(wargv[i]);
1378 argv[i] = &*
args[i].begin();
1383 WinCmdLineArgs::~WinCmdLineArgs()
1388 std::pair<int, char**> WinCmdLineArgs::get()
1390 return std::make_pair(argc, argv);
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
#define Assert(val)
Identity function.
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...
std::optional< const Command > GetCommand() const
Get the command and command args (returns std::nullopt if no command provided)
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.
std::list< SectionInfo > GetUnrecognizedSections() const
Log warnings for unrecognized section names in the config file.
@ ALLOW_ANY
disable validation
@ DISALLOW_NEGATION
disallow -nofoo syntax
@ DISALLOW_ELISION
disallow -foo syntax that doesn't assign any value
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 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.
util::SettingsValue GetPersistentSetting(const std::string &name) const
Get current setting from config file or read/write settings file, ignoring nonpersistent command line...
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 GetSettingsPath(fs::path *filepath=nullptr, bool temp=false, bool backup=false) const
Get settings file path, or return false if read-write settings were disabled with -nosettings.
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 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.
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr, bool backup=false) const
Write settings file or backup settings file.
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.
fs::path GetConfigFilePath() const
Return config file path (read-only)
void AddCommand(const std::string &cmd, const std::string &help)
Add subcommand.
std::vector< util::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
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.
fs::path GetPathArg(std::string arg, const fs::path &default_value={}) const
Return path argument or default value.
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
static const std::string REGTEST
static const std::string TESTNET
static const std::string SIGNET
static const std::string MAIN
Chain name strings.
Different type to mark Mutex at global scope.
const std::string & get_str() const
const std::string & getValStr() const
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
fs::path GetUniquePath(const fs::path &base)
Helper function for getting a unique path.
bool error(const char *fmt, const Args &... args)
static path absolute(const path &p)
static bool create_directories(const std::filesystem::path &p)
Create directory (and if necessary its parents), unless the leaf directory already exists or is a sym...
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to a 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,...
SettingsValue GetSetting(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config, bool ignore_nonpersistent, bool get_chain_name)
Get settings value from combined sources: forced settings, command line arguments,...
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.
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
std::string_view TrimStringView(std::string_view str, std::string_view 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.
std::string SysErrorString(int err)
Return system error string from errno value.
std::string FormatParagraph(std::string_view 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(std::string_view str)
Returns the lowercase equivalent of the given string.
void ReplaceAll(std::string &in_out, const std::string &search, const std::string &substitute)
bool HelpRequested(const ArgsManager &args)
bool LockDirectory(const fs::path &directory, const fs::path &lockfile_name, bool probe_only)
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
fs::path GetDefaultDataDir()
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.
const char *const BITCOIN_SETTINGS_FILENAME
static GlobalMutex cs_dir_locks
Mutex to protect dir_locks.
bool DirIsWritable(const fs::path &directory)
std::optional< std::string > SettingToString(const util::SettingsValue &value)
bool CheckDataDirOption(const ArgsManager &args)
bool RenameOver(fs::path src, fs::path dest)
Rename src to 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 DirectoryCommit(const fs::path &dirname)
Sync directory contents.
void ReleaseDirectoryLocks()
Release all directory locks.
bool IsConfSupported(KeyInfo &key, std::string &error)
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by 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...
static std::optional< util::SettingsValue > InterpretValue(const KeyInfo &key, const std::string *value, unsigned int flags, std::string &error)
Interpret settings value based on registered flags.
std::optional< int64_t > SettingToInt(const util::SettingsValue &value)
fs::path AbsPathForConfigVal(const ArgsManager &args, 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 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)
KeyInfo InterpretKey(std::string key)
Parse "name", "section.name", "noname", "section.noname" settings keys.
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.
fs::path GetConfigFile(const ArgsManager &args, const fs::path &configuration_file_path)
std::optional< bool > SettingToBool(const util::SettingsValue &value)
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)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
void UnlockDirectory(const fs::path &directory, const fs::path &lockfile_name)
std::string ShellEscape(const std::string &arg)