]> git.pld-linux.org Git - packages/pound.git/blame - pound-logfile.patch
- honour AddHeader if specified multiple times. patch from mailinglist
[packages/pound.git] / pound-logfile.patch
CommitLineData
df964c26
ER
1--- Pound-2.4.3-logfile/config.c 2008-12-11 00:22:22.509353295 +0200
2+++ Pound-2.4.3.logs/config.c 2009-01-08 17:47:08.523739629 +0200
c94e34ab
ER
3@@ -72,7 +72,7 @@
4 };
5 #endif
6
7-static regex_t Empty, Comment, User, Group, RootJail, Daemon, LogFacility, LogLevel, Alive, SSLEngine, Control;
df964c26 8+static regex_t Empty, Comment, User, Group, RootJail, Daemon, LogFacility, LogFile, LogLevel, ErrorLog, Alive, SSLEngine, Control;
c94e34ab
ER
9 static regex_t ListenHTTP, ListenHTTPS, End, Address, Port, Cert, xHTTP, Client, CheckURL;
10 static regex_t Err414, Err500, Err501, Err503, MaxRequest, HeadRemove, RewriteLocation, RewriteDestination;
11 static regex_t Service, ServiceName, URL, HeadRequire, HeadDeny, BackEnd, Emergency, Priority, HAport, HAportAddr;
df964c26 12@@ -1104,6 +1104,18 @@
c94e34ab
ER
13 def_facility = facilitynames[i].c_val;
14 break;
15 }
16+ } else if(!regexec(&LogFile, lin, 4, matches, 0)) {
17+ lin[matches[1].rm_eo] = '\0';
18+ if((log_file = strdup(lin + matches[1].rm_so)) == NULL) {
19+ logmsg(LOG_ERR, "line %d: LogFile config: out of memory - aborted", n_lin);
20+ exit(1);
21+ }
df964c26
ER
22+ } else if(!regexec(&ErrorLog, lin, 4, matches, 0)) {
23+ lin[matches[1].rm_eo] = '\0';
24+ if((error_log = strdup(lin + matches[1].rm_so)) == NULL) {
25+ logmsg(LOG_ERR, "line %d: ErrorLog config: out of memory - aborted", n_lin);
26+ exit(1);
27+ }
c94e34ab
ER
28 } else if(!regexec(&Grace, lin, 4, matches, 0)) {
29 grace = atoi(lin + matches[1].rm_so);
30 } else if(!regexec(&LogLevel, lin, 4, matches, 0)) {
df964c26 31@@ -1204,7 +1216,9 @@
c94e34ab
ER
32 || regcomp(&RootJail, "^[ \t]*RootJail[ \t]+\"(.+)\"[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
33 || regcomp(&Daemon, "^[ \t]*Daemon[ \t]+([01])[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
34 || regcomp(&LogFacility, "^[ \t]*LogFacility[ \t]+([a-z0-9-]+)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
35+ || regcomp(&LogFile, "^[ \t]*LogFile[ \t]+(.+)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
36 || regcomp(&LogLevel, "^[ \t]*LogLevel[ \t]+([0-5])[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
df964c26 37+ || regcomp(&ErrorLog, "^[ \t]*ErrorLog[ \t]+(.+)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
c94e34ab
ER
38 || regcomp(&Grace, "^[ \t]*Grace[ \t]+([0-9]+)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
39 || regcomp(&Alive, "^[ \t]*Alive[ \t]+([1-9][0-9]*)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
df964c26
ER
40 || regcomp(&SSLEngine, "^[ \t]*SSLEngine[ \t]+\"(.+)\"[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
41@@ -1329,6 +1343,8 @@
c94e34ab
ER
42 group = NULL;
43 root_jail = NULL;
44 ctrl_name = NULL;
45+ log_file = NULL;
df964c26 46+ error_log = NULL;
c94e34ab
ER
47
48 alive_to = 30;
49 daemonize = 1;
df964c26 50@@ -1358,7 +1374,9 @@
c94e34ab
ER
51 regfree(&RootJail);
52 regfree(&Daemon);
53 regfree(&LogFacility);
54+ regfree(&LogFile);
55 regfree(&LogLevel);
df964c26 56+ regfree(&ErrorLog);
c94e34ab
ER
57 regfree(&Grace);
58 regfree(&Alive);
df964c26 59 regfree(&SSLEngine);
c06a2f2e
ER
60--- Pound-2.4.3/pound.c 2009-01-08 19:02:26.160354939 +0200
61+++ Pound-2.4.3.logsz/pound.c 2009-01-09 15:43:41.595643815 +0200
56aaf98c 62@@ -33,6 +33,8 @@
c94e34ab
ER
63 *group, /* group to run as */
64 *root_jail, /* directory to chroot to */
65 *pid_name, /* file to record pid in */
56aaf98c
ER
66+ *log_file, /* print log messages to this file, instead of syslog */
67+ *error_log, /* print error messages to this file, instead of syslog */
c94e34ab
ER
68 *ctrl_name; /* control socket name */
69
70 int alive_to, /* check interval for resurrection */
c06a2f2e
ER
71@@ -54,6 +56,7 @@
72 AUTHORIZATION; /* the Authorisation header */
73
74 static int shut_down = 0;
75+static int flush_logs = 0;
76
77 #ifndef SOL_TCP
78 /* for systems without the definition */
79@@ -105,6 +108,33 @@
80 return (unsigned long)pthread_self();
81 }
82
83+static void
84+reopen_logs()
85+{
86+
87+ logmsg(LOG_NOTICE, "reopening logs...");
88+ // reopen logs, but check access first, as it might fail in chroot
89+ if (log_file) {
90+ if (access(log_file, F_OK) == 0 && access(log_file, W_OK) == -1) {
91+ logmsg(LOG_ERR, "%s: %s", log_file, strerror(errno));
92+ } else {
93+ stdout = freopen(log_file, "a", stdout);
94+ logmsg(LOG_ERR, "reopen stdout: %p", stdout);
95+ setlinebuf(stdout);
96+ }
97+ }
98+ if (error_log) {
99+ if (access(error_log, F_OK) == 0 && access(error_log, W_OK) == -1) {
100+ logmsg(LOG_ERR, "%s: %s", error_log, strerror(errno));
101+ } else {
102+ stderr = freopen(error_log, "a", stderr);
103+ logmsg(LOG_ERR, "reopen stderr: %p", stderr);
104+ setlinebuf(stderr);
105+ }
106+ }
107+ flush_logs = 0;
108+}
109+
110 /*
111 * handle SIGTERM/SIGQUIT - exit
112 */
113@@ -142,6 +172,21 @@
114 }
115
116 /*
117+ * handle SIGUSR1 - reopen logs
118+ */
119+static RETSIGTYPE
120+h_reopen(const int sig)
121+{
122+ logmsg(LOG_NOTICE, "%d received signal %d - reopening logs...", getpid(), sig);
123+ if (son > 0) {
124+ reopen_logs();
125+ kill(son, sig);
126+ } else {
127+ flush_logs = 1;
128+ }
129+}
130+
131+/*
132 * Pound: the reverse-proxy/load-balancer
133 *
134 * Arguments:
135@@ -175,6 +220,7 @@
136 signal(SIGINT, h_shut);
137 signal(SIGTERM, h_term);
138 signal(SIGQUIT, h_term);
139+ signal(SIGUSR1, h_reopen);
140 signal(SIGPIPE, SIG_IGN);
141
142 srandom(getpid());
143@@ -289,11 +335,23 @@
56aaf98c
ER
144 /* daemonize - make ourselves a subprocess. */
145 switch (fork()) {
146 case 0:
147- if(log_facility != -1) {
148- close(0);
149- close(1);
150- close(2);
56aaf98c
ER
151+ if (error_log) {
152+ stderr = freopen(error_log, "a", stderr);
153+ setlinebuf(stderr);
154+ } else {
155+ if (log_facility != -1) {
156+ close(2);
c06a2f2e
ER
157+ }
158+ }
159+ if (log_file) {
160+ stdout = freopen(log_file, "a", stdout);
161+ setlinebuf(stdout);
162+ } else {
163+ if (log_facility != -1) {
164+ close(1);
56aaf98c 165+ }
c94e34ab 166 }
c06a2f2e 167+ close(0);
c94e34ab
ER
168 break;
169 case -1:
c06a2f2e
ER
170 logmsg(LOG_ERR, "fork: %s - aborted", strerror(errno));
171@@ -351,7 +409,6 @@
172 logmsg(LOG_ERR, "MONITOR: worker exited (stopped?) %d, restarting...", status);
173 } else if (son == 0) {
174 #endif
175-
176 /* thread stuff */
177 pthread_attr_init(&attr);
178 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
179@@ -392,6 +449,11 @@
180 (void)unlink(ctrl_name);
181 exit(0);
182 }
183+
184+ if (flush_logs) {
185+ reopen_logs();
186+ }
187+
188 for(lstn = listeners, i = 0; i < n_listeners; lstn = lstn->next, i++) {
189 polls[i].events = POLLIN | POLLPRI;
190 polls[i].revents = 0;
56aaf98c
ER
191--- Pound-2.4.3-logfile/pound.h 2008-12-11 00:16:43.449299956 +0200
192+++ Pound-2.4.3.logs/pound.h 2009-01-08 17:47:38.940178535 +0200
193@@ -236,6 +236,8 @@
c94e34ab
ER
194 *group, /* group to run as */
195 *root_jail, /* directory to chroot to */
196 *pid_name, /* file to record pid in */
56aaf98c
ER
197+ *log_file, /* print log messages to this file, instead of syslog */
198+ *error_log, /* print error messages to this file, instead of syslog */
c94e34ab
ER
199 *ctrl_name; /* control socket name */
200
201 extern int alive_to, /* check interval for resurrection */
96bd9b50
ER
202--- Pound-2.4.3/svc.c 2009-01-14 15:16:55.002576968 +0200
203+++ Pound-2.4.3/svc.c 2009-01-14 15:20:43.342553651 +0200
204@@ -172,49 +172,47 @@
205 #ifdef HAVE_STDARG_H
206 void
207 logmsg(const int priority, const char *fmt, ...)
208-{
209- char buf[MAXBUF + 1];
210- va_list ap;
211- struct tm *t_now, t_res;
212-
213- buf[MAXBUF] = '\0';
214- va_start(ap, fmt);
215- vsnprintf(buf, MAXBUF, fmt, ap);
216- va_end(ap);
217- if(log_facility == -1) {
218- fprintf((priority == LOG_INFO || priority == LOG_DEBUG)? stdout: stderr, "%s\n", buf);
219- } else {
220- if(print_log)
221- printf("%s\n", buf);
222- else
223- syslog(log_facility | priority, "%s", buf);
224- }
225- return;
226-}
227 #else
228 void
229 logmsg(const int priority, const char *fmt, va_alist)
230 va_dcl
231+#endif
232 {
56aaf98c
ER
233 char buf[MAXBUF + 1];
234 va_list ap;
235 struct tm *t_now, t_res;
236+ int log = (priority == LOG_INFO || priority == LOG_DEBUG);
237
238 buf[MAXBUF] = '\0';
96bd9b50
ER
239+#ifdef HAVE_STDARG_H
240+ va_start(ap, fmt);
241+#else
242 va_start(ap);
243+#endif
56aaf98c
ER
244 vsnprintf(buf, MAXBUF, fmt, ap);
245 va_end(ap);
246- if(log_facility == -1) {
247- fprintf((priority == LOG_INFO || priority == LOG_DEBUG)? stdout: stderr, "%s\n", buf);
248+
249+ // if access log or error log are set, use them.
250+ if (log && log_file) {
56aaf98c
ER
251+ fprintf(stdout, "%s\n", buf);
252+ return;
253+ }
254+ if (!log && error_log) {
255+ fprintf(stderr, "%s\n", buf);
32fc1bde 256+ return;
56aaf98c
ER
257+ }
258+
259+ if (log_facility == -1) {
260+ fprintf(log ? stdout : stderr, "%s\n", buf);
261 } else {
96bd9b50
ER
262- if(print_log)
263+ if (print_log) {
56aaf98c 264 printf("%s\n", buf);
96bd9b50
ER
265- else
266+ } else {
267 syslog(log_facility | priority, "%s", buf);
268+ }
269 }
270 return;
271 }
272-#endif
273
274 /*
275 * Translate inet/inet6 address/port into a string
This page took 0.131144 seconds and 4 git commands to generate.