From dde78609dede4293f16fb8763d254f2a54d23d28 Mon Sep 17 00:00:00 2001 From: laforge Date: Mon, 1 Aug 2005 06:49:59 +0000 Subject: Today we have had to reboot our firewall and due to a loose crossover cable (sigh) between the firewall and the logger machine, ulogd was unable to connect to the mysql server. That resulted effectively a hang in the boot process: being unable to connect mysql_real_connect did not return (or the socket timeout was so long I was unable to wait out), ulogd could not reach the point to fork and init could not start the daemons, processes following ulogd. The attached simple patch adds the connect_timeout parameter to the MYSQL section and calls mysql_option when connect_timeout is set. (Jozsef Kadlecsik) --- ulogd/mysql/ulogd_MYSQL.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'ulogd') diff --git a/ulogd/mysql/ulogd_MYSQL.c b/ulogd/mysql/ulogd_MYSQL.c index 7765c71..9014a29 100644 --- a/ulogd/mysql/ulogd_MYSQL.c +++ b/ulogd/mysql/ulogd_MYSQL.c @@ -125,6 +125,12 @@ static config_entry_t reconnect_ce = { .type = CONFIG_TYPE_INT, }; +static config_entry_t connect_timeout_ce = { + .next = &reconnect_ce, + .key = "connect_timeout", + .type = CONFIG_TYPE_INT, +}; + static int _mysql_init_db(ulog_iret_t *result); /* our main output function, called by ulogd */ @@ -364,6 +370,9 @@ static int mysql_open_db(char *server, int port, char *user, char *pass, if (!dbh) return -1; + if (connect_timeout_ce.u.value) + mysql_options(dbh, MYSQL_OPT_CONNECT_TIMEOUT, (const char *) &connect_timeout_ce.u.value); + if (!mysql_real_connect(dbh, server, user, pass, db, port, NULL, 0)) return -1; @@ -422,7 +431,7 @@ static int _mysql_init_db(ulog_iret_t *result) static int _mysql_init(void) { /* have the opts parsed */ - config_parse_file("MYSQL", &reconnect_ce); + config_parse_file("MYSQL", &connect_timeout_ce); return _mysql_init_db(NULL); } -- cgit v1.2.3