[Asterisk-cvs] asterisk-addons res_config_mysql.c,1.1,1.2

markster at lists.digium.com markster at lists.digium.com
Fri Jan 7 13:09:03 CST 2005


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

Modified Files:
	res_config_mysql.c 
Log Message:
Fix locking on reconnect (bug #3248)


Index: res_config_mysql.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/res_config_mysql.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- res_config_mysql.c	3 Dec 2004 01:42:01 -0000	1.1
+++ res_config_mysql.c	7 Jan 2005 19:13:49 -0000	1.2
@@ -602,21 +602,25 @@
 
 static int mysql_reconnect()
 {
+	ast_mutex_lock(&mysql_lock);
 	if((!connected) && (dbhost || dbsock) && dbuser && dbpass && dbname) {
 		if(!mysql_init(&mysql)) {
 			ast_log(LOG_WARNING, "MySQL RealTime: Insufficient memory to allocate MySQL resource.\n");
 			connected = 0;
+			ast_mutex_unlock(&mysql_lock);
 			return 0;
 		}
 		if(mysql_real_connect(&mysql, dbhost, dbuser, dbpass, dbname, dbport, dbsock, 0)) {
 			ast_log(LOG_DEBUG, "MySQL RealTime: Successfully connected to database.\n");
 			connected = 1;
 			connect_time = time(NULL);
+			ast_mutex_unlock(&mysql_lock);
 			return 1;
 		} else {
 			ast_log(LOG_ERROR, "MySQL RealTime: Failed to connect database server %s on %s. Check debug for more info.\n", dbname, dbhost);
 			ast_log(LOG_DEBUG, "MySQL RealTime: Cannot Connect: %s\n", mysql_error(&mysql));
 			connected = 0;
+			ast_mutex_unlock(&mysql_lock);
 			return 0;
 		}
 	} else {
@@ -627,10 +631,12 @@
 			connected = 0;
 			ast_log(LOG_ERROR, "MySQL RealTime: Attempted to reconnect. Failed. Check debug for more info.\n");
 			ast_log(LOG_DEBUG, "MySQL RealTime: Server Error: %s\n", mysql_error(&mysql));
+			ast_mutex_unlock(&mysql_lock);
 			return 0;
 		}
 		ast_log(LOG_DEBUG, "MySQL RealTime: Everything is fine.\n");
 		connected = 1;
+		ast_mutex_unlock(&mysql_lock);
 		return 1;
 	}
 }




More information about the svn-commits mailing list