From: Florian Forster Date: Sat, 6 Jun 2015 20:33:34 +0000 (+0200) Subject: src/daemon/plugin.[ch]: Use cdtime_t for the interval argument of "register complex... X-Git-Tag: collectd-5.6.0~702 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=cce136946b879557f91183e4de58e92b81e138c8;p=collectd.git src/daemon/plugin.[ch]: Use cdtime_t for the interval argument of "register complex read". All plugins converted to "struct timespec", just so that plugin_register_complex_read() would convert back to cdtime_t again. This patch removed this crazyness; the new "determine automatically" value is zero (used to be NULL). --- diff --git a/src/apache.c b/src/apache.c index 0c6318e3..82a267b5 100644 --- a/src/apache.c +++ b/src/apache.c @@ -254,7 +254,7 @@ static int config_add (oconfig_item_t *ci) status = plugin_register_complex_read (/* group = */ NULL, /* name = */ callback_name, /* callback = */ apache_read_host, - /* interval = */ NULL, + /* interval = */ 0, /* user_data = */ &ud); } diff --git a/src/curl_json.c b/src/curl_json.c index 3a5a3ab8..937a237e 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -763,9 +763,6 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ { user_data_t ud; char *cb_name; - struct timespec interval = { 0, 0 }; - - CDTIME_T_TO_TIMESPEC (db->interval, &interval); if (db->instance == NULL) db->instance = strdup("default"); @@ -781,7 +778,7 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ db->instance, db->url ? db->url : db->sock); plugin_register_complex_read (/* group = */ NULL, cb_name, cj_read, - /* interval = */ (db->interval > 0) ? &interval : NULL, + /* interval = */ db->interval, &ud); sfree (cb_name); } diff --git a/src/curl_xml.c b/src/curl_xml.c index 689d5e15..97b964bf 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -1015,7 +1015,7 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */ cb_name = ssnprintf_alloc ("curl_xml-%s-%s", db->instance, db->url); plugin_register_complex_read (/* group = */ "curl_xml", cb_name, cx_read, - /* interval = */ NULL, &ud); + /* interval = */ 0, &ud); sfree (cb_name); } else diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index 3d364458..b3cb97f6 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -1245,7 +1245,7 @@ int plugin_register_read (const char *name, int plugin_register_complex_read (const char *group, const char *name, plugin_read_cb callback, - const struct timespec *interval, + cdtime_t interval, user_data_t *user_data) { read_func_t *rf; @@ -1266,10 +1266,7 @@ int plugin_register_complex_read (const char *group, const char *name, rf->rf_group[0] = '\0'; rf->rf_name = strdup (name); rf->rf_type = RF_COMPLEX; - if (interval != NULL) - rf->rf_interval = TIMESPEC_TO_CDTIME_T (interval); - else - rf->rf_interval = plugin_get_interval (); + rf->rf_interval = (interval != 0) ? interval : plugin_get_interval (); /* Set user data */ if (user_data == NULL) diff --git a/src/daemon/plugin.h b/src/daemon/plugin.h index 70a22326..2e20da4c 100644 --- a/src/daemon/plugin.h +++ b/src/daemon/plugin.h @@ -293,7 +293,7 @@ int plugin_register_read (const char *name, * "plugin_register_complex_read" returns an error (non-zero). */ int plugin_register_complex_read (const char *group, const char *name, plugin_read_cb callback, - const struct timespec *interval, + cdtime_t interval, user_data_t *user_data); int plugin_register_write (const char *name, plugin_write_cb callback, user_data_t *user_data); diff --git a/src/dbi.c b/src/dbi.c index a7963ea2..d2b9a0ea 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -406,7 +406,7 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ plugin_register_complex_read (/* group = */ NULL, /* name = */ name ? name : db->name, /* callback = */ cdbi_read_database, - /* interval = */ NULL, + /* interval = */ 0, /* user_data = */ &ud); free (name); } diff --git a/src/java.c b/src/java.c index 2f1efbf1..56a39d40 100644 --- a/src/java.c +++ b/src/java.c @@ -1438,7 +1438,7 @@ static jint JNICALL cjni_api_register_read (JNIEnv *jvm_env, /* {{{ */ ud.free_func = cjni_callback_info_destroy; plugin_register_complex_read (/* group = */ NULL, cbi->name, cjni_read, - /* interval = */ NULL, &ud); + /* interval = */ 0, &ud); (*jvm_env)->DeleteLocalRef (jvm_env, o_read); diff --git a/src/memcached.c b/src/memcached.c index e2ccfee6..ab9de56f 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -565,7 +565,7 @@ static int memcached_add_read_callback (memcached_t *st) status = plugin_register_complex_read (/* group = */ "memcached", /* name = */ callback_name, /* callback = */ memcached_read, - /* interval = */ NULL, + /* interval = */ 0, /* user_data = */ &ud); return (status); } /* int memcached_add_read_callback */ diff --git a/src/modbus.c b/src/modbus.c index e24f2ec8..97840fd6 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -1017,18 +1017,15 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */ { user_data_t ud; char name[1024]; - struct timespec interval = { 0, 0 }; ud.data = host; ud.free_func = host_free; ssnprintf (name, sizeof (name), "modbus-%s", host->host); - CDTIME_T_TO_TIMESPEC (host->interval, &interval); - plugin_register_complex_read (/* group = */ NULL, name, /* callback = */ mb_read, - /* interval = */ (host->interval > 0) ? &interval : NULL, + /* interval = */ host->interval, &ud); } else diff --git a/src/mysql.c b/src/mysql.c index 00cba094..bf77a2ff 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -213,7 +213,7 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */ plugin_register_complex_read (/* group = */ NULL, cb_name, mysql_read, - /* interval = */ NULL, &ud); + /* interval = */ 0, &ud); } else { diff --git a/src/netapp.c b/src/netapp.c index f446d597..020bfba1 100644 --- a/src/netapp.c +++ b/src/netapp.c @@ -2906,7 +2906,6 @@ static int cna_read (user_data_t *ud); static int cna_register_host (host_config_t *host) /* {{{ */ { char cb_name[256]; - struct timespec interval; user_data_t ud; if (host->vfiler) @@ -2915,15 +2914,13 @@ static int cna_register_host (host_config_t *host) /* {{{ */ else ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name); - CDTIME_T_TO_TIMESPEC (host->interval, &interval); - memset (&ud, 0, sizeof (ud)); ud.data = host; ud.free_func = (void (*) (void *)) free_host_config; plugin_register_complex_read (/* group = */ NULL, cb_name, /* callback = */ cna_read, - /* interval = */ (host->interval > 0) ? &interval : NULL, + /* interval = */ host->interval, /* user data = */ &ud); return (0); diff --git a/src/onewire.c b/src/onewire.c index 1383fc58..6cfea0ec 100644 --- a/src/onewire.c +++ b/src/onewire.c @@ -592,7 +592,6 @@ static int cow_shutdown (void) static int cow_init (void) { int status; - struct timespec cb_interval; if (device_g == NULL) { @@ -608,11 +607,8 @@ static int cow_init (void) return (1); } - CDTIME_T_TO_TIMESPEC (ow_interval, &cb_interval); - plugin_register_complex_read (/* group = */ NULL, "onewire", cow_read, - (ow_interval != 0) ? &cb_interval : NULL, - /* user data = */ NULL); + ow_interval, /* user data = */ NULL); plugin_register_shutdown ("onewire", cow_shutdown); return (0); diff --git a/src/openldap.c b/src/openldap.c index bca686e8..bd989e40 100644 --- a/src/openldap.c +++ b/src/openldap.c @@ -629,7 +629,7 @@ static int cldap_config_add (oconfig_item_t *ci) /* {{{ */ status = plugin_register_complex_read (/* group = */ NULL, /* name = */ callback_name, /* callback = */ cldap_read_host, - /* interval = */ NULL, + /* interval = */ 0, /* user_data = */ &ud); } diff --git a/src/postgresql.c b/src/postgresql.c index 54c856d6..929b925c 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -1196,7 +1196,6 @@ static int c_psql_config_database (oconfig_item_t *ci) c_psql_database_t *db; char cb_name[DATA_MAX_NAME_LEN]; - struct timespec cb_interval = { 0, 0 }; user_data_t ud; static _Bool have_flush = 0; @@ -1291,12 +1290,9 @@ static int c_psql_config_database (oconfig_item_t *ci) ssnprintf (cb_name, sizeof (cb_name), "postgresql-%s", db->instance); if (db->queries_num > 0) { - CDTIME_T_TO_TIMESPEC (db->interval, &cb_interval); - ++db->ref_cnt; plugin_register_complex_read ("postgresql", cb_name, c_psql_read, - /* interval = */ (db->interval > 0) ? &cb_interval : NULL, - &ud); + /* interval = */ db->interval, &ud); } if (db->writers_num > 0) { ++db->ref_cnt; diff --git a/src/python.c b/src/python.c index 8b378a29..d2ef1648 100644 --- a/src/python.c +++ b/src/python.c @@ -656,7 +656,6 @@ static PyObject *cpy_register_read(PyObject *self, PyObject *args, PyObject *kwd double interval = 0; char *name = NULL; PyObject *callback = NULL, *data = NULL; - struct timespec ts; static char *kwlist[] = {"callback", "interval", "data", "name", NULL}; if (PyArg_ParseTupleAndKeywords(args, kwds, "O|dOet", kwlist, &callback, &interval, &data, NULL, &name) == 0) return NULL; @@ -678,10 +677,8 @@ static PyObject *cpy_register_read(PyObject *self, PyObject *args, PyObject *kwd user_data = malloc(sizeof(*user_data)); user_data->free_func = cpy_destroy_user_data; user_data->data = c; - ts.tv_sec = interval; - ts.tv_nsec = (interval - ts.tv_sec) * 1000000000; plugin_register_complex_read(/* group = */ NULL, buf, - cpy_read_callback, &ts, user_data); + cpy_read_callback, DOUBLE_TO_CDTIME_T (interval), user_data); return cpy_string_to_unicode_or_bytes(buf); } diff --git a/src/routeros.c b/src/routeros.c index 4ca9d5b2..400ee42b 100644 --- a/src/routeros.c +++ b/src/routeros.c @@ -414,7 +414,7 @@ static int cr_config_router (oconfig_item_t *ci) /* {{{ */ user_data.free_func = (void *) cr_free_data; if (status == 0) status = plugin_register_complex_read (/* group = */ NULL, read_name, - cr_read, /* interval = */ NULL, &user_data); + cr_read, /* interval = */ 0, &user_data); if (status != 0) cr_free_data (router_data); diff --git a/src/snmp.c b/src/snmp.c index cb2bb36d..51afea1b 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -646,7 +646,6 @@ static int csnmp_config_add_host (oconfig_item_t *ci) /* Registration stuff. */ char cb_name[DATA_MAX_NAME_LEN]; user_data_t cb_data; - struct timespec cb_interval; hd = (host_definition_t *) malloc (sizeof (host_definition_t)); if (hd == NULL) @@ -779,11 +778,8 @@ static int csnmp_config_add_host (oconfig_item_t *ci) cb_data.data = hd; cb_data.free_func = csnmp_host_definition_destroy; - CDTIME_T_TO_TIMESPEC (hd->interval, &cb_interval); - status = plugin_register_complex_read (/* group = */ NULL, cb_name, - csnmp_read_host, /* interval = */ &cb_interval, - /* user_data = */ &cb_data); + csnmp_read_host, hd->interval, /* user_data = */ &cb_data); if (status != 0) { ERROR ("snmp plugin: Registering complex read function failed."); diff --git a/src/tail.c b/src/tail.c index ab063389..9ff0d0be 100644 --- a/src/tail.c +++ b/src/tail.c @@ -331,7 +331,6 @@ static int ctail_read (user_data_t *ud) static int ctail_init (void) { - struct timespec cb_interval; char str[255]; user_data_t ud; size_t i; @@ -346,8 +345,7 @@ static int ctail_init (void) { ud.data = (void *)tail_match_list[i]; ssnprintf(str, sizeof(str), "tail-%zu", i); - CDTIME_T_TO_TIMESPEC (tail_match_list_intervals[i], &cb_interval); - plugin_register_complex_read (NULL, str, ctail_read, &cb_interval, &ud); + plugin_register_complex_read (NULL, str, ctail_read, tail_match_list_intervals[i], &ud); } return (0); diff --git a/src/tail_csv.c b/src/tail_csv.c index a70b6658..61eeee34 100644 --- a/src/tail_csv.c +++ b/src/tail_csv.c @@ -421,7 +421,6 @@ static int tcsv_config_add_file(oconfig_item_t *ci) /* Registration variables */ char cb_name[DATA_MAX_NAME_LEN]; user_data_t cb_data; - struct timespec cb_interval; id = malloc(sizeof(*id)); if (id == NULL) @@ -486,8 +485,7 @@ static int tcsv_config_add_file(oconfig_item_t *ci) memset(&cb_data, 0, sizeof(cb_data)); cb_data.data = id; cb_data.free_func = tcsv_instance_definition_destroy; - CDTIME_T_TO_TIMESPEC(id->interval, &cb_interval); - status = plugin_register_complex_read(NULL, cb_name, tcsv_read, &cb_interval, &cb_data); + status = plugin_register_complex_read(NULL, cb_name, tcsv_read, id->interval, &cb_data); if (status != 0){ ERROR("tail_csv plugin: Registering complex read function failed."); diff --git a/src/varnish.c b/src/varnish.c index 8e6d95ee..1d8fb557 100644 --- a/src/varnish.c +++ b/src/varnish.c @@ -739,7 +739,7 @@ static int varnish_init (void) /* {{{ */ plugin_register_complex_read (/* group = */ "varnish", /* name = */ "varnish/localhost", /* callback = */ varnish_read, - /* interval = */ NULL, + /* interval = */ 0, /* user data = */ &ud); return (0);