OutputDebugStringF fix for Mac FileVault problem, take 3

(cannot use a CRITICAL_BLOCK because of undefined order calling static destructors;
instead, keep debug.log open, and tell people to use copytruncate when doing
log rotation)


git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@183 1a98c847-1fd6-4fd8-948a-caf3550aa51b
This commit is contained in:
gavinandresen 2010-11-18 00:11:33 +00:00
parent 2f7a9997c8
commit c4679ad0f1

View File

@ -145,8 +145,6 @@ int GetRandInt(int nMax)
inline int OutputDebugStringF(const char* pszFormat, ...) inline int OutputDebugStringF(const char* pszFormat, ...)
{ {
static CCriticalSection cs_OutputDebugStringF;
int ret = 0; int ret = 0;
if (fPrintToConsole) if (fPrintToConsole)
{ {
@ -157,22 +155,17 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
va_end(arg_ptr); va_end(arg_ptr);
} }
else else
{
CRITICAL_BLOCK(cs_OutputDebugStringF)
{ {
// print to debug.log // print to debug.log
static FILE* fileout = NULL; static FILE* fileout = NULL;
static int64 nOpenTime = 0;
if (GetTime()-nOpenTime > 10 * 60) if (!fileout)
{ {
if (fileout)
fclose(fileout);
char pszFile[MAX_PATH+100]; char pszFile[MAX_PATH+100];
GetDataDir(pszFile); GetDataDir(pszFile);
strlcat(pszFile, "/debug.log", sizeof(pszFile)); strlcat(pszFile, "/debug.log", sizeof(pszFile));
fileout = fopen(pszFile, "a"); fileout = fopen(pszFile, "a");
nOpenTime = GetTime(); setbuf(fileout, NULL); // unbuffered
} }
if (fileout) if (fileout)
{ {
@ -182,14 +175,14 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
va_start(arg_ptr, pszFormat); va_start(arg_ptr, pszFormat);
ret = vfprintf(fileout, pszFormat, arg_ptr); ret = vfprintf(fileout, pszFormat, arg_ptr);
va_end(arg_ptr); va_end(arg_ptr);
fflush(fileout);
}
} }
} }
#ifdef __WXMSW__ #ifdef __WXMSW__
if (fPrintToDebugger) if (fPrintToDebugger)
{ {
static CCriticalSection cs_OutputDebugStringF;
// accumulate a line at a time // accumulate a line at a time
CRITICAL_BLOCK(cs_OutputDebugStringF) CRITICAL_BLOCK(cs_OutputDebugStringF)
{ {