From: Florian Forster Date: Wed, 29 Feb 2012 19:47:08 +0000 (+0100) Subject: conntrack plugin: Strip newlie before calling parse_value(). X-Git-Tag: collectd-4.10.7~16 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f24b091a485607de74612a30b875f59453cf162a;p=collectd.git conntrack plugin: Strip newlie before calling parse_value(). Change-Id: Ifa4db20a6b937912db77a214d2c0ef3eeebfa164 --- diff --git a/src/conntrack.c b/src/conntrack.c index 4d677124..33236c45 100644 --- a/src/conntrack.c +++ b/src/conntrack.c @@ -49,11 +49,13 @@ static int conntrack_read (void) value_t conntrack; FILE *fh; char buffer[64]; + size_t buffer_len; fh = fopen (CONNTRACK_FILE, "r"); if (fh == NULL) return (-1); + memset (buffer, 0, sizeof (buffer)); if (fgets (buffer, sizeof (buffer), fh) == NULL) { fclose (fh); @@ -61,7 +63,15 @@ static int conntrack_read (void) } fclose (fh); - if (parse_value (buffer, &conntrack, DS_TYPE_GAUGE) == -1) + /* strip trailing newline. */ + buffer_len = strlen (buffer); + while ((buffer_len > 0) && isspace ((int) buffer[buffer_len - 1])) + { + buffer[buffer_len - 1] = 0; + buffer_len--; + } + + if (parse_value (buffer, &conntrack, DS_TYPE_GAUGE) != 0) return (-1); conntrack_submit (conntrack);