Merge branch 'collectd-5.4' into collectd-5.5
authorMarc Fournier <marc.fournier@camptocamp.com>
Mon, 30 Nov 2015 21:58:29 +0000 (22:58 +0100)
committerMarc Fournier <marc.fournier@camptocamp.com>
Mon, 30 Nov 2015 21:58:29 +0000 (22:58 +0100)
15 files changed:
configure.ac
src/Makefile.am
src/amqp.c
src/bind.c
src/cpu.c
src/csv.c
src/filecount.c
src/irq.c
src/modbus.c
src/ntpd.c
src/powerdns.c
src/processes.c
src/rrdtool.c
src/snmp.c
src/write_graphite.c

index bb62d8c..9c34443 100644 (file)
@@ -57,12 +57,23 @@ AC_PROG_YACC
 PKG_PROG_PKG_CONFIG
 
 AC_CHECK_PROG([have_protoc_c], [protoc-c], [yes], [no])
-AC_CHECK_HEADERS([google/protobuf-c/protobuf-c.h],
-                 [have_protobuf_c_h="yes"],
-                 [have_protobuf_c_h="no"])
-if test "x$have_protoc_c" = "xyes" && test "x$have_protobuf_c_h" != "xyes"
+if test "x$have_protoc_c" = "xno"
 then
-       have_protoc_c="no (unable to find <google/protobuf-c/protobuf-c.h>)"
+       have_protoc_c="no (protoc-c compiler not found)"
+fi
+
+if test "x$have_protoc_c" = "xyes"
+then
+       AC_CHECK_HEADERS([protobuf-c/protobuf-c.h google/protobuf-c/protobuf-c.h],
+                        [have_protoc_c="yes"; break],
+                        [have_protoc_c="no (<google/protobuf-c/protobuf-c.h> not found)"])
+fi
+if test "x$have_protoc_c" = "xyes"
+then
+       AC_CHECK_LIB([protobuf-c], [protobuf_c_message_pack],
+                    [have_protoc_c="yes"],
+                    [have_protoc_c="no (libprotobuf-c not found)"])
+
 fi
 AM_CONDITIONAL(HAVE_PROTOC_C, test "x$have_protoc_c" = "xyes")
 
@@ -2025,12 +2036,6 @@ then
                GCRYPT_CPPFLAGS=`"$with_libgcrypt_config" --cflags 2>/dev/null`
        fi
 
-       if test "x$GCRYPT_LDFLAGS" = "x"
-       then
-               gcrypt_exec_prefix=`"$with_libgcrypt_config" --exec-prefix 2>/dev/null`
-               GCRYPT_LDFLAGS="-L$gcrypt_exec_prefix/lib"
-       fi
-
        if test "x$GCRYPT_LIBS" = "x"
        then
                GCRYPT_LIBS=`"$with_libgcrypt_config" --libs 2>/dev/null`
@@ -2039,8 +2044,10 @@ fi
 
 SAVE_CPPFLAGS="$CPPFLAGS"
 SAVE_LDFLAGS="$LDFLAGS"
+SAVE_LIBS="$LIBS"
 CPPFLAGS="$CPPFLAGS $GCRYPT_CPPFLAGS"
 LDFLAGS="$LDFLAGS $GCRYPT_LDFLAGS"
+LIBS="$LIBS $GCRYPT_LIBS"
 
 if test "x$with_libgcrypt" = "xyes"
 then
@@ -2055,10 +2062,6 @@ fi
 
 if test "x$with_libgcrypt" = "xyes"
 then
-       if test "x$GCRYPT_LDFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([gcrypt LDFLAGS: $GCRYPT_LDFLAGS])
-       fi
        AC_CHECK_LIB(gcrypt, gcry_md_hash_buffer,
                [with_libgcrypt="yes"],
                [with_libgcrypt="no (symbol gcry_md_hash_buffer not found)"])
@@ -2072,6 +2075,7 @@ fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
 LDFLAGS="$SAVE_LDFLAGS"
+LIBS="$SAVE_LIBS"
 
 if test "x$with_libgcrypt" = "xyes"
 then
index a9a8089..d53ec0c 100644 (file)
@@ -1326,25 +1326,30 @@ EXTRA_DIST +=   collectd.conf.pod \
                echo "$@ has some POD errors!"; false; \
        fi
 
+AM_V_PROTOC_C = $(am__v_PROTOC_C_@AM_V@)
+am__v_PROTOC_C_ = $(am__v_PROTOC_C_@AM_DEFAULT_V@)
+am__v_PROTOC_C_0 = @echo "  PROTOC-C    " $@;
+am__v_PROTOC_C_1 =
+
 # Protocol buffer for the "pinba" plugin.
 EXTRA_DIST += pinba.proto
-if HAVE_PROTOC_C
+if BUILD_PLUGIN_PINBA
 CLEANFILES += pinba.pb-c.c pinba.pb-c.h
 BUILT_SOURCES += pinba.pb-c.c pinba.pb-c.h
 
 pinba.pb-c.c pinba.pb-c.h: pinba.proto
-       protoc-c -I$(srcdir) --c_out . $(srcdir)/pinba.proto
+       $(AM_V_PROTOC_C)protoc-c -I$(srcdir) --c_out . $(srcdir)/pinba.proto
 endif
 
 # Protocol buffer for the "write_riemann" plugin.
 EXTRA_DIST += riemann.proto
-if HAVE_PROTOC_C
+if BUILD_PLUGIN_WRITE_RIEMANN
 CLEANFILES += riemann.pb-c.c riemann.pb-c.h
 
 BUILT_SOURCES += riemann.pb-c.c riemann.pb-c.h
 
 riemann.pb-c.c riemann.pb-c.h: riemann.proto
-       protoc-c -I$(srcdir) --c_out . $(srcdir)/riemann.proto
+       $(AM_V_PROTOC_C)protoc-c -I$(srcdir) --c_out . $(srcdir)/riemann.proto
 endif
 
 install-exec-hook:
index aba4f01..4206bdc 100644 (file)
@@ -199,11 +199,11 @@ static char *camqp_strerror (camqp_config_t *conf, /* {{{ */
     switch (r.reply_type)
     {
         case AMQP_RESPONSE_NORMAL:
-            sstrncpy (buffer, "Success", sizeof (buffer));
+            sstrncpy (buffer, "Success", buffer_size);
             break;
 
         case AMQP_RESPONSE_NONE:
-            sstrncpy (buffer, "Missing RPC reply type", sizeof (buffer));
+            sstrncpy (buffer, "Missing RPC reply type", buffer_size);
             break;
 
         case AMQP_RESPONSE_LIBRARY_EXCEPTION:
@@ -215,7 +215,7 @@ static char *camqp_strerror (camqp_config_t *conf, /* {{{ */
                 return (sstrerror (r.library_error, buffer, buffer_size));
 #endif
             else
-                sstrncpy (buffer, "End of stream", sizeof (buffer));
+                sstrncpy (buffer, "End of stream", buffer_size);
             break;
 
         case AMQP_RESPONSE_SERVER_EXCEPTION:
index 32b0f16..c5327f1 100644 (file)
@@ -1666,7 +1666,7 @@ static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */
   if (tmp->name == NULL)
   {
     ERROR ("bind plugin: strdup failed.");
-    free (tmp);
+    sfree (views);
     return (-1);
   }
 
index 2a2a4a9..c946250 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -221,15 +221,25 @@ static int init (void)
 
        port_host = mach_host_self ();
 
-       /* FIXME: Free `cpu_list' if it's not NULL */
-       if ((status = host_processors (port_host, &cpu_list, &cpu_list_len)) != KERN_SUCCESS)
+       status = host_processors (port_host, &cpu_list, &cpu_list_len);
+       if (status == KERN_INVALID_ARGUMENT)
        {
-               ERROR ("cpu plugin: host_processors returned %i", (int) status);
+               ERROR ("cpu plugin: Don't have a privileged host control port. "
+                               "The most common cause for this problem is "
+                               "that collectd is running without root "
+                               "privileges, which are required to read CPU "
+                               "load information. "
+                               "<https://collectd.org/bugs/22>");
+               cpu_list_len = 0;
+               return (-1);
+       }
+       if (status != KERN_SUCCESS)
+       {
+               ERROR ("cpu plugin: host_processors() failed with status %d.", (int) status);
                cpu_list_len = 0;
                return (-1);
        }
 
-       DEBUG ("host_processors returned %i %s", (int) cpu_list_len, cpu_list_len == 1 ? "processor" : "processors");
        INFO ("cpu plugin: Found %i processor%s.", (int) cpu_list_len, cpu_list_len == 1 ? "" : "s");
 /* #endif PROCESSOR_CPU_LOAD_INFO */
 
index b6e535e..0772873 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
@@ -64,13 +64,16 @@ static int value_list_to_string (char *buffer, int buffer_len,
                                && (ds->ds[i].type != DS_TYPE_GAUGE)
                                && (ds->ds[i].type != DS_TYPE_DERIVE)
                                && (ds->ds[i].type != DS_TYPE_ABSOLUTE))
+               {
+                       sfree (rates);
                        return (-1);
+               }
 
-               if (ds->ds[i].type == DS_TYPE_GAUGE) 
+               if (ds->ds[i].type == DS_TYPE_GAUGE)
                {
                        status = ssnprintf (buffer + offset, buffer_len - offset,
                                        ",%lf", vl->values[i].gauge);
-               } 
+               }
                else if (store_rates != 0)
                {
                        if (rates == NULL)
index 47caf93..9ea8af7 100644 (file)
@@ -356,6 +356,7 @@ static int fc_config_add_dir (oconfig_item_t *ci)
   if (dir->path == NULL)
   {
     ERROR ("filecount plugin: strdup failed.");
+    sfree (dir);
     return (-1);
   }
 
index 6afacf0..93f3f53 100644 (file)
--- a/src/irq.c
+++ b/src/irq.c
@@ -120,6 +120,7 @@ static int irq_read (void)
        } else {
                ERROR ("irq plugin: unable to get CPU count from first line "
                                "of /proc/interrupts");
+               fclose (fh);
                return (-1);
        }
 
index 08871a2..97b98b7 100644 (file)
@@ -942,9 +942,15 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */
 
   status = cf_util_get_string_buffer (ci, host->host, sizeof (host->host));
   if (status != 0)
+  {
+    sfree (host);
     return (status);
+  }
   if (host->host[0] == 0)
+  {
+    sfree (host);
     return (EINVAL);
+  }
 
   for (i = 0; i < ci->children_num; i++)
   {
index 5fdfef3..ceb1442 100644 (file)
@@ -310,7 +310,7 @@ static int ntpd_config (const char *key, const char *value)
        return (0);
 }
 
-static void ntpd_submit (char *type, char *type_inst, double value)
+static void ntpd_submit (char *type, char *type_inst, gauge_t value)
 {
        value_t values[1];
        value_list_t vl = VALUE_LIST_INIT;
@@ -332,7 +332,7 @@ static void ntpd_submit (char *type, char *type_inst, double value)
  * sets the LSB based on whether the peer was reachable. If the LSB is zero,
  * the values are out of date. */
 static void ntpd_submit_reach (char *type, char *type_inst, uint8_t reach,
-               double value)
+               gauge_t value)
 {
        if (!(reach & 1))
                value = NAN;
@@ -905,9 +905,19 @@ static int ntpd_read (void)
        int                       ps_num;
        int                       ps_size;
 
+       gauge_t offset_loop;
+       gauge_t freq_loop;
+       gauge_t offset_error;
+
        int status;
        int i;
 
+       /* On Linux, if the STA_NANO bit is set in ik->status, then ik->offset
+        * is is nanoseconds, otherwise it's microseconds.
+        * TODO(octo): STA_NANO is defined in the Linux specific <sys/timex.h> header. */
+       double scale_loop  = 1e-6;
+       double scale_error = 1e-6;
+
        ik      = NULL;
        ik_num  = 0;
        ik_size = 0;
@@ -930,18 +940,19 @@ static int ntpd_read (void)
        }
 
        /* kerninfo -> estimated error */
+       offset_loop  = scale_loop * ((gauge_t) ntohl (ik->offset));
+       freq_loop    = ntpd_read_fp (ik->freq);
+       offset_error = scale_error * ((gauge_t) ntohl (ik->esterror));
 
        DEBUG ("info_kernel:\n"
-                       "  pll offset    = %.8f\n"
-                       "  pll frequency = %.8f\n" /* drift compensation */
-                       "  est error     = %.8f\n",
-                       ntpd_read_fp (ik->offset),
-                       ntpd_read_fp (ik->freq),
-                       ntpd_read_fp (ik->esterror));
-
-       ntpd_submit ("frequency_offset", "loop",  ntpd_read_fp (ik->freq));
-       ntpd_submit ("time_offset",      "loop",  ntpd_read_fp (ik->offset));
-       ntpd_submit ("time_offset",      "error", ntpd_read_fp (ik->esterror));
+                       "  pll offset    = %.8g\n"
+                       "  pll frequency = %.8g\n" /* drift compensation */
+                       "  est error     = %.8g\n",
+                       offset_loop, freq_loop, offset_error);
+
+       ntpd_submit ("frequency_offset", "loop",  freq_loop);
+       ntpd_submit ("time_offset",      "loop",  offset_loop);
+       ntpd_submit ("time_offset",      "error", offset_error);
 
        free (ik);
        ik = NULL;
index f9f291a..c9e9359 100644 (file)
@@ -123,7 +123,7 @@ user-msec           number of CPU milliseconds spent in 'user' mode
 
 const char* const default_server_fields[] = /* {{{ */
 {
-  "latency"
+  "latency",
   "packetcache-hit",
   "packetcache-miss",
   "packetcache-size",
index bac61c0..e437209 100644 (file)
@@ -280,6 +280,7 @@ static void ps_list_register (const char *name, const char *regexp)
                {
                        DEBUG ("ProcessMatch: compiling the regular expression \"%s\" failed.", regexp);
                        sfree(new->re);
+                       sfree(new);
                        return;
                }
        }
index 8497a24..9b5723a 100644 (file)
@@ -733,7 +733,10 @@ static int rrd_cache_insert (const char *filename,
        {
                rc = malloc (sizeof (*rc));
                if (rc == NULL)
+               {
+                       pthread_mutex_unlock (&cache_lock);
                        return (-1);
+               }
                rc->values_num = 0;
                rc->values = NULL;
                rc->first_value = 0;
@@ -1204,6 +1207,7 @@ static int rrd_init (void)
        cache = c_avl_create ((int (*) (const void *, const void *)) strcmp);
        if (cache == NULL)
        {
+               pthread_mutex_unlock (&cache_lock);
                ERROR ("rrdtool plugin: c_avl_create failed.");
                return (-1);
        }
index 3d66041..cf7d975 100644 (file)
@@ -1737,6 +1737,7 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data)
     res = NULL;
 
     sfree (errstr);
+    sfree (vl.values);
     csnmp_host_close_session (host);
 
     return (-1);
index 41451a8..a7eef3f 100644 (file)
@@ -132,7 +132,7 @@ static int wg_send_buffer (struct wg_callback *cb)
     ssize_t status = 0;
 
     status = swrite (cb->sock_fd, cb->send_buf, strlen (cb->send_buf));
-    if (status < 0)
+    if (status != 0)
     {
         const char *protocol = cb->protocol ? cb->protocol : WG_DEFAULT_PROTOCOL;