Merge branch 'collectd-5.4' into collectd-5.5
authorFlorian Forster <octo@collectd.org>
Wed, 17 Jun 2015 12:52:22 +0000 (14:52 +0200)
committerFlorian Forster <octo@collectd.org>
Wed, 17 Jun 2015 12:52:22 +0000 (14:52 +0200)
src/email.c
src/liboconfig/parser.y
src/network.c

index d1a8719..c2eab21 100644 (file)
@@ -575,10 +575,27 @@ static int email_init (void)
        return (0);
 } /* int email_init */
 
-static int email_shutdown (void)
+static void type_list_free (type_list_t *t)
 {
-       type_t *ptr = NULL;
+       type_t *this;
+
+       this = t->head;
+       while (this != NULL)
+       {
+               type_t *next = this->next;
+
+               sfree (this->name);
+               sfree (this);
+
+               this = next;
+       }
 
+       t->head = NULL;
+       t->tail = NULL;
+}
+
+static int email_shutdown (void)
+{
        int i = 0;
 
        if (connector != ((pthread_t) 0)) {
@@ -618,35 +635,12 @@ static int email_shutdown (void)
 
        pthread_mutex_unlock (&conns_mutex);
 
-       for (ptr = list_count.head; NULL != ptr; ptr = ptr->next) {
-               free (ptr->name);
-               free (ptr);
-       }
-
-       for (ptr = list_count_copy.head; NULL != ptr; ptr = ptr->next) {
-               free (ptr->name);
-               free (ptr);
-       }
-
-       for (ptr = list_size.head; NULL != ptr; ptr = ptr->next) {
-               free (ptr->name);
-               free (ptr);
-       }
-
-       for (ptr = list_size_copy.head; NULL != ptr; ptr = ptr->next) {
-               free (ptr->name);
-               free (ptr);
-       }
-
-       for (ptr = list_check.head; NULL != ptr; ptr = ptr->next) {
-               free (ptr->name);
-               free (ptr);
-       }
-
-       for (ptr = list_check_copy.head; NULL != ptr; ptr = ptr->next) {
-               free (ptr->name);
-               free (ptr);
-       }
+       type_list_free (&list_count);
+       type_list_free (&list_count_copy);
+       type_list_free (&list_size);
+       type_list_free (&list_size_copy);
+       type_list_free (&list_check);
+       type_list_free (&list_check_copy);
 
        unlink ((NULL == sock_file) ? SOCK_PATH : sock_file);
 
index d91df8c..f0e886c 100644 (file)
@@ -36,6 +36,7 @@ static int yyerror (const char *s);
 /* Lexer variables */
 extern int yylineno;
 extern char *yytext;
+extern int yylex (void);
 
 extern oconfig_item_t *ci_root;
 extern char           *c_file;
index 2b66f1e..d52da68 100644 (file)
@@ -2443,13 +2443,13 @@ static int network_receive (void) /* {{{ */
        int  buffer_len;
 
        int i;
-       int status;
+       int status = 0;
 
        receive_list_entry_t *private_list_head;
        receive_list_entry_t *private_list_tail;
        uint64_t              private_list_length;
 
-        assert (listen_sockets_num > 0);
+       assert (listen_sockets_num > 0);
 
        private_list_head = NULL;
        private_list_tail = NULL;
@@ -2458,15 +2458,14 @@ static int network_receive (void) /* {{{ */
        while (listen_loop == 0)
        {
                status = poll (listen_sockets_pollfd, listen_sockets_num, -1);
-
                if (status <= 0)
                {
                        char errbuf[1024];
                        if (errno == EINTR)
                                continue;
-                       ERROR ("poll failed: %s",
+                       ERROR ("network plugin: poll(2) failed: %s",
                                        sstrerror (errno, errbuf, sizeof (errbuf)));
-                       return (-1);
+                       break;
                }
 
                for (i = 0; (i < listen_sockets_num) && (status > 0); i++)
@@ -2484,10 +2483,10 @@ static int network_receive (void) /* {{{ */
                        if (buffer_len < 0)
                        {
                                char errbuf[1024];
-                               ERROR ("recv failed: %s",
-                                               sstrerror (errno, errbuf,
-                                                       sizeof (errbuf)));
-                               return (-1);
+                               status = (errno != 0) ? errno : -1;
+                               ERROR ("network plugin: recv(2) failed: %s",
+                                               sstrerror (errno, errbuf, sizeof (errbuf)));
+                               break;
                        }
 
                        stats_octets_rx += ((uint64_t) buffer_len);
@@ -2501,7 +2500,8 @@ static int network_receive (void) /* {{{ */
                        if (ent == NULL)
                        {
                                ERROR ("network plugin: malloc failed.");
-                               return (-1);
+                               status = ENOMEM;
+                               break;
                        }
                        memset (ent, 0, sizeof (receive_list_entry_t));
                        ent->data = malloc (network_config_packet_size);
@@ -2509,7 +2509,8 @@ static int network_receive (void) /* {{{ */
                        {
                                sfree (ent);
                                ERROR ("network plugin: malloc failed.");
-                               return (-1);
+                               status = ENOMEM;
+                               break;
                        }
                        ent->fd = listen_sockets_pollfd[i].fd;
                        ent->next = NULL;
@@ -2545,7 +2546,12 @@ static int network_receive (void) /* {{{ */
                                private_list_tail = NULL;
                                private_list_length = 0;
                        }
+
+                       status = 0;
                } /* for (listen_sockets_pollfd) */
+
+               if (status != 0)
+                       break;
        } /* while (listen_loop == 0) */
 
        /* Make sure everything is dispatched before exiting. */
@@ -2568,7 +2574,7 @@ static int network_receive (void) /* {{{ */
                pthread_mutex_unlock (&receive_list_lock);
        }
 
-       return (0);
+       return (status);
 } /* }}} int network_receive */
 
 static void *receive_thread (void __attribute__((unused)) *arg)