pgpool2.git / summary / log / commit / refs
commit 862a6ca3e1d3eb371f4007cacb668a9b79accd90
Author: Yugo Nagata <nagata@sraoss.co.jp>
Date: Fri Feb 01 01:58:44 2013 +0000
Fix segmentation fault while pgpool-II stating up or fail over when
watchdog is enabled. This is caused by wrong usage of pthread, namely
pthread_detach and pthread_join are mixed together. Solution is to
use pthread_join only if we need to get status of child thread. BTW,
the problem could occur on moderately modern OS such as Fedora 17, but
the reason why the problem is not observed on other OSs is, just we
were lucky.
Problem Reported in [pgpool-general: 1179] by Lonni J Friedman.
3.2.1 segfaults at startup on Fedora17.
http://www.sraoss.jp/pipermail/pgpool-general/2012-November/001198.html
Patch provided by chads.
http://www.pgpool.net/mantisbt/view.php?id=48
watchdog/wd_lifecheck.c | 15 +++++++--------
watchdog/wd_packet.c | 15 +++++++--------
watchdog/wd_ping.c | 8 +++-----
3 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/watchdog/wd_lifecheck.c b/watchdog/wd_lifecheck.c
index c78f240df..2b05b4b25 100644
--- a/watchdog/wd_lifecheck.c
+++ b/watchdog/wd_lifecheck.c
@@ -3,7 +3,7 @@
*
* Handles watchdog connection, and protocol communication with pgpool-II
*
- * pgpool: a language independent connection pool server for PostgreSQL
+ * pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
* Copyright (c) 2003-2012 PgPool Global Development Group
@@ -64,7 +64,7 @@ is_wd_lifecheck_ready(void)
{
PQclear(res);
}
- if ((status == PGRES_NONFATAL_ERROR )||
+ if ((status == PGRES_NONFATAL_ERROR )||
(status == PGRES_FATAL_ERROR ))
{
rtn = WD_NG;
@@ -146,7 +146,7 @@ wd_lifecheck(void)
{
int result;
- pool_debug("wd_lifecheck: checking pgpool %d (%s:%d)", i, p->hostname, p->pgpool_port);
+ pool_debug("wd_lifecheck: checking pgpool %d (%s:%d)", i, p->hostname, p->pgpool_port);
rc = pthread_join(thread[i], (void **)&result);
if ((rc != 0) && (errno == EINTR))
@@ -156,7 +156,7 @@ wd_lifecheck(void)
}
if (result == WD_OK)
{
- pool_debug("wd_lifecheck: OK, status: %d", p->status);
+ pool_debug("wd_lifecheck: OK, status: %d", p->status);
p->life = pool_config->wd_life_point;
if ((i == 0) &&
@@ -176,7 +176,7 @@ wd_lifecheck(void)
}
else
{
- pool_debug("wd_lifecheck: NG, status: %d life:%d", p->status, p->life);
+ pool_debug("wd_lifecheck: NG, status: %d life:%d", p->status, p->life);
if (p->life > 0)
{
@@ -199,7 +199,6 @@ wd_lifecheck(void)
}
}
}
- pthread_detach(thread[i]);
i++;
p++;
}
@@ -241,8 +240,8 @@ create_conn(char * hostname, int port)
snprintf(conninfo,sizeof(conninfo),
"host='%s' port='%d' dbname='template1' user='%s' password='%s' connect_timeout='%d'",
- hostname,
- port,
+ hostname,
+ port,
pool_config->recovery_user,
pool_config->recovery_password,
pool_config->wd_interval / 2 + 1);
diff --git a/watchdog/wd_packet.c b/watchdog/wd_packet.c
index 5a1f6d0b3..9be701141 100644
--- a/watchdog/wd_packet.c
+++ b/watchdog/wd_packet.c
@@ -3,7 +3,7 @@
*
* Handles watchdog connection, and protocol communication with pgpool-II
*
- * pgpool: a language independent connection pool server for PostgreSQL
+ * pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
* Copyright (c) 2003-2012 PgPool Global Development Group
@@ -132,7 +132,7 @@ wd_send_packet_no(WD_PACKET_NO packet_no )
/* set add request packet */
packet.packet_no = packet_no;
memcpy(&(packet.wd_body.wd_info),WD_List,sizeof(WdInfo));
- /* send packet to all watchdogs */
+ /* send packet to all watchdogs */
rtn = send_packet_4_nodes(&packet, WD_SEND_TO_MASTER );
if (rtn == WD_OK)
{
@@ -415,7 +415,7 @@ wd_send_packet(int sock, WdPacket * snd_pack)
FD_ZERO(&wmask);
FD_SET(sock,&wmask);
rtn = select(sock+1, (fd_set *)NULL, &wmask, (fd_set *)NULL, &timeout);
-
+
if (rtn < 0 )
{
if (errno == EAGAIN || errno == EINTR)
@@ -426,7 +426,7 @@ wd_send_packet(int sock, WdPacket * snd_pack)
}
else if (rtn & FD_ISSET(sock, &wmask))
{
- s = send(sock,send_ptr + send_size,buf_size - send_size ,flag);
+ s = send(sock,send_ptr + send_size,buf_size - send_size ,flag);
if (s < 0)
{
if (errno == EINTR || errno == EAGAIN)
@@ -467,7 +467,7 @@ wd_recv_packet(int sock, WdPacket * recv_pack)
memset(&buf,0,sizeof(WdPacket));
for (;;)
{
- r = recv(sock,read_ptr + read_size ,len - read_size, 0);
+ r = recv(sock,read_ptr + read_size ,len - read_size, 0);
if (r < 0)
{
if (errno == EINTR || errno == EAGAIN)
@@ -482,7 +482,7 @@ wd_recv_packet(int sock, WdPacket * recv_pack)
read_size += r;
if (read_size == len)
{
-
+
if ((ntohl(buf.packet_no) >= WD_INVALID) &&
(ntohl(buf.packet_no) <= WD_READY ))
{
@@ -673,7 +673,6 @@ send_packet_4_nodes(WdPacket *packet, WD_SEND_TYPE type)
rtn = WD_OK;
}
}
- pthread_detach(thread[i]);
i++;
}
@@ -866,7 +865,7 @@ wd_send_node_packet(WD_PACKET_NO packet_no, int *node_id_set, int count)
memcpy(packet.wd_body.wd_node_info.node_id_set,node_id_set,sizeof(int)*count);
packet.wd_body.wd_node_info.node_num = count;
- /* send packet to all watchdogs */
+ /* send packet to all watchdogs */
rtn = send_packet_4_nodes(&packet, WD_SEND_TO_MASTER );
if (rtn == WD_OK)
{
diff --git a/watchdog/wd_ping.c b/watchdog/wd_ping.c
index ccef70235..e88c9401c 100644
--- a/watchdog/wd_ping.c
+++ b/watchdog/wd_ping.c
@@ -3,7 +3,7 @@
*
* Handles watchdog connection, and protocol communication with pgpool-II
*
- * pgpool: a language independent connection pool server for PostgreSQL
+ * pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
* Copyright (c) 2003-2012 PgPool Global Development Group
@@ -100,7 +100,7 @@ wd_is_upper_ok(char * server_list)
}
if (cnt >= MAX_WATCHDOG_NUM)
{
- pool_debug("wd_is_upper_ok: trusted server num is out of range(%d)",cnt);
+ pool_debug("wd_is_upper_ok: trusted server num is out of range(%d)",cnt);
break;
}
}
@@ -118,7 +118,6 @@ wd_is_upper_ok(char * server_list)
{
rtn = WD_OK;
}
- pthread_detach(thread[i]);
i++;
}
free(buf);
@@ -163,7 +162,6 @@ wd_is_unused_ip(char * ip)
{
rtn = WD_OK;
}
- pthread_detach(thread);
return rtn;
}
@@ -282,7 +280,7 @@ get_result (char * ping_data)
sp = ping_data;
for ( i = 0 ; i < 4 ; i ++)
{
- sp = strchr(sp,'/');
+ sp = strchr(sp,'/');
if (sp == NULL)
{
return -1;
[parent: d3087686b262]