8 #ifdef ENABLE_EXTERNAL_SIGNER 12 #pragma GCC diagnostic push 13 #pragma GCC diagnostic ignored "-Wnarrowing" 15 #include <boost/process.hpp> 17 #pragma GCC diagnostic pop 19 #endif // ENABLE_EXTERNAL_SIGNER 32 #if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) 34 #include <pthread_np.h> 41 #ifdef _POSIX_C_SOURCE 42 #undef _POSIX_C_SOURCE 45 #define _POSIX_C_SOURCE 200112L 53 #include <sys/resource.h> 65 #ifdef HAVE_MALLOPT_ARENA_MAX 76 #include <system_error> 100 fs::path pathLockFile = directory / lockfile_name;
109 if (file) fclose(file);
110 auto lock = std::make_unique<fsbridge::FileLock>(pathLockFile);
111 if (!lock->TryLock()) {
112 return error(
"Error while attempting to lock directory %s: %s",
fs::PathToString(directory), lock->GetReason());
138 if (!file)
return false;
148 constexpr uint64_t min_disk_space = 52428800;
150 uint64_t free_bytes_available = fs::space(dir).available;
151 return free_bytes_available >= min_disk_space + additional_bytes;
154 std::streampos
GetFileSize(
const char* path, std::streamsize max) {
155 std::ifstream file{path, std::ios::binary};
157 return file.gcount();
177 if (strValue.empty())
179 return (LocaleIndependentAtoi<int>(strValue) != 0);
184 return arg.size() > 0 && arg[0] ==
'-' ? arg.substr(1) : arg;
205 size_t option_index = key.find(
'.');
206 if (option_index != std::string::npos) {
207 result.
section = key.substr(0, option_index);
208 key.erase(0, option_index + 1);
210 if (key.substr(0, 2) ==
"no") {
235 error =
strprintf(
"Negating of -%s is meaningless and therefore forbidden", key.
name);
240 LogPrintf(
"Warning: parsed potentially confusing double-negative -%s=%s\n", key.
name, *value);
246 error =
strprintf(
"Can not set -%s with no value. Please specify value with -%s=value.", key.
name, key.
name);
249 return value ? *value :
"";
260 std::set<std::string> unsuitables;
265 if (m_network.empty())
return std::set<std::string> {};
270 for (
const auto& arg : m_network_only_args) {
272 unsuitables.insert(arg);
281 static const std::set<std::string> available_sections{
289 std::list<SectionInfo> unrecognized = m_config_sections;
290 unrecognized.remove_if([](
const SectionInfo& appeared){
return available_sections.find(appeared.
m_name) != available_sections.end(); });
303 m_settings.command_line_options.clear();
305 for (
int i = 1; i < argc; i++) {
306 std::string key(argv[i]);
313 if (key.substr(0, 5) ==
"-psn_")
continue;
316 if (key ==
"-")
break;
317 std::optional<std::string> val;
318 size_t is_index = key.find(
'=');
319 if (is_index != std::string::npos) {
320 val = key.substr(is_index + 1);
330 if (!m_accept_any_command &&
m_command.empty()) {
347 if (key.length() > 1 && key[1] ==
'-')
364 if (!value)
return false;
366 m_settings.command_line_options[keyinfo.
name].push_back(*value);
370 if (
auto* includes =
util::FindKey(m_settings.command_line_options,
"includeconf")) {
374 error =
"-includeconf cannot be used from commandline; -includeconf=" +
values.begin()->write();
384 for (
const auto& arg_map : m_available_args) {
385 const auto search = arg_map.second.find(
name);
386 if (search != arg_map.second.end()) {
387 return search->second.m_flags;
396 std::string path_str =
GetArg(arg,
"");
397 if (path_str.empty())
return default_value;
400 return result.has_filename() ? result : result.parent_path();
406 fs::path& path = m_cached_blocks_path;
410 if (!path.empty())
return path;
414 if (!fs::is_directory(path)) {
431 fs::path& path = net_specific ? m_cached_network_datadir_path : m_cached_datadir_path;
435 if (!path.empty())
return path;
438 if (!datadir.empty()) {
440 if (!fs::is_directory(path)) {
452 if (net_specific && !
BaseParams().DataDir().empty()) {
467 m_cached_network_datadir_path =
fs::path();
480 if (!m_accept_any_command) {
482 ret.command = *(it++);
486 ret.args.push_back(*(it++));
493 std::vector<std::string> result;
495 result.push_back(value.isFalse() ?
"0" : value.isTrue() ?
"1" : value.get_str());
511 std::vector<std::string> errors;
526 if (settings.empty()) {
538 static void SaveErrors(
const std::vector<std::string> errors, std::vector<std::string>* error_out)
540 for (
const auto&
error : errors) {
542 error_out->emplace_back(
error);
557 m_settings.rw_settings.clear();
558 std::vector<std::string> read_errors;
563 for (
const auto& setting : m_settings.rw_settings) {
566 LogPrintf(
"Ignoring unknown rw_settings value %s\n", setting.first);
576 throw std::logic_error(
"Attempt to write settings file when dynamic settings are disabled.");
580 std::vector<std::string> write_errors;
606 return GetArg(strArg).value_or(strDefault);
617 if (value.
isNull())
return std::nullopt;
618 if (value.
isFalse())
return "0";
619 if (value.
isTrue())
return "1";
631 return GetIntArg(strArg).value_or(nDefault);
642 if (value.
isNull())
return std::nullopt;
644 if (value.
isTrue())
return 1;
646 return LocaleIndependentAtoi<int64_t>(value.
get_str());
667 if (value.
isNull())
return std::nullopt;
696 m_settings.forced_settings[
SettingName(strArg)] = strValue;
701 Assert(
cmd.find(
'=') == std::string::npos);
705 m_accept_any_command =
false;
716 size_t eq_index =
name.find(
'=');
717 if (eq_index == std::string::npos) {
718 eq_index =
name.size();
720 std::string arg_name =
name.substr(0, eq_index);
723 std::map<std::string, Arg>& arg_map = m_available_args[cat];
728 m_network_only_args.emplace(arg_name);
734 for (
const std::string&
name : names) {
741 const bool show_debug =
GetBoolArg(
"-help-debug",
false);
745 for (
const auto& arg_map : m_available_args) {
746 switch(arg_map.first) {
772 if (show_debug) usage +=
HelpMessageGroup(
"Wallet debugging/testing options:");
793 for (
const auto& arg : arg_map.second) {
796 if (arg.second.m_help_param.empty()) {
799 name = arg.first + arg.second.m_help_param;
824 return std::string(message) + std::string(
"\n\n");
827 std::string
HelpMessageOpt(
const std::string &option,
const std::string &message) {
828 return std::string(
optIndent,
' ') + std::string(option) +
829 std::string(
"\n") + std::string(
msgIndent,
' ') +
834 static std::string
FormatException(
const std::exception* pex, std::string_view thread_name)
838 GetModuleFileNameA(
nullptr, pszModule,
sizeof(pszModule));
840 const char* pszModule =
"bitcoin";
844 "EXCEPTION: %s \n%s \n%s in %s \n",
typeid(*pex).name(), pex->what(), pszModule, thread_name);
847 "UNKNOWN EXCEPTION \n%s in %s \n", pszModule, thread_name);
853 LogPrintf(
"\n\n************************\n%s\n", message);
854 tfm::format(std::cerr,
"\n\n************************\n%s\n", message);
864 return GetSpecialFolderPath(CSIDL_APPDATA) /
"Bitcoin";
867 char* pszHome = getenv(
"HOME");
868 if (pszHome ==
nullptr || strlen(pszHome) == 0)
874 return pathRet /
"Library/Application Support/Bitcoin";
877 return pathRet /
".bitcoin";
885 return datadir.empty() || fs::is_directory(
fs::absolute(datadir));
893 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)
896 std::string::size_type pos;
898 while (std::getline(stream, str)) {
899 bool used_hash =
false;
900 if ((pos = str.find(
'#')) != std::string::npos) {
901 str = str.substr(0, pos);
904 const static std::string pattern =
" \t\r\n";
907 if (*str.begin() ==
'[' && *str.rbegin() ==
']') {
908 const std::string section = str.substr(1, str.size() - 2);
909 sections.emplace_back(
SectionInfo{section, filepath, linenr});
911 }
else if (*str.begin() ==
'-') {
912 error =
strprintf(
"parse error on line %i: %s, options in configuration file must be specified without leading -", linenr, str);
914 }
else if ((pos = str.find(
'=')) != std::string::npos) {
916 std::string_view value =
TrimStringView(std::string_view{str}.substr(pos + 1), pattern);
917 if (used_hash &&
name.find(
"rpcpassword") != std::string::npos) {
918 error =
strprintf(
"parse error on line %i, using # in rpcpassword can be ambiguous and should be avoided", linenr);
921 options.emplace_back(
name, value);
922 if ((pos =
name.rfind(
'.')) != std::string::npos &&
prefix.length() <= pos) {
923 sections.emplace_back(
SectionInfo{
name.substr(0, pos), filepath, linenr});
927 if (str.size() >= 2 && str.substr(0, 2) ==
"no") {
928 error +=
strprintf(
", if you intended to specify a negated option, use %s=1 instead", str);
941 std::vector<std::pair<std::string, std::string>> options;
945 for (
const std::pair<std::string, std::string>& option : options) {
953 m_settings.ro_config[key.
section][key.
name].push_back(*value);
955 if (ignore_invalid_keys) {
956 LogPrintf(
"Ignoring unknown configuration value %s\n", option.first);
958 error =
strprintf(
"Invalid configuration value %s", option.first);
970 m_settings.ro_config.clear();
971 m_config_sections.clear();
978 if (
IsArgSet(
"-conf") && !stream.good()) {
989 bool use_conf_file{
true};
992 if (
auto* includes =
util::FindKey(m_settings.command_line_options,
"includeconf")) {
995 use_conf_file =
false;
1000 std::vector<std::string> conf_file_names;
1002 auto add_includes = [&](
const std::string& network,
size_t skip = 0) {
1003 size_t num_values = 0;
1005 if (
auto* section =
util::FindKey(m_settings.ro_config, network)) {
1008 conf_file_names.push_back((*
values)[i].get_str());
1010 num_values =
values->size();
1018 const size_t chain_includes = add_includes(chain_id);
1019 const size_t default_includes = add_includes({});
1021 for (
const std::string& conf_file_name : conf_file_names) {
1023 if (conf_file_stream.good()) {
1027 LogPrintf(
"Included configuration file %s\n", conf_file_name);
1029 error =
"Failed to include configuration file " + conf_file_name;
1035 conf_file_names.clear();
1036 add_includes(chain_id, chain_includes);
1037 add_includes({}, default_includes);
1039 if (chain_id_final != chain_id) {
1041 add_includes(chain_id_final);
1043 for (
const std::string& conf_file_name : conf_file_names) {
1044 tfm::format(std::cerr,
"warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", conf_file_name);
1060 auto get_net = [&](
const std::string& arg) {
1069 const bool fRegTest = get_net(
"-regtest");
1070 const bool fSigNet = get_net(
"-signet");
1071 const bool fTestNet = get_net(
"-testnet");
1072 const bool is_chain_arg_set =
IsArgSet(
"-chain");
1074 if ((
int)is_chain_arg_set + (
int)fRegTest + (
int)fSigNet + (
int)fTestNet > 1) {
1075 throw std::runtime_error(
"Invalid combination of -regtest, -signet, -testnet and -chain. Can use at most one.");
1108 const std::string&
prefix,
1109 const std::string& section,
1110 const std::map<std::string, std::vector<util::SettingsValue>>&
args)
const 1112 std::string section_str = section.empty() ?
"" :
"[" + section +
"] ";
1113 for (
const auto& arg :
args) {
1114 for (
const auto& value : arg.second) {
1117 std::string value_str = (*
flags &
SENSITIVE) ?
"****" : value.write();
1127 for (
const auto& section : m_settings.ro_config) {
1128 logArgsPrefix(
"Config file arg:", section.first, section.second);
1130 for (
const auto& setting : m_settings.rw_settings) {
1131 LogPrintf(
"Setting file arg: %s = %s\n", setting.first, setting.second.write());
1133 logArgsPrefix(
"Command-line arg:",
"", m_settings.command_line_options);
1145 return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(),
1146 MOVEFILE_REPLACE_EXISTING) != 0;
1148 std::error_code
error;
1149 fs::rename(src, dest,
error);
1164 }
catch (
const fs::filesystem_error&) {
1175 if (fflush(file) != 0) {
1176 LogPrintf(
"%s: fflush failed: %d\n", __func__, errno);
1180 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1181 if (FlushFileBuffers(hFile) == 0) {
1182 LogPrintf(
"%s: FlushFileBuffers failed: %d\n", __func__, GetLastError());
1185 #elif defined(MAC_OSX) && defined(F_FULLFSYNC) 1186 if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) {
1187 LogPrintf(
"%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno);
1190 #elif HAVE_FDATASYNC 1191 if (fdatasync(fileno(file)) != 0 && errno != EINVAL) {
1192 LogPrintf(
"%s: fdatasync failed: %d\n", __func__, errno);
1196 if (fsync(fileno(file)) != 0 && errno != EINVAL) {
1197 LogPrintf(
"%s: fsync failed: %d\n", __func__, errno);
1209 fsync(fileno(file));
1217 return _chsize(_fileno(file), length) == 0;
1219 return ftruncate(fileno(file), length) == 0;
1231 struct rlimit limitFD;
1232 if (getrlimit(RLIMIT_NOFILE, &limitFD) != -1) {
1233 if (limitFD.rlim_cur < (rlim_t)nMinFD) {
1234 limitFD.rlim_cur = nMinFD;
1235 if (limitFD.rlim_cur > limitFD.rlim_max)
1236 limitFD.rlim_cur = limitFD.rlim_max;
1237 setrlimit(RLIMIT_NOFILE, &limitFD);
1238 getrlimit(RLIMIT_NOFILE, &limitFD);
1240 return limitFD.rlim_cur;
1253 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1254 LARGE_INTEGER nFileSize;
1255 int64_t nEndPos = (int64_t)offset + length;
1256 nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF;
1257 nFileSize.u.HighPart = nEndPos >> 32;
1258 SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN);
1259 SetEndOfFile(hFile);
1260 #elif defined(MAC_OSX) 1265 fst.fst_flags = F_ALLOCATECONTIG;
1266 fst.fst_posmode = F_PEOFPOSMODE;
1268 fst.fst_length = length;
1269 fst.fst_bytesalloc = 0;
1270 if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
1271 fst.fst_flags = F_ALLOCATEALL;
1272 fcntl(fileno(file), F_PREALLOCATE, &fst);
1274 ftruncate(fileno(file), static_cast<off_t>(offset) + length);
1276 #if defined(HAVE_POSIX_FALLOCATE) 1278 off_t nEndPos = (off_t)offset + length;
1279 if (0 == posix_fallocate(fileno(file), 0, nEndPos))
return;
1283 static const char buf[65536] = {};
1284 if (fseek(file, offset, SEEK_SET)) {
1287 while (length > 0) {
1288 unsigned int now = 65536;
1291 fwrite(buf, 1, now, file);
1298 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate)
1302 if(SHGetSpecialFolderPathW(
nullptr, pszPath, nFolder, fCreate))
1307 LogPrintf(
"SHGetSpecialFolderPathW() failed, could not obtain requested path.\n");
1315 std::string escaped = arg;
1317 return "'" + escaped +
"'";
1322 void runCommand(
const std::string& strCommand)
1324 if (strCommand.empty())
return;
1326 int nErr = ::system(strCommand.c_str());
1328 int nErr = ::_wsystem(std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>().from_bytes(strCommand).c_str());
1331 LogPrintf(
"runCommand error: system(%s) returned %d\n", strCommand, nErr);
1337 #ifdef ENABLE_EXTERNAL_SIGNER 1338 namespace bp = boost::process;
1341 bp::opstream stdin_stream;
1342 bp::ipstream stdout_stream;
1343 bp::ipstream stderr_stream;
1349 bp::std_out > stdout_stream,
1350 bp::std_err > stderr_stream,
1351 bp::std_in < stdin_stream
1353 if (!str_std_in.empty()) {
1354 stdin_stream << str_std_in << std::endl;
1356 stdin_stream.pipe().close();
1360 std::getline(stdout_stream, result);
1361 std::getline(stderr_stream,
error);
1364 const int n_error = c.exit_code();
1365 if (n_error)
throw std::runtime_error(
strprintf(
"RunCommandParseJSON error: process(%s) returned %d: %s\n", str_command, n_error,
error));
1366 if (!result_json.
read(result))
throw std::runtime_error(
"Unable to parse JSON: " + result);
1370 throw std::runtime_error(
"Compiled without external signing support (required for external signing).");
1371 #endif // ENABLE_EXTERNAL_SIGNER 1376 #ifdef HAVE_MALLOPT_ARENA_MAX 1382 if (
sizeof(
void*) == 4) {
1383 mallopt(M_ARENA_MAX, 1);
1388 #if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) 1391 }
catch (
const std::runtime_error&) {
1392 setenv(
"LC_ALL",
"C.UTF-8", 1);
1394 #elif defined(WIN32) 1396 SetConsoleCP(CP_UTF8);
1397 SetConsoleOutputCP(CP_UTF8);
1406 int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
1407 if (
ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
1415 return std::thread::hardware_concurrency();
1426 if (path.is_absolute()) {
1435 const static sched_param param{};
1436 const int rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m);
1445 WinCmdLineArgs::WinCmdLineArgs()
1447 wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
1448 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t> utf8_cvt;
1449 argv =
new char*[argc];
1451 for (
int i = 0; i < argc; i++) {
1452 args[i] = utf8_cvt.to_bytes(wargv[i]);
1453 argv[i] = &*
args[i].begin();
1458 WinCmdLineArgs::~WinCmdLineArgs()
1463 std::pair<int, char**> WinCmdLineArgs::get()
1465 return std::make_pair(argc, argv);
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
UniValue RunCommandParseJSON(const std::string &str_command, const std::string &str_std_in)
Execute a command which returns JSON, and parse the result.
static path PathFromString(const std::string &string)
Convert byte string to path object.
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...
fs::path GetPathArg(std::string arg, const fs::path &default_value={}) const
Return path argument or default value.
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
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...
fs::path AbsPathJoin(const fs::path &base, const fs::path &path)
Helper function for joining two paths.
FILE * fopen(const fs::path &p, const char *mode)
size_t negated() const
Number of negated values.
void ScheduleBatchPriority()
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
static const std::string REGTEST
bool read(const char *raw, size_t len)
bool HelpRequested(const ArgsManager &args)
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
std::string ShellEscape(const std::string &arg)
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...
bool last_negated() const
True if the last value is negated.
std::optional< std::string > SettingToString(const util::SettingsValue &value)
std::string_view TrimStringView(std::string_view str, std::string_view pattern=" \\\)
void SelectConfigNetwork(const std::string &network)
Select the network in use.
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
bool ReadConfigStream(std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false)
util::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
const std::string & get_str() const
fs::path GetUniquePath(const fs::path &base)
Helper function for getting a unique path.
bool ParseParameters(int argc, const char *const argv[], std::string &error)
static GlobalMutex cs_dir_locks
Mutex to protect dir_locks.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
const char *const BITCOIN_SETTINGS_FILENAME
static bool InterpretBool(const std::string &strValue)
Interpret a string argument as a boolean.
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
const fs::path & GetDataDirBase() const
Get data directory path.
const std::string & getValStr() const
void ReleaseDirectoryLocks()
Release all directory locks.
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
std::string GetHelpMessage() const
Get the help string.
static const std::string MAIN
Chain name strings.
std::string SysErrorString(int err)
Return system error string from errno value.
static void SaveErrors(const std::vector< std::string > errors, std::vector< std::string > *error_out)
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...
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)
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
bool WriteSettings(const fs::path &path, const std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Write settings file.
disallow -foo syntax that doesn't assign any value
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 ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
void AddCommand(const std::string &cmd, const std::string &help)
Add subcommand.
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
static std::string PathToString(const path &path)
Convert path object to a byte string.
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
bool CheckDataDirOption()
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
int GetNumCores()
Return the number of cores available on the current system.
const int64_t nStartupTime
std::string MakeUnorderedList(const std::vector< std::string > &items)
Create an unordered multi-line list of items.
bool TruncateFile(FILE *file, unsigned int length)
bool RenameOver(fs::path src, fs::path dest)
Rename src to dest.
bool DirIsWritable(const fs::path &directory)
void PrintExceptionContinue(const std::exception *pex, std::string_view thread_name)
void ReplaceAll(std::string &in_out, const std::string &search, const std::string &substitute)
KeyInfo InterpretKey(std::string key)
Parse "name", "section.name", "noname", "section.noname" settings keys.
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::optional< const Command > GetCommand() const
Get the command and command args (returns std::nullopt if no command provided)
static const int msgIndent
std::streampos GetFileSize(const char *path, std::streamsize max)
Get the size of a file by scanning it.
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...
void logArgsPrefix(const std::string &prefix, const std::string §ion, const std::map< std::string, std::vector< util::SettingsValue >> &args) const
bool LockDirectory(const fs::path &directory, const fs::path &lockfile_name, bool probe_only)
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
static std::string SettingName(const std::string &arg)
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes)
std::string ToLower(std::string_view str)
Returns the lowercase equivalent of the given string.
const char *const BITCOIN_CONF_FILENAME
std::optional< int64_t > SettingToInt(const util::SettingsValue &value)
Accessor for list of settings that skips negated values when iterated over.
std::optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr, bool backup=false) const
Write settings file or backup settings file.
bool InitSettings(std::string &error)
Read and update settings file with saved settings.
fs::path GetDefaultDataDir()
void UnlockDirectory(const fs::path &directory, const fs::path &lockfile_name)
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
void LogArgs() const
Log the config file options and the command line arguments, useful for troubleshooting.
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
static const std::string TESTNET
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.
const fs::path & GetBlocksDirPath() const
Get blocks directory path.
static std::string FormatException(const std::exception *pex, std::string_view thread_name)
Different type to mark Mutex at global scope.
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.
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
static bool exists(const path &p)
util::SettingsValue GetPersistentSetting(const std::string &name) const
Get current setting from config file or read/write settings file, ignoring nonpersistent command line...
void ClearPathCache()
Clear cached directory paths.
int64_t GetTime()
DEPRECATED, see GetTime.
std::string TrimString(std::string_view str, std::string_view pattern=" \\\)
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, runtime read-write settings, and the read-only config file.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
std::vector< util::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
static path absolute(const path &p)
static const int optIndent
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 & GetDataDir(bool net_specific) const
Get data directory path.
bool error(const char *fmt, const Args &... args)
static const std::string SIGNET
fs::path GetConfigFile(const fs::path &configuration_file_path)
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.
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...
static const int screenWidth
#define Assert(val)
Identity function.
bool ReadSettings(const fs::path &path, std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Read settings file.
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
std::optional< bool > SettingToBool(const util::SettingsValue &value)