X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmodbus.c;h=d538fb3f717774bbc36b6c2eb7b7e1ff0919bc85;hb=5c2993e4121feae745551be182221b31bc23ff97;hp=08871a25732f60ab7bc5ef9c67fe248a303ecd48;hpb=fc6f1e3d33d646391adb5cedc62e7b3904c15003;p=collectd.git diff --git a/src/modbus.c b/src/modbus.c index 08871a25..d538fb3f 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -310,7 +310,9 @@ static int mb_init_connection (mb_host_t *host) /* {{{ */ if (host == NULL) return (EINVAL); +#if COLLECT_DEBUG modbus_set_debug (&host->connection, 1); +#endif /* We'll do the error handling ourselves. */ modbus_set_error_handling (&host->connection, NOP_ON_ERROR); @@ -390,7 +392,9 @@ static int mb_init_connection (mb_host_t *host) /* {{{ */ } } +#if COLLECT_DEBUG modbus_set_debug (host->connection, 1); +#endif /* We'll do the error handling ourselves. */ modbus_set_error_recovery (host->connection, 0); @@ -440,7 +444,7 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ if (ds->ds_num != 1) { - ERROR ("Modbus plugin: The type \"%s\" has %i data sources. " + ERROR ("Modbus plugin: The type \"%s\" has %zu data sources. " "I can only handle data sets with only one data source.", data->type, ds->ds_num); return (-1); @@ -942,9 +946,15 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */ status = cf_util_get_string_buffer (ci, host->host, sizeof (host->host)); if (status != 0) + { + sfree (host); return (status); + } if (host->host[0] == 0) + { + sfree (host); return (EINVAL); + } for (i = 0; i < ci->children_num; i++) { @@ -1014,18 +1024,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