Browse Source

Reopen debug.log on SIGHUP

The best log rotation method formerly available was to configure
logrotate with the copytruncate option.  As described in the logrotate
documentation, "there is a very small time slice between copying the
file and truncating it, so some logging data might be lost".

By sending SIGHUP to the server process, one can now reopen the debug
log file without losing any data.
pull/1/head
Michael Hendricks 11 years ago
parent
commit
9af080c351
  1. 12
      src/init.cpp
  2. 9
      src/util.cpp
  3. 1
      src/util.h

12
src/init.cpp

@ -80,6 +80,10 @@ void HandleSIGTERM(int) @@ -80,6 +80,10 @@ void HandleSIGTERM(int)
fRequestShutdown = true;
}
void HandleSIGHUP(int)
{
fReopenDebugLog = true;
}
@ -285,7 +289,13 @@ bool AppInit2() @@ -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");

9
src/util.cpp

@ -70,6 +70,7 @@ bool fTestNet = false; @@ -70,6 +70,7 @@ bool fTestNet = false;
bool fNoListen = false;
bool fLogTimestamps = false;
CMedianFilter<int64> vTimeOffsets(200,0);
bool fReopenDebugLog = false;
// Init openssl library multithreading support
static CCriticalSection** ppmutexOpenSSL;
@ -213,6 +214,14 @@ inline int OutputDebugStringF(const char* pszFormat, ...) @@ -213,6 +214,14 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
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)
fprintf(fileout, "%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());

1
src/util.h

@ -121,6 +121,7 @@ extern std::string strMiscWarning; @@ -121,6 +121,7 @@ extern std::string strMiscWarning;
extern bool fTestNet;
extern bool fNoListen;
extern bool fLogTimestamps;
extern bool fReopenDebugLog;
void RandAddSeed();
void RandAddSeedPerfmon();

Loading…
Cancel
Save