BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
Classes | Namespaces | Functions | Variables
util.cpp File Reference
#include <util.h>
#include <chainparamsbase.h>
#include <random.h>
#include <serialize.h>
#include <utilstrencodings.h>
#include <stdarg.h>
#include <algorithm>
#include <fcntl.h>
#include <sched.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
#include <openssl/rand.h>
#include <openssl/conf.h>
#include <thread>
Include dependency graph for util.cpp:

Go to the source code of this file.

Classes

class  CInit
 
class  ArgsManagerHelper
 Internal helper functions for ArgsManager. More...
 

Namespaces

 util
 

Functions

void locking_callback (int mode, int i, const char *file, int line) NO_THREAD_SAFETY_ANALYSIS
 
bool LockDirectory (const fs::path &directory, const std::string lockfile_name, bool probe_only)
 
void ReleaseDirectoryLocks ()
 Release all directory locks. More...
 
bool DirIsWritable (const fs::path &directory)
 
bool HelpRequested (const ArgsManager &args)
 
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...
 
void PrintExceptionContinue (const std::exception *pex, const char *pszThread)
 
fs::path GetDefaultDataDir ()
 
const fs::path & GetBlocksDir (bool fNetSpecific)
 
const fs::path & GetDataDir (bool fNetSpecific)
 
void ClearDatadirCache ()
 
fs::path GetConfigFile (const std::string &confPath)
 
fs::path GetPidFile ()
 
void CreatePidFile (const fs::path &path, pid_t pid)
 
bool RenameOver (fs::path src, fs::path dest)
 
bool TryCreateDirectories (const fs::path &p)
 Ignores exceptions thrown by Boost's create_directories if the requested directory exists. More...
 
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...
 
void runCommand (const std::string &strCommand)
 
void RenameThread (const char *name)
 
void SetupEnvironment ()
 
bool SetupNetworking ()
 
int GetNumCores ()
 Return the number of cores available on the current system. More...
 
std::string CopyrightHolders (const std::string &strPrefix)
 
int64_t GetStartupTime ()
 Server/client environment: argument handling, config file parsing, thread wrappers, startup time. More...
 
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 SetThreadPriority (int nPriority)
 
int ScheduleBatchPriority (void)
 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_PID_FILENAME = "bsha3d.pid"
 
ArgsManager gArgs
 
class CInit instance_of_cinit
 

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_specificForwarded to GetDataDir().
Returns
The normalized path.

Definition at line 1255 of file util.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 1097 of file util.cpp.

◆ ClearDatadirCache()

void ClearDatadirCache ( )

Definition at line 798 of file util.cpp.

◆ CopyrightHolders()

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

Definition at line 1238 of file util.cpp.

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

◆ CreatePidFile()

void CreatePidFile ( const fs::path &  path,
pid_t  pid 
)

Definition at line 988 of file util.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 177 of file util.cpp.

Here is the call graph for this function:

◆ FileCommit()

bool FileCommit ( FILE *  file)

Definition at line 1029 of file util.cpp.

◆ GetBlocksDir()

const fs::path& GetBlocksDir ( bool  fNetSpecific)

Definition at line 737 of file util.cpp.

Here is the caller graph for this function:

◆ GetConfigFile()

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

Definition at line 808 of file util.cpp.

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

◆ GetDataDir()

const fs::path& GetDataDir ( bool  fNetSpecific)

Definition at line 766 of file util.cpp.

Here is the caller graph for this function:

◆ GetDefaultDataDir()

fs::path GetDefaultDataDir ( )

Definition at line 705 of file util.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 1233 of file util.cpp.

Here is the caller graph for this function:

◆ GetPidFile()

fs::path GetPidFile ( )

Definition at line 983 of file util.cpp.

Here is the call graph for this function:
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 1250 of file util.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 671 of file util.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 675 of file util.cpp.

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 662 of file util.cpp.

Here is the call graph for this function:

◆ LockDirectory()

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

Definition at line 147 of file util.cpp.

Here is the caller graph for this function:

◆ locking_callback()

void locking_callback ( int  mode,
int  i,
const char *  file,
int  line 
)

Definition at line 92 of file util.cpp.

◆ PrintExceptionContinue()

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

Definition at line 698 of file util.cpp.

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 1074 of file util.cpp.

◆ 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 171 of file util.cpp.

◆ RenameOver()

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

Definition at line 999 of file util.cpp.

◆ RenameThread()

void RenameThread ( const char *  name)

Definition at line 1168 of file util.cpp.

Here is the caller graph for this function:

◆ runCommand()

void runCommand ( const std::string &  strCommand)

Definition at line 1156 of file util.cpp.

Here is the caller graph for this function:

◆ ScheduleBatchPriority()

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

Returns
The return value of sched_setschedule(), or 1 on systems without sched_setschedule().

Definition at line 1273 of file util.cpp.

◆ SetThreadPriority()

void SetThreadPriority ( int  nPriority)

Definition at line 1260 of file util.cpp.

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

◆ SetupEnvironment()

void SetupEnvironment ( )

Definition at line 1184 of file util.cpp.

Here is the caller graph for this function:

◆ SetupNetworking()

bool SetupNetworking ( )

Definition at line 1221 of file util.cpp.

Here is the caller graph for this function:

◆ TruncateFile()

bool TruncateFile ( FILE *  file,
unsigned int  length 
)

Definition at line 1062 of file util.cpp.

◆ TryCreateDirectories()

bool TryCreateDirectories ( const fs::path &  p)

Ignores exceptions thrown by Boost's 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 1015 of file util.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ BITCOIN_CONF_FILENAME

const char* const BITCOIN_CONF_FILENAME = "bitcoin.conf"

Definition at line 85 of file util.cpp.

◆ BITCOIN_PID_FILENAME

const char* const BITCOIN_PID_FILENAME = "bsha3d.pid"

Definition at line 86 of file util.cpp.

◆ gArgs

ArgsManager gArgs

Definition at line 88 of file util.cpp.

◆ instance_of_cinit

class CInit instance_of_cinit

◆ nStartupTime

const int64_t nStartupTime = GetTime()

Definition at line 83 of file util.cpp.