pgpool2.git / summary / log / commit / refs
commit c7e4261ff3da96a4b6fdea039eea4aa95fa63a5c
Author: at.mitani <at.mitani@gmail.com>
Date: Wed Jun 13 02:47:21 2012 +0000
modified pool_config for watchdog, add ps_display in watchdog.
pool_config.c | 2 +-
pool_config.l | 6 +++---
watchdog/watchdog.c | 34 +++++++++++++++++++++-------------
watchdog/wd_child.c | 21 ++++++++++++++-------
watchdog/wd_ext.h | 7 +++++--
watchdog/wd_packet.c | 8 ++++++++
6 files changed, 52 insertions(+), 26 deletions(-)
diff --git a/pool_config.c b/pool_config.c
index 57f3feb46..1787c2258 100644
--- a/pool_config.c
+++ b/pool_config.c
@@ -1861,7 +1861,7 @@ int pool_init_config(void)
pool_config->other_wd = malloc(sizeof(WdDesc));
if (pool_config->other_wd == NULL)
{
- pool_error("failed to allocate pool_config->other_wd");
+ pool_error("failed to allocate pool_config->cwother_wd");
return -1;
}
memset(pool_config->other_wd,0,sizeof(WdDesc));
diff --git a/pool_config.l b/pool_config.l
index 3f5651042..eeea265f6 100644
--- a/pool_config.l
+++ b/pool_config.l
@@ -1918,16 +1918,16 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
WD_INFO(slot).pgpool_port = atoi(yytext);
}
- else if (!strncmp(key, "other_pgpool_wd_port", 20) &&
+ else if (!strncmp(key, "other_wd_port", 13) &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
mypid == getpid()) /* this parameter must be modified by parent pid */
{
int slot;
- slot = atoi(key + 20);
+ slot = atoi(key + 13);
if (slot < 0 || slot >= MAX_CONNECTION_SLOTS)
{
- pool_error("pool_config: pgpool number %s for other_pgpool_wd_port out of range", key);
+ pool_error("pool_config: pgpool number %s for other_wd_port out of range", key);
fclose(fd);
return(-1);
}
diff --git a/watchdog/watchdog.c b/watchdog/watchdog.c
index 61c955a87..2d3c4d143 100644
--- a/watchdog/watchdog.c
+++ b/watchdog/watchdog.c
@@ -39,8 +39,9 @@
WdInfo * WD_List = NULL; /* watchdog server list */
unsigned char * WD_Node_List = NULL; /* node list */
+static pid_t child_pid;
-int wd_main(int fork_wait_time);
+pid_t wd_main(int fork_wait_time);
static void child_wait(int signo);
static void wd_exit(int exit_status);
static int wd_check_config(void);
@@ -70,6 +71,7 @@ wd_exit(int exit_signo)
wd_notice_server_down();
+ kill (child_pid, exit_signo);
kill (0, exit_signo);
child_wait(0);
@@ -91,7 +93,7 @@ wd_check_config(void)
}
-int
+pid_t
wd_main(int fork_wait_time)
{
int status = WD_INIT;
@@ -100,14 +102,14 @@ wd_main(int fork_wait_time)
if (!pool_config->use_watchdog)
{
- return WD_NG;
+ return 0;
}
/* check pool_config data */
status = wd_check_config();
if (status != WD_OK)
{
pool_error("wd_check_config failed");
- return WD_NG;
+ return 0;
}
/* initialize */
@@ -115,23 +117,31 @@ wd_main(int fork_wait_time)
if (status != WD_OK)
{
pool_error("wd_init failed");
- return WD_NG;
+ return 0;
}
/* launch child process */
- status = wd_child(1);
- if (status != WD_OK)
+ child_pid = wd_child(1);
+ if (child_pid < 0 )
{
pool_error("lunch wd_child failed");
- return WD_NG;
+ return child_pid;
}
pgid = getpgid(0);
pid = fork();
if (pid != 0)
{
- return WD_OK;
+ return pid;
+ }
+
+ if (fork_wait_time > 0) {
+ sleep(fork_wait_time);
}
+
+ myargv = save_ps_display_args(myargc, myargv);
+
+ init_ps_display("", "", "", "");
signal(SIGCHLD, SIG_DFL);
signal(SIGHUP, SIG_IGN);
@@ -141,10 +151,7 @@ wd_main(int fork_wait_time)
signal(SIGPIPE, SIG_IGN);
setpgid(0,pgid);
- if (fork_wait_time > 0) {
- sleep(fork_wait_time);
- }
-
+ set_ps_display("lifecheck",false);
/* wait until ready to go */
while (WD_OK != is_wd_lifecheck_ready())
{
@@ -158,4 +165,5 @@ wd_main(int fork_wait_time)
wd_lifecheck();
sleep(pool_config->wd_interval);
}
+ return pid;
}
diff --git a/watchdog/wd_child.c b/watchdog/wd_child.c
index 940e87ab4..56bf9d5e3 100644
--- a/watchdog/wd_child.c
+++ b/watchdog/wd_child.c
@@ -34,11 +34,11 @@
#include "watchdog.h"
#include "wd_ext.h"
-int wd_child(int fork_wait_time);
+pid_t wd_child(int fork_wait_time);
static void wd_child_exit(int exit_signo);
static int send_response(int sock, WdPacket * recv_pack);
-int
+pid_t
wd_child(int fork_wait_time)
{
int sock;
@@ -51,9 +51,16 @@ wd_child(int fork_wait_time)
pid = fork();
if (pid != 0)
{
- return WD_OK;
+ return pid;
}
+ if (fork_wait_time > 0)
+ {
+ sleep(fork_wait_time);
+ }
+
+ myargv = save_ps_display_args(myargc, myargv);
+
signal(SIGTERM, wd_child_exit);
signal(SIGINT, wd_child_exit);
signal(SIGQUIT, wd_child_exit);
@@ -65,10 +72,8 @@ wd_child(int fork_wait_time)
signal(SIGALRM, SIG_IGN);
setpgid(0,pgid);
- if (fork_wait_time > 0)
- {
- sleep(fork_wait_time);
- }
+ init_ps_display("", "", "", "");
+
if (WD_List == NULL)
{
/* memory allocate is not ready */
@@ -80,6 +85,7 @@ wd_child(int fork_wait_time)
/* socket create failed */
wd_child_exit(15);
}
+ set_ps_display("watchdog",false);
/* child loop */
for(;;)
{
@@ -96,6 +102,7 @@ wd_child(int fork_wait_time)
}
close(fd);
}
+ return pid;
}
static void
diff --git a/watchdog/wd_ext.h b/watchdog/wd_ext.h
index 9b1d74a0e..2c21cd496 100644
--- a/watchdog/wd_ext.h
+++ b/watchdog/wd_ext.h
@@ -27,10 +27,10 @@
#define WD_EXT_H
/* watchdog.c */
-extern int wd_main(int fork_wait_time);
+extern pid_t wd_main(int fork_wait_time);
/* wd_child.c */
-extern int wd_child(int fork_wait_time);
+extern pid_t wd_child(int fork_wait_time);
/* wd_init.c */
extern int wd_init(void);
@@ -71,4 +71,7 @@ extern int wd_IP_down(void);
extern int is_wd_lifecheck_ready(void);
extern int wd_lifecheck(void);
+/* main.c */
+extern int myargc;
+extern char **myargv;
#endif /* WD_EXT_H */
diff --git a/watchdog/wd_packet.c b/watchdog/wd_packet.c
index acbfbdbd7..449a8f9bb 100644
--- a/watchdog/wd_packet.c
+++ b/watchdog/wd_packet.c
@@ -561,6 +561,10 @@ send_packet_4_nodes(WdPacket *packet, WD_SEND_TYPE type)
{
return WD_NG;
}
+ if ((type == WD_SEND_TO_MASTER) && (p->status == WD_MASTER))
+ {
+ return WD_OK;
+ }
/* thread init */
pthread_attr_init(&attr);
@@ -600,6 +604,10 @@ send_packet_4_nodes(WdPacket *packet, WD_SEND_TYPE type)
p++;
}
+ if ((type == WD_SEND_TO_MASTER) && (cnt == 0))
+ {
+ return WD_OK;
+ }
pthread_attr_destroy(&attr);
rtn = (packet->packet_no == WD_STAND_FOR_MASTER)?WD_OK:WD_NG;
for (i=0; i<cnt; )
[parent: 6b86c284432c]