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
7 -static regex_t Empty, Comment, User, Group, RootJail, Daemon, LogFacility, LogLevel, Alive, SSLEngine, Control;
8 +static regex_t Empty, Comment, User, Group, RootJail, Daemon, LogFacility, LogFile, LogLevel, ErrorLog, Alive, SSLEngine, Control;
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;
12 @@ -1104,6 +1104,18 @@
13 def_facility = facilitynames[i].c_val;
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);
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);
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)) {
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)
37 + || regcomp(&ErrorLog, "^[ \t]*ErrorLog[ \t]+(.+)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
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)
40 || regcomp(&SSLEngine, "^[ \t]*SSLEngine[ \t]+\"(.+)\"[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
53 regfree(&LogFacility);
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
63 *group, /* group to run as */
64 *root_jail, /* directory to chroot to */
65 *pid_name, /* file to record pid in */
66 + *log_file, /* print log messages to this file, instead of syslog */
67 + *error_log, /* print error messages to this file, instead of syslog */
68 *ctrl_name; /* control socket name */
70 int alive_to, /* check interval for resurrection */
72 AUTHORIZATION; /* the Authorisation header */
74 static int shut_down = 0;
75 +static int flush_logs = 0;
78 /* for systems without the definition */
80 return (unsigned long)pthread_self();
87 + logmsg(LOG_NOTICE, "reopening logs...");
88 + // reopen logs, but check access first, as it might fail in chroot
90 + if (access(log_file, F_OK) == 0 && access(log_file, W_OK) == -1) {
91 + logmsg(LOG_ERR, "%s: %s", log_file, strerror(errno));
93 + stdout = freopen(log_file, "a", stdout);
94 + logmsg(LOG_ERR, "reopen stdout: %p", stdout);
99 + if (access(error_log, F_OK) == 0 && access(error_log, W_OK) == -1) {
100 + logmsg(LOG_ERR, "%s: %s", error_log, strerror(errno));
102 + stderr = freopen(error_log, "a", stderr);
103 + logmsg(LOG_ERR, "reopen stderr: %p", stderr);
104 + setlinebuf(stderr);
111 * handle SIGTERM/SIGQUIT - exit
117 + * handle SIGUSR1 - reopen logs
120 +h_reopen(const int sig)
122 + logmsg(LOG_NOTICE, "%d received signal %d - reopening logs...", getpid(), sig);
132 * Pound: the reverse-proxy/load-balancer
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);
143 @@ -289,11 +335,23 @@
144 /* daemonize - make ourselves a subprocess. */
147 - if(log_facility != -1) {
152 + stderr = freopen(error_log, "a", stderr);
153 + setlinebuf(stderr);
155 + if (log_facility != -1) {
160 + stdout = freopen(log_file, "a", stdout);
161 + setlinebuf(stdout);
163 + if (log_facility != -1) {
170 logmsg(LOG_ERR, "fork: %s - aborted", strerror(errno));
172 logmsg(LOG_ERR, "MONITOR: worker exited (stopped?) %d, restarting...", status);
173 } else if (son == 0) {
177 pthread_attr_init(&attr);
178 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
180 (void)unlink(ctrl_name);
188 for(lstn = listeners, i = 0; i < n_listeners; lstn = lstn->next, i++) {
189 polls[i].events = POLLIN | POLLPRI;
190 polls[i].revents = 0;
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
194 *group, /* group to run as */
195 *root_jail, /* directory to chroot to */
196 *pid_name, /* file to record pid in */
197 + *log_file, /* print log messages to this file, instead of syslog */
198 + *error_log, /* print error messages to this file, instead of syslog */
199 *ctrl_name; /* control socket name */
201 extern int alive_to, /* check interval for resurrection */
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 @@
207 logmsg(const int priority, const char *fmt, ...)
209 - char buf[MAXBUF + 1];
211 - struct tm *t_now, t_res;
213 - buf[MAXBUF] = '\0';
215 - vsnprintf(buf, MAXBUF, fmt, ap);
217 - if(log_facility == -1) {
218 - fprintf((priority == LOG_INFO || priority == LOG_DEBUG)? stdout: stderr, "%s\n", buf);
221 - printf("%s\n", buf);
223 - syslog(log_facility | priority, "%s", buf);
229 logmsg(const int priority, const char *fmt, va_alist)
233 char buf[MAXBUF + 1];
235 struct tm *t_now, t_res;
236 + int log = (priority == LOG_INFO || priority == LOG_DEBUG);
239 +#ifdef HAVE_STDARG_H
244 vsnprintf(buf, MAXBUF, fmt, ap);
246 - if(log_facility == -1) {
247 - fprintf((priority == LOG_INFO || priority == LOG_DEBUG)? stdout: stderr, "%s\n", buf);
249 + // if access log or error log are set, use them.
250 + if (log && log_file) {
251 + fprintf(stdout, "%s\n", buf);
254 + if (!log && error_log) {
255 + fprintf(stderr, "%s\n", buf);
259 + if (log_facility == -1) {
260 + fprintf(log ? stdout : stderr, "%s\n", buf);
267 syslog(log_facility | priority, "%s", buf);
275 * Translate inet/inet6 address/port into a string