Gentoo Archives: gentoo-commits

From: "Anthony G. Basile (blueness)" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in net-p2p/bitcoind/files: 0.6.0-reopen_log_file.patch 0.4.5-reopen_log_file.patch bitcoind.logrotate
Date: Fri, 27 Apr 2012 09:21:57
Message-Id: 20120427092132.2ACF12004B@flycatcher.gentoo.org
1 blueness 12/04/27 09:21:32
2
3 Added: 0.6.0-reopen_log_file.patch
4 0.4.5-reopen_log_file.patch bitcoind.logrotate
5 Log:
6 Version bump rc3's and add log rotation
7
8 (Portage version: 2.1.10.49/cvs/Linux x86_64)
9
10 Revision Changes Path
11 1.1 net-p2p/bitcoind/files/0.6.0-reopen_log_file.patch
12
13 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-p2p/bitcoind/files/0.6.0-reopen_log_file.patch?rev=1.1&view=markup
14 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-p2p/bitcoind/files/0.6.0-reopen_log_file.patch?rev=1.1&content-type=text/plain
15
16 Index: 0.6.0-reopen_log_file.patch
17 ===================================================================
18 diff --git a/src/init.cpp b/src/init.cpp
19 index 4078b7e..87a619f 100644
20 --- a/src/init.cpp
21 +++ b/src/init.cpp
22 @@ -8,6 +8,7 @@
23 #include "net.h"
24 #include "init.h"
25 #include "strlcpy.h"
26 +#include "util.h"
27 #include <boost/filesystem.hpp>
28 #include <boost/filesystem/fstream.hpp>
29 #include <boost/filesystem/convenience.hpp>
30 @@ -83,6 +84,10 @@ void HandleSIGTERM(int)
31 fRequestShutdown = true;
32 }
33
34 +void HandleSIGHUP(int)
35 +{
36 + fReopenDebugLog = true;
37 +}
38
39
40
41 @@ -144,7 +149,13 @@ bool AppInit2(int argc, char* argv[])
42 sa.sa_flags = 0;
43 sigaction(SIGTERM, &sa, NULL);
44 sigaction(SIGINT, &sa, NULL);
45 - sigaction(SIGHUP, &sa, NULL);
46 +
47 + // Reopen debug.log on SIGHUP
48 + struct sigaction sa_hup;
49 + sa_hup.sa_handler = HandleSIGHUP;
50 + sigemptyset(&sa_hup.sa_mask);
51 + sa_hup.sa_flags = 0;
52 + sigaction(SIGHUP, &sa_hup, NULL);
53 #endif
54
55 //
56 diff --git a/src/util.cpp b/src/util.cpp
57 index 08752e6..ca4e53b 100644
58 --- a/src/util.cpp
59 +++ b/src/util.cpp
60 @@ -32,6 +32,8 @@ bool fTestNet = false;
61 bool fNoListen = false;
62 bool fLogTimestamps = false;
63 CMedianFilter<int64> vTimeOffsets(200,0);
64 +FILE* fileout = NULL;
65 +bool fReopenDebugLog = false;
66
67
68
69 @@ -155,6 +157,13 @@ int GetRandInt(int nMax)
70
71
72
73 +string GetDebugLogName()
74 +{
75 + char pszFile[MAX_PATH+100];
76 + GetDataDir(pszFile);
77 + strlcat(pszFile, "/debug.log", sizeof(pszFile));
78 + return pszFile;
79 +}
80
81 inline int OutputDebugStringF(const char* pszFormat, ...)
82 {
83 @@ -170,19 +179,27 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
84 else
85 {
86 // print to debug.log
87 - static FILE* fileout = NULL;
88
89 if (!fileout)
90 {
91 - char pszFile[MAX_PATH+100];
92 - GetDataDir(pszFile);
93 - strlcat(pszFile, "/debug.log", sizeof(pszFile));
94 + const char* pszFile = GetDebugLogName().c_str();
95 fileout = fopen(pszFile, "a");
96 if (fileout) setbuf(fileout, NULL); // unbuffered
97 }
98 if (fileout)
99 {
100 static bool fStartedNewLine = true;
101 +#ifndef WIN32
102 + flockfile(fileout);
103 +
104 + // reopen the log file, if requested
105 + if (fReopenDebugLog) {
106 + fReopenDebugLog = false;
107 + const char* pszFile = GetDebugLogName().c_str();
108 + if (freopen(pszFile,"a",fileout) != NULL)
109 + setbuf(fileout, NULL); // unbuffered
110 + }
111 +#endif
112
113 // Debug print useful for profiling
114 if (fLogTimestamps && fStartedNewLine)
115 @@ -196,6 +213,9 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
116 va_start(arg_ptr, pszFormat);
117 ret = vfprintf(fileout, pszFormat, arg_ptr);
118 va_end(arg_ptr);
119 +#ifndef WIN32
120 + funlockfile(fileout);
121 +#endif
122 }
123 }
124
125 diff --git a/src/util.h b/src/util.h
126 index 4fa5a08..5981ab6 100644
127 --- a/src/util.h
128 +++ b/src/util.h
129 @@ -123,6 +123,7 @@ extern std::string strMiscWarning;
130 extern bool fTestNet;
131 extern bool fNoListen;
132 extern bool fLogTimestamps;
133 +extern bool fReopenDebugLog;
134
135 void RandAddSeed();
136 void RandAddSeedPerfmon();
137
138
139
140 1.1 net-p2p/bitcoind/files/0.4.5-reopen_log_file.patch
141
142 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-p2p/bitcoind/files/0.4.5-reopen_log_file.patch?rev=1.1&view=markup
143 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-p2p/bitcoind/files/0.4.5-reopen_log_file.patch?rev=1.1&content-type=text/plain
144
145 Index: 0.4.5-reopen_log_file.patch
146 ===================================================================
147 diff --git a/src/init.cpp b/src/init.cpp
148 index 2dccc81..630fc29 100644
149 --- a/src/init.cpp
150 +++ b/src/init.cpp
151 @@ -8,6 +8,7 @@
152 #include "net.h"
153 #include "init.h"
154 #include "strlcpy.h"
155 +#include "util.h"
156 #include <boost/filesystem.hpp>
157 #include <boost/filesystem/fstream.hpp>
158 #include <boost/interprocess/sync/file_lock.hpp>
159 @@ -71,6 +72,10 @@ void HandleSIGTERM(int)
160 fRequestShutdown = true;
161 }
162
163 +void HandleSIGHUP(int)
164 +{
165 + fReopenDebugLog = true;
166 +}
167
168
169
170 @@ -132,7 +137,13 @@ bool AppInit2(int argc, char* argv[])
171 sa.sa_flags = 0;
172 sigaction(SIGTERM, &sa, NULL);
173 sigaction(SIGINT, &sa, NULL);
174 - sigaction(SIGHUP, &sa, NULL);
175 +
176 + // Reopen debug.log on SIGHUP
177 + struct sigaction sa_hup;
178 + sa_hup.sa_handler = HandleSIGHUP;
179 + sigemptyset(&sa_hup.sa_mask);
180 + sa_hup.sa_flags = 0;
181 + sigaction(SIGHUP, &sa_hup, NULL);
182 #endif
183
184 //
185 diff --git a/src/util.cpp b/src/util.cpp
186 index 0f496bc..736fac6 100644
187 --- a/src/util.cpp
188 +++ b/src/util.cpp
189 @@ -30,6 +30,8 @@ string strMiscWarning;
190 bool fTestNet = false;
191 bool fNoListen = false;
192 bool fLogTimestamps = false;
193 +FILE* fileout = NULL;
194 +bool fReopenDebugLog = false;
195
196
197
198 @@ -154,6 +156,13 @@ int GetRandInt(int nMax)
199
200
201
202 +string GetDebugLogName()
203 +{
204 + char pszFile[MAX_PATH+100];
205 + GetDataDir(pszFile);
206 + strlcat(pszFile, "/debug.log", sizeof(pszFile));
207 + return pszFile;
208 +}
209
210 inline int OutputDebugStringF(const char* pszFormat, ...)
211 {
212 @@ -169,19 +178,27 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
213 else
214 {
215 // print to debug.log
216 - static FILE* fileout = NULL;
217
218 if (!fileout)
219 {
220 - char pszFile[MAX_PATH+100];
221 - GetDataDir(pszFile);
222 - strlcat(pszFile, "/debug.log", sizeof(pszFile));
223 + const char* pszFile = GetDebugLogName().c_str();
224 fileout = fopen(pszFile, "a");
225 if (fileout) setbuf(fileout, NULL); // unbuffered
226 }
227 if (fileout)
228 {
229 static bool fStartedNewLine = true;
230 +#ifndef WIN32
231 + flockfile(fileout);
232 +
233 + // reopen the log file, if requested
234 + if (fReopenDebugLog) {
235 + fReopenDebugLog = false;
236 + const char* pszFile = GetDebugLogName().c_str();
237 + if (freopen(pszFile,"a",fileout) != NULL)
238 + setbuf(fileout, NULL); // unbuffered
239 + }
240 +#endif
241
242 // Debug print useful for profiling
243 if (fLogTimestamps && fStartedNewLine)
244 @@ -195,6 +212,9 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
245 va_start(arg_ptr, pszFormat);
246 ret = vfprintf(fileout, pszFormat, arg_ptr);
247 va_end(arg_ptr);
248 +#ifndef WIN32
249 + funlockfile(fileout);
250 +#endif
251 }
252 }
253
254 diff --git a/src/util.h b/src/util.h
255 index 4e4cbb9..d2c19c9 100644
256 --- a/src/util.h
257 +++ b/src/util.h
258 @@ -166,6 +166,7 @@ extern std::string strMiscWarning;
259 extern bool fTestNet;
260 extern bool fNoListen;
261 extern bool fLogTimestamps;
262 +extern bool fReopenDebugLog;
263
264 void RandAddSeed();
265 void RandAddSeedPerfmon();
266
267
268
269 1.1 net-p2p/bitcoind/files/bitcoind.logrotate
270
271 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-p2p/bitcoind/files/bitcoind.logrotate?rev=1.1&view=markup
272 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-p2p/bitcoind/files/bitcoind.logrotate?rev=1.1&content-type=text/plain
273
274 Index: bitcoind.logrotate
275 ===================================================================
276 /var/lib/bitcoin/.bitcoin/debug.log {
277 weekly
278 sharedscripts
279 postrotate
280 killall -HUP bitcoind
281 endscript
282 }