[Asterisk-cvs] asterisk/cdr cdr_pgsql.c,1.14,1.15

markster at lists.digium.com markster at lists.digium.com
Sat Feb 19 14:12:06 CST 2005


Update of /usr/cvsroot/asterisk/cdr
In directory mongoose.digium.com:/tmp/cvs-serv8517/cdr

Modified Files:
	cdr_pgsql.c 
Log Message:
Make cdr_pgsql gracefully handle restarts (bug #3628)


Index: cdr_pgsql.c
===================================================================
RCS file: /usr/cvsroot/asterisk/cdr/cdr_pgsql.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cdr_pgsql.c	25 Jan 2005 06:10:19 -0000	1.14
+++ cdr_pgsql.c	19 Feb 2005 20:10:52 -0000	1.15
@@ -132,6 +132,19 @@
                         pgerror = PQresultErrorMessage(result);
 			ast_log(LOG_ERROR,"cdr_pgsql: Failed to insert call detail record into database!\n");
                         ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
+			ast_log(LOG_ERROR,"cdr_pgsql: Connection may have been lost... attempting to reconnect.\n");
+			PQreset(conn);
+			if (PQstatus(conn) == CONNECTION_OK) {
+				ast_log(LOG_ERROR, "cdr_pgsql: Connection reestablished.\n");
+				connected = 1;
+				result = PQexec(conn, sqlcmd);
+				if ( PQresultStatus(result) != PGRES_COMMAND_OK)
+				{
+					pgerror = PQresultErrorMessage(result);
+					ast_log(LOG_ERROR,"cdr_pgsql: HARD ERROR!  Attempted reconnection failed.  DROPPING CALL RECORD!\n");
+					ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
+				}
+			}
 			ast_mutex_unlock(&pgsql_lock);
 			return -1;
 		}
@@ -314,7 +327,7 @@
 		connected = 1;
 	} else {
                 pgerror = PQerrorMessage(conn);
-		ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s.  Calls will not be logged!\n", pghostname);
+		ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s.  CALLS WILL NOT BE LOGGED!!\n", pghostname);
                 ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror);
 		connected = 0;
 	}




More information about the svn-commits mailing list