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 ==
'/';
164 ALLOW_ANY = ALLOW_BOOL | ALLOW_INT | ALLOW_STRING,
171 NETWORK_ONLY = 0x200,
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);
191 NODISCARD bool ReadConfigStream(std::istream& stream,
const std::string& filepath, std::string&
error,
bool ignore_invalid_keys =
false);
212 std::vector<util::SettingsValue>
GetSettingsList(
const std::string& arg)
const;
221 void SelectConfigNetwork(
const std::string& network);
223 NODISCARD bool ParseParameters(
int argc,
const char*
const argv[], std::string&
error);
224 NODISCARD bool ReadConfigFiles(std::string&
error,
bool ignore_invalid_keys =
false);
232 const std::set<std::string> GetUnsuitableSectionOnlyArgs()
const;
237 const std::list<SectionInfo> GetUnrecognizedSections()
const;
245 std::vector<std::string> GetArgs(
const std::string& strArg)
const;
253 bool IsArgSet(
const std::string& strArg)
const;
262 bool IsArgNegated(
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);
307 bool SoftSetBoolArg(
const std::string& strArg,
bool fValue);
311 void ForceSetArg(
const std::string& strArg,
const std::string& strValue);
317 std::string GetChainName()
const;
327 void AddHiddenArgs(
const std::vector<std::string>& args);
334 m_available_args.clear();
335 m_network_only_args.clear();
341 std::string GetHelpMessage()
const;
354 bool InitSettings(std::string&
error);
360 bool GetSettingsPath(fs::path* filepath =
nullptr,
bool temp =
false)
const;
365 bool ReadSettingsFile(std::vector<std::string>* errors =
nullptr);
370 bool WriteSettingsFile(std::vector<std::string>* errors =
nullptr)
const;
375 template <
typename Fn>
386 void LogArgs()
const;
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
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)
static void LogPrintf(const char *fmt, const Args &...args)
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...
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...
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)
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
#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)
boost::optional< T > Optional
Substitute for C++17 std::optional.
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)
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.
UniValue RunCommandParseJSON(const std::string &str_command, const std::string &str_std_in="")
Execute a command which returns JSON, and parse the result.