X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmysql.c;h=448f7cbace4538c21d2195d6235a3787207666de;hb=358bf39b09f69220fc8e1b6c2fe98e5e185e3364;hp=cfc9b59f7a7f53825a883abac0ab5e5be8cd6927;hpb=be126043c2be20399d7670fe194645292018bde0;p=collectd.git diff --git a/src/mysql.c b/src/mysql.c index cfc9b59f..448f7cba 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -270,12 +270,16 @@ static MYSQL *getconnection(mysql_database_t *db) { } db->is_connected = 0; + /* Close the old connection before initializing a new one. */ + if (db->con != NULL) { + mysql_close(db->con); + db->con = NULL; + } + + db->con = mysql_init(NULL); if (db->con == NULL) { - db->con = mysql_init(NULL); - if (db->con == NULL) { - ERROR("mysql plugin: mysql_init failed: %s", mysql_error(db->con)); - return NULL; - } + ERROR("mysql plugin: mysql_init failed: %s", mysql_error(db->con)); + return NULL; } /* Configure TCP connect timeout (default: 0) */ @@ -497,14 +501,14 @@ static int mysql_read_slave_stats(mysql_database_t *db, MYSQL *con) { (db->slave_io_running)) { n.severity = NOTIF_WARNING; snprintf(n.message, sizeof(n.message), - "slave I/O thread not started or not connected to master"); + "slave I/O thread not started or not connected to master"); plugin_dispatch_notification(&n); db->slave_io_running = 0; } else if (((io != NULL) && (strcasecmp(io, "yes") == 0)) && (!db->slave_io_running)) { n.severity = NOTIF_OKAY; snprintf(n.message, sizeof(n.message), - "slave I/O thread started and connected to master"); + "slave I/O thread started and connected to master"); plugin_dispatch_notification(&n); db->slave_io_running = 1; }