Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
Lint: Code style violation: '/home/jimpo/Code/github.com/Bitcoin-ABC/bitcoin-abc/src/init.cpp' has code style errors. | |||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#if defined(HAVE_CONFIG_H) | #if defined(HAVE_CONFIG_H) | ||||
#include "config/bitcoin-config.h" | #include "config/bitcoin-config.h" | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Signal handlers are very limited in what they are allowed to do, so: | * Signal handlers are very limited in what they are allowed to do, so: | ||||
*/ | */ | ||||
void HandleSIGTERM(int) { | void HandleSIGTERM(int) { | ||||
fRequestShutdown = true; | fRequestShutdown = true; | ||||
} | } | ||||
void HandleSIGHUP(int) { | void HandleSIGHUP(int) { | ||||
fReopenDebugLog = true; | if (g_logger) g_logger->fReopenDebugLog = true; | ||||
} | } | ||||
static bool Bind(CConnman &connman, const CService &addr, unsigned int flags) { | static bool Bind(CConnman &connman, const CService &addr, unsigned int flags) { | ||||
if (!(flags & BF_EXPLICIT) && IsLimited(addr)) return false; | if (!(flags & BF_EXPLICIT) && IsLimited(addr)) return false; | ||||
std::string strError; | std::string strError; | ||||
if (!connman.BindListenPort(addr, strError, (flags & BF_WHITELIST) != 0)) { | if (!connman.BindListenPort(addr, strError, (flags & BF_WHITELIST) != 0)) { | ||||
if (flags & BF_REPORT_ERROR) return InitError(strError); | if (flags & BF_REPORT_ERROR) return InitError(strError); | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 933 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static std::string ResolveErrMsg(const char *const optname, | static std::string ResolveErrMsg(const char *const optname, | ||||
const std::string &strBind) { | const std::string &strBind) { | ||||
return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind); | return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind); | ||||
} | } | ||||
void InitLogging() { | void InitLogging() { | ||||
fPrintToConsole = gArgs.GetBoolArg("-printtoconsole", false); | g_logger.reset(new BCLog::Logger()); | ||||
fLogTimestamps = gArgs.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS); | g_logger->fPrintToConsole = gArgs.GetBoolArg("-printtoconsole", false); | ||||
fLogTimeMicros = gArgs.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS); | g_logger->fLogTimestamps = | ||||
gArgs.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS); | |||||
g_logger->fLogTimeMicros = | |||||
gArgs.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS); | |||||
deadalnixUnsubmitted Not Done Inline Actionsg_logger vs gArgs ? deadalnix: g_logger vs gArgs ? | |||||
jimpoAuthorUnsubmitted Not Done Inline ActionsI don't understand the question. The idea is to read the command line argument and set it on the logger object, which stores configuration as public fields. jimpo: I don't understand the question. The idea is to read the command line argument and set it on… | |||||
fLogIPs = gArgs.GetBoolArg("-logips", DEFAULT_LOGIPS); | fLogIPs = gArgs.GetBoolArg("-logips", DEFAULT_LOGIPS); | ||||
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); | LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); | ||||
LogPrintf("%s version %s\n", CLIENT_NAME, FormatFullVersion()); | LogPrintf("%s version %s\n", CLIENT_NAME, FormatFullVersion()); | ||||
} | } | ||||
namespace { // Variables internal to initialization process only | namespace { // Variables internal to initialization process only | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | bool AppInitParameterInteraction(Config &config) { | ||||
// Step 3: parameter-to-internal-flags | // Step 3: parameter-to-internal-flags | ||||
if (gArgs.IsArgSet("-debug")) { | if (gArgs.IsArgSet("-debug")) { | ||||
// Special-case: if -debug=0/-nodebug is set, turn off debugging | // Special-case: if -debug=0/-nodebug is set, turn off debugging | ||||
// messages | // messages | ||||
const std::vector<std::string> &categories = gArgs.GetArgs("-debug"); | const std::vector<std::string> &categories = gArgs.GetArgs("-debug"); | ||||
if (find(categories.begin(), categories.end(), std::string("0")) == | if (find(categories.begin(), categories.end(), std::string("0")) == | ||||
categories.end()) { | categories.end()) { | ||||
for (const auto &cat : categories) { | for (const auto &cat : categories) { | ||||
uint32_t flag = 0; | BCLog::LogFlags flag; | ||||
if (!GetLogCategory(&flag, &cat)) { | if (!GetLogCategory(flag, cat)) { | ||||
InitWarning( | InitWarning( | ||||
strprintf(_("Unsupported logging category %s=%s."), | strprintf(_("Unsupported logging category %s=%s."), | ||||
"-debug", cat)); | "-debug", cat)); | ||||
} | } | ||||
logCategories |= flag; | g_logger->EnableCategory(flag); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Now remove the logging categories which were explicitly excluded | // Now remove the logging categories which were explicitly excluded | ||||
if (gArgs.IsArgSet("-debugexclude")) { | if (gArgs.IsArgSet("-debugexclude")) { | ||||
for (const std::string &cat : gArgs.GetArgs("-debugexclude")) { | for (const std::string &cat : gArgs.GetArgs("-debugexclude")) { | ||||
uint32_t flag; | BCLog::LogFlags flag; | ||||
if (!GetLogCategory(&flag, &cat)) { | if (!GetLogCategory(flag, cat)) { | ||||
InitWarning(strprintf(_("Unsupported logging category %s=%s."), | InitWarning(strprintf(_("Unsupported logging category %s=%s."), | ||||
"-debugexclude", cat)); | "-debugexclude", cat)); | ||||
} | } | ||||
logCategories &= ~flag; | g_logger->DisableCategory(flag); | ||||
} | } | ||||
} | } | ||||
// Check for -debugnet | // Check for -debugnet | ||||
if (gArgs.GetBoolArg("-debugnet", false)) | if (gArgs.GetBoolArg("-debugnet", false)) | ||||
InitWarning( | InitWarning( | ||||
_("Unsupported argument -debugnet ignored, use -debug=net.")); | _("Unsupported argument -debugnet ignored, use -debug=net.")); | ||||
// Check for -socks - as this is a privacy risk to continue, exit here | // Check for -socks - as this is a privacy risk to continue, exit here | ||||
▲ Show 20 Lines • Show All 323 Lines • ▼ Show 20 Lines | bool AppInitMain(Config &config, boost::thread_group &threadGroup, | ||||
if (!LockDataDirectory(false)) { | if (!LockDataDirectory(false)) { | ||||
// Detailed error printed inside LockDataDirectory | // Detailed error printed inside LockDataDirectory | ||||
return false; | return false; | ||||
} | } | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
CreatePidFile(GetPidFile(), getpid()); | CreatePidFile(GetPidFile(), getpid()); | ||||
#endif | #endif | ||||
if (gArgs.GetBoolArg("-shrinkdebugfile", logCategories != BCLog::NONE)) { | bool default_shrinkdebugfile = g_logger->DefaultShrinkDebugFile(); | ||||
if (gArgs.GetBoolArg("-shrinkdebugfile", default_shrinkdebugfile)) { | |||||
// Do this first since it both loads a bunch of debug.log into memory, | // Do this first since it both loads a bunch of debug.log into memory, | ||||
// and because this needs to happen before any other debug.log printing. | // and because this needs to happen before any other debug.log printing. | ||||
ShrinkDebugFile(); | g_logger->ShrinkDebugFile(); | ||||
} | } | ||||
if (fPrintToDebugLog) { | if (g_logger->fPrintToDebugLog) { | ||||
OpenDebugLog(); | g_logger->OpenDebugLog(); | ||||
} | } | ||||
if (!fLogTimestamps) { | if (!g_logger->fLogTimestamps) { | ||||
LogPrintf("Startup time: %s\n", | LogPrintf("Startup time: %s\n", | ||||
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime())); | DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime())); | ||||
} | } | ||||
LogPrintf("Default data directory %s\n", GetDefaultDataDir().string()); | LogPrintf("Default data directory %s\n", GetDefaultDataDir().string()); | ||||
LogPrintf("Using data directory %s\n", GetDataDir().string()); | LogPrintf("Using data directory %s\n", GetDataDir().string()); | ||||
LogPrintf( | LogPrintf( | ||||
"Using config file %s\n", | "Using config file %s\n", | ||||
GetConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME)).string()); | GetConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME)).string()); | ||||
▲ Show 20 Lines • Show All 543 Lines • Show Last 20 Lines |
'/home/jimpo/Code/github.com/Bitcoin-ABC/bitcoin-abc/src/init.cpp' has code style errors.