![]() |
Bitcoin Core
23.99.0
P2P Digital Currency
|
#include <util/system.h>
#include <boost/process.hpp>
#include <chainparamsbase.h>
#include <fs.h>
#include <sync.h>
#include <util/check.h>
#include <util/getuniquepath.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/syserror.h>
#include <util/translation.h>
#include <algorithm>
#include <cassert>
#include <fcntl.h>
#include <sched.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <univalue.h>
#include <fstream>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <system_error>
#include <thread>
#include <typeinfo>
Go to the source code of this file.
Classes | |
struct | KeyInfo |
Namespaces | |
util | |
Functions | |
static std::map< std::string, std::unique_ptr< fsbridge::FileLock > > dir_locks | GUARDED_BY (cs_dir_locks) |
A map that contains all the currently held directory locks. More... | |
bool | LockDirectory (const fs::path &directory, const fs::path &lockfile_name, bool probe_only) |
void | UnlockDirectory (const fs::path &directory, const fs::path &lockfile_name) |
void | ReleaseDirectoryLocks () |
Release all directory locks. More... | |
bool | DirIsWritable (const fs::path &directory) |
bool | CheckDiskSpace (const fs::path &dir, uint64_t additional_bytes) |
std::streampos | GetFileSize (const char *path, std::streamsize max) |
Get the size of a file by scanning it. More... | |
static bool | InterpretBool (const std::string &strValue) |
Interpret a string argument as a boolean. More... | |
static std::string | SettingName (const std::string &arg) |
KeyInfo | InterpretKey (std::string key) |
Parse "name", "section.name", "noname", "section.noname" settings keys. More... | |
static std::optional< util::SettingsValue > | InterpretValue (const KeyInfo &key, const std::string *value, unsigned int flags, std::string &error) |
Interpret settings value based on registered flags. More... | |
static void | SaveErrors (const std::vector< std::string > errors, std::vector< std::string > *error_out) |
std::optional< std::string > | SettingToString (const util::SettingsValue &value) |
std::string | SettingToString (const util::SettingsValue &value, const std::string &strDefault) |
std::optional< int64_t > | SettingToInt (const util::SettingsValue &value) |
int64_t | SettingToInt (const util::SettingsValue &value, int64_t nDefault) |
std::optional< bool > | SettingToBool (const util::SettingsValue &value) |
bool | SettingToBool (const util::SettingsValue &value, bool fDefault) |
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... | |
static std::string | FormatException (const std::exception *pex, const char *pszThread) |
void | PrintExceptionContinue (const std::exception *pex, const char *pszThread) |
fs::path | GetDefaultDataDir () |
bool | CheckDataDirOption () |
fs::path | GetConfigFile (const fs::path &configuration_file_path) |
static bool | GetConfigOptions (std::istream &stream, const std::string &filepath, std::string &error, std::vector< std::pair< std::string, std::string >> &options, std::list< SectionInfo > §ions) |
bool | RenameOver (fs::path src, fs::path dest) |
Rename src to dest. More... | |
bool | TryCreateDirectories (const fs::path &p) |
Ignores exceptions thrown by create_directories if the requested directory exists. More... | |
bool | FileCommit (FILE *file) |
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsync(). More... | |
void | DirectoryCommit (const fs::path &dirname) |
Sync directory contents. More... | |
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... | |
std::string | ShellEscape (const std::string &arg) |
UniValue | RunCommandParseJSON (const std::string &str_command, const std::string &str_std_in) |
Execute a command which returns JSON, and parse the result. More... | |
void | SetupEnvironment () |
bool | SetupNetworking () |
int | GetNumCores () |
Return the number of cores available on the current system. More... | |
int64_t | GetStartupTime () |
fs::path | AbsPathForConfigVal (const fs::path &path, bool net_specific) |
Most paths passed as configuration arguments are treated as relative to the datadir if they are not absolute. More... | |
void | ScheduleBatchPriority () |
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive. More... | |
Variables | |
const int64_t | nStartupTime = GetTime() |
const char *const | BITCOIN_CONF_FILENAME = "bitcoin.conf" |
const char *const | BITCOIN_SETTINGS_FILENAME = "settings.json" |
ArgsManager | gArgs |
static GlobalMutex | cs_dir_locks |
Mutex to protect dir_locks. More... | |
static const int | screenWidth = 79 |
static const int | optIndent = 2 |
static const int | msgIndent = 7 |
Most paths passed as configuration arguments are treated as relative to the datadir if they are not absolute.
path | The path to be conditionally prefixed with datadir. |
net_specific | Use network specific datadir variant |
Definition at line 1424 of file system.cpp.
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 1250 of file system.cpp.
bool CheckDataDirOption | ( | ) |
Definition at line 882 of file system.cpp.
bool CheckDiskSpace | ( | const fs::path & | dir, |
uint64_t | additional_bytes | ||
) |
void DirectoryCommit | ( | const fs::path & | dirname | ) |
Sync directory contents.
This is required on some environments to ensure that newly created files are committed to disk.
Definition at line 1204 of file system.cpp.
bool DirIsWritable | ( | const fs::path & | directory | ) |
Definition at line 133 of file system.cpp.
bool FileCommit | ( | FILE * | file | ) |
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsync().
Definition at line 1173 of file system.cpp.
|
static |
Definition at line 888 of file system.cpp.
|
static |
Definition at line 893 of file system.cpp.
fs::path GetDefaultDataDir | ( | ) |
std::streampos GetFileSize | ( | const char * | path, |
std::streamsize | max = std::numeric_limits< std::streamsize >::max() |
||
) |
Get the size of a file by scanning it.
[in] | path | The file path |
[in] | max | Stop seeking beyond this limit |
Definition at line 154 of file system.cpp.
int GetNumCores | ( | ) |
Return the number of cores available on the current system.
Definition at line 1413 of file system.cpp.
int64_t GetStartupTime | ( | ) |
|
static |
A map that contains all the currently held directory locks.
After successful locking, these will be held here until the global destructor cleans them up and thus automatically unlocks them, or ReleaseDirectoryLocks is called.
std::string HelpMessageGroup | ( | const std::string & | message | ) |
Format a string to be used as group of options in help messages.
message | Group name (e.g. "RPC server options:") |
Definition at line 823 of file system.cpp.
std::string HelpMessageOpt | ( | const std::string & | option, |
const std::string & | message | ||
) |
Format a string to be used as option description in help messages.
option | Option message (e.g. "-rpcuser=<user>") |
message | Option description (e.g. "Username for JSON-RPC connections") |
Definition at line 827 of file system.cpp.
bool HelpRequested | ( | const ArgsManager & | args | ) |
Definition at line 808 of file system.cpp.
|
static |
Interpret a string argument as a boolean.
The definition of LocaleIndependentAtoi<int>() requires that non-numeric string values like "foo", return 0. This means that if a user unintentionally supplies a non-integer argument here, the return value is always false. This means that -foo=false does what the user probably expects, but -foo=true is well defined but does not do what they probably expected.
The return value of LocaleIndependentAtoi<int>(...) is zero when given input not representable as an int.
For a more extensive discussion of this topic (and a wide range of opinions on the Right Way to change this code), see PR12713.
Definition at line 175 of file system.cpp.
KeyInfo InterpretKey | ( | std::string | key | ) |
Parse "name", "section.name", "noname", "section.noname" settings keys.
Definition at line 201 of file system.cpp.
|
static |
Interpret settings value based on registered flags.
[in] | key | key information to know if key was negated |
[in] | value | string value of setting to be parsed |
[in] | flags | ArgsManager registered argument flags |
[out] | error | Error description if settings value is not valid |
Definition at line 229 of file system.cpp.
Definition at line 97 of file system.cpp.
void PrintExceptionContinue | ( | const std::exception * | pex, |
const char * | pszThread | ||
) |
Definition at line 850 of file system.cpp.
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 1227 of file system.cpp.
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 127 of file system.cpp.
Rename src to dest.
Definition at line 1136 of file system.cpp.
UniValue RunCommandParseJSON | ( | const std::string & | str_command, |
const std::string & | str_std_in = "" |
||
) |
Execute a command which returns JSON, and parse the result.
str_command | The command to execute, including any arguments |
str_std_in | string to pass to stdin |
Definition at line 1335 of file system.cpp.
|
static |
Definition at line 538 of file system.cpp.
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 1432 of file system.cpp.
|
static |
std::optional<bool> SettingToBool | ( | const util::SettingsValue & | value | ) |
Definition at line 665 of file system.cpp.
bool SettingToBool | ( | const util::SettingsValue & | value, |
bool | fDefault | ||
) |
std::optional<int64_t> SettingToInt | ( | const util::SettingsValue & | value | ) |
Definition at line 640 of file system.cpp.
int64_t SettingToInt | ( | const util::SettingsValue & | value, |
int64_t | nDefault | ||
) |
std::optional<std::string> SettingToString | ( | const util::SettingsValue & | value | ) |
Definition at line 615 of file system.cpp.
std::string SettingToString | ( | const util::SettingsValue & | value, |
const std::string & | strDefault | ||
) |
void SetupEnvironment | ( | ) |
void SetupHelpOptions | ( | ArgsManager & | args | ) |
Add help options to the args manager.
Definition at line 813 of file system.cpp.
bool SetupNetworking | ( | ) |
std::string ShellEscape | ( | const std::string & | arg | ) |
Definition at line 1313 of file system.cpp.
bool TruncateFile | ( | FILE * | file, |
unsigned int | length | ||
) |
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 1159 of file system.cpp.
Definition at line 121 of file system.cpp.
const char* const BITCOIN_CONF_FILENAME = "bitcoin.conf" |
Definition at line 83 of file system.cpp.
const char* const BITCOIN_SETTINGS_FILENAME = "settings.json" |
Definition at line 84 of file system.cpp.
|
static |
Mutex to protect dir_locks.
Definition at line 89 of file system.cpp.
ArgsManager gArgs |
Definition at line 86 of file system.cpp.
|
static |
Definition at line 821 of file system.cpp.
const int64_t nStartupTime = GetTime() |
Definition at line 81 of file system.cpp.
|
static |
Definition at line 820 of file system.cpp.
|
static |
Definition at line 819 of file system.cpp.