X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmodbus.c;h=ec429698bda23d1c7ca62c031b3099c809989fb9;hb=71bbf854d3e6f8c6d6c3582527263bb01a3a7e04;hp=c04b308d81728e74f4621737b64fb394eb47430d;hpb=65c20e41cfad6e7ab024983f561835fd347124ce;p=collectd.git diff --git a/src/modbus.c b/src/modbus.c index c04b308d..ec429698 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -80,7 +80,7 @@ enum mb_register_type_e /* {{{ */ REG_TYPE_UINT32, REG_TYPE_FLOAT }; /* }}} */ -enum mb_mreg_type_e /* {{{ */ +enum mb_mreg_type_e /* {{{ */ { MREG_HOLDING, MREG_INPUT @@ -257,7 +257,7 @@ static int mb_submit (mb_host_t *host, mb_slave_t *slave, /* {{{ */ if ((host == NULL) || (slave == NULL) || (data == NULL)) return (EINVAL); - if (host->interval <= 0) + if (host->interval == 0) host->interval = plugin_get_interval (); if (slave->instance[0] == 0) @@ -427,7 +427,7 @@ static int mb_init_connection (mb_host_t *host) /* {{{ */ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ mb_data_t *data) { - uint16_t values[2]; + uint16_t values[2] = { 0 }; int values_num; const data_set_t *ds; int status = 0; @@ -444,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); @@ -459,7 +459,6 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ "is not UINT32.", data->type, DS_TYPE_TO_STRING (ds->ds[0].type)); } - memset (values, 0, sizeof (values)); if ((data->register_type == REG_TYPE_INT32) || (data->register_type == REG_TYPE_UINT32) || (data->register_type == REG_TYPE_FLOAT)) @@ -503,7 +502,7 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ modbus_free (host->connection); #endif } - + #if LEGACY_LIBMODBUS /* Version 2.0.3: Pass the connection struct as a pointer and pass the slave * id to each call of "read_holding_registers". */ @@ -720,11 +719,10 @@ static void host_free (void *void_host) /* {{{ */ static int mb_config_add_data (oconfig_item_t *ci) /* {{{ */ { - mb_data_t data; + mb_data_t data = { 0 }; int status; int i; - memset (&data, 0, sizeof (data)); data.name = NULL; data.register_type = REG_TYPE_UINT16; data.next = NULL; @@ -820,23 +818,17 @@ static int mb_config_set_host_address (mb_host_t *host, /* {{{ */ { struct addrinfo *ai_list; struct addrinfo *ai_ptr; - struct addrinfo ai_hints; int status; if ((host == NULL) || (address == NULL)) return (EINVAL); - memset (&ai_hints, 0, sizeof (ai_hints)); -#if AI_ADDRCONFIG - ai_hints.ai_flags |= AI_ADDRCONFIG; -#endif - /* XXX: libmodbus can only handle IPv4 addresses. */ - ai_hints.ai_family = AF_INET; - ai_hints.ai_addr = NULL; - ai_hints.ai_canonname = NULL; - ai_hints.ai_next = NULL; + struct addrinfo ai_hints = { + /* XXX: libmodbus can only handle IPv4 addresses. */ + .ai_family = AF_INET, + .ai_flags = AI_ADDRCONFIG + }; - ai_list = NULL; status = getaddrinfo (address, /* service = */ NULL, &ai_hints, &ai_list); if (status != 0) @@ -938,10 +930,9 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */ int status; int i; - host = malloc (sizeof (*host)); + host = calloc (1, sizeof (*host)); if (host == NULL) return (ENOMEM); - memset (host, 0, sizeof (*host)); host->slaves = NULL; status = cf_util_get_string_buffer (ci, host->host, sizeof (host->host)); @@ -1024,18 +1015,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