Changeset View
Changeset View
Standalone View
Standalone View
src/util.cpp
Show First 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | |||||
* options that are not normally boolean (e.g. using -nodebuglogfile to request | * options that are not normally boolean (e.g. using -nodebuglogfile to request | ||||
* that debug log output is not sent to any file at all). | * that debug log output is not sent to any file at all). | ||||
*/ | */ | ||||
void ArgsManager::InterpretNegatedOption(std::string &key, std::string &val) { | void ArgsManager::InterpretNegatedOption(std::string &key, std::string &val) { | ||||
if (key.substr(0, 3) == "-no") { | if (key.substr(0, 3) == "-no") { | ||||
bool bool_val = InterpretBool(val); | bool bool_val = InterpretBool(val); | ||||
if (!bool_val) { | if (!bool_val) { | ||||
// Double negatives like -nofoo=0 are supported (but discouraged) | // Double negatives like -nofoo=0 are supported (but discouraged) | ||||
LogPrintf( | LogPrint( | ||||
BCLog::INIT, | |||||
"Warning: parsed potentially confusing double-negative %s=%s\n", | "Warning: parsed potentially confusing double-negative %s=%s\n", | ||||
key, val); | key, val); | ||||
} | } | ||||
key.erase(1, 2); | key.erase(1, 2); | ||||
m_negated_args.insert(key); | m_negated_args.insert(key); | ||||
val = bool_val ? "0" : "1"; | val = bool_val ? "0" : "1"; | ||||
} else { | } else { | ||||
// In an invocation like "bitcoind -nofoo -foo" we want to unmark -foo | // In an invocation like "bitcoind -nofoo -foo" we want to unmark -foo | ||||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | #endif | ||||
} else { | } else { | ||||
return strprintf("UNKNOWN EXCEPTION \n%s in %s \n", | return strprintf("UNKNOWN EXCEPTION \n%s in %s \n", | ||||
pszModule, pszThread); | pszModule, pszThread); | ||||
} | } | ||||
} | } | ||||
void PrintExceptionContinue(const std::exception *pex, const char *pszThread) { | void PrintExceptionContinue(const std::exception *pex, const char *pszThread) { | ||||
std::string message = FormatException(pex, pszThread); | std::string message = FormatException(pex, pszThread); | ||||
LogPrintf("\n\n************************\n%s\n", message); | LogPrint(BCLog::UTIL, "\n\n************************\n%s\n", message); | ||||
fprintf(stderr, "\n\n************************\n%s\n", message.c_str()); | fprintf(stderr, "\n\n************************\n%s\n", message.c_str()); | ||||
} | } | ||||
fs::path GetDefaultDataDir() { | fs::path GetDefaultDataDir() { | ||||
// Windows < Vista: C:\Documents and Settings\Username\Application Data\Bitcoin | // Windows < Vista: C:\Documents and Settings\Username\Application Data\Bitcoin | ||||
// Windows >= Vista: C:\Users\Username\AppData\Roaming\Bitcoin | // Windows >= Vista: C:\Users\Username\AppData\Roaming\Bitcoin | ||||
// Mac: ~/Library/Application Support/Bitcoin | // Mac: ~/Library/Application Support/Bitcoin | ||||
// Unix: ~/.bitcoin | // Unix: ~/.bitcoin | ||||
Show All 22 Lines | |||||
static fs::path pathCachedNetSpecific; | static fs::path pathCachedNetSpecific; | ||||
static CCriticalSection csPathCached; | static CCriticalSection csPathCached; | ||||
const fs::path &GetDataDir(bool fNetSpecific) { | const fs::path &GetDataDir(bool fNetSpecific) { | ||||
LOCK(csPathCached); | LOCK(csPathCached); | ||||
fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached; | fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached; | ||||
// This can be called during exceptions by LogPrintf(), so we cache the | // This can be called during exceptions by LogPrint(), so we cache the | ||||
// value so we don't have to do memory allocations after that. | // value so we don't have to do memory allocations after that. | ||||
if (!path.empty()) { | if (!path.empty()) { | ||||
return path; | return path; | ||||
} | } | ||||
if (gArgs.IsArgSet("-datadir")) { | if (gArgs.IsArgSet("-datadir")) { | ||||
path = fs::system_complete(gArgs.GetArg("-datadir", "")); | path = fs::system_complete(gArgs.GetArg("-datadir", "")); | ||||
if (!fs::is_directory(path)) { | if (!fs::is_directory(path)) { | ||||
▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Lines | |||||
#ifdef WIN32 | #ifdef WIN32 | ||||
fs::path GetSpecialFolderPath(int nFolder, bool fCreate) { | fs::path GetSpecialFolderPath(int nFolder, bool fCreate) { | ||||
char pszPath[MAX_PATH] = ""; | char pszPath[MAX_PATH] = ""; | ||||
if (SHGetSpecialFolderPathA(nullptr, pszPath, nFolder, fCreate)) { | if (SHGetSpecialFolderPathA(nullptr, pszPath, nFolder, fCreate)) { | ||||
return fs::path(pszPath); | return fs::path(pszPath); | ||||
} | } | ||||
LogPrintf( | LogPrint( | ||||
BCLog::INIT, | |||||
"SHGetSpecialFolderPathA() failed, could not obtain requested path.\n"); | "SHGetSpecialFolderPathA() failed, could not obtain requested path.\n"); | ||||
return fs::path(""); | return fs::path(""); | ||||
} | } | ||||
#endif | #endif | ||||
void runCommand(const std::string &strCommand) { | void runCommand(const std::string &strCommand) { | ||||
if (strCommand.empty()) { | if (strCommand.empty()) { | ||||
return; | return; | ||||
} | } | ||||
int nErr = ::system(strCommand.c_str()); | int nErr = ::system(strCommand.c_str()); | ||||
if (nErr) { | if (nErr) { | ||||
LogPrintf("runCommand error: system(%s) returned %d\n", strCommand, | LogPrint(BCLog::UTIL, "runCommand error: system(%s) returned %d\n", | ||||
nErr); | strCommand, nErr); | ||||
} | } | ||||
} | } | ||||
void RenameThread(const char *name) { | void RenameThread(const char *name) { | ||||
#if defined(PR_SET_NAME) | #if defined(PR_SET_NAME) | ||||
// Only the first 15 characters are used (16 - NUL terminator) | // Only the first 15 characters are used (16 - NUL terminator) | ||||
::prctl(PR_SET_NAME, name, 0, 0, 0); | ::prctl(PR_SET_NAME, name, 0, 0, 0); | ||||
#elif (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) | #elif (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) | ||||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |