From: Florian Forster Date: Thu, 1 Nov 2007 09:06:52 +0000 (+0100) Subject: tcpconns plugin: Done complain when reading one of the files fails. X-Git-Tag: collectd-4.2.1~8 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7ada660342c3341e6bdf3c44768af38f2acd16ed;p=collectd.git tcpconns plugin: Done complain when reading one of the files fails. This should remove an error message on non-IPv6-enabled hosts.. --- diff --git a/src/tcpconns.c b/src/tcpconns.c index 74874ae3..00cad0e4 100644 --- a/src/tcpconns.c +++ b/src/tcpconns.c @@ -336,12 +336,7 @@ static int conn_read_file (const char *file) fh = fopen (file, "r"); if (fh == NULL) - { - char errbuf[1024]; - ERROR ("tcpconns plugin: fopen (%s) failed: %s", - file, sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); - } while (fgets (buffer, sizeof (buffer), fh) != NULL) { @@ -411,12 +406,25 @@ static int conn_init (void) static int conn_read (void) { + int errors_num = 0; + conn_reset_port_entry (); - conn_read_file ("/proc/net/tcp"); - conn_read_file ("/proc/net/tcp6"); + if (conn_read_file ("/proc/net/tcp") != 0) + errors_num++; + if (conn_read_file ("/proc/net/tcp6") != 0) + errors_num++; - conn_submit_all (); + if (errors_num < 2) + { + conn_submit_all (); + } + else + { + ERROR ("tcpconns plugin: Neither /proc/net/tcp nor /proc/net/tcp6 " + "coult be read."); + return (-1); + } return (0); } /* int conn_read */