pgpool2.git / summary / log / commit / refs
commit 4faccee16d33fb0a359b179f6734cf95773001f9
Author: Muhammad Usama <m.usama@gmail.com>
Date: Fri Dec 12 18:08:00 2014 +0000
0000119: Signal might be sent to pid=1 (init process) in send_failback_request()
This is more of a guard against a situation where a crash of the pgpool main
process can make the child processes to send the signal to system's init process
A new wrapper function pool_signal_parent() is added for delivering the signal
to pgpool main process from children, The function checks the PPID of process
and compares it with the parent PID saved at the pgpool startup, And if the bids
differ that means the parent pgpool parent process is dead and in that case
the child commits the suicide.
src/include/utils/pool_signal.h | 2 +-
src/main/pgpool_main.c | 2 +-
src/pcp_con/pcp_child.c | 6 +++---
src/pcp_con/recovery.c | 2 +-
src/protocol/pool_process_query.c | 2 +-
src/utils/pool_signal.c | 25 +++++++++++++++++++++++++
6 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/src/include/utils/pool_signal.h b/src/include/utils/pool_signal.h
index 68c9835ec..53e114d80 100644
--- a/src/include/utils/pool_signal.h
+++ b/src/include/utils/pool_signal.h
@@ -57,5 +57,5 @@ int pqsigsetmask(int mask);
typedef void (*pool_sighandler_t) (int);
extern pool_sighandler_t pool_signal(int signo, pool_sighandler_t func);
extern void poolinitmask(void);
-
+extern int pool_signal_parent(int sig);
#endif /* POOL_SIGNAL_H */
diff --git a/src/main/pgpool_main.c b/src/main/pgpool_main.c
index b2a8e4c20..cda23eba2 100644
--- a/src/main/pgpool_main.c
+++ b/src/main/pgpool_main.c
@@ -591,7 +591,7 @@ bool register_node_operation_request(POOL_REQUEST_KIND kind, int* node_id_set, i
POOL_SETMASK(&oldmask);
if(failover_in_progress == false)
{
- kill(getppid(), SIGUSR1);
+ pool_signal_parent(SIGUSR1);
}
}
diff --git a/src/pcp_con/pcp_child.c b/src/pcp_con/pcp_child.c
index 9008f55b7..c92b7b4a7 100644
--- a/src/pcp_con/pcp_child.c
+++ b/src/pcp_con/pcp_child.c
@@ -1501,21 +1501,21 @@ process_shutown_request(char mode)
ereport(DEBUG1,
(errmsg("PCP: processing shutdown request"),
errdetail("sending SIGTERM to the parent process with PID:%d", ppid)));
- kill(ppid, SIGTERM);
+ pool_signal_parent(SIGTERM);
}
else if (mode == 'f')
{
ereport(DEBUG1,
(errmsg("PCP: processing shutdown request"),
errdetail("sending SIGINT to the parent process with PID:%d", ppid)));
- kill(ppid, SIGINT);
+ pool_signal_parent(SIGINT);
}
else if (mode == 'i')
{
ereport(DEBUG1,
(errmsg("PCP: processing shutdown request"),
errdetail("sending SIGQUIT to the parent process with PID:%d", ppid)));
- kill(ppid, SIGQUIT);
+ pool_signal_parent(SIGQUIT);
}
else
{
diff --git a/src/pcp_con/recovery.c b/src/pcp_con/recovery.c
index d19caa4ab..3665ff733 100644
--- a/src/pcp_con/recovery.c
+++ b/src/pcp_con/recovery.c
@@ -195,7 +195,7 @@ void finish_recovery(void)
}
*InRecovery = RECOVERY_INIT;
- kill(getppid(), SIGUSR2);
+ pool_signal_parent(SIGUSR2);
}
/*
diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c
index 82f9ccae4..7ec8354e9 100644
--- a/src/protocol/pool_process_query.c
+++ b/src/protocol/pool_process_query.c
@@ -459,7 +459,7 @@ POOL_STATUS pool_parallel_exec(POOL_CONNECTION *frontend,
(errmsg("executing parallel query"),
errdetail("sending HUP signal to parent")));
- kill(getppid(), SIGHUP); /* send HUP signal to parent */
+ pool_signal_parent(SIGHUP); /* send HUP signal to parent */
/* we need to loop over here since we will get HUP signal while sleeping */
while (stime > 0)
diff --git a/src/utils/pool_signal.c b/src/utils/pool_signal.c
index e8f12e699..3a7a949cb 100644
--- a/src/utils/pool_signal.c
+++ b/src/utils/pool_signal.c
@@ -25,7 +25,10 @@
*/
#include "config.h"
+#include "pool.h"
#include "utils/pool_signal.h"
+#include "utils/elog.h"
+#include <unistd.h>
#include <signal.h>
#ifdef HAVE_SIGPROCMASK
@@ -155,4 +158,26 @@ pool_signal(int signo, pool_sighandler_t func)
#endif /* !HAVE_POSIX_SIGNALS */
}
+int pool_signal_parent(int sig)
+{
+ /*
+ * Check if saved parent pid is same as current parent.
+ * This is a guard against sending the signal to init process
+ * pgpool-II parent process crashed and left the child processes
+ * orphan.
+ */
+ if(mypid != getppid())
+ {
+ /*
+ * pgpool parent is no more alive, commiting sucide.
+ */
+ ereport(PANIC,
+ (errmsg("pgpool-II main process died unexpectedly. exiting current process")));
+ }
+ ereport(DEBUG1,
+ (errmsg("sending %d to the parent process with PID:%d", sig ,mypid)));
+
+ return kill(mypid, sig);
+}
+
#endif /* WIN32 */
[parent: 4e495b960175]