gentoo-overlay/net-p2p/bitcoind/files/0.4.7-reopen_log_file.patch

94 lines
2.6 KiB
Diff

diff --git a/src/init.cpp b/src/init.cpp
index 393d250..fd8bb1f 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -71,6 +71,10 @@ void HandleSIGTERM(int)
fRequestShutdown = true;
}
+void HandleSIGHUP(int)
+{
+ fReopenDebugLog = true;
+}
@@ -132,7 +136,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 cae01df..0b804c1 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -42,6 +42,7 @@ string strMiscWarning;
bool fTestNet = false;
bool fNoListen = false;
bool fLogTimestamps = false;
+bool fReopenDebugLog = false;
@@ -166,6 +167,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, ...)
{
@@ -185,10 +193,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
if (!fileout)
{
- char pszFile[MAX_PATH+100];
- GetDataDir(pszFile);
- strlcat(pszFile, "/debug.log", sizeof(pszFile));
- fileout = fopen(pszFile, "a");
+ fileout = fopen(GetDebugLogName().c_str(), "a");
if (fileout) setbuf(fileout, NULL); // unbuffered
}
if (fileout)
@@ -197,6 +202,13 @@ 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;
+ if (freopen(GetDebugLogName().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());
diff --git a/src/util.h b/src/util.h
index 284cf33..c8ce9b8 100644
--- a/src/util.h
+++ b/src/util.h
@@ -162,6 +162,7 @@ extern std::string strMiscWarning;
extern bool fTestNet;
extern bool fNoListen;
extern bool fLogTimestamps;
+extern bool fReopenDebugLog;
void RandAddSeed();
void RandAddSeedPerfmon();