[collectd] Modbus segfault

Matt Baker matt at sevenone.com
Mon Jan 30 00:00:35 CET 2012


Hello Stefan,

I just tried your patch below and found it fixed my previous problem with segfaults when the modbus module was enabled. This was with collectd 5.0.2/libmodbus 3.0.1 on i386. Thankyou!

I am though now seeing a slightly odd situation where after a period of time all data points that are collected via the modbus module are reported as zero.   Other collectd modules are still collecting correctly. A restart of collectd fixes the problem for awhile, but then it occurs again. I don't think it's a connectivity to the modbus device issue as it occurs after a few hours.

Using 'rrdtool dump' I can see the logged values for the time periods and <last_ds> both reported as zero.  


I need to recompile with debugging enabled to see if I can track down the problem but I was wondering if you had seen anything similar?


Cheers,

Matt


> Hi all,
> 
> I also stumbled across the modbus segfault (collectd 5.0.1 / libmodbus 3.0.1 / gentoo, both i386 & x86_64).
> 
> The problem is that host->connection is simply never initialized in mb_read_data() before being passed to libmodbus.
> The only place mb_init_connection() is called is from within the reconnection loop below.
> 
> Adding this before the call to modbus_set_slave() makes the crash go away:
> 
>   if (host->connection == NULL)
>   {
>     status = mb_init_connection (host);
>     if (status != 0)
>     {
>       ERROR ("Modbus plugin: mb_init_connection (%s/%s) failed. ",
>           host->host, host->node);
>       return (-1);
>     }
>   }
> 
> As I'm reading float values I also had to modify mb_register_to_float() to get what I was expecting.
> But not sure whether this is due to running on a 64bit machine or just my PLC being backwards.
> What I'm doing is
> 
> static float mb_register_to_float (uint16_t hi, uint16_t lo) /* {{{ */
> {
>   union
>   {
>     uint8_t b[4];
>     uint16_t s[2];
>     float f;
>   } conv;
> 
> #if BYTE_ORDER == LITTLE_ENDIAN
>   conv.s[0] = hi;
>   conv.s[1] = lo;
> #else
> ...
> 
> -- 
> Cheers, Stefan
> _______________________________________________
> collectd mailing list
> collectd at verplant.org
> http://mailman.verplant.org/listinfo/collectd




More information about the collectd mailing list