pgpool2.git / summary / log / commit / refs
commit 63ea8f20d5e994d8d81a42786a62cd5868acbfc3
Author: Yugo Nagata <nagata@sraoss.co.jp>
Date: Fri Feb 20 06:10:59 2015 +0000
Fix to set SIGCHLD to SIG_DFL instead of SIG_IGN in watchdog processes
When using waitpid, it isn't necessary to set SIGCHLD SIG_IGN. Rather,
waitpid returns ECHLD and WIFEXITED could be zero even when the child
process exit successfully. Due to this, it was recognized that ping
exited abnormally in error.
In addition, signal functions are replaced to pool_singal.
src/watchdog/watchdog.c | 13 ++++++-------
src/watchdog/wd_child.c | 19 +++++++++----------
src/watchdog/wd_heartbeat.c | 37 ++++++++++++++++++-------------------
src/watchdog/wd_if.c | 8 +-------
src/watchdog/wd_lifecheck.c | 1 -
src/watchdog/wd_ping.c | 2 +-
6 files changed, 35 insertions(+), 45 deletions(-)
diff --git a/src/watchdog/watchdog.c b/src/watchdog/watchdog.c
index 3774b7aa4..b70337603 100644
--- a/src/watchdog/watchdog.c
+++ b/src/watchdog/watchdog.c
@@ -24,7 +24,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <signal.h>
#include <ctype.h>
#include <sys/un.h>
#include <sys/types.h>
@@ -177,12 +176,12 @@ fork_a_lifecheck(int fork_wait_time)
init_ps_display("", "", "", "");
- signal(SIGTERM, wd_exit);
- signal(SIGINT, wd_exit);
- signal(SIGQUIT, wd_exit);
- signal(SIGCHLD, SIG_DFL);
- signal(SIGHUP, SIG_IGN);
- signal(SIGPIPE, SIG_IGN);
+ pool_signal(SIGTERM, wd_exit);
+ pool_signal(SIGINT, wd_exit);
+ pool_signal(SIGQUIT, wd_exit);
+ pool_signal(SIGCHLD, SIG_DFL);
+ pool_signal(SIGHUP, SIG_IGN);
+ pool_signal(SIGPIPE, SIG_IGN);
/* Create per loop iteration memory context */
ProcessLoopContext = AllocSetContextCreate(TopMemoryContext,
diff --git a/src/watchdog/wd_child.c b/src/watchdog/wd_child.c
index f9dd9890c..25f13cdfa 100644
--- a/src/watchdog/wd_child.c
+++ b/src/watchdog/wd_child.c
@@ -23,7 +23,6 @@
*/
#include <sys/types.h>
#include <sys/socket.h>
-#include <signal.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
@@ -71,15 +70,15 @@ wd_child(int fork_wait_time)
POOL_SETMASK(&UnBlockSig);
- signal(SIGTERM, wd_child_exit);
- signal(SIGINT, wd_child_exit);
- signal(SIGQUIT, wd_child_exit);
- signal(SIGCHLD, SIG_IGN);
- signal(SIGHUP, SIG_IGN);
- signal(SIGUSR1, SIG_IGN);
- signal(SIGUSR2, SIG_IGN);
- signal(SIGPIPE, SIG_IGN);
- signal(SIGALRM, SIG_IGN);
+ pool_signal(SIGTERM, wd_child_exit);
+ pool_signal(SIGINT, wd_child_exit);
+ pool_signal(SIGQUIT, wd_child_exit);
+ pool_signal(SIGCHLD, SIG_DFL);
+ pool_signal(SIGHUP, SIG_IGN);
+ pool_signal(SIGUSR1, SIG_IGN);
+ pool_signal(SIGUSR2, SIG_IGN);
+ pool_signal(SIGPIPE, SIG_IGN);
+ pool_signal(SIGALRM, SIG_IGN);
init_ps_display("", "", "", "");
diff --git a/src/watchdog/wd_heartbeat.c b/src/watchdog/wd_heartbeat.c
index e608dea40..9974aaafa 100644
--- a/src/watchdog/wd_heartbeat.c
+++ b/src/watchdog/wd_heartbeat.c
@@ -27,7 +27,6 @@
#include <time.h>
#include <string.h>
#include <stdlib.h>
-#include <signal.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <sys/types.h>
@@ -347,15 +346,15 @@ wd_hb_receiver(int fork_wait_time, WdHbIf *hb_if)
POOL_SETMASK(&UnBlockSig);
- signal(SIGTERM, hb_receiver_exit);
- signal(SIGINT, hb_receiver_exit);
- signal(SIGQUIT, hb_receiver_exit);
- signal(SIGCHLD, SIG_IGN);
- signal(SIGHUP, SIG_IGN);
- signal(SIGUSR1, SIG_IGN);
- signal(SIGUSR2, SIG_IGN);
- signal(SIGPIPE, SIG_IGN);
- signal(SIGALRM, SIG_IGN);
+ pool_signal(SIGTERM, hb_receiver_exit);
+ pool_signal(SIGINT, hb_receiver_exit);
+ pool_signal(SIGQUIT, hb_receiver_exit);
+ pool_signal(SIGCHLD, SIG_DFL);
+ pool_signal(SIGHUP, SIG_IGN);
+ pool_signal(SIGUSR1, SIG_IGN);
+ pool_signal(SIGUSR2, SIG_IGN);
+ pool_signal(SIGPIPE, SIG_IGN);
+ pool_signal(SIGALRM, SIG_IGN);
init_ps_display("", "", "", "");
/* Create per loop iteration memory context */
@@ -482,15 +481,15 @@ wd_hb_sender(int fork_wait_time, WdHbIf *hb_if)
POOL_SETMASK(&UnBlockSig);
- signal(SIGTERM, hb_sender_exit);
- signal(SIGINT, hb_sender_exit);
- signal(SIGQUIT, hb_sender_exit);
- signal(SIGCHLD, SIG_IGN);
- signal(SIGHUP, SIG_IGN);
- signal(SIGUSR1, SIG_IGN);
- signal(SIGUSR2, SIG_IGN);
- signal(SIGPIPE, SIG_IGN);
- signal(SIGALRM, SIG_IGN);
+ pool_signal(SIGTERM, hb_sender_exit);
+ pool_signal(SIGINT, hb_sender_exit);
+ pool_signal(SIGQUIT, hb_sender_exit);
+ pool_signal(SIGCHLD, SIG_DFL);
+ pool_signal(SIGHUP, SIG_IGN);
+ pool_signal(SIGUSR1, SIG_IGN);
+ pool_signal(SIGUSR2, SIG_IGN);
+ pool_signal(SIGPIPE, SIG_IGN);
+ pool_signal(SIGALRM, SIG_IGN);
init_ps_display("", "", "", "");
/* Create per loop iteration memory context */
diff --git a/src/watchdog/wd_if.c b/src/watchdog/wd_if.c
index 2bb719b0b..7a278d080 100644
--- a/src/watchdog/wd_if.c
+++ b/src/watchdog/wd_if.c
@@ -180,7 +180,6 @@ exec_if_cmd(char * path,char * command)
int pid, i = 0;
char* buf;
char *bp, *ep;
- sighandler_t sig_org;
if (pipe(pfd) == -1)
{
@@ -219,8 +218,6 @@ exec_if_cmd(char * path,char * command)
}
args[i++] = NULL;
- sig_org = signal(SIGCHLD, SIG_DFL);
-
pid = fork();
if (pid == -1)
{
@@ -246,7 +243,7 @@ exec_if_cmd(char * path,char * command)
{
int result;
result = wait(&status);
- if (result < 0 && errno != ECHILD)
+ if (result < 0)
{
if (errno == EINTR)
continue;
@@ -255,7 +252,6 @@ exec_if_cmd(char * path,char * command)
(errmsg("watchdog exec wait()failed"),
errdetail("wait() system call failed with reason \"%s\"", strerror(errno))));
- signal(SIGCHLD, sig_org);
return WD_NG;
}
@@ -265,7 +261,6 @@ exec_if_cmd(char * path,char * command)
(errmsg("watchdog exec interface up/down command failed"),
errdetail("'%s' failed. exit status: %d",command, WEXITSTATUS(status))));
- signal(SIGCHLD, sig_org);
return WD_NG;
}
else
@@ -276,7 +271,6 @@ exec_if_cmd(char * path,char * command)
ereport(DEBUG1,
(errmsg("watchdog exec interface up/down command: '%s' succeeded", command)));
- signal(SIGCHLD, sig_org);
return WD_OK;
}
diff --git a/src/watchdog/wd_lifecheck.c b/src/watchdog/wd_lifecheck.c
index 3ccd6e006..8b160ccee 100644
--- a/src/watchdog/wd_lifecheck.c
+++ b/src/watchdog/wd_lifecheck.c
@@ -27,7 +27,6 @@
#include <time.h>
#include <string.h>
#include <stdlib.h>
-#include <signal.h>
#include <unistd.h>
#include <netdb.h>
#include "pool.h"
diff --git a/src/watchdog/wd_ping.c b/src/watchdog/wd_ping.c
index dda6f6a65..4f60dc466 100644
--- a/src/watchdog/wd_ping.c
+++ b/src/watchdog/wd_ping.c
@@ -237,7 +237,7 @@ exec_ping(void * arg)
{
int r;
r = waitpid(pid, &status, 0);
- if (r < 0 && errno != ECHILD)
+ if (r < 0)
{
if (errno == EINTR)
continue;
[parent: 80ddec29397f]