From: Florian Forster Date: Thu, 21 Dec 2006 12:27:56 +0000 (+0100) Subject: Bug#404018: Break out of the `while (loop)'-loop when no socket can be opened. X-Git-Tag: collectd-3.10.4~2 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=84f4eefa0e9e628b9d507321aacb3f0532b7c3d2 Bug#404018: Break out of the `while (loop)'-loop when no socket can be opened. This fixes the first part of the bug reported by Max Kellermann. --- diff --git a/src/collectd.c b/src/collectd.c index 0d9c90fc..c9385d95 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -221,16 +221,27 @@ static int start_client (void) #if HAVE_LIBRRD static int start_server (void) { - /* FIXME use stack here! */ char *host; char *type; char *instance; char *values; - while (loop == 0) + int error_counter = 0; + int status; + + while ((loop == 0) && (error_counter < 3)) { - if (network_receive (&host, &type, &instance, &values) == 0) - plugin_write (host, type, instance, values); + status = network_receive (&host, &type, &instance, &values); + + if (status != 0) + { + if (status < 0) + error_counter++; + continue; + } + error_counter = 0; + + plugin_write (host, type, instance, values); if (host != NULL) free (host); host = NULL; if (type != NULL) free (type); type = NULL; diff --git a/src/network.c b/src/network.c index 22e911a8..c233de68 100644 --- a/src/network.c +++ b/src/network.c @@ -451,7 +451,7 @@ int network_receive (char **host, char **type, char **inst, char **value) { syslog (LOG_WARNING, "Invalid message from `%s'", *host); free (*host); *host = NULL; - return (-1); + return (1); } if ((*type = strdup (fields[0])) == NULL)