diff --git a/src/watchdog/wd_lifecheck.c b/src/watchdog/wd_lifecheck.c index a9790d48..ac6dff84 100644 --- a/src/watchdog/wd_lifecheck.c +++ b/src/watchdog/wd_lifecheck.c @@ -62,7 +62,8 @@ typedef struct { LifeCheckNode *lifeCheckNode; int retry; /* retry times (not used?) */ -} WdPgpoolThreadArg; + char *password; +}WdPgpoolThreadArg; typedef struct WdUpstreamConnectionData { @@ -80,7 +81,7 @@ static bool wd_ping_all_server(void); static WdUpstreamConnectionData * wd_get_server_from_pid(pid_t pid); static void *thread_ping_pgpool(void *arg); -static PGconn *create_conn(char *hostname, int port); +static PGconn *create_conn(char *hostname, int port, char *password); static pid_t lifecheck_main(void); static void check_pgpool_status(void); @@ -103,7 +104,7 @@ static const char *lifecheck_child_name(pid_t pid); static void reaper(void); static int is_wd_lifecheck_ready(void); static int wd_lifecheck(void); -static int wd_ping_pgpool(LifeCheckNode * node); +static int wd_ping_pgpool(LifeCheckNode * node, char *password); static pid_t fork_lifecheck_child(void); @@ -644,11 +645,13 @@ is_wd_lifecheck_ready(void) for (i = 0; i < gslifeCheckCluster->nodeCount; i++) { LifeCheckNode *node = &gslifeCheckCluster->lifeCheckNodes[i]; + char *password = get_pgpool_config_user_password(pool_config->wd_lifecheck_user, + pool_config->wd_lifecheck_password); /* query mode */ if (pool_config->wd_lifecheck_method == LIFECHECK_BY_QUERY) { - if (wd_ping_pgpool(node) == WD_NG) + if (wd_ping_pgpool(node, password) == WD_NG) { ereport(DEBUG1, (errmsg("watchdog checking life check is ready"), @@ -656,6 +659,8 @@ is_wd_lifecheck_ready(void) i, node->hostName, node->pgpoolPort))); rtn = WD_NG; } + if (password) + pfree(password); } /* heartbeat mode */ else if (pool_config->wd_lifecheck_method == LIFECHECK_BY_HB) @@ -803,6 +808,8 @@ check_pgpool_status_by_query(void) LifeCheckNode *node; int rc, i; + char *password = get_pgpool_config_user_password(pool_config->wd_lifecheck_user, + pool_config->wd_lifecheck_password); /* thread init */ pthread_attr_init(&attr); @@ -813,6 +820,7 @@ check_pgpool_status_by_query(void) { node = &gslifeCheckCluster->lifeCheckNodes[i]; thread_arg[i].lifeCheckNode = node; + thread_arg[i].password = password; rc = watchdog_thread_create(&thread[i], &attr, thread_ping_pgpool, (void *) &thread_arg[i]); } @@ -874,6 +882,8 @@ check_pgpool_status_by_query(void) inform_node_status(node, "unable to connect to node"); } } + if (password) + pfree(password); } } @@ -887,7 +897,7 @@ thread_ping_pgpool(void *arg) uintptr_t rtn; WdPgpoolThreadArg *thread_arg = (WdPgpoolThreadArg *) arg; - rtn = (uintptr_t) wd_ping_pgpool(thread_arg->lifeCheckNode); + rtn = (uintptr_t) wd_ping_pgpool(thread_arg->lifeCheckNode,thread_arg->password); pthread_exit((void *) rtn); } @@ -896,13 +906,10 @@ thread_ping_pgpool(void *arg) * Create connection to pgpool */ static PGconn * -create_conn(char *hostname, int port) +create_conn(char *hostname, int port, char *password) { static char conninfo[1024]; PGconn *conn; - char *password = get_pgpool_config_user_password(pool_config->wd_lifecheck_user, - pool_config->wd_lifecheck_password); - if (strlen(pool_config->wd_lifecheck_dbname) == 0) { @@ -928,9 +935,6 @@ create_conn(char *hostname, int port) pool_config->wd_interval / 2 + 1); conn = PQconnectdb(conninfo); - if (password) - pfree(password); - if (PQstatus(conn) != CONNECTION_OK) { ereport(DEBUG1, @@ -987,11 +991,11 @@ wd_check_heartbeat(LifeCheckNode * node) * Check if pgpool can accept the lifecheck query. */ static int -wd_ping_pgpool(LifeCheckNode * node) +wd_ping_pgpool(LifeCheckNode * node, char* password) { PGconn *conn; - conn = create_conn(node->hostName, node->pgpoolPort); + conn = create_conn(node->hostName, node->pgpoolPort, password); if (conn == NULL) return WD_NG; return ping_pgpool(conn);