[dovecot-cvs] dovecot/src/lib-sql driver-mysql.c,1.7,1.8

cras at dovecot.org cras at dovecot.org
Thu Jun 9 21:31:45 EEST 2005


Update of /var/lib/cvs/dovecot/src/lib-sql
In directory talvi:/tmp/cvs-serv6540

Modified Files:
	driver-mysql.c 
Log Message:
Make MySQL connect abort in 10 seconds if it can't connect.



Index: driver-mysql.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/driver-mysql.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- driver-mysql.c	16 Apr 2005 19:44:10 -0000	1.7
+++ driver-mysql.c	9 Jun 2005 18:31:43 -0000	1.8
@@ -6,10 +6,14 @@
 
 #ifdef HAVE_MYSQL
 #include <stdlib.h>
+#include <unistd.h>
 #include <time.h>
 #include <mysql.h>
 #include <errmsg.h>
 
+/* Abort connect() if it can't connect within this time. */
+#define MYSQL_CONNECT_FAILURE_TIMEOUT 10
+
 /* Minimum delay between reconnecting to same server */
 #define CONNECT_MIN_DELAY 1
 /* Maximum time to avoiding reconnecting to same server */
@@ -65,6 +69,7 @@
 	struct mysql_db *db = conn->db;
 	const char *unix_socket, *host;
 	time_t now;
+	int failed;
 
 	if (conn->connected)
 		return TRUE;
@@ -98,9 +103,12 @@
 #endif
 	}
 
-	if (mysql_real_connect(conn->mysql, host, db->user, db->password,
-			       db->dbname, db->port, unix_socket,
-			       db->client_flags) == NULL) {
+	alarm(MYSQL_CONNECT_FAILURE_TIMEOUT);
+	failed = mysql_real_connect(conn->mysql, host, db->user, db->password,
+				    db->dbname, db->port, unix_socket,
+				    db->client_flags) == NULL;
+	alarm(0);
+	if (failed) {
 		if (conn->connect_failure_count > 0) {
 			/* increase delay between reconnections to this
 			   server */



More information about the dovecot-cvs mailing list