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