15 #if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) 17 #include <pthread_np.h> 24 #ifdef _POSIX_C_SOURCE 25 #undef _POSIX_C_SOURCE 28 #define _POSIX_C_SOURCE 200112L 35 #include <sys/resource.h> 41 #pragma warning(disable:4786) 42 #pragma warning(disable:4804) 43 #pragma warning(disable:4805) 44 #pragma warning(disable:4717) 50 #define _WIN32_WINNT 0x0501 55 #define _WIN32_IE 0x0501 57 #define WIN32_LEAN_AND_MEAN 1 68 #ifdef HAVE_SYS_PRCTL_H 69 #include <sys/prctl.h> 72 #ifdef HAVE_MALLOPT_ARENA_MAX 76 #include <boost/thread.hpp> 77 #include <openssl/crypto.h> 78 #include <openssl/rand.h> 79 #include <openssl/conf.h> 91 static std::unique_ptr<CCriticalSection[]> ppmutexOpenSSL;
94 if (mode & CRYPTO_LOCK) {
131 CRYPTO_set_locking_callback(
nullptr);
133 ppmutexOpenSSL.reset();
143 static std::map<std::string, std::unique_ptr<fsbridge::FileLock>> dir_locks;
145 static std::mutex cs_dir_locks;
147 bool LockDirectory(
const fs::path& directory,
const std::string lockfile_name,
bool probe_only)
149 std::lock_guard<std::mutex> ulock(cs_dir_locks);
150 fs::path pathLockFile = directory / lockfile_name;
153 if (dir_locks.count(pathLockFile.string())) {
159 if (file) fclose(file);
160 auto lock = MakeUnique<fsbridge::FileLock>(pathLockFile);
161 if (!lock->TryLock()) {
162 return error(
"Error while attempting to lock directory %s: %s", directory.string(), lock->GetReason());
166 dir_locks.emplace(pathLockFile.string(), std::move(lock));
173 std::lock_guard<std::mutex> ulock(cs_dir_locks);
179 fs::path tmpFile = directory / fs::unique_path();
182 if (!file)
return false;
207 static bool InterpretBool(
const std::string& strValue)
209 if (strValue.empty())
211 return (
atoi(strValue) != 0);
217 typedef std::map<std::string, std::vector<std::string>>
MapArgs;
229 assert(arg.length() > 1 && arg[0] ==
'-');
230 return "-" + am.m_network +
"." + arg.substr(1);
234 static inline void AddArgs(std::vector<std::string>& res,
const MapArgs& map_args,
const std::string& arg)
236 auto it = map_args.find(arg);
237 if (it != map_args.end()) {
238 res.insert(res.end(), it->second.begin(), it->second.end());
245 static inline std::pair<bool,std::string>
GetArgHelper(
const MapArgs& map_args,
const std::string& arg,
bool getLast =
false)
247 auto it = map_args.find(arg);
249 if (it == map_args.end() || it->second.empty()) {
250 return std::make_pair(
false, std::string());
254 return std::make_pair(
true, it->second.back());
256 return std::make_pair(
true, it->second.front());
267 std::pair<bool,std::string> found_result(
false, std::string());
272 found_result =
GetArgHelper(am.m_override_args, arg,
true);
273 if (found_result.first) {
280 if (!am.m_network.empty()) {
282 if (found_result.first) {
289 if (found_result.first) {
302 std::pair<bool,std::string> found_result(
false,std::string());
303 found_result =
GetArgHelper(am.m_override_args, net_arg,
true);
304 if (!found_result.first) {
305 found_result =
GetArgHelper(am.m_config_args, net_arg,
true);
306 if (!found_result.first) {
310 return InterpretBool(found_result.second);
335 static bool InterpretNegatedOption(std::string& key, std::string& val)
337 assert(key[0] ==
'-');
339 size_t option_index = key.find(
'.');
340 if (option_index == std::string::npos) {
345 if (key.substr(option_index, 2) ==
"no") {
346 bool bool_val = InterpretBool(val);
347 key.erase(option_index, 2);
350 LogPrintf(
"Warning: parsed potentially confusing double-negative %s=%s\n", key, val);
366 "-addnode",
"-connect",
368 "-rpcport",
"-rpcbind",
380 if (m_network.empty())
return;
385 for (
const auto& arg : m_network_only_args) {
386 std::pair<bool, std::string> found_result;
390 if (found_result.first)
continue;
394 if (found_result.first)
continue;
398 if (!found_result.first)
continue;
401 LogPrintf(
"Warning: Config setting for %s only applied on %s network when in [%s] section.\n", arg, m_network, m_network);
414 m_override_args.clear();
416 for (
int i = 1; i < argc; i++) {
417 std::string key(argv[i]);
419 size_t is_index = key.find(
'=');
420 if (is_index != std::string::npos) {
421 val = key.substr(is_index + 1);
425 std::transform(key.begin(), key.end(), key.begin(), ::tolower);
434 if (key.length() > 1 && key[1] ==
'-')
438 if (InterpretNegatedOption(key, val)) {
439 m_override_args[key].clear();
441 m_override_args[key].push_back(val);
454 auto it = m_override_args.find(
"-includeconf");
455 if (it != m_override_args.end()) {
456 if (it->second.size() > 0) {
457 for (
const auto& ic : it->second) {
458 error +=
"-includeconf cannot be used from commandline; -includeconf=" + ic +
"\n";
468 size_t option_index = key.find(
'.');
469 std::string arg_no_net;
470 if (option_index == std::string::npos) {
473 arg_no_net = std::string(
"-") + key.substr(option_index + 1, std::string::npos);
477 for (
const auto& arg_map : m_available_args) {
478 if (arg_map.second.count(arg_no_net))
return true;
485 std::vector<std::string> result = {};
491 if (!m_network.empty()) {
512 const auto& ov = m_override_args.find(strArg);
513 if (ov != m_override_args.end())
return ov->second.empty();
515 if (!m_network.empty()) {
517 if (cfs != m_config_args.end())
return cfs->second.empty();
520 const auto& cf = m_config_args.find(strArg);
521 if (cf != m_config_args.end())
return cf->second.empty();
530 if (found_res.first)
return found_res.second;
538 if (found_res.first)
return atoi64(found_res.second);
546 if (found_res.first)
return InterpretBool(found_res.second);
569 m_override_args[strArg] = {strValue};
575 size_t eq_index =
name.find(
'=');
576 if (eq_index == std::string::npos) {
577 eq_index =
name.size();
581 std::map<std::string, Arg>& arg_map = m_available_args[cat];
582 auto ret = arg_map.emplace(
name.substr(0, eq_index),
Arg(
name.substr(eq_index,
name.size() - eq_index),
help, debug_only));
588 for (
const std::string&
name : names) {
597 std::string usage =
"";
599 for (
const auto& arg_map : m_available_args) {
600 switch(arg_map.first) {
626 if (show_debug) usage +=
HelpMessageGroup(
"Wallet debugging/testing options:");
647 for (
const auto& arg : arg_map.second) {
648 if (show_debug || !arg.second.m_debug_only) {
650 if (arg.second.m_help_param.empty()) {
653 name = arg.first + arg.second.m_help_param;
667 static const int screenWidth = 79;
668 static const int optIndent = 2;
669 static const int msgIndent = 7;
672 return std::string(message) + std::string(
"\n\n");
675 std::string
HelpMessageOpt(
const std::string &option,
const std::string &message) {
676 return std::string(optIndent,
' ') + std::string(option) +
677 std::string(
"\n") + std::string(msgIndent,
' ') +
682 static std::string FormatException(
const std::exception* pex,
const char* pszThread)
686 GetModuleFileNameA(
nullptr, pszModule,
sizeof(pszModule));
688 const char* pszModule =
"bitcoin";
692 "EXCEPTION: %s \n%s \n%s in %s \n",
typeid(*pex).name(), pex->what(), pszModule, pszThread);
695 "UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread);
700 std::string message = FormatException(pex, pszThread);
701 LogPrintf(
"\n\n************************\n%s\n", message);
702 fprintf(stderr,
"\n\n************************\n%s\n", message.c_str());
713 return GetSpecialFolderPath(CSIDL_APPDATA) /
"BSHA3";
716 char* pszHome = getenv(
"HOME");
717 if (pszHome ==
nullptr || strlen(pszHome) == 0)
718 pathRet = fs::path(
"/");
720 pathRet = fs::path(pszHome);
723 return pathRet /
"Library/Application Support/BSHA3";
726 return pathRet /
".bsha3";
731 static fs::path g_blocks_path_cached;
732 static fs::path g_blocks_path_cache_net_specific;
733 static fs::path pathCached;
734 static fs::path pathCachedNetSpecific;
742 fs::path &path = fNetSpecific ? g_blocks_path_cache_net_specific : g_blocks_path_cached;
750 path = fs::system_complete(
gArgs.
GetArg(
"-blocksdir",
""));
751 if (!fs::is_directory(path)) {
762 fs::create_directories(path);
771 fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached;
779 path = fs::system_complete(
gArgs.
GetArg(
"-datadir",
""));
780 if (!fs::is_directory(path)) {
790 if (fs::create_directories(path)) {
792 fs::create_directories(path /
"wallets");
802 pathCached = fs::path();
803 pathCachedNetSpecific = fs::path();
804 g_blocks_path_cached = fs::path();
805 g_blocks_path_cache_net_specific = fs::path();
813 static std::string TrimString(
const std::string& str,
const std::string& pattern)
815 std::string::size_type front = str.find_first_not_of(pattern);
816 if (front == std::string::npos) {
817 return std::string();
819 std::string::size_type
end = str.find_last_not_of(pattern);
820 return str.substr(front,
end - front + 1);
823 static bool GetConfigOptions(std::istream& stream, std::string&
error, std::vector<std::pair<std::string, std::string>> &options)
826 std::string::size_type pos;
828 while (std::getline(stream, str)) {
829 if ((pos = str.find(
'#')) != std::string::npos) {
830 str = str.substr(0, pos);
832 const static std::string pattern =
" \t\r\n";
833 str = TrimString(str, pattern);
835 if (*str.begin() ==
'[' && *str.rbegin() ==
']') {
836 prefix = str.substr(1, str.size() - 2) +
'.';
837 }
else if (*str.begin() ==
'-') {
838 error =
strprintf(
"parse error on line %i: %s, options in configuration file must be specified without leading -", linenr, str);
840 }
else if ((pos = str.find(
'=')) != std::string::npos) {
841 std::string
name =
prefix + TrimString(str.substr(0, pos), pattern);
842 std::string value = TrimString(str.substr(pos + 1), pattern);
843 options.emplace_back(
name, value);
846 if (str.size() >= 2 && str.substr(0, 2) ==
"no") {
847 error +=
strprintf(
", if you intended to specify a negated option, use %s=1 instead", str);
860 std::vector<std::pair<std::string, std::string>> options;
861 if (!GetConfigOptions(stream,
error, options)) {
864 for (
const std::pair<std::string, std::string>& option : options) {
865 std::string strKey = std::string(
"-") + option.first;
866 std::string strValue = option.second;
868 if (InterpretNegatedOption(strKey, strValue)) {
869 m_config_args[strKey].clear();
871 m_config_args[strKey].push_back(strValue);
876 if (!ignore_invalid_keys) {
877 error =
strprintf(
"Invalid configuration value %s", option.first.c_str());
880 LogPrintf(
"Ignoring unknown configuration value %s\n", option.first);
891 m_config_args.clear();
904 bool emptyIncludeConf;
907 emptyIncludeConf = m_override_args.count(
"-includeconf") == 0;
909 if (emptyIncludeConf) {
911 std::vector<std::string> includeconf(
GetArgs(
"-includeconf"));
915 std::vector<std::string> includeconf_net(
GetArgs(std::string(
"-") + chain_id +
".includeconf"));
916 includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end());
923 m_config_args.erase(
"-includeconf");
924 m_config_args.erase(std::string(
"-") + chain_id +
".includeconf");
927 for (
const std::string& to_include : includeconf) {
929 if (include_config.good()) {
933 LogPrintf(
"Included configuration file %s\n", to_include.c_str());
935 error =
"Failed to include configuration file " + to_include;
941 includeconf =
GetArgs(
"-includeconf");
943 std::vector<std::string> includeconf_net(
GetArgs(std::string(
"-") + chain_id +
".includeconf"));
944 includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end());
946 if (chain_id_final != chain_id) {
948 includeconf_net =
GetArgs(std::string(
"-") + chain_id_final +
".includeconf");
949 includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end());
952 for (
const std::string& to_include : includeconf) {
953 fprintf(stderr,
"warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", to_include.c_str());
973 if (fTestNet && fRegTest)
974 throw std::runtime_error(
"Invalid combination of -regtest and -testnet.");
993 fprintf(file,
"%d\n", pid);
1002 return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(),
1003 MOVEFILE_REPLACE_EXISTING) != 0;
1005 int rc = std::rename(src.string().c_str(), dest.string().c_str());
1019 return fs::create_directories(p);
1020 }
catch (
const fs::filesystem_error&) {
1021 if (!fs::exists(p) || !fs::is_directory(p))
1031 if (fflush(file) != 0) {
1032 LogPrintf(
"%s: fflush failed: %d\n", __func__, errno);
1036 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1037 if (FlushFileBuffers(hFile) == 0) {
1038 LogPrintf(
"%s: FlushFileBuffers failed: %d\n", __func__, GetLastError());
1042 #if defined(__linux__) || defined(__NetBSD__) 1043 if (fdatasync(fileno(file)) != 0 && errno != EINVAL) {
1044 LogPrintf(
"%s: fdatasync failed: %d\n", __func__, errno);
1047 #elif defined(MAC_OSX) && defined(F_FULLFSYNC) 1048 if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) {
1049 LogPrintf(
"%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno);
1053 if (fsync(fileno(file)) != 0 && errno != EINVAL) {
1054 LogPrintf(
"%s: fsync failed: %d\n", __func__, errno);
1064 return _chsize(_fileno(file), length) == 0;
1066 return ftruncate(fileno(file), length) == 0;
1078 struct rlimit limitFD;
1079 if (getrlimit(RLIMIT_NOFILE, &limitFD) != -1) {
1080 if (limitFD.rlim_cur < (rlim_t)nMinFD) {
1081 limitFD.rlim_cur = nMinFD;
1082 if (limitFD.rlim_cur > limitFD.rlim_max)
1083 limitFD.rlim_cur = limitFD.rlim_max;
1084 setrlimit(RLIMIT_NOFILE, &limitFD);
1085 getrlimit(RLIMIT_NOFILE, &limitFD);
1087 return limitFD.rlim_cur;
1100 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1101 LARGE_INTEGER nFileSize;
1102 int64_t nEndPos = (int64_t)offset + length;
1103 nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF;
1104 nFileSize.u.HighPart = nEndPos >> 32;
1105 SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN);
1106 SetEndOfFile(hFile);
1107 #elif defined(MAC_OSX) 1110 fst.fst_flags = F_ALLOCATECONTIG;
1111 fst.fst_posmode = F_PEOFPOSMODE;
1113 fst.fst_length = (off_t)offset + length;
1114 fst.fst_bytesalloc = 0;
1115 if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
1116 fst.fst_flags = F_ALLOCATEALL;
1117 fcntl(fileno(file), F_PREALLOCATE, &fst);
1119 ftruncate(fileno(file), fst.fst_length);
1120 #elif defined(__linux__) 1122 off_t nEndPos = (off_t)offset + length;
1123 posix_fallocate(fileno(file), 0, nEndPos);
1127 static const char buf[65536] = {};
1128 if (fseek(file, offset, SEEK_SET)) {
1131 while (length > 0) {
1132 unsigned int now = 65536;
1135 fwrite(buf, 1, now, file);
1142 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate)
1146 if(SHGetSpecialFolderPathW(
nullptr, pszPath, nFolder, fCreate))
1148 return fs::path(pszPath);
1151 LogPrintf(
"SHGetSpecialFolderPathW() failed, could not obtain requested path.\n");
1152 return fs::path(
"");
1158 if (strCommand.empty())
return;
1160 int nErr = ::system(strCommand.c_str());
1162 int nErr = ::_wsystem(std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>().from_bytes(strCommand).c_str());
1165 LogPrintf(
"runCommand error: system(%s) returned %d\n", strCommand, nErr);
1170 #if defined(PR_SET_NAME) 1172 ::prctl(PR_SET_NAME,
name, 0, 0, 0);
1173 #elif (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) 1174 pthread_set_name_np(pthread_self(),
name);
1176 #elif defined(MAC_OSX) 1177 pthread_setname_np(
name);
1186 #ifdef HAVE_MALLOPT_ARENA_MAX 1192 if (
sizeof(
void*) == 4) {
1193 mallopt(M_ARENA_MAX, 1);
1198 #if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) 1201 }
catch (
const std::runtime_error&) {
1202 setenv(
"LC_ALL",
"C", 1);
1204 #elif defined(WIN32) 1206 SetConsoleCP(CP_UTF8);
1207 SetConsoleOutputCP(CP_UTF8);
1213 std::locale loc = fs::path::imbue(std::locale::classic());
1215 fs::path::imbue(loc);
1217 fs::path::imbue(std::locale(loc,
new std::codecvt_utf8_utf16<wchar_t>()));
1226 int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
1227 if (
ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
1235 return std::thread::hardware_concurrency();
1244 strCopyrightHolders +=
"\n" + strPrefix +
"The BSHA3 developers";
1246 return strCopyrightHolders;
1257 return fs::absolute(path,
GetDataDir(net_specific));
1266 setpriority(PRIO_THREAD, 0, nPriority);
1267 #else // PRIO_THREAD 1268 setpriority(PRIO_PROCESS, 0, nPriority);
1269 #endif // PRIO_THREAD 1276 const static sched_param param{0};
1277 if (
int ret = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m)) {
1278 LogPrintf(
"Failed to pthread_setschedparam: %s\n", strerror(errno));
1289 WinCmdLineArgs::WinCmdLineArgs()
1291 wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
1292 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t> utf8_cvt;
1293 argv =
new char*[argc];
1295 for (
int i = 0; i < argc; i++) {
1296 args[i] = utf8_cvt.to_bytes(wargv[i]);
1297 argv[i] = &*args[i].begin();
1302 WinCmdLineArgs::~WinCmdLineArgs()
1307 std::pair<int, char**> WinCmdLineArgs::get()
1309 return std::make_pair(argc, argv);
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
bool FileCommit(FILE *file)
#define COPYRIGHT_HOLDERS_SUBSTITUTION
#define COPYRIGHT_HOLDERS
bool HelpRequested(const ArgsManager &args)
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
#define NO_THREAD_SAFETY_ANALYSIS
static bool GetNetBoolArg(const ArgsManager &am, const std::string &net_arg) EXCLUSIVE_LOCKS_REQUIRED(am.cs_args)
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
const int64_t nStartupTime
void SetThreadPriority(int nPriority)
FILE * fopen(const fs::path &p, const char *mode)
const char *const BITCOIN_CONF_FILENAME
void ReleaseDirectoryLocks()
Release all directory locks.
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
const char *const BITCOIN_PID_FILENAME
UniValue ret(UniValue::VARR)
int64_t GetStartupTime()
Server/client environment: argument handling, config file parsing, thread wrappers, startup time.
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
void WarnForSectionOnlyArgs()
Log warnings for options in m_section_only_args when they are specified in the default section but no...
void SelectConfigNetwork(const std::string &network)
Select the network in use.
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
bool ParseParameters(int argc, const char *const argv[], std::string &error)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
void locking_callback(int mode, int i, const char *file, int line) NO_THREAD_SAFETY_ANALYSIS
bool IsArgKnown(const std::string &key) const
Check whether we know of this arg.
static bool UseDefaultSection(const ArgsManager &am, const std::string &arg) EXCLUSIVE_LOCKS_REQUIRED(am.cs_args)
Determine whether to use config settings in the default section, See also comments around ArgsManager...
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...
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
void RenameThread(const char *name)
bool LockDirectory(const fs::path &directory, const std::string lockfile_name, bool probe_only)
const std::string & DataDir() const
std::string GetHelpMessage() const
Get the help string.
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
class CInit instance_of_cinit
int ScheduleBatchPriority(void)
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
bool TruncateFile(FILE *file, unsigned int length)
#define LEAVE_CRITICAL_SECTION(cs)
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...
static std::string NetworkArg(const ArgsManager &am, const std::string &arg)
Convert regular argument into the network-specific setting.
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...
UniValue help(const JSONRPCRequest &jsonRequest)
static std::pair< bool, std::string > GetArg(const ArgsManager &am, const std::string &arg)
bool RenameOver(fs::path src, fs::path dest)
std::map< std::string, std::vector< std::string > > MapArgs
std::string CopyrightHolders(const std::string &strPrefix)
fs::path GetDefaultDataDir()
const fs::path & GetBlocksDir(bool fNetSpecific)
#define ENTER_CRITICAL_SECTION(cs)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
bool IsSwitchChar(char c)
Internal helper functions for ArgsManager.
fs::path GetConfigFile(const std::string &confPath)
void AddArg(const std::string &name, const std::string &help, const bool debug_only, const OptionsCategory &cat)
Add argument.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
bool DirIsWritable(const fs::path &directory)
void runCommand(const std::string &strCommand)
int64_t atoi64(const char *psz)
bool ReadConfigStream(std::istream &stream, std::string &error, bool ignore_invalid_keys=false)
bool error(const char *fmt, const Args &... args)
static const std::string TESTNET
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
const fs::path & GetDataDir(bool fNetSpecific)
void CreatePidFile(const fs::path &path, pid_t pid)
int64_t GetTime()
GetTimeMicros() and GetTimeMillis() both return the system time, but in different units...
int GetNumCores()
Return the number of cores available on the current system.
static void AddArgs(std::vector< std::string > &res, const MapArgs &map_args, const std::string &arg)
Find arguments in a map and add them to a vector.
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
std::string _(const char *psz)
Translation function.
int atoi(const std::string &str)
static std::pair< bool, std::string > GetArgHelper(const MapArgs &map_args, const std::string &arg, bool getLast=false)
Return true/false if an argument is set in a map, and also return the first (or last) of the possibly...