Bitcoin ABC  0.26.3
P2P Digital Currency
Classes | Namespaces | Enumerations | Functions | Variables
system.h File Reference
#include <compat.h>
#include <compat/assumptions.h>
#include <fs.h>
#include <logging.h>
#include <sync.h>
#include <tinyformat.h>
#include <util/settings.h>
#include <util/time.h>
#include <any>
#include <cstdint>
#include <exception>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <utility>
#include <vector>
Include dependency graph for system.h:

Go to the source code of this file.

Classes

struct  SectionInfo
 
class  ArgsManager
 
struct  ArgsManager::Arg
 

Namespaces

 util
 

Enumerations

enum class  OptionsCategory {
  OPTIONS , CONNECTION , WALLET , WALLET_DEBUG_TEST ,
  ZMQ , DEBUG_TEST , CHAINPARAMS , NODE_RELAY ,
  BLOCK_CREATION , RPC , GUI , COMMANDS ,
  REGISTER_COMMANDS , AVALANCHE , CHRONIK , HIDDEN
}
 

Functions

int64_t GetStartupTime ()
 Server/client environment: argument handling, config file parsing, thread wrappers, startup time. More...
 
void SetupEnvironment ()
 
bool SetupNetworking ()
 
template<typename... Args>
bool error (const char *fmt, const Args &...args)
 
void PrintExceptionContinue (const std::exception *pex, const char *pszThread)
 
bool FileCommit (FILE *file)
 
bool TruncateFile (FILE *file, unsigned int length)
 
int RaiseFileDescriptorLimit (int nMinFD)
 This function tries to raise the file descriptor limit to the requested number. More...
 
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 is advisory, and the range specified in the arguments will never contain live data. More...
 
bool RenameOver (fs::path src, fs::path dest)
 
bool LockDirectory (const fs::path &directory, const std::string lockfile_name, bool probe_only=false)
 
void UnlockDirectory (const fs::path &directory, const std::string &lockfile_name)
 
bool DirIsWritable (const fs::path &directory)
 
bool CheckDiskSpace (const fs::path &dir, uint64_t additional_bytes=0)
 
std::streampos GetFileSize (const char *path, std::streamsize max=std::numeric_limits< std::streamsize >::max())
 Get the size of a file by scanning it. More...
 
void ReleaseDirectoryLocks ()
 Release all directory locks. More...
 
bool TryCreateDirectories (const fs::path &p)
 Ignores exceptions thrown by create_directories if the requested directory exists. More...
 
fs::path GetDefaultDataDir ()
 
bool CheckDataDirOption ()
 
fs::path GetConfigFile (const std::string &confPath)
 
std::string ShellEscape (const std::string &arg)
 
bool ParseKeyValue (std::string &key, std::string &val)
 
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 absolute. More...
 
bool IsSwitchChar (char c)
 
std::string SettingToString (const util::SettingsValue &, const std::string &)
 
std::optional< std::string > SettingToString (const util::SettingsValue &)
 
int64_t SettingToInt (const util::SettingsValue &, int64_t)
 
std::optional< int64_t > SettingToInt (const util::SettingsValue &)
 
bool SettingToBool (const util::SettingsValue &, bool)
 
std::optional< bool > SettingToBool (const util::SettingsValue &)
 
bool HelpRequested (const ArgsManager &args)
 
void SetupHelpOptions (ArgsManager &args)
 Add help options to the args manager. More...
 
std::string HelpMessageGroup (const std::string &message)
 Format a string to be used as group of options in help messages. More...
 
std::string HelpMessageOpt (const std::string &option, const std::string &message)
 Format a string to be used as option description in help messages. More...
 
int GetNumCores ()
 Return the number of cores available on the current system. More...
 
std::string CopyrightHolders (const std::string &strPrefix)
 
void ScheduleBatchPriority ()
 On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive. More...
 
template<typename Tdst , typename Tsrc >
void util::insert (Tdst &dst, const Tsrc &src)
 Simplification of std insertion. More...
 
template<typename TsetT , typename Tsrc >
void util::insert (std::set< TsetT > &dst, const Tsrc &src)
 
template<typename T >
T * util::AnyPtr (const std::any &any) noexcept
 Helper function to access the contained object of a std::any instance. More...
 

Variables

const char *const BITCOIN_CONF_FILENAME
 
const char *const BITCOIN_SETTINGS_FILENAME
 
ArgsManager gArgs
 

Enumeration Type Documentation

◆ OptionsCategory

enum OptionsCategory
strong
Enumerator
OPTIONS 
CONNECTION 
WALLET 
WALLET_DEBUG_TEST 
ZMQ 
DEBUG_TEST 
CHAINPARAMS 
NODE_RELAY 
BLOCK_CREATION 
RPC 
GUI 
COMMANDS 
REGISTER_COMMANDS 
AVALANCHE 
CHRONIK 
HIDDEN 

Definition at line 116 of file system.h.

Function Documentation

◆ AbsPathForConfigVal()

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 absolute.

Parameters
pathThe path to be conditionally prefixed with datadir.
net_specificUse network specific datadir variant
Returns
The normalized path.

Definition at line 1453 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AllocateFileRange()

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 is advisory, and the range specified in the arguments will never contain live data.

Definition at line 1306 of file system.cpp.

Here is the caller graph for this function:

◆ CheckDataDirOption()

bool CheckDataDirOption ( )

Definition at line 917 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckDiskSpace()

bool CheckDiskSpace ( const fs::path dir,
uint64_t  additional_bytes = 0 
)

Definition at line 145 of file system.cpp.

Here is the caller graph for this function:

◆ CopyrightHolders()

std::string CopyrightHolders ( const std::string &  strPrefix)

Definition at line 1443 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DirIsWritable()

bool DirIsWritable ( const fs::path directory)

Definition at line 131 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ error()

template<typename... Args>
bool error ( const char *  fmt,
const Args &...  args 
)

Definition at line 45 of file system.h.

Here is the call graph for this function:

◆ FileCommit()

bool FileCommit ( FILE *  file)

Definition at line 1231 of file system.cpp.

Here is the caller graph for this function:

◆ GetConfigFile()

fs::path GetConfigFile ( const std::string &  confPath)

Definition at line 922 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDefaultDataDir()

fs::path GetDefaultDataDir ( )

Definition at line 892 of file system.cpp.

Here is the caller graph for this function:

◆ GetFileSize()

std::streampos GetFileSize ( const char *  path,
std::streamsize  max = std::numeric_limits< std::streamsize >::max() 
)

Get the size of a file by scanning it.

Parameters
[in]pathThe file path
[in]maxStop seeking beyond this limit
Returns
The file size or max

Definition at line 153 of file system.cpp.

Here is the caller graph for this function:

◆ GetNumCores()

int GetNumCores ( )

Return the number of cores available on the current system.

Note
This does count virtual cores, such as those provided by HyperThreading.

Definition at line 1439 of file system.cpp.

Here is the caller graph for this function:

◆ GetStartupTime()

int64_t GetStartupTime ( )

Server/client environment: argument handling, config file parsing, thread wrappers, startup time.

Definition at line 1449 of file system.cpp.

Here is the caller graph for this function:

◆ HelpMessageGroup()

std::string HelpMessageGroup ( const std::string &  message)

Format a string to be used as group of options in help messages.

Parameters
messageGroup name (e.g. "RPC server options:")
Returns
the formatted string

Definition at line 856 of file system.cpp.

Here is the caller graph for this function:

◆ HelpMessageOpt()

std::string HelpMessageOpt ( const std::string &  option,
const std::string &  message 
)

Format a string to be used as option description in help messages.

Parameters
optionOption message (e.g. "-rpcuser=<user>")
messageOption description (e.g. "Username for JSON-RPC connections")
Returns
the formatted string

Definition at line 860 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HelpRequested()

bool HelpRequested ( const ArgsManager args)
Returns
true if help has been requested via a command-line arg

Definition at line 841 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsSwitchChar()

bool IsSwitchChar ( char  c)
inline

Definition at line 108 of file system.h.

Here is the caller graph for this function:

◆ LockDirectory()

bool LockDirectory ( const fs::path directory,
const std::string  lockfile_name,
bool  probe_only = false 
)

Definition at line 92 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseKeyValue()

bool ParseKeyValue ( std::string &  key,
std::string &  val 
)

Definition at line 298 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrintExceptionContinue()

void PrintExceptionContinue ( const std::exception *  pex,
const char *  pszThread 
)

Definition at line 886 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RaiseFileDescriptorLimit()

int RaiseFileDescriptorLimit ( int  nMinFD)

This function tries to raise the file descriptor limit to the requested number.

It returns the actual file descriptor limit (which may be more or less than nMinFD)

Definition at line 1280 of file system.cpp.

Here is the caller graph for this function:

◆ ReleaseDirectoryLocks()

void ReleaseDirectoryLocks ( )

Release all directory locks.

This is used for unit testing only, at runtime the global destructor will take care of the locks.

Definition at line 126 of file system.cpp.

◆ RenameOver()

bool RenameOver ( fs::path  src,
fs::path  dest 
)

Definition at line 1202 of file system.cpp.

Here is the caller graph for this function:

◆ ScheduleBatchPriority()

void ScheduleBatchPriority ( )

On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive.

See SCHED_BATCH in sched(7) for details.

Definition at line 1461 of file system.cpp.

Here is the caller graph for this function:

◆ SettingToBool() [1/2]

std::optional<bool> SettingToBool ( const util::SettingsValue value)

Definition at line 674 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SettingToBool() [2/2]

bool SettingToBool ( const util::SettingsValue value,
bool  fDefault 
)

Definition at line 684 of file system.cpp.

Here is the call graph for this function:

◆ SettingToInt() [1/2]

std::optional<int64_t> SettingToInt ( const util::SettingsValue value)

Definition at line 645 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SettingToInt() [2/2]

int64_t SettingToInt ( const util::SettingsValue value,
int64_t  nDefault 
)

Definition at line 661 of file system.cpp.

Here is the call graph for this function:

◆ SettingToString() [1/2]

std::optional<std::string> SettingToString ( const util::SettingsValue value)

Definition at line 614 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SettingToString() [2/2]

std::string SettingToString ( const util::SettingsValue value,
const std::string &  strDefault 
)

Definition at line 630 of file system.cpp.

Here is the call graph for this function:

◆ SetupEnvironment()

void SetupEnvironment ( )

Definition at line 1398 of file system.cpp.

Here is the caller graph for this function:

◆ SetupHelpOptions()

void SetupHelpOptions ( ArgsManager args)

Add help options to the args manager.

Definition at line 846 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetupNetworking()

bool SetupNetworking ( )

Definition at line 1426 of file system.cpp.

Here is the caller graph for this function:

◆ ShellEscape()

std::string ShellEscape ( const std::string &  arg)

Definition at line 1371 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TruncateFile()

bool TruncateFile ( FILE *  file,
unsigned int  length 
)

Definition at line 1267 of file system.cpp.

Here is the caller graph for this function:

◆ TryCreateDirectories()

bool TryCreateDirectories ( const fs::path p)

Ignores exceptions thrown by create_directories if the requested directory exists.

Specifically handles case where path p exists, but it wasn't possible for the user to write to the parent directory.

Definition at line 1217 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnlockDirectory()

void UnlockDirectory ( const fs::path directory,
const std::string &  lockfile_name 
)

Definition at line 120 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ BITCOIN_CONF_FILENAME

const char* const BITCOIN_CONF_FILENAME
extern

Definition at line 77 of file system.cpp.

◆ BITCOIN_SETTINGS_FILENAME

const char* const BITCOIN_SETTINGS_FILENAME
extern

Definition at line 78 of file system.cpp.

◆ gArgs

ArgsManager gArgs
extern

Definition at line 80 of file system.cpp.