SOURCES: pound-logfile.patch - reopen logs on USR1

glen glen at pld-linux.org
Fri Jan 9 14:48:31 CET 2009


Author: glen                         Date: Fri Jan  9 13:48:31 2009 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- reopen logs on USR1

---- Files affected:
SOURCES:
   pound-logfile.patch (1.4 -> 1.5) 

---- Diffs:

================================================================
Index: SOURCES/pound-logfile.patch
diff -u SOURCES/pound-logfile.patch:1.4 SOURCES/pound-logfile.patch:1.5
--- SOURCES/pound-logfile.patch:1.4	Thu Jan  8 17:52:18 2009
+++ SOURCES/pound-logfile.patch	Fri Jan  9 14:48:25 2009
@@ -57,8 +57,8 @@
      regfree(&Grace);
      regfree(&Alive);
      regfree(&SSLEngine);
---- Pound-2.4.3.logs/pound.c	2009-01-08 18:03:00.316961385 +0200
-+++ Pound-2.4.3.logs/pound.c	2009-01-08 18:03:00.316961385 +0200
+--- Pound-2.4.3/pound.c	2009-01-08 19:02:26.160354939 +0200
++++ Pound-2.4.3.logsz/pound.c	2009-01-09 15:43:41.595643815 +0200
 @@ -33,6 +33,8 @@
              *group,             /* group to run as */
              *root_jail,         /* directory to chroot to */
@@ -68,7 +68,79 @@
              *ctrl_name;         /* control socket name */
  
  int         alive_to,           /* check interval for resurrection */
-@@ -289,10 +291,22 @@
+@@ -54,6 +56,7 @@
+         AUTHORIZATION;      /* the Authorisation header */
+ 
+ static int  shut_down = 0;
++static int  flush_logs = 0;
+ 
+ #ifndef  SOL_TCP
+ /* for systems without the definition */
+@@ -105,6 +108,33 @@
+     return (unsigned long)pthread_self();
+ }
+ 
++static void
++reopen_logs()
++{
++
++    logmsg(LOG_NOTICE, "reopening logs...");
++    // reopen logs, but check access first, as it might fail in chroot
++    if (log_file) {
++        if (access(log_file, F_OK) == 0 && access(log_file, W_OK) == -1) {
++            logmsg(LOG_ERR, "%s: %s", log_file, strerror(errno));
++        } else {
++            stdout = freopen(log_file, "a", stdout);
++            logmsg(LOG_ERR, "reopen stdout: %p", stdout);
++            setlinebuf(stdout);
++        }
++    }
++    if (error_log) {
++        if (access(error_log, F_OK) == 0 && access(error_log, W_OK) == -1) {
++            logmsg(LOG_ERR, "%s: %s", error_log, strerror(errno));
++        } else {
++            stderr = freopen(error_log, "a", stderr);
++            logmsg(LOG_ERR, "reopen stderr: %p", stderr);
++            setlinebuf(stderr);
++        }
++    }
++    flush_logs = 0;
++}
++
+ /*
+  * handle SIGTERM/SIGQUIT - exit
+  */
+@@ -142,6 +172,21 @@
+ }
+ 
+ /*
++ * handle SIGUSR1 - reopen logs
++ */
++static RETSIGTYPE
++h_reopen(const int sig)
++{
++    logmsg(LOG_NOTICE, "%d received signal %d - reopening logs...", getpid(), sig);
++    if (son > 0) {
++        reopen_logs();
++        kill(son, sig);
++    } else {
++        flush_logs = 1;
++    }
++}
++
++/*
+  * Pound: the reverse-proxy/load-balancer
+  *
+  * Arguments:
+@@ -175,6 +220,7 @@
+     signal(SIGINT, h_shut);
+     signal(SIGTERM, h_term);
+     signal(SIGQUIT, h_term);
++    signal(SIGUSR1, h_reopen);
+     signal(SIGPIPE, SIG_IGN);
+ 
+     srandom(getpid());
+@@ -289,11 +335,23 @@
          /* daemonize - make ourselves a subprocess. */
          switch (fork()) {
              case 0:
@@ -76,15 +148,6 @@
 -                    close(0);
 -                    close(1);
 -                    close(2);
-+                close(0);
-+                if (log_file) {
-+                    stdout = freopen(log_file, "a", stdout);
-+                    setlinebuf(stdout);
-+                } else {
-+                    if (log_facility != -1) {
-+                        close(1);
-+                    }
-+                }
 +                if (error_log) {
 +                    stderr = freopen(error_log, "a", stderr);
 +                    setlinebuf(stderr);
@@ -92,9 +155,39 @@
 +                    if (log_facility != -1) {
 +                        close(2);
 +                    }
++                }
++                if (log_file) {
++                    stdout = freopen(log_file, "a", stdout);
++                    setlinebuf(stdout);
++                } else {
++                    if (log_facility != -1) {
++                        close(1);
++                    }
                  }
++                close(0);
                  break;
              case -1:
+                 logmsg(LOG_ERR, "fork: %s - aborted", strerror(errno));
+@@ -351,7 +409,6 @@
+                 logmsg(LOG_ERR, "MONITOR: worker exited (stopped?) %d, restarting...", status);
+         } else if (son == 0) {
+ #endif
+-
+             /* thread stuff */
+             pthread_attr_init(&attr);
+             pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+@@ -392,6 +449,11 @@
+                         (void)unlink(ctrl_name);
+                     exit(0);
+                 }
++
++				if (flush_logs) {
++                    reopen_logs();
++				}
++
+                 for(lstn = listeners, i = 0; i < n_listeners; lstn = lstn->next, i++) {
+                     polls[i].events = POLLIN | POLLPRI;
+                     polls[i].revents = 0;
 --- Pound-2.4.3-logfile/pound.h	2008-12-11 00:16:43.449299956 +0200
 +++ Pound-2.4.3.logs/pound.h	2009-01-08 17:47:38.940178535 +0200
 @@ -236,6 +236,8 @@
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/pound-logfile.patch?r1=1.4&r2=1.5&f=u



More information about the pld-cvs-commit mailing list