diff --git a/src/init.cpp b/src/init.cpp index b027a53d81f0b..726950bdb60bd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -80,6 +80,10 @@ void HandleSIGTERM(int) fRequestShutdown = true; } +void HandleSIGHUP(int) +{ + fReopenDebugLog = true; +} @@ -285,7 +289,13 @@ bool AppInit2() sa.sa_flags = 0; sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL); - sigaction(SIGHUP, &sa, NULL); + + // Reopen debug.log on SIGHUP + struct sigaction sa_hup; + sa_hup.sa_handler = HandleSIGHUP; + sigemptyset(&sa_hup.sa_mask); + sa_hup.sa_flags = 0; + sigaction(SIGHUP, &sa_hup, NULL); #endif fTestNet = GetBoolArg("-testnet"); diff --git a/src/util.cpp b/src/util.cpp index b0c80f6dfc4d3..e3a49dcbcf276 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -25,6 +25,7 @@ namespace boost { #include #include #include +#include #include #include #include @@ -69,6 +70,7 @@ bool fTestNet = false; bool fNoListen = false; bool fLogTimestamps = false; CMedianFilter vTimeOffsets(200,0); +bool fReopenDebugLog = false; // Init openssl library multithreading support static CCriticalSection** ppmutexOpenSSL; @@ -209,6 +211,16 @@ inline int OutputDebugStringF(const char* pszFormat, ...) if (fileout) { static bool fStartedNewLine = true; + static boost::mutex mutexDebugLog; + boost::mutex::scoped_lock scoped_lock(mutexDebugLog); + + // reopen the log file, if requested + if (fReopenDebugLog) { + fReopenDebugLog = false; + boost::filesystem::path pathDebug = GetDataDir() / "debug.log"; + if (freopen(pathDebug.string().c_str(),"a",fileout) != NULL) + setbuf(fileout, NULL); // unbuffered + } // Debug print useful for profiling if (fLogTimestamps && fStartedNewLine) diff --git a/src/util.h b/src/util.h index f7bdaf53323f6..edef354443b94 100644 --- a/src/util.h +++ b/src/util.h @@ -121,6 +121,7 @@ extern std::string strMiscWarning; extern bool fTestNet; extern bool fNoListen; extern bool fLogTimestamps; +extern bool fReopenDebugLog; void RandAddSeed(); void RandAddSeedPerfmon();