X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmodbus.c;h=80a2aca17953e0735d36006a976cc0908d0f64b4;hb=cb262c0e23692b6374d57ad3b3decb0d6c397949;hp=f2d07cc8149e9d06de8a94aa61465f9915e37b84;hpb=79963d13c1884d1d92667cc502ad20758b084a12;p=collectd.git diff --git a/src/modbus.c b/src/modbus.c index f2d07cc8..80a2aca1 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -443,6 +443,8 @@ static int mb_read_data(mb_host_t *host, mb_slave_t *slave, /* {{{ */ if (host->connection == NULL) { status = EBADF; } else if (host->conntype == MBCONN_TCP) { + /* getpeername() is used only to determine if the socket is connected, not + * because we're really interested in the peer's IP address. */ if (getpeername(modbus_get_socket(host->connection), (void *)&(struct sockaddr_storage){0}, &(socklen_t){sizeof(struct sockaddr_storage)}) != 0) @@ -930,17 +932,16 @@ static int mb_config_add_host(oconfig_item_t *ci) /* {{{ */ } if (status == 0) { - user_data_t ud; char name[1024]; - ud.data = host; - ud.free_func = host_free; - ssnprintf(name, sizeof(name), "modbus-%s", host->host); plugin_register_complex_read(/* group = */ NULL, name, /* callback = */ mb_read, - /* interval = */ host->interval, &ud); + /* interval = */ host->interval, + &(user_data_t){ + .data = host, .free_func = host_free, + }); } else { host_free(host); } @@ -981,5 +982,3 @@ void module_register(void) { plugin_register_complex_config("modbus", mb_config); plugin_register_shutdown("modbus", mb_shutdown); } /* void module_register */ - -/* vim: set sw=2 sts=2 et fdm=marker : */