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)
75 [[nodiscard]]
bool RenameOver(fs::path src, fs::path dest);
76 bool LockDirectory(
const fs::path& directory,
const std::string lockfile_name,
bool probe_only=
false);
77 void UnlockDirectory(
const fs::path& directory,
const std::string& lockfile_name);
79 bool CheckDiskSpace(
const fs::path& dir, uint64_t additional_bytes = 0);
87 std::streampos
GetFileSize(
const char* path, std::streamsize max = std::numeric_limits<std::streamsize>::max());
98 const fs::path &
GetDataDir(
bool fNetSpecific =
true);
105 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate =
true);
111 void runCommand(
const std::string& strCommand);
113 #ifdef HAVE_BOOST_PROCESS 122 #endif // HAVE_BOOST_PROCESS 137 return c ==
'-' || c ==
'/';
176 ALLOW_ANY = ALLOW_BOOL | ALLOW_INT | ALLOW_STRING,
183 NETWORK_ONLY = 0x200,
199 std::set<std::string> m_network_only_args
GUARDED_BY(cs_args);
200 std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args
GUARDED_BY(cs_args);
201 std::list<SectionInfo> m_config_sections
GUARDED_BY(cs_args);
203 [[nodiscard]]
bool ReadConfigStream(std::istream& stream,
const std::string& filepath, std::string&
error,
bool ignore_invalid_keys =
false);
224 std::vector<util::SettingsValue>
GetSettingsList(
const std::string& arg)
const;
233 void SelectConfigNetwork(
const std::string& network);
235 [[nodiscard]]
bool ParseParameters(
int argc,
const char*
const argv[], std::string&
error);
236 [[nodiscard]]
bool ReadConfigFiles(std::string&
error,
bool ignore_invalid_keys =
false);
244 const std::set<std::string> GetUnsuitableSectionOnlyArgs()
const;
249 const std::list<SectionInfo> GetUnrecognizedSections()
const;
257 std::vector<std::string> GetArgs(
const std::string& strArg)
const;
265 bool IsArgSet(
const std::string& strArg)
const;
274 bool IsArgNegated(
const std::string& strArg)
const;
283 std::string GetArg(
const std::string& strArg,
const std::string& strDefault)
const;
292 int64_t GetArg(
const std::string& strArg, int64_t nDefault)
const;
301 bool GetBoolArg(
const std::string& strArg,
bool fDefault)
const;
310 bool SoftSetArg(
const std::string& strArg,
const std::string& strValue);
319 bool SoftSetBoolArg(
const std::string& strArg,
bool fValue);
323 void ForceSetArg(
const std::string& strArg,
const std::string& strValue);
329 std::string GetChainName()
const;
339 void AddHiddenArgs(
const std::vector<std::string>& args);
346 m_available_args.clear();
347 m_network_only_args.clear();
353 std::string GetHelpMessage()
const;
366 bool InitSettings(std::string&
error);
372 bool GetSettingsPath(fs::path* filepath =
nullptr,
bool temp =
false)
const;
377 bool ReadSettingsFile(std::vector<std::string>* errors =
nullptr);
382 bool WriteSettingsFile(std::vector<std::string>* errors =
nullptr)
const;
387 template <
typename Fn>
398 void LogArgs()
const;
403 const std::string&
prefix,
404 const std::string& section,
405 const std::map<std::string, std::vector<util::SettingsValue>>& args)
const;
433 std::string
HelpMessageOpt(
const std::string& option,
const std::string& message);
453 catch (
const boost::thread_interrupted&)
455 LogPrintf(
"%s thread interrupt\n", name);
458 catch (
const std::exception& e) {
480 template <
typename Tdst,
typename Tsrc>
481 inline void insert(Tdst& dst,
const Tsrc& src) {
482 dst.insert(dst.begin(), src.begin(), src.end());
484 template <
typename TsetT,
typename Tsrc>
485 inline void insert(std::set<TsetT>& dst,
const Tsrc& src) {
486 dst.insert(src.begin(), src.end());
495 std::pair<int, char**>
get();
500 std::vector<std::string> args;
506 #endif // BITCOIN_UTIL_SYSTEM_H
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)
fs::path GetConfigFile(const std::string &confPath)
SettingsValue GetSetting(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config, bool get_chain_name)
Get settings value from combined sources: forced settings, command line arguments, runtime read-write settings, and the read-only config file.
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name...
static void LogPrintf(const char *fmt, const Args &... args)
void ScheduleBatchPriority()
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
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 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...
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< SettingsValue > GetSettingsList(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config)
Get combined setting value similar to GetSetting(), except if setting was specified multiple times...
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)
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
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
fs::path GetDefaultDataDir()
void ClearDatadirCache()
Tests only.
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...
bool IsSwitchChar(char c)
std::string CopyrightHolders(const std::string &strPrefix)
void LockSettings(Fn &&fn)
Access settings with lock held.
void insert(std::set< TsetT > &dst, const Tsrc &src)
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)
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.
std::optional< T > Optional
Substitute for C++17 std::optional DEPRECATED use std::optional in new code.
UniValue RunCommandParseJSON(const std::string &str_command, const std::string &str_std_in="")
Execute a command which returns JSON, and parse the result.