Merge branch 'collectd-5.4' into collectd-5.5
authorFlorian Forster <octo@collectd.org>
Sat, 5 Dec 2015 07:56:17 +0000 (08:56 +0100)
committerFlorian Forster <octo@collectd.org>
Sat, 5 Dec 2015 07:56:17 +0000 (08:56 +0100)
src/daemon/configfile.c
src/df.c
src/multimeter.c
src/perl.c
src/pinba.c
src/postgresql.c
src/table.c
src/teamspeak2.c
src/threshold.c
src/utils_fbhash.c
src/vmem.c

index ae3e798..16e0724 100644 (file)
@@ -716,6 +716,7 @@ static oconfig_item_t *cf_read_dir (const char *dir,
        if (root == NULL)
        {
                ERROR ("configfile: malloc failed.");
+               closedir (dh);
                return (NULL);
        }
        memset (root, 0, sizeof (oconfig_item_t));
@@ -735,6 +736,7 @@ static oconfig_item_t *cf_read_dir (const char *dir,
                        ERROR ("configfile: Not including `%s/%s' because its"
                                        " name is too long.",
                                        dir, de->d_name);
+                       closedir (dh);
                        for (i = 0; i < filenames_num; ++i)
                                free (filenames[i]);
                        free (filenames);
@@ -747,6 +749,7 @@ static oconfig_item_t *cf_read_dir (const char *dir,
                                filenames_num * sizeof (*filenames));
                if (tmp == NULL) {
                        ERROR ("configfile: realloc failed.");
+                       closedir (dh);
                        for (i = 0; i < filenames_num - 1; ++i)
                                free (filenames[i]);
                        free (filenames);
@@ -759,7 +762,10 @@ static oconfig_item_t *cf_read_dir (const char *dir,
        }
 
        if (filenames == NULL)
+       {
+               closedir (dh);
                return (root);
+       }
 
        qsort ((void *) filenames, filenames_num, sizeof (*filenames),
                        cf_compare_string);
@@ -784,11 +790,12 @@ static oconfig_item_t *cf_read_dir (const char *dir,
                free (name);
        }
 
+       closedir (dh);
        free(filenames);
        return (root);
 } /* oconfig_item_t *cf_read_dir */
 
-/* 
+/*
  * cf_read_generic
  *
  * Path is stat'ed and either cf_read_file or cf_read_dir is called
index cb0ff2f..ef9e413 100644 (file)
--- a/src/df.c
+++ b/src/df.c
@@ -204,6 +204,7 @@ static int df_read (void)
        {
                unsigned long long blocksize;
                char disk_name[256];
+               cu_mount_t *dup_ptr;
                uint64_t blk_free;
                uint64_t blk_reserved;
                uint64_t blk_used;
@@ -219,6 +220,27 @@ static int df_read (void)
                if (ignorelist_match (il_fstype, mnt_ptr->type))
                        continue;
 
+               /* search for duplicates *in front of* the current mnt_ptr. */
+               for (dup_ptr = mnt_list; dup_ptr != NULL; dup_ptr = dup_ptr->next)
+               {
+                       /* No duplicate found: mnt_ptr is the first of its kind. */
+                       if (dup_ptr == mnt_ptr)
+                       {
+                               dup_ptr = NULL;
+                               break;
+                       }
+
+                       /* Duplicate found: leave non-NULL dup_ptr. */
+                       if (by_device && (strcmp (mnt_ptr->spec_device, dup_ptr->spec_device) == 0))
+                               break;
+                       else if (!by_device && (strcmp (mnt_ptr->dir, dup_ptr->dir) == 0))
+                               break;
+               }
+
+               /* ignore duplicates */
+               if (dup_ptr != NULL)
+                       continue;
+
                if (STATANYFS (mnt_ptr->dir, &statbuf) < 0)
                {
                        char errbuf[1024];
index 775eb57..03608e6 100644 (file)
@@ -153,9 +153,9 @@ static int multimeter_init (void)
 
        for (i = 0; i < 10; i++)
        {
-               device[strlen(device)-1] = i + '0'; 
+               device[strlen(device)-1] = i + '0';
 
-               if ((fd = open(device, O_RDWR | O_NOCTTY)) > 0)
+               if ((fd = open(device, O_RDWR | O_NOCTTY)) != -1)
                {
                        struct termios tios;
                        int rts = TIOCM_RTS;
@@ -171,7 +171,7 @@ static int multimeter_init (void)
                        tcflush(fd, TCIFLUSH);
                        tcsetattr(fd, TCSANOW, &tios);
                        ioctl(fd, TIOCMBIC, &rts);
-                       
+
                        if (multimeter_read_value (&value) < -1)
                        {
                                close (fd);
index a964cce..1ce09f4 100644 (file)
@@ -1649,15 +1649,15 @@ static XS (Collectd_plugin_dispatch_values)
 
        values = ST (/* stack index = */ 0);
 
+       if (NULL == values)
+               XSRETURN_EMPTY;
+
        /* Make sure the argument is a hash reference. */
        if (! (SvROK (values) && (SVt_PVHV == SvTYPE (SvRV (values))))) {
                log_err ("Collectd::plugin_dispatch_values: Invalid values.");
                XSRETURN_EMPTY;
        }
 
-       if (NULL == values)
-               XSRETURN_EMPTY;
-
        ret = pplugin_dispatch_values (aTHX_ (HV *)SvRV (values));
 
        if (0 == ret)
index 9f0a800..e94ad8f 100644 (file)
@@ -336,6 +336,7 @@ static int pb_add_socket (pinba_socket_t *s, /* {{{ */
     char errbuf[1024];
     ERROR ("pinba plugin: bind(2) failed: %s",
         sstrerror (errno, errbuf, sizeof (errbuf)));
+    close (fd);
     return (0);
   }
 
index 54c856d..73d590a 100644 (file)
@@ -1045,7 +1045,7 @@ static int config_query_param_add (udb_query_t *q, oconfig_item_t *ci)
 
        data = udb_query_get_user_data (q);
        if (NULL == data) {
-               data = (c_psql_user_data_t *) smalloc (sizeof (*data));
+               data = (c_psql_user_data_t *) malloc (sizeof (*data));
                if (NULL == data) {
                        log_err ("Out of memory.");
                        return -1;
index beded1a..fcbac4f 100644 (file)
@@ -188,7 +188,7 @@ static int tbl_config_result (tbl_t *tbl, oconfig_item_t *ci)
 
        res = (tbl_result_t *)realloc (tbl->results,
                        (tbl->results_num + 1) * sizeof (*tbl->results));
-       if (NULL == tbl) {
+       if (res == NULL) {
                char errbuf[1024];
                log_err ("realloc failed: %s.",
                                sstrerror (errno, errbuf, sizeof (errbuf)));
index 201e182..0e683ce 100644 (file)
@@ -258,6 +258,7 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh)
                        WARNING ("teamspeak2 plugin: connect failed: %s",
                                        sstrerror (errno, errbuf, sizeof (errbuf)));
                        close (sd);
+                       sd = -1;
                        continue;
                }
 
index 8dcb711..a5e50a2 100644 (file)
@@ -872,6 +872,7 @@ int ut_config (oconfig_item_t *ci)
 { /* {{{ */
   int i;
   int status = 0;
+  int old_size = c_avl_size (threshold_tree);
 
   threshold_t th;
 
@@ -915,7 +916,9 @@ int ut_config (oconfig_item_t *ci)
       break;
   }
 
-  if (c_avl_size (threshold_tree) > 0) {
+  /* register callbacks if this is the first time we see a valid config */
+  if ((old_size == 0) && (c_avl_size (threshold_tree) > 0))
+  {
     plugin_register_missing ("threshold", ut_missing,
         /* user data = */ NULL);
     plugin_register_write ("threshold", ut_check_threshold,
index 70b8908..cbd1506 100644 (file)
@@ -41,7 +41,7 @@ struct fbhash_s
   c_avl_tree_t *tree;
 };
 
-/* 
+/*
  * Private functions
  */
 static void fbh_free_tree (c_avl_tree_t *tree) /* {{{ */
@@ -198,7 +198,7 @@ static int fbh_check_file (fbhash_t *h) /* {{{ */
   return (status);
 } /* }}} int fbh_check_file */
 
-/* 
+/*
  * Public functions
  */
 fbhash_t *fbh_create (const char *file) /* {{{ */
@@ -228,6 +228,7 @@ fbhash_t *fbh_create (const char *file) /* {{{ */
   if (status != 0)
   {
     fbh_destroy (h);
+    free (h);
     return (NULL);
   }
 
index 5e609e6..7bb0433 100644 (file)
@@ -227,6 +227,19 @@ static int vmem_read (void)
       value_t value  = { .derive = counter };
       submit_one (inst, "vmpage_action", "refill", value);
     }
+    else if (strncmp ("pgsteal_kswapd_", key, strlen ("pgsteal_kswapd_")) == 0)
+    {
+      char *inst = key + strlen ("pgsteal_kswapd_");
+      value_t value  = { .derive = counter };
+      submit_one (inst, "vmpage_action", "steal_kswapd", value);
+    }
+    else if (strncmp ("pgsteal_direct_", key, strlen ("pgsteal_direct_")) == 0)
+    {
+      char *inst = key + strlen ("pgsteal_direct_");
+      value_t value  = { .derive = counter };
+      submit_one (inst, "vmpage_action", "steal_direct", value);
+    }
+    /* For backwards compatibility (somewhen before 4.2.3) */
     else if (strncmp ("pgsteal_", key, strlen ("pgsteal_")) == 0)
     {
       char *inst = key + strlen ("pgsteal_");