10 #ifndef BITCOIN_UTIL_SYSTEM_H
11 #define BITCOIN_UTIL_SYSTEM_H
13 #if defined(HAVE_CONFIG_H)
79 std::streampos
GetFileSize(
const char* path, std::streamsize max = std::numeric_limits<std::streamsize>::max());
92 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate =
true);
98 void runCommand(
const std::string& strCommand);
115 return c ==
'-' || c ==
'/';
203 [[nodiscard]]
bool ReadConfigStream(std::istream& stream,
const std::string& filepath, std::string&
error,
bool ignore_invalid_keys =
false);
225 std::vector<util::SettingsValue>
GetSettingsList(
const std::string& arg)
const;
268 std::optional<const Command>
GetCommand()
const;
302 std::vector<std::string>
GetArgs(
const std::string& strArg)
const;
310 bool IsArgSet(
const std::string& strArg)
const;
328 std::string
GetArg(
const std::string& strArg,
const std::string& strDefault)
const;
329 std::optional<std::string>
GetArg(
const std::string& strArg)
const;
350 int64_t
GetIntArg(
const std::string& strArg, int64_t nDefault)
const;
351 std::optional<int64_t>
GetIntArg(
const std::string& strArg)
const;
360 bool GetBoolArg(
const std::string& strArg,
bool fDefault)
const;
361 std::optional<bool>
GetBoolArg(
const std::string& strArg)
const;
370 bool SoftSetArg(
const std::string& strArg,
const std::string& strValue);
383 void ForceSetArg(
const std::string& strArg,
const std::string& strValue);
411 m_available_args.clear();
412 m_network_only_args.clear();
424 std::optional<unsigned int>
GetArgFlags(
const std::string&
name)
const;
441 bool WriteSettingsFile(std::vector<std::string>* errors =
nullptr,
bool backup =
false)
const;
452 template <
typename Fn>
476 const std::string&
prefix,
477 const std::string& section,
478 const std::map<std::string, std::vector<util::SettingsValue>>&
args)
const;
506 std::string
HelpMessageOpt(
const std::string& option,
const std::string& message);
524 template <
typename Tdst,
typename Tsrc>
525 inline void insert(Tdst& dst,
const Tsrc& src) {
526 dst.insert(dst.begin(), src.begin(), src.end());
528 template <
typename TsetT,
typename Tsrc>
529 inline void insert(std::set<TsetT>& dst,
const Tsrc& src) {
530 dst.insert(src.begin(), src.end());
541 T*
const* ptr = std::any_cast<T*>(&any);
542 return ptr ? *ptr :
nullptr;
551 std::pair<int, char**> get();
556 std::vector<std::string>
args;
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...
std::optional< const Command > GetCommand() const
Get the command and command args (returns std::nullopt if no command provided)
const fs::path & GetBlocksDirPath() const
Get blocks directory path.
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
std::list< SectionInfo > GetUnrecognizedSections() const
Log warnings for unrecognized section names in the config file.
Flags
Flags controlling how config and command line arguments are validated and interpreted.
@ ALLOW_ANY
disable validation
@ DISALLOW_NEGATION
disallow -nofoo syntax
@ DISALLOW_ELISION
disallow -foo syntax that doesn't assign any value
bool ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
void logArgsPrefix(const std::string &prefix, const std::string §ion, const std::map< std::string, std::vector< util::SettingsValue >> &args) const
fs::path m_cached_datadir_path GUARDED_BY(cs_args)
bool ParseParameters(int argc, const char *const argv[], std::string &error)
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
util::SettingsValue GetPersistentSetting(const std::string &name) const
Get current setting from config file or read/write settings file, ignoring nonpersistent command line...
std::optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
const fs::path & GetDataDirBase() const
Get data directory path.
std::string m_network GUARDED_BY(cs_args)
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.
void LockSettings(Fn &&fn)
Access settings with lock held.
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
void SelectConfigNetwork(const std::string &network)
Select the network in use.
std::string GetHelpMessage() const
Get the help string.
void ClearPathCache()
Clear cached directory paths.
fs::path m_cached_blocks_path GUARDED_BY(cs_args)
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr, bool backup=false) const
Write settings file or backup settings file.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
std::map< OptionsCategory, std::map< std::string, Arg > > m_available_args GUARDED_BY(cs_args)
const fs::path & GetDataDir(bool net_specific) const
Get data directory path.
std::vector< std::string > m_command GUARDED_BY(cs_args)
void ClearArgs()
Clear available arguments.
fs::path GetConfigFilePath() const
Return config file path (read-only)
util::Settings m_settings GUARDED_BY(cs_args)
void AddCommand(const std::string &cmd, const std::string &help)
Add subcommand.
std::vector< util::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
bool m_accept_any_command GUARDED_BY(cs_args)
void LogArgs() const
Log the config file options and the command line arguments, useful for troubleshooting.
fs::path m_cached_network_datadir_path GUARDED_BY(cs_args)
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...
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
std::set< std::string > m_network_only_args GUARDED_BY(cs_args)
util::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
bool ReadConfigStream(std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false)
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
fs::path GetPathArg(std::string arg, const fs::path &default_value={}) const
Return path argument or default value.
std::list< SectionInfo > m_config_sections GUARDED_BY(cs_args)
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
#define T(expected, seed, data)
bool error(const char *fmt, const Args &... args)
T * AnyPtr(const std::any &any) noexcept
Helper function to access the contained object of a std::any instance.
void insert(Tdst &dst, const Tsrc &src)
Simplification of std insertion.
std::vector< std::string > args
If command is non-empty: Any args that followed it If command is empty: The unregistered command and ...
std::string command
The command (if one has been registered with AddCommand), or empty.
bool HelpRequested(const ArgsManager &args)
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
fs::path GetDefaultDataDir()
bool LockDirectory(const fs::path &directory, const fs::path &lockfile_name, bool probe_only=false)
const char *const BITCOIN_SETTINGS_FILENAME
bool SettingToBool(const util::SettingsValue &, bool)
bool DirIsWritable(const fs::path &directory)
bool CheckDataDirOption(const ArgsManager &args)
bool RenameOver(fs::path src, fs::path dest)
Rename src to dest.
int64_t SettingToInt(const util::SettingsValue &, int64_t)
fs::path AbsPathForConfigVal(const ArgsManager &args, 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...
void ScheduleBatchPriority()
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
std::streampos GetFileSize(const char *path, std::streamsize max=std::numeric_limits< std::streamsize >::max())
Get the size of a file by scanning it.
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
void ReleaseDirectoryLocks()
Release all directory locks.
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length)
this function tries to make a particular range of a file allocated (corresponding to disk space) it i...
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
const char *const BITCOIN_CONF_FILENAME
bool IsSwitchChar(char c)
bool TruncateFile(FILE *file, unsigned int length)
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes=0)
int GetNumCores()
Return the number of cores available on the current system.
fs::path GetConfigFile(const ArgsManager &args, const fs::path &configuration_file_path)
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
void UnlockDirectory(const fs::path &directory, const fs::path &lockfile_name)
std::string SettingToString(const util::SettingsValue &, const std::string &)
std::string ShellEscape(const std::string &arg)
#define EXCLUSIVE_LOCKS_REQUIRED(...)