Dogecoin Core  1.14.2
P2P Digital Currency
Classes | Functions | Variables
util.cpp File Reference
#include "util.h"
#include "chainparamsbase.h"
#include "random.h"
#include "serialize.h"
#include "sync.h"
#include "utilstrencodings.h"
#include "utiltime.h"
#include <stdarg.h>
#include <algorithm>
#include <fcntl.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/foreach.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
#include <openssl/rand.h>
#include <openssl/conf.h>
Include dependency graph for util.cpp:

Go to the source code of this file.

Classes

class  CInit
 

Functions

std::atomic< bool > fReopenDebugLog (false)
 
void locking_callback (int mode, int i, const char *file, int line) NO_THREAD_SAFETY_ANALYSIS
 
void OpenDebugLog ()
 
bool LogAcceptCategory (const char *category)
 Return true if log accepts specified category. More...
 
int LogPrintStr (const std::string &str)
 Send a string to the log output. More...
 
void ParseParameters (int argc, const char *const argv[])
 
bool IsArgSet (const std::string &strArg)
 Return true if the given argument has been manually set. More...
 
std::string GetArg (const std::string &strArg, const std::string &strDefault)
 Return string argument or default value. More...
 
int64_t GetArg (const std::string &strArg, int64_t nDefault)
 Return integer argument or default value. More...
 
bool GetBoolArg (const std::string &strArg, bool fDefault)
 Return boolean argument or default value. More...
 
bool SoftSetArg (const std::string &strArg, const std::string &strValue)
 Set an argument if it doesn't already have a value. More...
 
bool SoftSetBoolArg (const std::string &strArg, bool fValue)
 Set a boolean argument if it doesn't already have a value. More...
 
void ForceSetArg (const std::string &strArg, const std::string &strValue)
 
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)
 
boost::filesystem::path GetDefaultDataDir ()
 
const boost::filesystem::path & GetDataDir (bool fNetSpecific)
 
void ClearDatadirCache ()
 
boost::filesystem::path GetConfigFile (const std::string &confPath)
 
void ReadConfigFile (const std::string &confPath)
 
boost::filesystem::path GetPidFile ()
 
void CreatePidFile (const boost::filesystem::path &path, pid_t pid)
 
bool RenameOver (boost::filesystem::path src, boost::filesystem::path dest)
 
bool TryCreateDirectory (const boost::filesystem::path &p)
 Ignores exceptions thrown by Boost's create_directory if the requested directory exists. More...
 
void 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 ShrinkDebugFile ()
 
void runCommand (const std::string &strCommand)
 
void RenameThread (const char *name)
 
void SetupEnvironment ()
 
bool SetupNetworking ()
 
int GetNumCores ()
 Return the number of physical cores available on the current system. More...
 
std::string CopyrightHolders (const std::string &strPrefix)
 

Variables

const char *const BITCOIN_CONF_FILENAME = "dogecoin.conf"
 
const char *const BITCOIN_PID_FILENAME = "dogecoind.pid"
 
CCriticalSection cs_args
 
map< string, string > mapArgs
 
const map< string, vector< string > > & mapMultiArgs = _mapMultiArgs
 
bool fDebug = false
 
bool fPrintToConsole = false
 
bool fPrintToDebugLog = true
 
bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS
 
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS
 
bool fLogIPs = DEFAULT_LOGIPS
 
CTranslationInterface translationInterface
 
class CInit instance_of_cinit
 

Function Documentation

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

◆ ClearDatadirCache()

void ClearDatadirCache ( )

Definition at line 543 of file util.cpp.

◆ CopyrightHolders()

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

Definition at line 847 of file util.cpp.

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

◆ CreatePidFile()

void CreatePidFile ( const boost::filesystem::path &  path,
pid_t  pid 
)

Definition at line 594 of file util.cpp.

◆ FileCommit()

void FileCommit ( FILE *  file)

Definition at line 635 of file util.cpp.

◆ ForceSetArg()

void ForceSetArg ( const std::string &  strArg,
const std::string &  strValue 
)

Definition at line 436 of file util.cpp.

◆ fReopenDebugLog()

std::atomic<bool> fReopenDebugLog ( false  )

◆ GetArg() [1/2]

std::string GetArg ( const std::string &  strArg,
const std::string &  strDefault 
)

Return string argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
default(e.g. "1")
Returns
command-line argument or default value

Definition at line 395 of file util.cpp.

Here is the caller graph for this function:

◆ GetArg() [2/2]

int64_t GetArg ( const std::string &  strArg,
int64_t  nDefault 
)

Return integer argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
default(e.g. 1)
Returns
command-line argument (0 if invalid number) or default value

Definition at line 403 of file util.cpp.

Here is the call graph for this function:

◆ GetBoolArg()

bool GetBoolArg ( const std::string &  strArg,
bool  fDefault 
)

Return boolean argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
default(true or false)
Returns
command-line argument or default value

Definition at line 411 of file util.cpp.

Here is the caller graph for this function:

◆ GetConfigFile()

boost::filesystem::path GetConfigFile ( const std::string &  confPath)

Definition at line 551 of file util.cpp.

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

◆ GetDataDir()

const boost::filesystem::path& GetDataDir ( bool  fNetSpecific)

Definition at line 513 of file util.cpp.

Here is the caller graph for this function:

◆ GetDefaultDataDir()

boost::filesystem::path GetDefaultDataDir ( )

Definition at line 482 of file util.cpp.

Here is the caller graph for this function:

◆ GetNumCores()

int GetNumCores ( )

Return the number of physical cores available on the current system.

Note
This does not count virtual cores, such as those provided by HyperThreading when boost is newer than 1.56.

Definition at line 838 of file util.cpp.

◆ GetPidFile()

boost::filesystem::path GetPidFile ( )

Definition at line 587 of file util.cpp.

Here is the call 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 448 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 452 of file util.cpp.

Here is the caller graph for this function:

◆ IsArgSet()

bool IsArgSet ( const std::string &  strArg)

Return true if the given argument has been manually set.

Parameters
strArgArgument to get (e.g. "-foo")
Returns
true if the argument has been set

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

◆ LogAcceptCategory()

bool LogAcceptCategory ( const char *  category)

Return true if log accepts specified category.

Definition at line 234 of file util.cpp.

◆ LogPrintStr()

int LogPrintStr ( const std::string &  str)

Send a string to the log output.

Definition at line 295 of file util.cpp.

Here is the caller graph for this function:

◆ OpenDebugLog()

void OpenDebugLog ( )

Definition at line 212 of file util.cpp.

◆ ParseParameters()

void ParseParameters ( int  argc,
const char *const  argv[] 
)

Definition at line 353 of file util.cpp.

Here is the caller graph for this function:

◆ PrintExceptionContinue()

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

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

◆ ReadConfigFile()

void ReadConfigFile ( const std::string &  confPath)

Definition at line 560 of file util.cpp.

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

◆ RenameOver()

bool RenameOver ( boost::filesystem::path  src,
boost::filesystem::path  dest 
)

Definition at line 605 of file util.cpp.

Here is the caller graph for this function:

◆ RenameThread()

void RenameThread ( const char *  name)

Definition at line 781 of file util.cpp.

Here is the caller graph for this function:

◆ runCommand()

void runCommand ( const std::string &  strCommand)

Definition at line 774 of file util.cpp.

Here is the caller graph for this function:

◆ SetupEnvironment()

void SetupEnvironment ( )

Definition at line 797 of file util.cpp.

Here is the caller graph for this function:

◆ SetupNetworking()

bool SetupNetworking ( )

Definition at line 826 of file util.cpp.

Here is the caller graph for this function:

◆ ShrinkDebugFile()

void ShrinkDebugFile ( )

Definition at line 729 of file util.cpp.

Here is the call graph for this function:

◆ SoftSetArg()

bool SoftSetArg ( const std::string &  strArg,
const std::string &  strValue 
)

Set an argument if it doesn't already have a value.

Parameters
strArgArgument to set (e.g. "-foo")
strValueValue (e.g. "1")
Returns
true if argument gets set, false if it already had a value

Definition at line 419 of file util.cpp.

Here is the caller graph for this function:

◆ SoftSetBoolArg()

bool SoftSetBoolArg ( const std::string &  strArg,
bool  fValue 
)

Set a boolean argument if it doesn't already have a value.

Parameters
strArgArgument to set (e.g. "-foo")
fValueValue (e.g. false)
Returns
true if argument gets set, false if it already had a value

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

◆ TryCreateDirectory()

bool TryCreateDirectory ( const boost::filesystem::path &  p)

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

Here is the caller graph for this function:

Variable Documentation

◆ BITCOIN_CONF_FILENAME

const char* const BITCOIN_CONF_FILENAME = "dogecoin.conf"

Definition at line 106 of file util.cpp.

◆ BITCOIN_PID_FILENAME

const char* const BITCOIN_PID_FILENAME = "dogecoind.pid"

Definition at line 107 of file util.cpp.

◆ cs_args

Definition at line 109 of file util.cpp.

◆ fDebug

bool fDebug = false

Definition at line 113 of file util.cpp.

◆ fLogIPs

bool fLogIPs = DEFAULT_LOGIPS

Definition at line 119 of file util.cpp.

◆ fLogTimeMicros

bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS

Definition at line 118 of file util.cpp.

◆ fLogTimestamps

bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS

Definition at line 117 of file util.cpp.

◆ fPrintToConsole

bool fPrintToConsole = false

Definition at line 114 of file util.cpp.

◆ fPrintToDebugLog

bool fPrintToDebugLog = true

Definition at line 115 of file util.cpp.

◆ instance_of_cinit

class CInit instance_of_cinit

◆ mapArgs

map<string, string> mapArgs

Definition at line 110 of file util.cpp.

◆ mapMultiArgs

const map<string, vector<string> >& mapMultiArgs = _mapMultiArgs

Definition at line 112 of file util.cpp.

◆ translationInterface

CTranslationInterface translationInterface

Definition at line 121 of file util.cpp.