diff options
Diffstat (limited to 'src/util.cpp')
| -rw-r--r-- | src/util.cpp | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/util.cpp b/src/util.cpp index 136a03548..cfaf5bdf8 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -78,7 +78,6 @@ bool fPrintToConsole = false; bool fPrintToDebugger = false; bool fDaemon = false; bool fServer = false; -bool fCommandLine = false; string strMiscWarning; bool fNoListen = false; bool fLogTimestamps = false; @@ -166,7 +165,7 @@ void RandAddSeedPerfmon() { RAND_add(pdata, nSize, nSize/100.0); OPENSSL_cleanse(pdata, nSize); - printf("RandAddSeed() %lu bytes\n", nSize); + LogPrint("rand", "RandAddSeed() %lu bytes\n", nSize); } #endif } @@ -198,15 +197,7 @@ uint256 GetRandHash() return hash; } - - - - - - -// -// OutputDebugStringF (aka printf -- there is a #define that we really -// should get rid of one day) has been broken a couple of times now +// LogPrintf() has been broken a couple of times now // by well-meaning people adding mutexes in the most straightforward way. // It breaks because it may be called by global destructors during shutdown. // Since the order of destruction of static/global objects is undefined, @@ -233,8 +224,16 @@ static void DebugPrintInit() mutexDebugLog = new boost::mutex(); } -int OutputDebugStringF(const char* pszFormat, ...) +int LogPrint(const char* category, const char* pszFormat, ...) { + if (category != NULL) + { + if (!fDebug) return 0; + const vector<string>& categories = mapMultiArgs["-debug"]; + if (find(categories.begin(), categories.end(), string(category)) == categories.end()) + return 0; + } + int ret = 0; // Returns total number of characters written if (fPrintToConsole) { @@ -360,7 +359,7 @@ bool error(const char *format, ...) va_start(arg_ptr, format); std::string str = vstrprintf(format, arg_ptr); va_end(arg_ptr); - printf("ERROR: %s\n", str.c_str()); + LogPrintf("ERROR: %s\n", str.c_str()); return false; } @@ -994,13 +993,13 @@ static std::string FormatException(std::exception* pex, const char* pszThread) void LogException(std::exception* pex, const char* pszThread) { std::string message = FormatException(pex, pszThread); - printf("\n%s", message.c_str()); + LogPrintf("\n%s", message.c_str()); } void PrintException(std::exception* pex, const char* pszThread) { std::string message = FormatException(pex, pszThread); - printf("\n\n************************\n%s\n", message.c_str()); + LogPrintf("\n\n************************\n%s\n", message.c_str()); fprintf(stderr, "\n\n************************\n%s\n", message.c_str()); strMiscWarning = message; throw; @@ -1009,7 +1008,7 @@ void PrintException(std::exception* pex, const char* pszThread) void PrintExceptionContinue(std::exception* pex, const char* pszThread) { std::string message = FormatException(pex, pszThread); - printf("\n\n************************\n%s\n", message.c_str()); + LogPrintf("\n\n************************\n%s\n", message.c_str()); fprintf(stderr, "\n\n************************\n%s\n", message.c_str()); strMiscWarning = message; } @@ -1057,7 +1056,7 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) fs::path &path = pathCached[nNet]; - // This can be called during exceptions by printf, so we cache the + // This can be called during exceptions by LogPrintf(), so we cache the // value so we don't have to do memory allocations after that. if (!path.empty()) return path; @@ -1156,6 +1155,8 @@ void FileCommit(FILE *fileout) #else #if defined(__linux__) || defined(__NetBSD__) fdatasync(fileno(fileout)); + #elif defined(__APPLE__) && defined(F_FULLFSYNC) + fcntl(fileno(fileout), F_FULLFSYNC, 0); #else fsync(fileno(fileout)); #endif @@ -1320,7 +1321,7 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) // Add data vTimeOffsets.input(nOffsetSample); - printf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); + LogPrintf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) { int64 nMedian = vTimeOffsets.median(); @@ -1348,17 +1349,17 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) fDone = true; string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong Bitcoin will not work properly."); strMiscWarning = strMessage; - printf("*** %s\n", strMessage.c_str()); + LogPrintf("*** %s\n", strMessage.c_str()); uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_WARNING); } } } if (fDebug) { BOOST_FOREACH(int64 n, vSorted) - printf("%+"PRI64d" ", n); - printf("| "); + LogPrintf("%+"PRI64d" ", n); + LogPrintf("| "); } - printf("nTimeOffset = %+"PRI64d" (%+"PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60); + LogPrintf("nTimeOffset = %+"PRI64d" (%+"PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60); } } @@ -1420,7 +1421,7 @@ boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate) return fs::path(pszPath); } - printf("SHGetSpecialFolderPathA() failed, could not obtain requested path.\n"); + LogPrintf("SHGetSpecialFolderPathA() failed, could not obtain requested path.\n"); return fs::path(""); } #endif @@ -1440,7 +1441,7 @@ boost::filesystem::path GetTempPath() { path = boost::filesystem::path("/tmp"); #endif if (path.empty() || !boost::filesystem::is_directory(path)) { - printf("GetTempPath(): failed to find temp path\n"); + LogPrintf("GetTempPath(): failed to find temp path\n"); return boost::filesystem::path(""); } return path; @@ -1451,7 +1452,7 @@ void runCommand(std::string strCommand) { int nErr = ::system(strCommand.c_str()); if (nErr) - printf("runCommand error: system(%s) returned %d\n", strCommand.c_str(), nErr); + LogPrintf("runCommand error: system(%s) returned %d\n", strCommand.c_str(), nErr); } void RenameThread(const char* name) |