X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fmysql.c;h=40707be364f8e0818decb3fbff5ad527a8f55a85;hp=b6edce0d36115192752fe2a12bb9b4f3f864e27f;hb=d486225f89ea52d8ed2b4242eba2ad94c409f837;hpb=662c44a84ae3daecd4ffdea940fffce35a41b52a diff --git a/src/mysql.c b/src/mysql.c index b6edce0d..40707be3 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; /* }}} */ @@ -147,8 +147,8 @@ static int mysql_config_database(oconfig_item_t *ci) /* {{{ */ db->timeout = 0; /* trigger a notification, if it's not running */ - db->slave_io_running = 1; - db->slave_sql_running = 1; + db->slave_io_running = true; + db->slave_sql_running = true; status = cf_util_get_string(ci, &db->instance); if (status != 0) { @@ -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)); @@ -268,14 +268,18 @@ static MYSQL *getconnection(mysql_database_t *db) { WARNING("mysql plugin: Lost connection to instance \"%s\": %s", db->instance, mysql_error(db->con)); } - db->is_connected = 0; + db->is_connected = false; + /* 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) */ @@ -301,7 +305,7 @@ static MYSQL *getconnection(mysql_database_t *db) { mysql_get_host_info(db->con), (cipher != NULL) ? cipher : "", mysql_get_server_info(db->con), mysql_get_proto_info(db->con)); - db->is_connected = 1; + db->is_connected = true; return db->con; } /* static MYSQL *getconnection (mysql_database_t *db) */ @@ -496,31 +500,31 @@ 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; + db->slave_io_running = false; } 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; + db->slave_io_running = true; } 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; + db->slave_sql_running = false; } 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; + db->slave_sql_running = true; } }