 |
Bitcoin Core
23.99.0
P2P Digital Currency
|
Go to the documentation of this file.
10 #ifndef BITCOIN_UTIL_SYSTEM_H
11 #define BITCOIN_UTIL_SYSTEM_H
13 #if defined(HAVE_CONFIG_H)
47 template<
typename... Args>
89 std::streampos
GetFileSize(
const char* path, std::streamsize max = std::numeric_limits<std::streamsize>::max());
102 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate =
true);
108 void runCommand(
const std::string& strCommand);
132 return c ==
'-' || c ==
'/';
213 std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args
GUARDED_BY(
cs_args);
220 [[nodiscard]]
bool ReadConfigStream(std::istream& stream,
const std::string& filepath, std::string&
error,
bool ignore_invalid_keys =
false);
242 std::vector<util::SettingsValue>
GetSettingsList(
const std::string& arg)
const;
280 std::optional<const Command>
GetCommand()
const;
316 std::vector<std::string>
GetArgs(
const std::string& strArg)
const;
324 bool IsArgSet(
const std::string& strArg)
const;
342 std::string
GetArg(
const std::string& strArg,
const std::string& strDefault)
const;
343 std::optional<std::string>
GetArg(
const std::string& strArg)
const;
364 int64_t
GetIntArg(
const std::string& strArg, int64_t nDefault)
const;
365 std::optional<int64_t>
GetIntArg(
const std::string& strArg)
const;
374 bool GetBoolArg(
const std::string& strArg,
bool fDefault)
const;
375 std::optional<bool>
GetBoolArg(
const std::string& strArg)
const;
384 bool SoftSetArg(
const std::string& strArg,
const std::string& strValue);
397 void ForceSetArg(
const std::string& strArg,
const std::string& strValue);
425 m_available_args.clear();
426 m_network_only_args.clear();
438 std::optional<unsigned int>
GetArgFlags(
const std::string&
name)
const;
462 bool WriteSettingsFile(std::vector<std::string>* errors =
nullptr,
bool backup =
false)
const;
473 template <
typename Fn>
498 const std::string&
prefix,
499 const std::string& section,
500 const std::map<std::string, std::vector<util::SettingsValue>>&
args)
const;
528 std::string
HelpMessageOpt(
const std::string& option,
const std::string& message);
546 template <
typename Tdst,
typename Tsrc>
547 inline void insert(Tdst& dst,
const Tsrc& src) {
548 dst.insert(dst.begin(), src.begin(), src.end());
550 template <
typename TsetT,
typename Tsrc>
551 inline void insert(std::set<TsetT>& dst,
const Tsrc& src) {
552 dst.insert(src.begin(), src.end());
563 T*
const* ptr = std::any_cast<T*>(&any);
564 return ptr ? *ptr :
nullptr;
573 std::pair<int, char**> get();
578 std::vector<std::string>
args;
584 #endif // BITCOIN_UTIL_SYSTEM_H
fs::path GetPathArg(std::string arg, const fs::path &default_value={}) const
Return path argument or default value.
bool RenameOver(fs::path src, fs::path dest)
Rename src to dest.
void LogArgs() const
Log the config file options and the command line arguments, useful for troubleshooting.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
void ClearPathCache()
Clear cached directory paths.
bool HelpRequested(const ArgsManager &args)
std::optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
std::vector< std::string > args
If command is non-empty: Any args that followed it If command is empty: The unregistered command and ...
std::streampos GetFileSize(const char *path, std::streamsize max=std::numeric_limits< std::streamsize >::max())
Get the size of a file by scanning it.
util::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
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...
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
const fs::path & GetBlocksDirPath() const
Get blocks directory path.
const char *const BITCOIN_SETTINGS_FILENAME
std::string GetHelpMessage() const
Get the help string.
bool m_accept_any_command GUARDED_BY(cs_args)
@ ALLOW_ANY
disable validation
@ DISALLOW_NEGATION
disallow -nofoo syntax
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
util::SettingsValue GetPersistentSetting(const std::string &name) const
Get current setting from config file or read/write settings file, ignoring nonpersistent command line...
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length)
this function tries to make a particular range of a file allocated (corresponding to disk space) it i...
bool InitSettings(std::string &error)
Read and update settings file with saved settings.
@ DISALLOW_ELISION
disallow -foo syntax that doesn't assign any value
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
bool CheckDataDirOption()
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
const fs::path & GetDataDirBase() const
Get data directory path.
fs::path GetDefaultDataDir()
fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific=true)
Most paths passed as configuration arguments are treated as relative to the datadir if they are not a...
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes=0)
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
void UnlockDirectory(const fs::path &directory, const fs::path &lockfile_name)
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
bool IsSwitchChar(char c)
bool DirIsWritable(const fs::path &directory)
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...
void ForceSetArg(const std::string &strArg, const std::string &strValue)
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
std::string command
The command (if one has been registered with AddCommand), or empty.
bool ParseParameters(int argc, const char *const argv[], std::string &error)
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr, bool backup=false) const
Write settings file or backup settings file.
util::Settings m_settings GUARDED_BY(cs_args)
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
void ScheduleBatchPriority()
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
bool ReadConfigStream(std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false)
Flags
Flags controlling how config and command line arguments are validated and interpreted.
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
bool ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
void SelectConfigNetwork(const std::string &network)
Select the network in use.
void LockSettings(Fn &&fn)
Access settings with lock held.
std::vector< util::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
void logArgsPrefix(const std::string &prefix, const std::string §ion, const std::map< std::string, std::vector< util::SettingsValue >> &args) const
void insert(Tdst &dst, const Tsrc &src)
Simplification of std insertion.
const std::list< SectionInfo > GetUnrecognizedSections() const
Log warnings for unrecognized section names in the config file.
void ClearArgs()
Clear available arguments.
std::optional< const Command > GetCommand() const
Get the command and command args (returns std::nullopt if no command provided)
bool SettingToBool(const util::SettingsValue &, bool)
int64_t SettingToInt(const util::SettingsValue &, int64_t)
bool GetSettingsPath(fs::path *filepath=nullptr, bool temp=false, bool backup=false) const
Get settings file path, or return false if read-write settings were disabled with -nosettings.
T * AnyPtr(const std::any &any) noexcept
Helper function to access the contained object of a std::any instance.
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
void ReleaseDirectoryLocks()
Release all directory locks.
bool error(const char *fmt, const Args &... args)
const char *const BITCOIN_CONF_FILENAME
#define T(expected, seed, data)
fs::path GetConfigFile(const fs::path &configuration_file_path)
UniValue RunCommandParseJSON(const std::string &str_command, const std::string &str_std_in="")
Execute a command which returns JSON, and parse the result.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
bool TruncateFile(FILE *file, unsigned int length)
void AddCommand(const std::string &cmd, const std::string &help)
Add subcommand.
bool LockDirectory(const fs::path &directory, const fs::path &lockfile_name, bool probe_only=false)
std::string ShellEscape(const std::string &arg)
int GetNumCores()
Return the number of cores available on the current system.
const fs::path & GetDataDir(bool net_specific) const
Get data directory path.
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
std::string SettingToString(const util::SettingsValue &, const std::string &)