X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmysql.c;h=1396e9541cfe84cd5ed63120e0d0dd63d9c19a1e;hb=61a4ed99b1a5b6d371bb745933d0efc5dff9505c;hp=7fe6d76470724861304a0a601d24c1993d19da2b;hpb=65bdbbfb9c6b287de835e5aa81faee8cd864c1e9;p=collectd.git diff --git a/src/mysql.c b/src/mysql.c index 7fe6d764..1396e954 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -58,17 +58,17 @@ struct mysql_database_s /* {{{ */ int port; int timeout; - _Bool master_stats; - _Bool slave_stats; - _Bool innodb_stats; - _Bool wsrep_stats; + bool master_stats; + bool slave_stats; + bool innodb_stats; + bool wsrep_stats; - _Bool slave_notif; - _Bool slave_io_running; - _Bool slave_sql_running; + bool slave_notif; + bool slave_io_running; + bool slave_sql_running; MYSQL *con; - _Bool is_connected; + bool is_connected; }; typedef struct mysql_database_s mysql_database_t; /* }}} */ @@ -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) */