Fix SIGCHLD signal handling. Child processes are restarted in signal
authorYoshiyuki Asaba <y-asaba at pgfoundry.org>
Wed, 20 Jun 2007 08:53:49 +0000 (08:53 +0000)
committerYoshiyuki Asaba <y-asaba at pgfoundry.org>
Wed, 20 Jun 2007 08:53:49 +0000 (08:53 +0000)
safe places.

main.c

diff --git a/main.c b/main.c
index 5d8fc9fdf1890ba447da7a43a74f3982328ad05c..f44bd6fd8632b9ad580ff942eb5978ccb1e801fc 100644 (file)
--- a/main.c
+++ b/main.c
@@ -46,7 +46,7 @@
 
 #include "version.h"
 
-#define CHECK_FAILOVER_REQUEST \
+#define CHECK_REQUEST \
        do \
        { \
                if (failover_request) \
                        failover(failover_request); \
                        failover_request = 0; \
                } \
+               if (sigchld_request) \
+               { \
+                       reaper(); \
+                       sigchld_request = 0; \
+               } \
        } while (0)
 
 #define PGPOOLMAXLITSENQUEUELENGTH 10000
@@ -65,6 +70,7 @@ static int create_unix_domain_socket(void);
 static int create_inet_domain_socket(const char *hostname);
 static void myexit(int code);
 static void failover(int sig);
+static void reaper(void);
 
 static RETSIGTYPE exit_handler(int sig);
 static RETSIGTYPE reap_handler(int sig);
@@ -98,6 +104,7 @@ static int switch_over_sig = SIGUSR1;        /* switch over signal default value */
 
 static int health_check_timer_expired;         /* non 0 if health check timer expired */
 static volatile int failover_request = 0;
+static volatile int sigchld_request = 0;
 
 int myargc;
 char **myargv;
@@ -323,7 +330,7 @@ int main(int argc, char **argv)
         */
        for (;;)
        {
-               CHECK_FAILOVER_REQUEST;
+               CHECK_REQUEST;
 
                /* do we need health checking for PostgreSQL? */
                if (!degenerated && pool_config.health_check_period > 0)
@@ -373,7 +380,7 @@ int main(int argc, char **argv)
                        while (sleep_time > 0)
                        {
                                sleep_time = sleep(sleep_time);
-                               CHECK_FAILOVER_REQUEST;
+                               CHECK_REQUEST;
                        }
                }
                else
@@ -997,6 +1004,12 @@ static RETSIGTYPE health_check_timer_handler(int sig)
  * handle SIGCHLD
  */
 static RETSIGTYPE reap_handler(int sig)
+{
+       sigchld_request = 1;
+}
+
+
+static void reaper(void)
 {
        pid_t pid;
        int status;