Browse Source

Merge pull request #917 from mndrix/reopen-log-file

Reopen log file on SIGHUP
miguelfreitas
Pieter Wuille 13 years ago
parent
commit
63407fd6e2
  1. 12
      src/init.cpp
  2. 12
      src/util.cpp
  3. 1
      src/util.h

12
src/init.cpp

@ -82,6 +82,10 @@ void HandleSIGTERM(int)
fRequestShutdown = true; fRequestShutdown = true;
} }
void HandleSIGHUP(int)
{
fReopenDebugLog = true;
}
@ -291,7 +295,13 @@ bool AppInit2()
sa.sa_flags = 0; sa.sa_flags = 0;
sigaction(SIGTERM, &sa, NULL); sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &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 #endif
fTestNet = GetBoolArg("-testnet"); fTestNet = GetBoolArg("-testnet");

12
src/util.cpp

@ -25,6 +25,7 @@ namespace boost {
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h> #include <openssl/crypto.h>
#include <openssl/rand.h> #include <openssl/rand.h>
#include <stdarg.h> #include <stdarg.h>
@ -69,6 +70,7 @@ bool fTestNet = false;
bool fNoListen = false; bool fNoListen = false;
bool fLogTimestamps = false; bool fLogTimestamps = false;
CMedianFilter<int64> vTimeOffsets(200,0); CMedianFilter<int64> vTimeOffsets(200,0);
bool fReopenDebugLog = false;
// Init openssl library multithreading support // Init openssl library multithreading support
static CCriticalSection** ppmutexOpenSSL; static CCriticalSection** ppmutexOpenSSL;
@ -207,6 +209,16 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
if (fileout) if (fileout)
{ {
static bool fStartedNewLine = true; 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 // Debug print useful for profiling
if (fLogTimestamps && fStartedNewLine) if (fLogTimestamps && fStartedNewLine)

1
src/util.h

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

Loading…
Cancel
Save