119 lines
3.1 KiB
Diff
119 lines
3.1 KiB
Diff
diff --git a/src/init.cpp b/src/init.cpp
|
|
index 4078b7e..87a619f 100644
|
|
--- a/src/init.cpp
|
|
+++ b/src/init.cpp
|
|
@@ -8,6 +8,7 @@
|
|
#include "net.h"
|
|
#include "init.h"
|
|
#include "strlcpy.h"
|
|
+#include "util.h"
|
|
#include <boost/filesystem.hpp>
|
|
#include <boost/filesystem/fstream.hpp>
|
|
#include <boost/filesystem/convenience.hpp>
|
|
@@ -83,6 +84,10 @@ void HandleSIGTERM(int)
|
|
fRequestShutdown = true;
|
|
}
|
|
|
|
+void HandleSIGHUP(int)
|
|
+{
|
|
+ fReopenDebugLog = true;
|
|
+}
|
|
|
|
|
|
|
|
@@ -144,7 +149,13 @@ bool AppInit2(int argc, char* argv[])
|
|
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
|
|
|
|
//
|
|
diff --git a/src/util.cpp b/src/util.cpp
|
|
index 08752e6..ca4e53b 100644
|
|
--- a/src/util.cpp
|
|
+++ b/src/util.cpp
|
|
@@ -32,6 +32,8 @@ bool fTestNet = false;
|
|
bool fNoListen = false;
|
|
bool fLogTimestamps = false;
|
|
CMedianFilter<int64> vTimeOffsets(200,0);
|
|
+FILE* fileout = NULL;
|
|
+bool fReopenDebugLog = false;
|
|
|
|
|
|
|
|
@@ -155,6 +157,13 @@ int GetRandInt(int nMax)
|
|
|
|
|
|
|
|
+string GetDebugLogName()
|
|
+{
|
|
+ char pszFile[MAX_PATH+100];
|
|
+ GetDataDir(pszFile);
|
|
+ strlcat(pszFile, "/debug.log", sizeof(pszFile));
|
|
+ return pszFile;
|
|
+}
|
|
|
|
inline int OutputDebugStringF(const char* pszFormat, ...)
|
|
{
|
|
@@ -170,19 +179,27 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
|
|
else
|
|
{
|
|
// print to debug.log
|
|
- static FILE* fileout = NULL;
|
|
|
|
if (!fileout)
|
|
{
|
|
- char pszFile[MAX_PATH+100];
|
|
- GetDataDir(pszFile);
|
|
- strlcat(pszFile, "/debug.log", sizeof(pszFile));
|
|
+ const char* pszFile = GetDebugLogName().c_str();
|
|
fileout = fopen(pszFile, "a");
|
|
if (fileout) setbuf(fileout, NULL); // unbuffered
|
|
}
|
|
if (fileout)
|
|
{
|
|
static bool fStartedNewLine = true;
|
|
+#ifndef WIN32
|
|
+ flockfile(fileout);
|
|
+
|
|
+ // reopen the log file, if requested
|
|
+ if (fReopenDebugLog) {
|
|
+ fReopenDebugLog = false;
|
|
+ const char* pszFile = GetDebugLogName().c_str();
|
|
+ if (freopen(pszFile,"a",fileout) != NULL)
|
|
+ setbuf(fileout, NULL); // unbuffered
|
|
+ }
|
|
+#endif
|
|
|
|
// Debug print useful for profiling
|
|
if (fLogTimestamps && fStartedNewLine)
|
|
@@ -196,6 +213,9 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
|
|
va_start(arg_ptr, pszFormat);
|
|
ret = vfprintf(fileout, pszFormat, arg_ptr);
|
|
va_end(arg_ptr);
|
|
+#ifndef WIN32
|
|
+ funlockfile(fileout);
|
|
+#endif
|
|
}
|
|
}
|
|
|
|
diff --git a/src/util.h b/src/util.h
|
|
index 4fa5a08..5981ab6 100644
|
|
--- a/src/util.h
|
|
+++ b/src/util.h
|
|
@@ -123,6 +123,7 @@ extern std::string strMiscWarning;
|
|
extern bool fTestNet;
|
|
extern bool fNoListen;
|
|
extern bool fLogTimestamps;
|
|
+extern bool fReopenDebugLog;
|
|
|
|
void RandAddSeed();
|
|
void RandAddSeedPerfmon();
|