[collectd] Modbus segfault

Matt Baker matt at sevenone.com
Wed Feb 8 00:01:01 CET 2012

Hi Stefan,

I too found that it must have been an intermittent connection issue so I started to look at the code.

I went back to the original modbus.c file from the 3.0.2 distribution and found that there is currently a for loop which does the connection (I am not a C programmer), but this loop when it exits doesn't check if the connection actually did occur. Instead it just falls into assuming the connection is all okay. So at the end of the for loop I added the following check:

 if (status == 0) {
      DEBUG ("Modbus plugin: connection issue, giving up!");
      modbus_close (host->connection);
      modbus_free (host->connection);
      host->connection = NULL;
      return (-1);

And this appears to work.  It still occasionally has the timeout issue, but it at least then continues and retry's the connection then next time around.  I have been running this now for the past 3-4 days and everything is working well.  I will now need to try to resolve the timeout problem, maybe increasing the timeout value might help.



> Hi Matt,
> on my side collectd worked apparently perfect (with debug, in foreground) since my last mail.
> But I just pulled the Ethernet plug on my PLC for a bit and the collectd side does not recover - looking similar to what you sent - so that's a start :)
> My idea is that since collectd calls the plugin repeatedly anyways to just check whether there is a connection (the getpeername() trick is something I found on the net, not sure about caveats), if not try to establish one and then give it a single try.
> Hope to find some time soon to look into this,
> Stefan

More information about the collectd mailing list