Merge remote-tracking branch 'github/pr/1087'
authorFlorian Forster <octo@collectd.org>
Wed, 17 Jun 2015 12:53:11 +0000 (14:53 +0200)
committerFlorian Forster <octo@collectd.org>
Wed, 17 Jun 2015 12:53:11 +0000 (14:53 +0200)
15 files changed:
README
configure.ac
src/barometer.c
src/ceph.c
src/daemon/configfile.c
src/daemon/utils_avltree.c
src/daemon/utils_llist.c
src/email.c
src/liboconfig/oconfig.c
src/liboconfig/parser.y
src/liboconfig/scanner.l
src/network.c
src/perl.c
src/target_notification.c
src/utils_rrdcreate.c

diff --git a/README b/README
index 6f2fb72..6ac7e2b 100644 (file)
--- a/README
+++ b/README
@@ -468,7 +468,7 @@ Features
       database.
 
   * Logging is, as everything in collectd, provided by plugins. The following
-    plugins keep up informed about what's going on:
+    plugins keep us informed about what's going on:
 
     - logfile
       Writes log messages to a file or STDOUT/STDERR.
index 4e88a26..44d10cf 100644 (file)
@@ -115,7 +115,7 @@ then
        AC_DEFINE(_REENTRANT,               1, [Define to enable reentrancy interfaces.])
 
        AC_MSG_CHECKING([whether compiler builds 64bit binaries])
-       AC_PREPROC_IFELSE([AC_LANG_PROGRAM([
+       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
                           #ifndef _LP64
                           # error "Compiler not in 64bit mode."
                           #endif
index 2bfd51e..c1a7fa9 100644 (file)
@@ -253,11 +253,9 @@ static averaging_t temperature_averaging = { NULL, 0, 0L, 0 };
  *
  * @return Zero when successful
  */
-static int averaging_create(averaging_t * avg, int size)
+static int averaging_create(averaging_t *avg, int size)
 {
-    int a;
-
-    avg->ring_buffer = (long int *) malloc(size * sizeof(*avg));
+    avg->ring_buffer = calloc ((size_t) size, sizeof (*avg));
     if (avg->ring_buffer == NULL)
     {
         ERROR ("barometer: averaging_create - ring buffer allocation of size %d failed",
@@ -265,11 +263,6 @@ static int averaging_create(averaging_t * avg, int size)
         return -1;
     }
 
-    for (a=0; a<size; ++a)
-    {
-      avg->ring_buffer[a] = 0L;
-    }
-
     avg->ring_buffer_size = size;
     avg->ring_buffer_sum  = 0L;
     avg->ring_buffer_head = 0;
index 56e349c..d928a7b 100644 (file)
@@ -657,7 +657,8 @@ static int cc_handle_bool(struct oconfig_item_s *item, int *dest)
 static int cc_add_daemon_config(oconfig_item_t *ci)
 {
     int ret, i;
-    struct ceph_daemon *array, *nd, cd;
+    struct ceph_daemon *nd, cd;
+    struct ceph_daemon **tmp;
     memset(&cd, 0, sizeof(struct ceph_daemon));
 
     if((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
@@ -709,21 +710,21 @@ static int cc_add_daemon_config(oconfig_item_t *ci)
         return -EINVAL;
     }
 
-    array = realloc(g_daemons,
-                    sizeof(struct ceph_daemon *) * (g_num_daemons + 1));
-    if(array == NULL)
+    tmp = realloc(g_daemons, (g_num_daemons+1) * sizeof(*g_daemons));
+    if(tmp == NULL)
     {
         /* The positive return value here indicates that this is a
          * runtime error, not a configuration error.  */
         return ENOMEM;
     }
-    g_daemons = (struct ceph_daemon**) array;
-    nd = malloc(sizeof(struct ceph_daemon));
+    g_daemons = tmp;
+
+    nd = malloc(sizeof(*nd));
     if(!nd)
     {
         return ENOMEM;
     }
-    memcpy(nd, &cd, sizeof(struct ceph_daemon));
+    memcpy(nd, &cd, sizeof(*nd));
     g_daemons[g_num_daemons++] = nd;
     return 0;
 }
index da7ed5f..f34adae 100644 (file)
@@ -73,7 +73,7 @@ typedef struct cf_complex_callback_s
 typedef struct cf_value_map_s
 {
        char *key;
-       int (*func) (const oconfig_item_t *);
+       int (*func) (oconfig_item_t *);
 } cf_value_map_t;
 
 typedef struct cf_global_option_s
@@ -86,9 +86,10 @@ typedef struct cf_global_option_s
 /*
  * Prototypes of callback functions
  */
-static int dispatch_value_typesdb (const oconfig_item_t *ci);
-static int dispatch_value_plugindir (const oconfig_item_t *ci);
-static int dispatch_loadplugin (const oconfig_item_t *ci);
+static int dispatch_value_typesdb (oconfig_item_t *ci);
+static int dispatch_value_plugindir (oconfig_item_t *ci);
+static int dispatch_loadplugin (oconfig_item_t *ci);
+static int dispatch_block_plugin (oconfig_item_t *ci);
 
 /*
  * Private variables
@@ -100,7 +101,8 @@ static cf_value_map_t cf_value_map[] =
 {
        {"TypesDB",    dispatch_value_typesdb},
        {"PluginDir",  dispatch_value_plugindir},
-       {"LoadPlugin", dispatch_loadplugin}
+       {"LoadPlugin", dispatch_loadplugin},
+       {"Plugin",     dispatch_block_plugin}
 };
 static int cf_value_map_num = STATIC_ARRAY_SIZE (cf_value_map);
 
@@ -225,7 +227,7 @@ static int dispatch_global_option (const oconfig_item_t *ci)
        return (-1);
 } /* int dispatch_global_option */
 
-static int dispatch_value_typesdb (const oconfig_item_t *ci)
+static int dispatch_value_typesdb (oconfig_item_t *ci)
 {
        int i = 0;
 
@@ -251,7 +253,7 @@ static int dispatch_value_typesdb (const oconfig_item_t *ci)
        return (0);
 } /* int dispatch_value_typesdb */
 
-static int dispatch_value_plugindir (const oconfig_item_t *ci)
+static int dispatch_value_plugindir (oconfig_item_t *ci)
 {
        assert (strcasecmp (ci->key, "PluginDir") == 0);
        
@@ -264,7 +266,7 @@ static int dispatch_value_plugindir (const oconfig_item_t *ci)
        return (0);
 }
 
-static int dispatch_loadplugin (const oconfig_item_t *ci)
+static int dispatch_loadplugin (oconfig_item_t *ci)
 {
        int i;
        const char *name;
@@ -353,7 +355,7 @@ static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci)
        return (cf_dispatch (plugin, ci->key, buffer_ptr));
 } /* int dispatch_value_plugin */
 
-static int dispatch_value (const oconfig_item_t *ci)
+static int dispatch_value (oconfig_item_t *ci)
 {
        int ret = -2;
        int i;
index 04e5403..da793b3 100644 (file)
@@ -617,10 +617,18 @@ int c_avl_pick (c_avl_tree_t *t, void **key, void **value)
        n = t->root;
        while ((n->left != NULL) || (n->right != NULL))
        {
-               int height_left  = (n->left  == NULL) ? 0 : n->left->height;
-               int height_right = (n->right == NULL) ? 0 : n->right->height;
+               if (n->left == NULL)
+               {
+                       n = n->right;
+                       continue;
+               }
+               else if (n->right == NULL)
+               {
+                       n = n->left;
+                       continue;
+               }
 
-               if (height_left > height_right)
+               if (n->left->height > n->right->height)
                        n = n->left;
                else
                        n = n->right;
index 09c9834..4265286 100644 (file)
@@ -123,6 +123,9 @@ void llist_remove (llist_t *l, llentry_t *e)
 {
        llentry_t *prev;
 
+       if ((l == NULL) || (e == NULL))
+               return;
+
        prev = l->head;
        while ((prev != NULL) && (prev->next != e))
                prev = prev->next;
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 bf21b90..f422f5a 100644 (file)
@@ -33,6 +33,7 @@
 #include "oconfig.h"
 
 extern FILE *yyin;
+extern int yyparse (void);
 
 oconfig_item_t *ci_root;
 const char     *c_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 cb3754d..08524fd 100644 (file)
  */
 
 %{
+/* lex and yacc do some weird stuff, so turn off some warnings. */
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunused-function"
+# pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
+#endif
+
 #include <stdlib.h>
 #include "oconfig.h"
 #include "aux_types.h"
index 311bfb5..4edc4f6 100644 (file)
@@ -2028,6 +2028,7 @@ static sockent_t *sockent_create (int type) /* {{{ */
        if (type == SOCKENT_TYPE_SERVER)
        {
                se->data.server.fd = NULL;
+               se->data.server.fd_num = 0;
 #if HAVE_LIBGCRYPT
                se->data.server.security_level = SECURITY_LEVEL_NONE;
                se->data.server.auth_file = NULL;
@@ -2241,6 +2242,9 @@ static int sockent_server_listen (sockent_t *se) /* {{{ */
        if (se == NULL)
                return (-1);
 
+       assert (se->data.server.fd == NULL);
+       assert (se->data.server.fd_num == 0);
+
         node = se->node;
         service = se->service;
 
@@ -2440,13 +2444,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;
@@ -2455,15 +2459,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++)
@@ -2481,10 +2484,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);
@@ -2498,7 +2501,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);
@@ -2506,7 +2510,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;
@@ -2542,7 +2547,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. */
@@ -2565,7 +2575,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)
index cc8faeb..a964cce 100644 (file)
@@ -516,7 +516,6 @@ static int av2notification_meta (pTHX_ AV *array, notification_meta_t **meta)
                if (NULL == (tmp = hv_fetch (hash, "value", 5, 0))) {
                        log_warn ("av2notification_meta: Skipping invalid "
                                        "meta information.");
-                       free ((*m)->name);
                        free (*m);
                        continue;
                }
index 2e5ab3b..ceb454e 100644 (file)
@@ -181,7 +181,7 @@ static int tn_create (const oconfig_item_t *ci, void **user_data) /* {{{ */
 
   if (status != 0)
   {
-    tn_destroy ((void *) data);
+    tn_destroy ((void *) &data);
     return (status);
   }
 
index 0e2d86c..220446a 100644 (file)
@@ -709,18 +709,32 @@ int cu_rrd_create_file (const char *filename, /* {{{ */
   }
   else /* synchronous */
   {
-    status = srrd_create (filename, stepsize, last_up,
-        argc, (const char **) argv);
-
+    status = lock_file (filename);
     if (status != 0)
     {
-      WARNING ("cu_rrd_create_file: srrd_create (%s) returned status %i.",
-          filename, status);
+      if (status == EEXIST)
+        NOTICE ("cu_rrd_create_file: File \"%s\" is already being created.",
+            filename);
+      else
+        ERROR ("cu_rrd_create_file: Unable to lock file \"%s\".",
+            filename);
     }
     else
     {
-      DEBUG ("cu_rrd_create_file: Successfully created RRD file \"%s\".",
-          filename);
+      status = srrd_create (filename, stepsize, last_up,
+          argc, (const char **) argv);
+
+      if (status != 0)
+      {
+        WARNING ("cu_rrd_create_file: srrd_create (%s) returned status %i.",
+            filename, status);
+      }
+      else
+      {
+        DEBUG ("cu_rrd_create_file: Successfully created RRD file \"%s\".",
+            filename);
+      }
+      unlock_file (filename);
     }
   }