10 #ifndef BITCOIN_UTIL_SYSTEM_H 11 #define BITCOIN_UTIL_SYSTEM_H 13 #if defined(HAVE_CONFIG_H) 48 template<
typename... Args>
49 bool error(
const char* fmt,
const Args&... args)
72 [[nodiscard]]
bool RenameOver(fs::path src, fs::path dest);
73 bool LockDirectory(
const fs::path& directory,
const std::string lockfile_name,
bool probe_only=
false);
74 void UnlockDirectory(
const fs::path& directory,
const std::string& lockfile_name);
76 bool CheckDiskSpace(
const fs::path& dir, uint64_t additional_bytes = 0);
84 std::streampos
GetFileSize(
const char* path, std::streamsize max = std::numeric_limits<std::streamsize>::max());
97 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate =
true);
103 void runCommand(
const std::string& strCommand);
127 return c ==
'-' || c ==
'/';
192 std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args
GUARDED_BY(
cs_args);
199 [[nodiscard]]
bool ReadConfigStream(std::istream& stream,
const std::string& filepath, std::string&
error,
bool ignore_invalid_keys =
false);
220 std::vector<util::SettingsValue>
GetSettingsList(
const std::string& arg)
const;
259 std::optional<const Command>
GetCommand()
const;
295 std::vector<std::string>
GetArgs(
const std::string& strArg)
const;
303 bool IsArgSet(
const std::string& strArg)
const;
321 std::string
GetArg(
const std::string& strArg,
const std::string& strDefault)
const;
330 int64_t
GetArg(
const std::string& strArg, int64_t nDefault)
const;
339 bool GetBoolArg(
const std::string& strArg,
bool fDefault)
const;
348 bool SoftSetArg(
const std::string& strArg,
const std::string& strValue);
361 void ForceSetArg(
const std::string& strArg,
const std::string& strValue);
389 m_available_args.clear();
390 m_network_only_args.clear();
402 std::optional<unsigned int>
GetArgFlags(
const std::string&
name)
const;
415 bool GetSettingsPath(fs::path* filepath =
nullptr,
bool temp =
false)
const;
430 template <
typename Fn>
451 const fs::path&
GetDataDir(
bool net_specific)
const;
455 const std::string&
prefix,
456 const std::string& section,
457 const std::map<std::string, std::vector<util::SettingsValue>>& args)
const;
485 std::string
HelpMessageOpt(
const std::string& option,
const std::string& message);
505 template <
typename Tdst,
typename Tsrc>
506 inline void insert(Tdst& dst,
const Tsrc& src) {
507 dst.insert(dst.begin(), src.begin(), src.end());
509 template <
typename TsetT,
typename Tsrc>
510 inline void insert(std::set<TsetT>& dst,
const Tsrc& src) {
511 dst.insert(src.begin(), src.end());
522 T*
const* ptr = std::any_cast<T*>(&any);
523 return ptr ? *ptr :
nullptr;
532 std::pair<int, char**>
get();
537 std::vector<std::string> args;
543 #endif // BITCOIN_UTIL_SYSTEM_H bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
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 IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
bool TruncateFile(FILE *file, unsigned int length)
bool GetSettingsPath(fs::path *filepath=nullptr, bool temp=false) const
Get settings file path, or return false if read-write settings were disabled with -nosettings...
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
fs::path GetConfigFile(const std::string &confPath)
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
T * AnyPtr(const std::any &any) noexcept
Helper function to access the contained object of a std::any instance.
void SelectConfigNetwork(const std::string &network)
Select the network in use.
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr) const
Write settings file.
bool ReadConfigStream(std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false)
util::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
void ScheduleBatchPriority()
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
void insert(Tdst &dst, const Tsrc &src)
Simplification of std insertion.
bool ParseParameters(int argc, const char *const argv[], std::string &error)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
util::Settings m_settings GUARDED_BY(cs_args)
bool RenameOver(fs::path src, fs::path dest)
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
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 ForceSetArg(const std::string &strArg, const std::string &strValue)
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 SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
const fs::path & GetDataDirBase() const
Get data directory path.
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
bool DirIsWritable(const fs::path &directory)
std::string GetHelpMessage() const
Get the help string.
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
bool ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
void AddCommand(const std::string &cmd, const std::string &help)
Add subcommand.
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
const char *const BITCOIN_CONF_FILENAME
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes=0)
bool HelpRequested(const ArgsManager &args)
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
bool CheckDataDirOption()
void ClearArgs()
Clear available arguments.
std::optional< const Command > GetCommand() const
Get the command and command args (returns std::nullopt if no command provided)
void logArgsPrefix(const std::string &prefix, const std::string §ion, const std::map< std::string, std::vector< util::SettingsValue >> &args) const
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
const char *const BITCOIN_SETTINGS_FILENAME
std::optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
bool InitSettings(std::string &error)
Read and update settings file with saved settings.
fs::path GetDefaultDataDir()
bool m_accept_any_command GUARDED_BY(cs_args)
std::string command
The command (if one has been registered with AddCommand), or empty.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
void LogArgs() const
Log the config file options and the command line arguments, useful for troubleshooting.
void UnlockDirectory(const fs::path &directory, const std::string &lockfile_name)
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
const std::list< SectionInfo > GetUnrecognizedSections() const
Log warnings for unrecognized section names in the config file.
const fs::path & GetBlocksDirPath() const
Get blocks directory path.
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by Boost's create_directories if the requested directory exists...
bool IsSwitchChar(char c)
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 CopyrightHolders(const std::string &strPrefix)
void LockSettings(Fn &&fn)
Access settings with lock held.
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
void ClearPathCache()
Clear cached directory paths.
std::vector< util::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
bool LockDirectory(const fs::path &directory, const std::string lockfile_name, bool probe_only=false)
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...
const fs::path & GetDataDir(bool net_specific) const
Get data directory path.
bool error(const char *fmt, const Args &... args)
void ReleaseDirectoryLocks()
Release all directory locks.
std::string ShellEscape(const std::string &arg)
int GetNumCores()
Return the number of cores available on the current system.
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...
UniValue RunCommandParseJSON(const std::string &str_command, const std::string &str_std_in="")
Execute a command which returns JSON, and parse the result.
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.