Code

Bug#404018: Break out of the `while (loop)'-loop when no socket can be opened.
authorFlorian Forster <octo@huhu.verplant.org>
Thu, 21 Dec 2006 12:27:56 +0000 (13:27 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 21 Dec 2006 19:18:03 +0000 (20:18 +0100)
This fixes the first part of the bug reported by Max Kellermann.

src/collectd.c
src/network.c

index 0d9c90fce19a5dd2fe1e222c8a61f3d07e63a67d..c9385d95796419da090cdf6dd7290ab3458d831d 100644 (file)
@@ -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;
index 22e911a87b8e4d4fe89d805abc9c9559ce2463c6..c233de6826ebab9c7c7de45ef24042de0791fefb 100644 (file)
@@ -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)