From 93e161256d448a286619dc44de8647385b5f9d17 Mon Sep 17 00:00:00 2001
From: Joshua Colp <jcolp@digium.com>
Date: Mon, 18 Sep 2006 15:15:33 +0000
Subject: [PATCH] Use a better check to ensure database connection is up
 (pointer to connection must exist, and connection must report status being
 ok) (issue #7955 reported by sorg)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@43162 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 res/res_config_pgsql.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index d3d11446a0..4665823f33 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -729,7 +729,7 @@ static int pgsql_reconnect(const char *database)
 		free(connInfo);
 		connInfo = NULL;
 		ast_log(LOG_DEBUG, "pgsqlConn=%p\n", pgsqlConn);
-		if (pgsqlConn) {
+		if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) {
 			ast_log(LOG_DEBUG, "Postgresql RealTime: Successfully connected to database.\n");
 			connect_time = time(NULL);
 			return 1;
-- 
GitLab