1 diff -urNp -x '*.orig' Pound-2.8.org/config.c Pound-2.8/config.c
2 --- Pound-2.8.org/config.c 2021-10-04 21:55:51.849501382 +0200
3 +++ Pound-2.8/config.c 2021-10-04 21:55:51.876168039 +0200
4 @@ -73,7 +73,7 @@ static CODE facilitynames[] = {
8 -static regex_t Empty, Comment, User, Group, RootJail, Daemon, LogFacility, LogLevel, Alive, SSLEngine, Control;
9 +static regex_t Empty, Comment, User, Group, RootJail, Daemon, LogFacility, LogFile, LogLevel, ErrorLog, Alive, SSLEngine, Control;
10 static regex_t ListenHTTP, ListenHTTPS, End, Address, Port, Cert, xHTTP, Client, CheckURL;
11 static regex_t Err414, Err500, Err501, Err503, MaxRequest, HeadRemove, RewriteLocation, RewriteDestination;
12 static regex_t Service, ServiceName, URL, HeadRequire, HeadDeny, BackEnd, Emergency, Priority, HAport, HAportAddr;
13 @@ -1330,6 +1330,18 @@ parse_file(void)
14 def_facility = facilitynames[i].c_val;
17 + } else if(!regexec(&LogFile, lin, 4, matches, 0)) {
18 + lin[matches[1].rm_eo] = '\0';
19 + if((log_file = strdup(lin + matches[1].rm_so)) == NULL) {
20 + logmsg(LOG_ERR, "line %d: LogFile config: out of memory - aborted", n_lin);
23 + } else if(!regexec(&ErrorLog, lin, 4, matches, 0)) {
24 + lin[matches[1].rm_eo] = '\0';
25 + if((error_log = strdup(lin + matches[1].rm_so)) == NULL) {
26 + logmsg(LOG_ERR, "line %d: ErrorLog config: out of memory - aborted", n_lin);
29 } else if(!regexec(&Grace, lin, 4, matches, 0)) {
30 grace = atoi(lin + matches[1].rm_so);
31 } else if(!regexec(&LogLevel, lin, 4, matches, 0)) {
32 @@ -1436,7 +1448,9 @@ config_parse(const int argc, char **cons
33 || regcomp(&Daemon, "^[ \t]*Daemon[ \t]+([01])[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
34 || regcomp(&Threads, "^[ \t]*Threads[ \t]+([1-9][0-9]*)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
35 || regcomp(&LogFacility, "^[ \t]*LogFacility[ \t]+([a-z0-9-]+)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
36 + || regcomp(&LogFile, "^[ \t]*LogFile[ \t]+(.+)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
37 || regcomp(&LogLevel, "^[ \t]*LogLevel[ \t]+([0-5])[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
38 + || regcomp(&ErrorLog, "^[ \t]*ErrorLog[ \t]+(.+)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
39 || regcomp(&Grace, "^[ \t]*Grace[ \t]+([0-9]+)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
40 || regcomp(&Alive, "^[ \t]*Alive[ \t]+([1-9][0-9]*)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
41 || regcomp(&SSLEngine, "^[ \t]*SSLEngine[ \t]+\"(.+)\"[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
42 @@ -1572,6 +1586,8 @@ config_parse(const int argc, char **cons
51 @@ -1601,7 +1617,9 @@ config_parse(const int argc, char **cons
54 regfree(&LogFacility);
61 diff -urNp -x '*.orig' Pound-2.8.org/pound.c Pound-2.8/pound.c
62 --- Pound-2.8.org/pound.c 2018-05-11 12:16:05.000000000 +0200
63 +++ Pound-2.8/pound.c 2021-10-04 21:55:51.876168039 +0200
64 @@ -32,6 +32,8 @@ char *user, /* user
65 *group, /* group to run as */
66 *root_jail, /* directory to chroot to */
67 *pid_name, /* file to record pid in */
68 + *log_file, /* print log messages to this file, instead of syslog */
69 + *error_log, /* print error messages to this file, instead of syslog */
70 *ctrl_name; /* control socket name */
72 int alive_to, /* check interval for resurrection */
73 @@ -54,6 +56,7 @@ regex_t HEADER, /* Allowed h
74 AUTHORIZATION; /* the Authorisation header */
76 static int shut_down = 0;
77 +static int flush_logs = 0;
80 /* for systems without the definition */
81 @@ -183,6 +186,33 @@ get_thr_qlen(void)
89 + logmsg(LOG_NOTICE, "reopening logs...");
90 + // reopen logs, but check access first, as it might fail in chroot
92 + if (access(log_file, F_OK) == 0 && access(log_file, W_OK) == -1) {
93 + logmsg(LOG_ERR, "%s: %s", log_file, strerror(errno));
95 + stdout = freopen(log_file, "a", stdout);
96 + logmsg(LOG_ERR, "reopen stdout: %p", stdout);
101 + if (access(error_log, F_OK) == 0 && access(error_log, W_OK) == -1) {
102 + logmsg(LOG_ERR, "%s: %s", error_log, strerror(errno));
104 + stderr = freopen(error_log, "a", stderr);
105 + logmsg(LOG_ERR, "reopen stderr: %p", stderr);
106 + setlinebuf(stderr);
113 * handle SIGTERM/SIGQUIT - exit
115 @@ -220,6 +250,21 @@ h_shut(const int sig)
119 + * handle SIGUSR1 - reopen logs
122 +h_reopen(const int sig)
124 + logmsg(LOG_NOTICE, "%d received signal %d - reopening logs...", getpid(), sig);
134 * Pound: the reverse-proxy/load-balancer
137 @@ -254,6 +299,7 @@ main(const int argc, char **argv)
138 signal(SIGINT, h_shut);
139 signal(SIGTERM, h_term);
140 signal(SIGQUIT, h_term);
141 + signal(SIGUSR1, h_reopen);
142 signal(SIGPIPE, SIG_IGN);
145 @@ -386,11 +432,23 @@ main(const int argc, char **argv)
146 /* daemonize - make ourselves a subprocess. */
149 - if(log_facility != -1) {
154 + stderr = freopen(error_log, "a", stderr);
155 + setlinebuf(stderr);
157 + if (log_facility != -1) {
162 + stdout = freopen(log_file, "a", stdout);
163 + setlinebuf(stdout);
165 + if (log_facility != -1) {
172 logmsg(LOG_ERR, "fork: %s - aborted", strerror(errno));
173 @@ -448,7 +506,6 @@ main(const int argc, char **argv)
174 logmsg(LOG_ERR, "MONITOR: worker exited (stopped?) %d, restarting...", status);
175 } else if (son == 0) {
179 pthread_attr_init(&attr);
180 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
181 @@ -499,6 +556,11 @@ main(const int argc, char **argv)
182 (void)unlink(ctrl_name);
190 for(lstn = listeners, i = 0; i < n_listeners; lstn = lstn->next, i++) {
191 polls[i].events = POLLIN | POLLPRI;
192 polls[i].revents = 0;
193 diff -urNp -x '*.orig' Pound-2.8.org/pound.h Pound-2.8/pound.h
194 --- Pound-2.8.org/pound.h 2018-05-11 12:16:05.000000000 +0200
195 +++ Pound-2.8/pound.h 2021-10-04 21:55:51.876168039 +0200
196 @@ -264,6 +264,8 @@ extern char *user, /* user
197 *group, /* group to run as */
198 *root_jail, /* directory to chroot to */
199 *pid_name, /* file to record pid in */
200 + *log_file, /* print log messages to this file, instead of syslog */
201 + *error_log, /* print error messages to this file, instead of syslog */
202 *ctrl_name; /* control socket name */
204 extern int numthreads, /* number of worker threads */
205 diff -urNp -x '*.orig' Pound-2.8.org/svc.c Pound-2.8/svc.c
206 --- Pound-2.8.org/svc.c 2021-10-04 21:55:51.849501382 +0200
207 +++ Pound-2.8/svc.c 2021-10-04 21:55:51.876168039 +0200
208 @@ -220,49 +220,47 @@ t_clean(LHASH_OF(TABNODE) *const tab, vo
211 logmsg(const int priority, const char *fmt, ...)
213 - char buf[MAXBUF + 1];
215 - struct tm *t_now, t_res;
217 - buf[MAXBUF] = '\0';
219 - vsnprintf(buf, MAXBUF, fmt, ap);
221 - if(log_facility == -1) {
222 - fprintf((priority == LOG_INFO || priority == LOG_DEBUG)? stdout: stderr, "%s\n", buf);
225 - printf("%s\n", buf);
227 - syslog(log_facility | priority, "%s", buf);
233 logmsg(const int priority, const char *fmt, va_alist)
237 char buf[MAXBUF + 1];
239 struct tm *t_now, t_res;
240 + int log = (priority == LOG_INFO || priority == LOG_DEBUG);
243 +#ifdef HAVE_STDARG_H
248 vsnprintf(buf, MAXBUF, fmt, ap);
250 - if(log_facility == -1) {
251 - fprintf((priority == LOG_INFO || priority == LOG_DEBUG)? stdout: stderr, "%s\n", buf);
253 + // if access log or error log are set, use them.
254 + if (log && log_file) {
255 + fprintf(stdout, "%s\n", buf);
258 + if (!log && error_log) {
259 + fprintf(stderr, "%s\n", buf);
263 + if (log_facility == -1) {
264 + fprintf(log ? stdout : stderr, "%s\n", buf);
271 syslog(log_facility | priority, "%s", buf);
279 * Translate inet/inet6 address/port into a string