10 #ifndef BITCOIN_UTIL_SYSTEM_H
11 #define BITCOIN_UTIL_SYSTEM_H
13 #if defined(HAVE_CONFIG_H)
38 #include <boost/thread/condition_variable.hpp>
51 template<
typename... Args>
52 bool error(
const char* fmt,
const Args&... args)
64 bool LockDirectory(
const fs::path& directory,
const std::string lockfile_name,
bool probe_only=
false);
65 void UnlockDirectory(
const fs::path& directory,
const std::string& lockfile_name);
67 bool CheckDiskSpace(
const fs::path& dir, uint64_t additional_bytes = 0);
75 std::streampos
GetFileSize(
const char* path, std::streamsize max = std::numeric_limits<std::streamsize>::max());
86 const fs::path &
GetDataDir(
bool fNetSpecific =
true);
93 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate =
true);
99 void runCommand(
const std::string& strCommand);
101 #ifdef HAVE_BOOST_PROCESS
110 #endif // HAVE_BOOST_PROCESS
125 return c ==
'-' || c ==
'/';
187 std::set<std::string> m_network_only_args
GUARDED_BY(cs_args);
188 std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args
GUARDED_BY(cs_args);
189 std::list<SectionInfo> m_config_sections
GUARDED_BY(cs_args);
212 std::vector<util::SettingsValue>
GetSettingsList(
const std::string& arg)
const;
245 std::vector<std::string>
GetArgs(
const std::string& strArg)
const;
253 bool IsArgSet(
const std::string& strArg)
const;
271 std::string
GetArg(
const std::string& strArg,
const std::string& strDefault)
const;
280 int64_t
GetArg(
const std::string& strArg, int64_t nDefault)
const;
289 bool GetBoolArg(
const std::string& strArg,
bool fDefault)
const;
298 bool SoftSetArg(
const std::string& strArg,
const std::string& strValue);
311 void ForceSetArg(
const std::string& strArg,
const std::string& strValue);
334 m_available_args.clear();
335 m_network_only_args.clear();
360 bool GetSettingsPath(fs::path* filepath =
nullptr,
bool temp =
false)
const;
375 template <
typename Fn>
391 const std::string&
prefix,
392 const std::string& section,
393 const std::map<std::string, std::vector<util::SettingsValue>>& args)
const;
421 std::string
HelpMessageOpt(
const std::string& option,
const std::string& message);
441 catch (
const boost::thread_interrupted&)
443 LogPrintf(
"%s thread interrupt\n", name);
446 catch (
const std::exception& e) {
468 template <
typename Tdst,
typename Tsrc>
469 inline void insert(Tdst& dst,
const Tsrc& src) {
470 dst.insert(dst.begin(), src.begin(), src.end());
472 template <
typename TsetT,
typename Tsrc>
473 inline void insert(std::set<TsetT>& dst,
const Tsrc& src) {
474 dst.insert(src.begin(), src.end());
483 std::pair<int, char**>
get();
488 std::vector<std::string> args;
494 #endif // BITCOIN_UTIL_SYSTEM_H
NODISCARD bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
Optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
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 TruncateFile(FILE *file, unsigned int length)
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
fs::path GetConfigFile(const std::string &confPath)
const std::list< SectionInfo > GetUnrecognizedSections() const
Log warnings for unrecognized section names in the config file.
static void LogPrintf(const char *fmt, const Args &...args)
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name...
void logArgsPrefix(const std::string &prefix, const std::string §ion, const std::map< std::string, std::vector< util::SettingsValue >> &args) const
void SelectConfigNetwork(const std::string &network)
Select the network in use.
NODISCARD bool ReadConfigStream(std::istream &stream, const std::string &filepath, 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...
void insert(Tdst &dst, const Tsrc &src)
Simplification of std insertion.
NODISCARD bool ParseParameters(int argc, const char *const argv[], std::string &error)
util::Settings m_settings GUARDED_BY(cs_args)
bool RenameOver(fs::path src, fs::path dest)
const fs::path & GetBlocksDir()
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.
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
bool DirIsWritable(const fs::path &directory)
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
const fs::path & GetDataDir(bool fNetSpecific=true)
std::vector< util::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
bool ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
bool error(const char *fmt, const Args &...args)
const char *const BITCOIN_CONF_FILENAME
bool FileCommit(FILE *file)
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes=0)
util::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
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...
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.
void TraceThread(const char *name, Callable func)
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
#define EXCLUSIVE_LOCKS_REQUIRED(...)
bool InitSettings(std::string &error)
Read and update settings file with saved settings.
fs::path GetDefaultDataDir()
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr) const
Write settings file.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
void ClearDatadirCache()
Tests only.
std::string GetHelpMessage() const
Get the help string.
void UnlockDirectory(const fs::path &directory, const std::string &lockfile_name)
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by Boost's create_directories if the requested directory exists...
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
bool IsSwitchChar(char c)
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...
boost::optional< T > Optional
Substitute for C++17 std::optional.
std::string CopyrightHolders(const std::string &strPrefix)
void LogArgs() const
Log the config file options and the command line arguments, useful for troubleshooting.
void LockSettings(Fn &&fn)
Access settings with lock held.
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)
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 IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
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.