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