Bitcoin Core  0.20.99
P2P Digital Currency
system.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2020 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <util/system.h>
7 
8 #include <chainparamsbase.h>
9 #include <util/strencodings.h>
10 #include <util/string.h>
11 #include <util/translation.h>
12 
13 
14 #if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
15 #include <pthread.h>
16 #include <pthread_np.h>
17 #endif
18 
19 #ifndef WIN32
20 // for posix_fallocate, in configure.ac we check if it is present after this
21 #ifdef __linux__
22 
23 #ifdef _POSIX_C_SOURCE
24 #undef _POSIX_C_SOURCE
25 #endif
26 
27 #define _POSIX_C_SOURCE 200112L
28 
29 #endif // __linux__
30 
31 #include <algorithm>
32 #include <fcntl.h>
33 #include <sched.h>
34 #include <sys/resource.h>
35 #include <sys/stat.h>
36 
37 #else
38 
39 #ifdef _MSC_VER
40 #pragma warning(disable:4786)
41 #pragma warning(disable:4804)
42 #pragma warning(disable:4805)
43 #pragma warning(disable:4717)
44 #endif
45 
46 #ifdef _WIN32_IE
47 #undef _WIN32_IE
48 #endif
49 #define _WIN32_IE 0x0501
50 
51 #define WIN32_LEAN_AND_MEAN 1
52 #ifndef NOMINMAX
53 #define NOMINMAX
54 #endif
55 #include <codecvt>
56 
57 #include <io.h> /* for _commit */
58 #include <shellapi.h>
59 #include <shlobj.h>
60 #endif
61 
62 #ifdef HAVE_MALLOPT_ARENA_MAX
63 #include <malloc.h>
64 #endif
65 
66 #include <boost/algorithm/string/replace.hpp>
67 #include <thread>
68 #include <typeinfo>
69 #include <univalue.h>
70 
71 // Application startup time (used for uptime calculation)
72 const int64_t nStartupTime = GetTime();
73 
74 const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf";
75 
77 
83 static std::map<std::string, std::unique_ptr<fsbridge::FileLock>> dir_locks;
85 static std::mutex cs_dir_locks;
86 
87 bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only)
88 {
89  std::lock_guard<std::mutex> ulock(cs_dir_locks);
90  fs::path pathLockFile = directory / lockfile_name;
91 
92  // If a lock for this directory already exists in the map, don't try to re-lock it
93  if (dir_locks.count(pathLockFile.string())) {
94  return true;
95  }
96 
97  // Create empty lock file if it doesn't exist.
98  FILE* file = fsbridge::fopen(pathLockFile, "a");
99  if (file) fclose(file);
100  auto lock = MakeUnique<fsbridge::FileLock>(pathLockFile);
101  if (!lock->TryLock()) {
102  return error("Error while attempting to lock directory %s: %s", directory.string(), lock->GetReason());
103  }
104  if (!probe_only) {
105  // Lock successful and we're not just probing, put it into the map
106  dir_locks.emplace(pathLockFile.string(), std::move(lock));
107  }
108  return true;
109 }
110 
111 void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name)
112 {
113  std::lock_guard<std::mutex> lock(cs_dir_locks);
114  dir_locks.erase((directory / lockfile_name).string());
115 }
116 
118 {
119  std::lock_guard<std::mutex> ulock(cs_dir_locks);
120  dir_locks.clear();
121 }
122 
123 bool DirIsWritable(const fs::path& directory)
124 {
125  fs::path tmpFile = directory / fs::unique_path();
126 
127  FILE* file = fsbridge::fopen(tmpFile, "a");
128  if (!file) return false;
129 
130  fclose(file);
131  remove(tmpFile);
132 
133  return true;
134 }
135 
136 bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes)
137 {
138  constexpr uint64_t min_disk_space = 52428800; // 50 MiB
139 
140  uint64_t free_bytes_available = fs::space(dir).available;
141  return free_bytes_available >= min_disk_space + additional_bytes;
142 }
143 
144 std::streampos GetFileSize(const char* path, std::streamsize max) {
145  std::ifstream file(path, std::ios::binary);
146  file.ignore(max);
147  return file.gcount();
148 }
149 
167 static bool InterpretBool(const std::string& strValue)
168 {
169  if (strValue.empty())
170  return true;
171  return (atoi(strValue) != 0);
172 }
173 
174 static std::string SettingName(const std::string& arg)
175 {
176  return arg.size() > 0 && arg[0] == '-' ? arg.substr(1) : arg;
177 }
178 
199 static util::SettingsValue InterpretOption(std::string& section, std::string& key, const std::string& value)
200 {
201  // Split section name from key name for keys like "testnet.foo" or "regtest.bar"
202  size_t option_index = key.find('.');
203  if (option_index != std::string::npos) {
204  section = key.substr(0, option_index);
205  key.erase(0, option_index + 1);
206  }
207  if (key.substr(0, 2) == "no") {
208  key.erase(0, 2);
209  // Double negatives like -nofoo=0 are supported (but discouraged)
210  if (!InterpretBool(value)) {
211  LogPrintf("Warning: parsed potentially confusing double-negative -%s=%s\n", key, value);
212  return true;
213  }
214  return false;
215  }
216  return value;
217 }
218 
226 static bool CheckValid(const std::string& key, const util::SettingsValue& val, unsigned int flags, std::string& error)
227 {
228  if (val.isBool() && !(flags & ArgsManager::ALLOW_BOOL)) {
229  error = strprintf("Negating of -%s is meaningless and therefore forbidden", key);
230  return false;
231  }
232  return true;
233 }
234 
235 // Define default constructor and destructor that are not inline, so code instantiating this class doesn't need to
236 // #include class definitions for all members.
237 // For example, m_settings has an internal dependency on univalue.
240 
241 const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const
242 {
243  std::set<std::string> unsuitables;
244 
245  LOCK(cs_args);
246 
247  // if there's no section selected, don't worry
248  if (m_network.empty()) return std::set<std::string> {};
249 
250  // if it's okay to use the default section for this network, don't worry
251  if (m_network == CBaseChainParams::MAIN) return std::set<std::string> {};
252 
253  for (const auto& arg : m_network_only_args) {
254  if (OnlyHasDefaultSectionSetting(m_settings, m_network, SettingName(arg))) {
255  unsuitables.insert(arg);
256  }
257  }
258  return unsuitables;
259 }
260 
261 const std::list<SectionInfo> ArgsManager::GetUnrecognizedSections() const
262 {
263  // Section names to be recognized in the config file.
264  static const std::set<std::string> available_sections{
268  };
269 
270  LOCK(cs_args);
271  std::list<SectionInfo> unrecognized = m_config_sections;
272  unrecognized.remove_if([](const SectionInfo& appeared){ return available_sections.find(appeared.m_name) != available_sections.end(); });
273  return unrecognized;
274 }
275 
276 void ArgsManager::SelectConfigNetwork(const std::string& network)
277 {
278  LOCK(cs_args);
279  m_network = network;
280 }
281 
282 bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::string& error)
283 {
284  LOCK(cs_args);
285  m_settings.command_line_options.clear();
286 
287  for (int i = 1; i < argc; i++) {
288  std::string key(argv[i]);
289 
290 #ifdef MAC_OSX
291  // At the first time when a user gets the "App downloaded from the
292  // internet" warning, and clicks the Open button, macOS passes
293  // a unique process serial number (PSN) as -psn_... command-line
294  // argument, which we filter out.
295  if (key.substr(0, 5) == "-psn_") continue;
296 #endif
297 
298  if (key == "-") break; //bitcoin-tx using stdin
299  std::string val;
300  size_t is_index = key.find('=');
301  if (is_index != std::string::npos) {
302  val = key.substr(is_index + 1);
303  key.erase(is_index);
304  }
305 #ifdef WIN32
306  key = ToLower(key);
307  if (key[0] == '/')
308  key[0] = '-';
309 #endif
310 
311  if (key[0] != '-')
312  break;
313 
314  // Transform --foo to -foo
315  if (key.length() > 1 && key[1] == '-')
316  key.erase(0, 1);
317 
318  // Transform -foo to foo
319  key.erase(0, 1);
320  std::string section;
321  util::SettingsValue value = InterpretOption(section, key, val);
323 
324  // Unknown command line options and command line options with dot
325  // characters (which are returned from InterpretOption with nonempty
326  // section strings) are not valid.
327  if (!flags || !section.empty()) {
328  error = strprintf("Invalid parameter %s", argv[i]);
329  return false;
330  }
331 
332  if (!CheckValid(key, value, *flags, error)) return false;
333 
334  m_settings.command_line_options[key].push_back(value);
335  }
336 
337  // we do not allow -includeconf from command line
338  bool success = true;
339  if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
340  for (const auto& include : util::SettingsSpan(*includes)) {
341  error += "-includeconf cannot be used from commandline; -includeconf=" + include.get_str() + "\n";
342  success = false;
343  }
344  }
345  return success;
346 }
347 
349 {
350  LOCK(cs_args);
351  for (const auto& arg_map : m_available_args) {
352  const auto search = arg_map.second.find(name);
353  if (search != arg_map.second.end()) {
354  return search->second.m_flags;
355  }
356  }
357  return nullopt;
358 }
359 
360 std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
361 {
362  std::vector<std::string> result;
363  for (const util::SettingsValue& value : GetSettingsList(strArg)) {
364  result.push_back(value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str());
365  }
366  return result;
367 }
368 
369 bool ArgsManager::IsArgSet(const std::string& strArg) const
370 {
371  return !GetSetting(strArg).isNull();
372 }
373 
374 bool ArgsManager::IsArgNegated(const std::string& strArg) const
375 {
376  return GetSetting(strArg).isFalse();
377 }
378 
379 std::string ArgsManager::GetArg(const std::string& strArg, const std::string& strDefault) const
380 {
381  const util::SettingsValue value = GetSetting(strArg);
382  return value.isNull() ? strDefault : value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str();
383 }
384 
385 int64_t ArgsManager::GetArg(const std::string& strArg, int64_t nDefault) const
386 {
387  const util::SettingsValue value = GetSetting(strArg);
388  return value.isNull() ? nDefault : value.isFalse() ? 0 : value.isTrue() ? 1 : value.isNum() ? value.get_int64() : atoi64(value.get_str());
389 }
390 
391 bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const
392 {
393  const util::SettingsValue value = GetSetting(strArg);
394  return value.isNull() ? fDefault : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
395 }
396 
397 bool ArgsManager::SoftSetArg(const std::string& strArg, const std::string& strValue)
398 {
399  LOCK(cs_args);
400  if (IsArgSet(strArg)) return false;
401  ForceSetArg(strArg, strValue);
402  return true;
403 }
404 
405 bool ArgsManager::SoftSetBoolArg(const std::string& strArg, bool fValue)
406 {
407  if (fValue)
408  return SoftSetArg(strArg, std::string("1"));
409  else
410  return SoftSetArg(strArg, std::string("0"));
411 }
412 
413 void ArgsManager::ForceSetArg(const std::string& strArg, const std::string& strValue)
414 {
415  LOCK(cs_args);
416  m_settings.forced_settings[SettingName(strArg)] = strValue;
417 }
418 
419 void ArgsManager::AddArg(const std::string& name, const std::string& help, unsigned int flags, const OptionsCategory& cat)
420 {
421  // Split arg name from its help param
422  size_t eq_index = name.find('=');
423  if (eq_index == std::string::npos) {
424  eq_index = name.size();
425  }
426  std::string arg_name = name.substr(0, eq_index);
427 
428  LOCK(cs_args);
429  std::map<std::string, Arg>& arg_map = m_available_args[cat];
430  auto ret = arg_map.emplace(arg_name, Arg{name.substr(eq_index, name.size() - eq_index), help, flags});
431  assert(ret.second); // Make sure an insertion actually happened
432 
433  if (flags & ArgsManager::NETWORK_ONLY) {
434  m_network_only_args.emplace(arg_name);
435  }
436 }
437 
438 void ArgsManager::AddHiddenArgs(const std::vector<std::string>& names)
439 {
440  for (const std::string& name : names) {
442  }
443 }
444 
445 std::string ArgsManager::GetHelpMessage() const
446 {
447  const bool show_debug = gArgs.GetBoolArg("-help-debug", false);
448 
449  std::string usage = "";
450  LOCK(cs_args);
451  for (const auto& arg_map : m_available_args) {
452  switch(arg_map.first) {
454  usage += HelpMessageGroup("Options:");
455  break;
457  usage += HelpMessageGroup("Connection options:");
458  break;
460  usage += HelpMessageGroup("ZeroMQ notification options:");
461  break;
463  usage += HelpMessageGroup("Debugging/Testing options:");
464  break;
466  usage += HelpMessageGroup("Node relay options:");
467  break;
469  usage += HelpMessageGroup("Block creation options:");
470  break;
472  usage += HelpMessageGroup("RPC server options:");
473  break;
475  usage += HelpMessageGroup("Wallet options:");
476  break;
478  if (show_debug) usage += HelpMessageGroup("Wallet debugging/testing options:");
479  break;
481  usage += HelpMessageGroup("Chain selection options:");
482  break;
484  usage += HelpMessageGroup("UI Options:");
485  break;
487  usage += HelpMessageGroup("Commands:");
488  break;
490  usage += HelpMessageGroup("Register Commands:");
491  break;
492  default:
493  break;
494  }
495 
496  // When we get to the hidden options, stop
497  if (arg_map.first == OptionsCategory::HIDDEN) break;
498 
499  for (const auto& arg : arg_map.second) {
500  if (show_debug || !(arg.second.m_flags & ArgsManager::DEBUG_ONLY)) {
501  std::string name;
502  if (arg.second.m_help_param.empty()) {
503  name = arg.first;
504  } else {
505  name = arg.first + arg.second.m_help_param;
506  }
507  usage += HelpMessageOpt(name, arg.second.m_help_text);
508  }
509  }
510  }
511  return usage;
512 }
513 
514 bool HelpRequested(const ArgsManager& args)
515 {
516  return args.IsArgSet("-?") || args.IsArgSet("-h") || args.IsArgSet("-help") || args.IsArgSet("-help-debug");
517 }
518 
520 {
521  args.AddArg("-?", "Print this help message and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
522  args.AddHiddenArgs({"-h", "-help"});
523 }
524 
525 static const int screenWidth = 79;
526 static const int optIndent = 2;
527 static const int msgIndent = 7;
528 
529 std::string HelpMessageGroup(const std::string &message) {
530  return std::string(message) + std::string("\n\n");
531 }
532 
533 std::string HelpMessageOpt(const std::string &option, const std::string &message) {
534  return std::string(optIndent,' ') + std::string(option) +
535  std::string("\n") + std::string(msgIndent,' ') +
537  std::string("\n\n");
538 }
539 
540 static std::string FormatException(const std::exception* pex, const char* pszThread)
541 {
542 #ifdef WIN32
543  char pszModule[MAX_PATH] = "";
544  GetModuleFileNameA(nullptr, pszModule, sizeof(pszModule));
545 #else
546  const char* pszModule = "bitcoin";
547 #endif
548  if (pex)
549  return strprintf(
550  "EXCEPTION: %s \n%s \n%s in %s \n", typeid(*pex).name(), pex->what(), pszModule, pszThread);
551  else
552  return strprintf(
553  "UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread);
554 }
555 
556 void PrintExceptionContinue(const std::exception* pex, const char* pszThread)
557 {
558  std::string message = FormatException(pex, pszThread);
559  LogPrintf("\n\n************************\n%s\n", message);
560  tfm::format(std::cerr, "\n\n************************\n%s\n", message);
561 }
562 
564 {
565  // Windows < Vista: C:\Documents and Settings\Username\Application Data\Bitcoin
566  // Windows >= Vista: C:\Users\Username\AppData\Roaming\Bitcoin
567  // Mac: ~/Library/Application Support/Bitcoin
568  // Unix: ~/.bitcoin
569 #ifdef WIN32
570  // Windows
571  return GetSpecialFolderPath(CSIDL_APPDATA) / "Bitcoin";
572 #else
573  fs::path pathRet;
574  char* pszHome = getenv("HOME");
575  if (pszHome == nullptr || strlen(pszHome) == 0)
576  pathRet = fs::path("/");
577  else
578  pathRet = fs::path(pszHome);
579 #ifdef MAC_OSX
580  // Mac
581  return pathRet / "Library/Application Support/Bitcoin";
582 #else
583  // Unix
584  return pathRet / ".bitcoin";
585 #endif
586 #endif
587 }
588 
590 static fs::path pathCached;
591 static fs::path pathCachedNetSpecific;
593 
594 const fs::path &GetBlocksDir()
595 {
596  LOCK(csPathCached);
597  fs::path &path = g_blocks_path_cache_net_specific;
598 
599  // Cache the path to avoid calling fs::create_directories on every call of
600  // this function
601  if (!path.empty()) return path;
602 
603  if (gArgs.IsArgSet("-blocksdir")) {
604  path = fs::system_complete(gArgs.GetArg("-blocksdir", ""));
605  if (!fs::is_directory(path)) {
606  path = "";
607  return path;
608  }
609  } else {
610  path = GetDataDir(false);
611  }
612 
613  path /= BaseParams().DataDir();
614  path /= "blocks";
615  fs::create_directories(path);
616  return path;
617 }
618 
619 const fs::path &GetDataDir(bool fNetSpecific)
620 {
621  LOCK(csPathCached);
622  fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached;
623 
624  // Cache the path to avoid calling fs::create_directories on every call of
625  // this function
626  if (!path.empty()) return path;
627 
628  std::string datadir = gArgs.GetArg("-datadir", "");
629  if (!datadir.empty()) {
630  path = fs::system_complete(datadir);
631  if (!fs::is_directory(path)) {
632  path = "";
633  return path;
634  }
635  } else {
636  path = GetDefaultDataDir();
637  }
638  if (fNetSpecific)
639  path /= BaseParams().DataDir();
640 
641  if (fs::create_directories(path)) {
642  // This is the first run, create wallets subdirectory too
643  fs::create_directories(path / "wallets");
644  }
645 
646  return path;
647 }
648 
650 {
651  std::string datadir = gArgs.GetArg("-datadir", "");
652  return datadir.empty() || fs::is_directory(fs::system_complete(datadir));
653 }
654 
656 {
657  LOCK(csPathCached);
658 
659  pathCached = fs::path();
660  pathCachedNetSpecific = fs::path();
662 }
663 
664 fs::path GetConfigFile(const std::string& confPath)
665 {
666  return AbsPathForConfigVal(fs::path(confPath), false);
667 }
668 
669 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)
670 {
671  std::string str, prefix;
672  std::string::size_type pos;
673  int linenr = 1;
674  while (std::getline(stream, str)) {
675  bool used_hash = false;
676  if ((pos = str.find('#')) != std::string::npos) {
677  str = str.substr(0, pos);
678  used_hash = true;
679  }
680  const static std::string pattern = " \t\r\n";
681  str = TrimString(str, pattern);
682  if (!str.empty()) {
683  if (*str.begin() == '[' && *str.rbegin() == ']') {
684  const std::string section = str.substr(1, str.size() - 2);
685  sections.emplace_back(SectionInfo{section, filepath, linenr});
686  prefix = section + '.';
687  } else if (*str.begin() == '-') {
688  error = strprintf("parse error on line %i: %s, options in configuration file must be specified without leading -", linenr, str);
689  return false;
690  } else if ((pos = str.find('=')) != std::string::npos) {
691  std::string name = prefix + TrimString(str.substr(0, pos), pattern);
692  std::string value = TrimString(str.substr(pos + 1), pattern);
693  if (used_hash && name.find("rpcpassword") != std::string::npos) {
694  error = strprintf("parse error on line %i, using # in rpcpassword can be ambiguous and should be avoided", linenr);
695  return false;
696  }
697  options.emplace_back(name, value);
698  if ((pos = name.rfind('.')) != std::string::npos && prefix.length() <= pos) {
699  sections.emplace_back(SectionInfo{name.substr(0, pos), filepath, linenr});
700  }
701  } else {
702  error = strprintf("parse error on line %i: %s", linenr, str);
703  if (str.size() >= 2 && str.substr(0, 2) == "no") {
704  error += strprintf(", if you intended to specify a negated option, use %s=1 instead", str);
705  }
706  return false;
707  }
708  }
709  ++linenr;
710  }
711  return true;
712 }
713 
714 bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys)
715 {
716  LOCK(cs_args);
717  std::vector<std::pair<std::string, std::string>> options;
718  if (!GetConfigOptions(stream, filepath, error, options, m_config_sections)) {
719  return false;
720  }
721  for (const std::pair<std::string, std::string>& option : options) {
722  std::string section;
723  std::string key = option.first;
724  util::SettingsValue value = InterpretOption(section, key, option.second);
726  if (flags) {
727  if (!CheckValid(key, value, *flags, error)) {
728  return false;
729  }
730  m_settings.ro_config[section][key].push_back(value);
731  } else {
732  if (ignore_invalid_keys) {
733  LogPrintf("Ignoring unknown configuration value %s\n", option.first);
734  } else {
735  error = strprintf("Invalid configuration value %s", option.first);
736  return false;
737  }
738  }
739  }
740  return true;
741 }
742 
743 bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
744 {
745  {
746  LOCK(cs_args);
747  m_settings.ro_config.clear();
748  m_config_sections.clear();
749  }
750 
751  const std::string confPath = GetArg("-conf", BITCOIN_CONF_FILENAME);
752  fsbridge::ifstream stream(GetConfigFile(confPath));
753 
754  // ok to not have a config file
755  if (stream.good()) {
756  if (!ReadConfigStream(stream, confPath, error, ignore_invalid_keys)) {
757  return false;
758  }
759  // `-includeconf` cannot be included in the command line arguments except
760  // as `-noincludeconf` (which indicates that no included conf file should be used).
761  bool use_conf_file{true};
762  {
763  LOCK(cs_args);
764  if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
765  // ParseParameters() fails if a non-negated -includeconf is passed on the command-line
766  assert(util::SettingsSpan(*includes).last_negated());
767  use_conf_file = false;
768  }
769  }
770  if (use_conf_file) {
771  std::string chain_id = GetChainName();
772  std::vector<std::string> conf_file_names;
773 
774  auto add_includes = [&](const std::string& network, size_t skip = 0) {
775  size_t num_values = 0;
776  LOCK(cs_args);
777  if (auto* section = util::FindKey(m_settings.ro_config, network)) {
778  if (auto* values = util::FindKey(*section, "includeconf")) {
779  for (size_t i = std::max(skip, util::SettingsSpan(*values).negated()); i < values->size(); ++i) {
780  conf_file_names.push_back((*values)[i].get_str());
781  }
782  num_values = values->size();
783  }
784  }
785  return num_values;
786  };
787 
788  // We haven't set m_network yet (that happens in SelectParams()), so manually check
789  // for network.includeconf args.
790  const size_t chain_includes = add_includes(chain_id);
791  const size_t default_includes = add_includes({});
792 
793  for (const std::string& conf_file_name : conf_file_names) {
794  fsbridge::ifstream conf_file_stream(GetConfigFile(conf_file_name));
795  if (conf_file_stream.good()) {
796  if (!ReadConfigStream(conf_file_stream, conf_file_name, error, ignore_invalid_keys)) {
797  return false;
798  }
799  LogPrintf("Included configuration file %s\n", conf_file_name);
800  } else {
801  error = "Failed to include configuration file " + conf_file_name;
802  return false;
803  }
804  }
805 
806  // Warn about recursive -includeconf
807  conf_file_names.clear();
808  add_includes(chain_id, /* skip= */ chain_includes);
809  add_includes({}, /* skip= */ default_includes);
810  std::string chain_id_final = GetChainName();
811  if (chain_id_final != chain_id) {
812  // Also warn about recursive includeconf for the chain that was specified in one of the includeconfs
813  add_includes(chain_id_final);
814  }
815  for (const std::string& conf_file_name : conf_file_names) {
816  tfm::format(std::cerr, "warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", conf_file_name);
817  }
818  }
819  }
820 
821  // If datadir is changed in .conf file:
823  if (!CheckDataDirOption()) {
824  error = strprintf("specified data directory \"%s\" does not exist.", gArgs.GetArg("-datadir", ""));
825  return false;
826  }
827  return true;
828 }
829 
830 std::string ArgsManager::GetChainName() const
831 {
832  auto get_net = [&](const std::string& arg) {
833  LOCK(cs_args);
834  util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg),
835  /* ignore_default_section_config= */ false,
836  /* get_chain_name= */ true);
837  return value.isNull() ? false : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
838  };
839 
840  const bool fRegTest = get_net("-regtest");
841  const bool fTestNet = get_net("-testnet");
842  const bool is_chain_arg_set = IsArgSet("-chain");
843 
844  if ((int)is_chain_arg_set + (int)fRegTest + (int)fTestNet > 1) {
845  throw std::runtime_error("Invalid combination of -regtest, -testnet and -chain. Can use at most one.");
846  }
847  if (fRegTest)
849  if (fTestNet)
851  return GetArg("-chain", CBaseChainParams::MAIN);
852 }
853 
854 bool ArgsManager::UseDefaultSection(const std::string& arg) const
855 {
856  return m_network == CBaseChainParams::MAIN || m_network_only_args.count(arg) == 0;
857 }
858 
859 util::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
860 {
861  LOCK(cs_args);
862  return util::GetSetting(
863  m_settings, m_network, SettingName(arg), !UseDefaultSection(arg), /* get_chain_name= */ false);
864 }
865 
866 std::vector<util::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const
867 {
868  LOCK(cs_args);
869  return util::GetSettingsList(m_settings, m_network, SettingName(arg), !UseDefaultSection(arg));
870 }
871 
873  const std::string& prefix,
874  const std::string& section,
875  const std::map<std::string, std::vector<util::SettingsValue>>& args) const
876 {
877  std::string section_str = section.empty() ? "" : "[" + section + "] ";
878  for (const auto& arg : args) {
879  for (const auto& value : arg.second) {
880  Optional<unsigned int> flags = GetArgFlags('-' + arg.first);
881  if (flags) {
882  std::string value_str = (*flags & SENSITIVE) ? "****" : value.write();
883  LogPrintf("%s %s%s=%s\n", prefix, section_str, arg.first, value_str);
884  }
885  }
886  }
887 }
888 
890 {
891  LOCK(cs_args);
892  for (const auto& section : m_settings.ro_config) {
893  logArgsPrefix("Config file arg:", section.first, section.second);
894  }
895  logArgsPrefix("Command-line arg:", "", m_settings.command_line_options);
896 }
897 
898 bool RenameOver(fs::path src, fs::path dest)
899 {
900 #ifdef WIN32
901  return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(),
902  MOVEFILE_REPLACE_EXISTING) != 0;
903 #else
904  int rc = std::rename(src.string().c_str(), dest.string().c_str());
905  return (rc == 0);
906 #endif /* WIN32 */
907 }
908 
914 bool TryCreateDirectories(const fs::path& p)
915 {
916  try
917  {
918  return fs::create_directories(p);
919  } catch (const fs::filesystem_error&) {
920  if (!fs::exists(p) || !fs::is_directory(p))
921  throw;
922  }
923 
924  // create_directories didn't create the directory, it had to have existed already
925  return false;
926 }
927 
928 bool FileCommit(FILE *file)
929 {
930  if (fflush(file) != 0) { // harmless if redundantly called
931  LogPrintf("%s: fflush failed: %d\n", __func__, errno);
932  return false;
933  }
934 #ifdef WIN32
935  HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
936  if (FlushFileBuffers(hFile) == 0) {
937  LogPrintf("%s: FlushFileBuffers failed: %d\n", __func__, GetLastError());
938  return false;
939  }
940 #else
941  #if defined(__linux__) || defined(__NetBSD__)
942  if (fdatasync(fileno(file)) != 0 && errno != EINVAL) { // Ignore EINVAL for filesystems that don't support sync
943  LogPrintf("%s: fdatasync failed: %d\n", __func__, errno);
944  return false;
945  }
946  #elif defined(MAC_OSX) && defined(F_FULLFSYNC)
947  if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) { // Manpage says "value other than -1" is returned on success
948  LogPrintf("%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno);
949  return false;
950  }
951  #else
952  if (fsync(fileno(file)) != 0 && errno != EINVAL) {
953  LogPrintf("%s: fsync failed: %d\n", __func__, errno);
954  return false;
955  }
956  #endif
957 #endif
958  return true;
959 }
960 
961 bool TruncateFile(FILE *file, unsigned int length) {
962 #if defined(WIN32)
963  return _chsize(_fileno(file), length) == 0;
964 #else
965  return ftruncate(fileno(file), length) == 0;
966 #endif
967 }
968 
973 int RaiseFileDescriptorLimit(int nMinFD) {
974 #if defined(WIN32)
975  return 2048;
976 #else
977  struct rlimit limitFD;
978  if (getrlimit(RLIMIT_NOFILE, &limitFD) != -1) {
979  if (limitFD.rlim_cur < (rlim_t)nMinFD) {
980  limitFD.rlim_cur = nMinFD;
981  if (limitFD.rlim_cur > limitFD.rlim_max)
982  limitFD.rlim_cur = limitFD.rlim_max;
983  setrlimit(RLIMIT_NOFILE, &limitFD);
984  getrlimit(RLIMIT_NOFILE, &limitFD);
985  }
986  return limitFD.rlim_cur;
987  }
988  return nMinFD; // getrlimit failed, assume it's fine
989 #endif
990 }
991 
996 void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
997 #if defined(WIN32)
998  // Windows-specific version
999  HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1000  LARGE_INTEGER nFileSize;
1001  int64_t nEndPos = (int64_t)offset + length;
1002  nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF;
1003  nFileSize.u.HighPart = nEndPos >> 32;
1004  SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN);
1005  SetEndOfFile(hFile);
1006 #elif defined(MAC_OSX)
1007  // OSX specific version
1008  // NOTE: Contrary to other OS versions, the OSX version assumes that
1009  // NOTE: offset is the size of the file.
1010  fstore_t fst;
1011  fst.fst_flags = F_ALLOCATECONTIG;
1012  fst.fst_posmode = F_PEOFPOSMODE;
1013  fst.fst_offset = 0;
1014  fst.fst_length = length; // mac os fst_length takes the # of free bytes to allocate, not desired file size
1015  fst.fst_bytesalloc = 0;
1016  if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
1017  fst.fst_flags = F_ALLOCATEALL;
1018  fcntl(fileno(file), F_PREALLOCATE, &fst);
1019  }
1020  ftruncate(fileno(file), static_cast<off_t>(offset) + length);
1021 #else
1022  #if defined(HAVE_POSIX_FALLOCATE)
1023  // Version using posix_fallocate
1024  off_t nEndPos = (off_t)offset + length;
1025  if (0 == posix_fallocate(fileno(file), 0, nEndPos)) return;
1026  #endif
1027  // Fallback version
1028  // TODO: just write one byte per block
1029  static const char buf[65536] = {};
1030  if (fseek(file, offset, SEEK_SET)) {
1031  return;
1032  }
1033  while (length > 0) {
1034  unsigned int now = 65536;
1035  if (length < now)
1036  now = length;
1037  fwrite(buf, 1, now, file); // allowed to fail; this function is advisory anyway
1038  length -= now;
1039  }
1040 #endif
1041 }
1042 
1043 #ifdef WIN32
1044 fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
1045 {
1046  WCHAR pszPath[MAX_PATH] = L"";
1047 
1048  if(SHGetSpecialFolderPathW(nullptr, pszPath, nFolder, fCreate))
1049  {
1050  return fs::path(pszPath);
1051  }
1052 
1053  LogPrintf("SHGetSpecialFolderPathW() failed, could not obtain requested path.\n");
1054  return fs::path("");
1055 }
1056 #endif
1057 
1058 #ifndef WIN32
1059 std::string ShellEscape(const std::string& arg)
1060 {
1061  std::string escaped = arg;
1062  boost::replace_all(escaped, "'", "'\"'\"'");
1063  return "'" + escaped + "'";
1064 }
1065 #endif
1066 
1067 #if HAVE_SYSTEM
1068 void runCommand(const std::string& strCommand)
1069 {
1070  if (strCommand.empty()) return;
1071 #ifndef WIN32
1072  int nErr = ::system(strCommand.c_str());
1073 #else
1074  int nErr = ::_wsystem(std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t>().from_bytes(strCommand).c_str());
1075 #endif
1076  if (nErr)
1077  LogPrintf("runCommand error: system(%s) returned %d\n", strCommand, nErr);
1078 }
1079 #endif
1080 
1082 {
1083 #ifdef HAVE_MALLOPT_ARENA_MAX
1084  // glibc-specific: On 32-bit systems set the number of arenas to 1.
1085  // By default, since glibc 2.10, the C library will create up to two heap
1086  // arenas per core. This is known to cause excessive virtual address space
1087  // usage in our usage. Work around it by setting the maximum number of
1088  // arenas to 1.
1089  if (sizeof(void*) == 4) {
1090  mallopt(M_ARENA_MAX, 1);
1091  }
1092 #endif
1093  // On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
1094  // may be invalid, in which case the "C.UTF-8" locale is used as fallback.
1095 #if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
1096  try {
1097  std::locale(""); // Raises a runtime error if current locale is invalid
1098  } catch (const std::runtime_error&) {
1099  setenv("LC_ALL", "C.UTF-8", 1);
1100  }
1101 #elif defined(WIN32)
1102  // Set the default input/output charset is utf-8
1103  SetConsoleCP(CP_UTF8);
1104  SetConsoleOutputCP(CP_UTF8);
1105 #endif
1106  // The path locale is lazy initialized and to avoid deinitialization errors
1107  // in multithreading environments, it is set explicitly by the main thread.
1108  // A dummy locale is used to extract the internal default locale, used by
1109  // fs::path, which is then used to explicitly imbue the path.
1110  std::locale loc = fs::path::imbue(std::locale::classic());
1111 #ifndef WIN32
1112  fs::path::imbue(loc);
1113 #else
1114  fs::path::imbue(std::locale(loc, new std::codecvt_utf8_utf16<wchar_t>()));
1115 #endif
1116 }
1117 
1119 {
1120 #ifdef WIN32
1121  // Initialize Windows Sockets
1122  WSADATA wsadata;
1123  int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
1124  if (ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
1125  return false;
1126 #endif
1127  return true;
1128 }
1129 
1131 {
1132  return std::thread::hardware_concurrency();
1133 }
1134 
1135 std::string CopyrightHolders(const std::string& strPrefix)
1136 {
1137  const auto copyright_devs = strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION);
1138  std::string strCopyrightHolders = strPrefix + copyright_devs;
1139 
1140  // Make sure Bitcoin Core copyright is not removed by accident
1141  if (copyright_devs.find("Bitcoin Core") == std::string::npos) {
1142  strCopyrightHolders += "\n" + strPrefix + "The Bitcoin Core developers";
1143  }
1144  return strCopyrightHolders;
1145 }
1146 
1147 // Obtain the application startup time (used for uptime calculation)
1149 {
1150  return nStartupTime;
1151 }
1152 
1153 fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific)
1154 {
1155  if (path.is_absolute()) {
1156  return path;
1157  }
1158  return fs::absolute(path, GetDataDir(net_specific));
1159 }
1160 
1162 {
1163 #ifdef SCHED_BATCH
1164  const static sched_param param{};
1165  if (pthread_setschedparam(pthread_self(), SCHED_BATCH, &param) != 0) {
1166  LogPrintf("Failed to pthread_setschedparam: %s\n", strerror(errno));
1167  }
1168 #endif
1169 }
1170 
1171 namespace util {
1172 #ifdef WIN32
1173 WinCmdLineArgs::WinCmdLineArgs()
1174 {
1175  wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
1176  std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> utf8_cvt;
1177  argv = new char*[argc];
1178  args.resize(argc);
1179  for (int i = 0; i < argc; i++) {
1180  args[i] = utf8_cvt.to_bytes(wargv[i]);
1181  argv[i] = &*args[i].begin();
1182  }
1183  LocalFree(wargv);
1184 }
1185 
1186 WinCmdLineArgs::~WinCmdLineArgs()
1187 {
1188  delete[] argv;
1189 }
1190 
1191 std::pair<int, char**> WinCmdLineArgs::get()
1192 {
1193  return std::make_pair(argc, argv);
1194 }
1195 #endif
1196 } // namespace util
NODISCARD bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
Definition: system.cpp:743
static const int optIndent
Definition: system.cpp:526
#define COPYRIGHT_HOLDERS_SUBSTITUTION
#define COPYRIGHT_HOLDERS
bool OnlyHasDefaultSectionSetting(const Settings &settings, const std::string &section, const std::string &name)
Return true if a setting is set in the default config file section, and not overridden by a higher pr...
Definition: settings.cpp:150
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:369
std::string FormatParagraph(const std::string &in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line...
bool isBool() const
Definition: univalue.h:80
bool FileCommit(FILE *file)
Definition: system.cpp:928
Definition: httprpc.h:8
static std::map< std::string, std::unique_ptr< fsbridge::FileLock > > dir_locks
A map that contains all the currently held directory locks.
Definition: system.cpp:83
std::string ToLower(const std::string &str)
Returns the lowercase equivalent of the given string.
bool DirIsWritable(const fs::path &directory)
Definition: system.cpp:123
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:19
size_t negated() const
Number of negated values.
Definition: settings.cpp:170
fs::path GetDefaultDataDir()
Definition: system.cpp:563
bool get_bool() const
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn&#39;t already have a value.
Definition: system.cpp:405
static const int msgIndent
Definition: system.cpp:527
static const std::string REGTEST
int GetNumCores()
Return the number of cores available on the current system.
Definition: system.cpp:1130
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
const char * prefix
Definition: rest.cpp:648
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
Definition: system.cpp:438
SettingsValue GetSetting(const Settings &settings, const std::string &section, const std::string &name, bool ignore_default_section_config, bool get_chain_name)
Get settings value from combined sources: forced settings, command line arguments and the read-only c...
Definition: settings.cpp:52
~ArgsManager()
Definition: system.cpp:239
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by Boost&#39;s create_directories if the requested directory exists...
Definition: system.cpp:914
fs::ifstream ifstream
Definition: fs.h:90
#define MAX_PATH
Definition: compat.h:69
static std::string SettingName(const std::string &arg)
Definition: system.cpp:174
bool last_negated() const
True if the last value is negated.
Definition: settings.cpp:169
void SetupEnvironment()
Definition: system.cpp:1081
static bool InterpretBool(const std::string &strValue)
Interpret a string argument as a boolean.
Definition: system.cpp:167
std::string CopyrightHolders(const std::string &strPrefix)
Definition: system.cpp:1135
void SelectConfigNetwork(const std::string &network)
Select the network in use.
Definition: system.cpp:276
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
static std::mutex cs_dir_locks
Mutex to protect dir_locks.
Definition: system.cpp:85
NODISCARD bool ReadConfigStream(std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false)
Definition: system.cpp:714
static void LogPrintf(const char *fmt, const Args &... args)
Definition: logging.h:164
util::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
Definition: system.cpp:859
const std::string & get_str() const
static auto & nullopt
Substitute for C++17 std::nullopt.
Definition: optional.h:24
bool isNum() const
Definition: univalue.h:82
NODISCARD bool ParseParameters(int argc, const char *const argv[], std::string &error)
Definition: system.cpp:282
const fs::path & GetBlocksDir()
Definition: system.cpp:594
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
Definition: system.cpp:973
RecursiveMutex cs_args
Definition: system.h:171
void ReleaseDirectoryLocks()
Release all directory locks.
Definition: system.cpp:117
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:391
int64_t get_int64() const
void ClearDatadirCache()
Tests only.
Definition: system.cpp:655
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: system.cpp:413
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes)
Definition: system.cpp:136
Optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
Definition: system.cpp:348
const char *const BITCOIN_CONF_FILENAME
Definition: system.cpp:74
bool SetupNetworking()
Definition: system.cpp:1118
static RecursiveMutex csPathCached
Definition: system.cpp:592
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn&#39;t already have a value.
Definition: system.cpp:397
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
Definition: settings.h:86
std::string m_name
Definition: system.h:138
const std::string & DataDir() const
std::string GetHelpMessage() const
Get the help string.
Definition: system.cpp:445
static const std::string MAIN
Chain name strings.
bool CheckDataDirOption()
Definition: system.cpp:649
std::vector< SettingsValue > GetSettingsList(const Settings &settings, const std::string &section, const std::string &name, bool ignore_default_section_config)
Get combined setting value similar to GetSetting(), except if setting was specified multiple times...
Definition: settings.cpp:105
bool LockDirectory(const fs::path &directory, const std::string lockfile_name, bool probe_only)
Definition: system.cpp:87
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
Definition: system.cpp:374
NODISCARD std::string TrimString(const std::string &str, const std::string &pattern=" \\\)
Definition: string.h:16
bool isFalse() const
Definition: univalue.h:79
#define LOCK(cs)
Definition: sync.h:218
const char * name
Definition: rest.cpp:41
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:52
int atoi(const std::string &str)
void format(std::ostream &out, const char *fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1062
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:419
bool HelpRequested(const ArgsManager &args)
Definition: system.cpp:514
const fs::path & GetDataDir(bool fNetSpecific)
Definition: system.cpp:619
static util::SettingsValue InterpretOption(std::string &section, std::string &key, const std::string &value)
Interpret -nofoo as if the user supplied -foo=0.
Definition: system.cpp:199
UniValue help(const JSONRPCRequest &jsonRequest)
Definition: server.cpp:131
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
Definition: system.cpp:556
void logArgsPrefix(const std::string &prefix, const std::string &section, const std::map< std::string, std::vector< util::SettingsValue >> &args) const
Definition: system.cpp:872
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...
Definition: system.cpp:1153
bool isNull() const
Definition: univalue.h:77
bool isTrue() const
Definition: univalue.h:78
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...
Definition: system.cpp:996
bool RenameOver(fs::path src, fs::path dest)
Definition: system.cpp:898
int flags
Definition: bitcoin-tx.cpp:509
std::string ShellEscape(const std::string &arg)
Definition: system.cpp:1059
Accessor for list of settings that skips negated values when iterated over.
Definition: settings.h:69
static fs::path g_blocks_path_cache_net_specific
Definition: system.cpp:589
int64_t atoi64(const char *psz)
int64_t GetStartupTime()
Server/client environment: argument handling, config file parsing, thread wrappers, startup time.
Definition: system.cpp:1148
static const int screenWidth
Definition: system.cpp:525
bool TruncateFile(FILE *file, unsigned int length)
Definition: system.cpp:961
fs::path GetConfigFile(const std::string &confPath)
Definition: system.cpp:664
void UnlockDirectory(const fs::path &directory, const std::string &lockfile_name)
Definition: system.cpp:111
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:379
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)
Definition: system.cpp:669
ArgsManager gArgs
Definition: system.cpp:76
void LogArgs() const
Log the config file options and the command line arguments, useful for troubleshooting.
Definition: system.cpp:889
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
Definition: system.cpp:519
static fs::path pathCachedNetSpecific
Definition: system.cpp:591
static const std::string TESTNET
std::streampos GetFileSize(const char *path, std::streamsize max)
Get the size of a file by scanning it.
Definition: system.cpp:144
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
Definition: system.cpp:830
const std::list< SectionInfo > GetUnrecognizedSections() const
Log warnings for unrecognized section names in the config file.
Definition: system.cpp:261
static fs::path pathCached
Definition: system.cpp:590
OptionsCategory
Definition: system.h:118
void ScheduleBatchPriority()
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
Definition: system.cpp:1161
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:14
const int64_t nStartupTime
Definition: system.cpp:72
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
Definition: system.cpp:360
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
Definition: system.cpp:533
int64_t GetTime()
Return system time (or mocked time, if set)
Definition: time.cpp:23
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition: system.cpp:529
std::vector< util::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
Definition: system.cpp:866
static std::string FormatException(const std::exception *pex, const char *pszThread)
Definition: system.cpp:540
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...
Definition: system.cpp:241
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
static bool CheckValid(const std::string &key, const util::SettingsValue &val, unsigned int flags, std::string &error)
Check settings value validity according to flags.
Definition: system.cpp:226
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...
Definition: system.cpp:854