X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fmysql.c;h=448f7cbace4538c21d2195d6235a3787207666de;hp=b6edce0d36115192752fe2a12bb9b4f3f864e27f;hb=a9e50e9e30ecde17e167e271060c8183bfcbf407;hpb=9655d4a6d9fa2c4f02032759b831e93933d68bd9 diff --git a/src/mysql.c b/src/mysql.c index b6edce0d..448f7cba 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -218,7 +218,7 @@ static int mysql_config_database(oconfig_item_t *ci) /* {{{ */ (db->database != NULL) ? db->database : ""); if (db->instance != NULL) - ssnprintf(cb_name, sizeof(cb_name), "mysql-%s", db->instance); + snprintf(cb_name, sizeof(cb_name), "mysql-%s", db->instance); else sstrncpy(cb_name, "mysql", sizeof(cb_name)); @@ -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) */ @@ -496,15 +500,15 @@ static int mysql_read_slave_stats(mysql_database_t *db, MYSQL *con) { if (((io == NULL) || (strcasecmp(io, "yes") != 0)) && (db->slave_io_running)) { n.severity = NOTIF_WARNING; - ssnprintf(n.message, sizeof(n.message), - "slave I/O thread not started or not connected to master"); + snprintf(n.message, sizeof(n.message), + "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; - ssnprintf(n.message, sizeof(n.message), - "slave I/O thread started and connected to master"); + snprintf(n.message, sizeof(n.message), + "slave I/O thread started and connected to master"); plugin_dispatch_notification(&n); db->slave_io_running = 1; } @@ -512,13 +516,13 @@ static int mysql_read_slave_stats(mysql_database_t *db, MYSQL *con) { if (((sql == NULL) || (strcasecmp(sql, "yes") != 0)) && (db->slave_sql_running)) { n.severity = NOTIF_WARNING; - ssnprintf(n.message, sizeof(n.message), "slave SQL thread not started"); + snprintf(n.message, sizeof(n.message), "slave SQL thread not started"); plugin_dispatch_notification(&n); db->slave_sql_running = 0; } else if (((sql != NULL) && (strcasecmp(sql, "yes") == 0)) && (!db->slave_sql_running)) { n.severity = NOTIF_OKAY; - ssnprintf(n.message, sizeof(n.message), "slave SQL thread started"); + snprintf(n.message, sizeof(n.message), "slave SQL thread started"); plugin_dispatch_notification(&n); db->slave_sql_running = 1; }