Skip to contentSkip to conversation

ulogd mysql fix

PATCH In review Eric Leblond 2 participants 4 messages Aug 1, 2007 – Aug 6, 2007 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ulogd mysql fix

Hi,

MySQL 5.0 has changed the default for database reconnection after timeout. It is now not enabled by default. The following patch restores the reconnection functionnality for the ulogd-mysql plugin.

BR,

Signature · 3 lines
Éric Leblond, [email protected]
Téléphone : 01 44 89 46 39, Fax : 01 44 89 45 01
INL, http://www.inl.fr
ulogd_MYSQL.c +16 -0
Index: mysql/ulogd_MYSQL.c
===================================================================
@@ -407,6 +407,9 @@
 static int mysql_open_db(char *server, int port, char *user, char *pass, 
 			 char *db)
 {
+#ifdef MYSQL_OPT_RECONNECT
+	my_bool trueval = 1;
+#endif 
 	dbh = mysql_init(NULL);
 	if (!dbh)
 		return -1;
@@ -415,12 +418,25 @@
 		mysql_options(dbh, MYSQL_OPT_CONNECT_TIMEOUT,
 			(const char *) &connect_timeout_ce.u.value);
 
+#ifdef MYSQL_OPT_RECONNECT
+#  if defined(MYSQL_VERSION_ID) && (MYSQL_VERSION_ID >= 50019)
+	mysql_options(dbh, MYSQL_OPT_RECONNECT, &trueval);
+#  endif
+#endif 
+
+
 	if (!mysql_real_connect(dbh, server, user, pass, db, port, NULL, 0))
 	{
 		_mysql_fini();
 		return -1;
 	}
 
+#ifdef MYSQL_OPT_RECONNECT
+#  if defined(MYSQL_VERSION_ID) && (MYSQL_VERSION_ID < 50019)
+	mysql_options(dbh, MYSQL_OPT_RECONNECT, &trueval);
+#  endif
+#endif
+
 	return 0;
 }
 
#1 lore raw

Hi Eric,

Quoted 3 lines · Eric Leblond

MySQL 5.0 has changed the default for database reconnection after timeout. It is now not enabled by default. The following patch restores the reconnection functionnality for the ulogd-mysql plugin.

Why don't we inconditionally enable it? I mean, we can just forget about the version checking. If I understood well, mysql <= 5.0 enables reconnection by default and >= 5.0 doesn't, so we can inconditionally enable it and forget about future default behaviours. What do you think?

Signature · 2 lines
"Será preciso viajar a través de los ojos de los idiotas" -- Poeta en
Nueva York -- Federico García Lorca.
#2 lore raw

Hi,

Quoted 11 lines · Pablo Neira Ayuso

Hi Eric,

Quoted 3 lines · Eric Leblond

MySQL 5.0 has changed the default for database reconnection after timeout. It is now not enabled by default. The following patch restores the reconnection functionnality for the ulogd-mysql plugin.

Why don't we inconditionally enable it? I mean, we can just forget about the version checking. If I understood well, mysql <= 5.0 enables reconnection by default and >= 5.0 doesn't, so we can inconditionally enable it and forget about future default behaviours. What do you think?

In fact, MYSQL_OPT_RECONNECT option has been introduced in MySQL 5.0.13 to restore the capability to reconnect to server after inactivity. Furthermore, the functionnality was partially broken before 5.0.19 and this explains the two calls to mysql_option.

BR,

Signature · 3 lines
Éric Leblond, [email protected]
Téléphone : 01 44 89 46 39, Fax : 01 44 89 45 01
INL, http://www.inl.fr
#3 lore raw
Quoted 4 lines · Eric Leblond

In fact, MYSQL_OPT_RECONNECT option has been introduced in MySQL 5.0.13 to restore the capability to reconnect to server after inactivity. Furthermore, the functionnality was partially broken before 5.0.19 and this explains the two calls to mysql_option.

Ick! scary thing. Two point less for the mysql guys... Applied, thanks Eric.

Signature · 2 lines
"Será preciso viajar a través de los ojos de los idiotas" -- Poeta en
Nueva York -- Federico García Lorca.