Merge remote-tracking branch 'github/pr/1082'
authorFlorian Forster <octo@collectd.org>
Thu, 25 Jun 2015 19:40:27 +0000 (21:40 +0200)
committerFlorian Forster <octo@collectd.org>
Thu, 25 Jun 2015 19:40:27 +0000 (21:40 +0200)
63 files changed:
README
configure.ac
contrib/redhat/collectd.spec
src/Makefile.am
src/amqp.c
src/apache.c
src/barometer.c
src/battery.c
src/ceph.c
src/collectd.conf.pod
src/collectdmon.c
src/curl.c
src/curl_json.c
src/curl_xml.c
src/daemon/collectd.c
src/daemon/common.c
src/daemon/configfile.c
src/daemon/filter_chain.c
src/daemon/utils_avltree.c
src/daemon/utils_cache.c
src/daemon/utils_llist.c
src/df.c
src/disk.c
src/email.c
src/exec.c
src/gmond.c
src/ipvs.c
src/java.c
src/libcollectdclient/client.c
src/liboconfig/Makefile.am
src/liboconfig/oconfig.c
src/liboconfig/parser.y
src/liboconfig/scanner.l
src/memcachec.c
src/modbus.c
src/mysql.c
src/network.c
src/nfs.c
src/ntpd.c
src/onewire.c
src/openldap.c
src/openvpn.c
src/perl.c
src/ping.c
src/powerdns.c
src/rrdtool.c
src/snmp.c
src/table.c
src/tail.c
src/tail_csv.c
src/target_notification.c
src/ted.c
src/threshold.c
src/turbostat.c
src/utils_cmd_flush.c
src/utils_cmd_putval.c
src/utils_db_query.c
src/utils_ignorelist.c
src/utils_latency.c
src/utils_rrdcreate.c
src/virt.c
src/write_redis.c
src/write_sensu.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 f6fe57c..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
@@ -298,7 +298,8 @@ AC_CHECK_HEADERS(netinet/udp.h, [], [],
 #endif
 ])
 
-AC_CHECK_TYPES([struct ip6_ext], [], [],
+have_ip6_ext="no"
+AC_CHECK_TYPES([struct ip6_ext], [have_ip6_ext="yes"], [have_ip6_ext="no"],
 [#if HAVE_STDINT_H
 # include <stdint.h>
 #endif
@@ -316,6 +317,35 @@ AC_CHECK_TYPES([struct ip6_ext], [], [],
 #endif
 ])
 
+if test "x$have_ip6_ext" = "xno"; then
+       SAVE_CFLAGS="$CFLAGS"
+       CFLAGS="$CFLAGS -DSOLARIS2=8"
+
+       AC_CHECK_TYPES([struct ip6_ext],
+                      [have_ip6_ext="yes, with -DSOLARIS2=8"],
+                      [have_ip6_ext="no"],
+[#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_NETINET_IN_SYSTM_H
+# include <netinet/in_systm.h>
+#endif
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#if HAVE_NETINET_IP6_H
+# include <netinet/ip6.h>
+#endif
+])
+
+       if test "x$have_ip6_ext" = "xno"; then
+               CFLAGS="$SAVE_CFLAGS"
+       fi
+fi
+
 # For cpu modules
 AC_CHECK_HEADERS(sys/dkstat.h)
 if test "x$ac_system" = "xDarwin"
@@ -614,14 +644,14 @@ AC_CHECK_HEADERS(asm/msr-index.h, [have_asm_msrindex_h="yes"])
 
 if test "x$have_asm_msrindex_h" = "xyes"
 then
-  AC_CACHE_CHECK([whether asm/msr-index.h has MSR_CORE_C3_RESIDENCY],
+  AC_CACHE_CHECK([whether asm/msr-index.h has MSR_PKG_C10_RESIDENCY],
                  [c_cv_have_usable_asm_msrindex_h],
                  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
 [[[
 #include<asm/msr-index.h>
 ]]],
 [[[
-int y = MSR_CORE_C3_RESIDENCY;
+int y = MSR_PKG_C10_RESIDENCY;
 return(y);
 ]]]
   )],
index fd4cb46..5e83b0f 100644 (file)
@@ -226,7 +226,7 @@ Source:             http://collectd.org/files/%{name}-%{version}.tar.bz2
 License:       GPLv2
 Group:         System Environment/Daemons
 BuildRoot:     %{_tmppath}/%{name}-%{version}-root
-BuildRequires: libgcrypt-devel, kernel-headers, libtool-ltdl-devel, libcap-devel, flex, bison
+BuildRequires: libgcrypt-devel, kernel-headers, libtool-ltdl-devel, libcap-devel
 Vendor:                collectd development team <collectd@verplant.org>
 
 %if 0%{?el7:1}
@@ -1585,9 +1585,6 @@ Collectd utilities
 %define _with_zookeeper --disable-zookeeper
 %endif
 
-export YACC=bison
-export YFLAGS=-y
-
 %configure CFLAGS="%{optflags} -DLT_LAZY_OR_NOW=\"RTLD_LAZY|RTLD_GLOBAL\"" \
        --disable-static \
        --without-included-ltdl \
index 1282f22..65bb91a 100644 (file)
@@ -23,13 +23,25 @@ AM_CPPFLAGS += -DPKGDATADIR='"${pkgdatadir}"'
 
 AUTOMAKE_OPTIONS = subdir-objects
 
-noinst_LTLIBRARIES = libmount.la liblookup.la
+noinst_LTLIBRARIES =
+check_PROGRAMS =
+TESTS =
 
+noinst_LTLIBRARIES += liblookup.la
+liblookup_la_SOURCES = utils_vl_lookup.c utils_vl_lookup.h
+liblookup_la_LIBADD = daemon/libavltree.la
+check_PROGRAMS += test_utils_vl_lookup
+TESTS += test_utils_vl_lookup
+test_utils_vl_lookup_SOURCES = utils_vl_lookup_test.c testing.h
+test_utils_vl_lookup_LDADD = liblookup.la daemon/libcommon.la daemon/libplugin_mock.la
+
+noinst_LTLIBRARIES += libmount.la
 libmount_la_SOURCES = utils_mount.c utils_mount.h
-libmount_la_LIBADD = daemon/libcommon.la
+check_PROGRAMS += test_utils_mount
+TESTS += test_utils_mount
+test_utils_mount_SOURCES = utils_mount_test.c testing.h
+test_utils_mount_LDADD = libmount.la daemon/libcommon.la daemon/libplugin_mock.la
 
-liblookup_la_SOURCES = utils_vl_lookup.c utils_vl_lookup.h
-liblookup_la_LIBADD = daemon/libavltree.la daemon/libcommon.la
 
 sbin_PROGRAMS = collectdmon
 bin_PROGRAMS = collectd-nagios collectdctl collectd-tg
@@ -954,7 +966,7 @@ pkglib_LTLIBRARIES += statsd.la
 statsd_la_SOURCES = statsd.c \
                     utils_latency.h utils_latency.c
 statsd_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-statsd_la_LIBADD = -lpthread
+statsd_la_LIBADD = -lpthread -lm
 endif
 
 if BUILD_PLUGIN_SWAP
@@ -1387,12 +1399,4 @@ uninstall-hook:
        rm -f $(DESTDIR)$(sysconfdir)/collectd.conf
        rm -f $(DESTDIR)$(pkgdatadir)/postgresql_default.conf;
 
-check_PROGRAMS = test_utils_mount test_utils_vl_lookup
-
-test_utils_mount_SOURCES = utils_mount_test.c testing.h
-test_utils_mount_LDADD = libmount.la daemon/libplugin_mock.la
-
-test_utils_vl_lookup_SOURCES = utils_vl_lookup_test.c testing.h
-test_utils_vl_lookup_LDADD = liblookup.la daemon/libplugin_mock.la
 
-TESTS = test_utils_mount test_utils_vl_lookup
index 97359cf..aba4f01 100644 (file)
@@ -716,7 +716,7 @@ static void *camqp_subscribe_thread (void *user_data) /* {{{ */
             continue;
         }
 
-        status = camqp_read_header (conf);
+        camqp_read_header (conf);
 
         amqp_maybe_release_buffers (conf->connection);
     } /* while (subscriber_threads_running) */
index 82a267b..e384d80 100644 (file)
@@ -81,6 +81,7 @@ static void apache_free (apache_t *st)
                curl_easy_cleanup(st->curl);
                st->curl = NULL;
        }
+       sfree (st);
 } /* apache_free */
 
 static size_t apache_curl_callback (void *buf, size_t size, size_t nmemb,
index 2bfd51e..a6d9835 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->ring_buffer));
     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;
@@ -588,7 +581,7 @@ static int MPL115_detect(void)
     return 0;
 }
 
-/** 
+/**
  * Read the MPL115 sensor conversion coefficients.
  *
  * These are (device specific) constants so we can read them just once.
@@ -597,18 +590,18 @@ static int MPL115_detect(void)
  */
 static int MPL115_read_coeffs(void)
 {
-    uint8_t mpl115_coeffs[MPL115_NUM_COEFFS]
+    uint8_t mpl115_coeffs[MPL115_NUM_COEFFS] = { 0 };
     int32_t res;
 
     int8_t  sia0MSB, sia0LSB, sib1MSB, sib1LSB, sib2MSB, sib2LSB;
     int8_t  sic12MSB, sic12LSB, sic11MSB, sic11LSB, sic22MSB, sic22LSB;
     int16_t sia0, sib1, sib2, sic12, sic11, sic22;
-      
+
     char errbuf[1024];
 
-    res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, 
-                                        MPL115_ADDR_COEFFS, 
-                                        MPL115_NUM_COEFFS, 
+    res = i2c_smbus_read_i2c_block_data(i2c_bus_fd,
+                                        MPL115_ADDR_COEFFS,
+                                        STATIC_ARRAY_SIZE (mpl115_coeffs),
                                         mpl115_coeffs);
     if (res < 0)
     {
@@ -616,7 +609,7 @@ static int MPL115_read_coeffs(void)
                sstrerror (errno, errbuf, sizeof (errbuf)));
         return -1;
     }
-   
+
     /* Using perhaps less elegant/efficient code, but more readable. */
     /* a0: 16total 1sign 12int 4fract 0pad */
     sia0MSB = mpl115_coeffs[0];
@@ -625,7 +618,7 @@ static int MPL115_read_coeffs(void)
     sia0 += (int16_t) sia0LSB & 0x00FF;    /* Add LSB to 16bit number */
     mpl115_coeffA0 = (double) (sia0);
     mpl115_coeffA0 /= 8.0;                 /* 3 fract bits */
-    
+
     /* b1: 16total 1sign 2int 13fract 0pad */
     sib1MSB= mpl115_coeffs[2];
     sib1LSB= mpl115_coeffs[3];
@@ -633,7 +626,7 @@ static int MPL115_read_coeffs(void)
     sib1 += sib1LSB & 0x00FF;              /* Add LSB to 16bit number */
     mpl115_coeffB1 = (double) (sib1);
     mpl115_coeffB1 /= 8192.0;              /* 13 fract */
-    
+
     /* b2: 16total 1sign 1int 14fract 0pad */
     sib2MSB= mpl115_coeffs[4];
     sib2LSB= mpl115_coeffs[5];
@@ -670,11 +663,11 @@ static int MPL115_read_coeffs(void)
     mpl115_coeffC22 /= 33554432.0;          /* 10+15=25 fract */
 
     DEBUG("barometer: MPL115_read_coeffs: a0=%lf, b1=%lf, b2=%lf, c12=%lf, c11=%lf, c22=%lf",
-          mpl115_coeffA0, 
-          mpl115_coeffB1, 
-          mpl115_coeffB2, 
-          mpl115_coeffC12, 
-          mpl115_coeffC11, 
+          mpl115_coeffA0,
+          mpl115_coeffB1,
+          mpl115_coeffB2,
+          mpl115_coeffC12,
+          mpl115_coeffC11,
           mpl115_coeffC22);
     return 0;
 }
@@ -706,7 +699,7 @@ static void MPL115_convert_adc_to_real(double   adc_pressure,
 }
 
 
-/** 
+/**
  * Read sensor averegaed measurements
  *
  * @param pressure    averaged measured pressure
@@ -716,7 +709,7 @@ static void MPL115_convert_adc_to_real(double   adc_pressure,
  */
 static int MPL115_read_averaged(double * pressure, double * temperature)
 {
-    uint8_t mpl115_conv[MPL115_NUM_CONV]
+    uint8_t mpl115_conv[MPL115_NUM_CONV] = { 0 };
     int8_t  res;
     int     retries;
     int     conv_pressure;
@@ -727,7 +720,7 @@ static int MPL115_read_averaged(double * pressure, double * temperature)
 
     *pressure    = 0.0;
     *temperature = 0.0;
-   
+
     /* start conversion of both temp and presure */
     retries = MPL115_CONVERSION_RETRIES;
     while (retries>0)
@@ -763,8 +756,8 @@ static int MPL115_read_averaged(double * pressure, double * temperature)
     {
         res = i2c_smbus_read_i2c_block_data(i2c_bus_fd,
                                             MPL115_ADDR_CONV,
-                                            MPL115_NUM_CONV,
-                                            mpl115_conv); 
+                                            STATIC_ARRAY_SIZE (mpl115_conv),
+                                            mpl115_conv);
         if (res >= 0)
             break;
 
@@ -784,7 +777,7 @@ static int MPL115_read_averaged(double * pressure, double * temperature)
             return -1;
         }
     }
-    
+
     conv_pressure    = ((mpl115_conv[0] << 8) | mpl115_conv[1]) >> 6;
     conv_temperature = ((mpl115_conv[2] << 8) | mpl115_conv[3]) >> 6;
     DEBUG ("barometer: MPL115_read_averaged, raw pressure ADC value = %d, " \
@@ -803,7 +796,7 @@ static int MPL115_read_averaged(double * pressure, double * temperature)
            adc_temperature,
            *pressure,
            *temperature);
-    
+
     return 0;
 }
 
index 9b060dd..c4c050d 100644 (file)
@@ -556,7 +556,7 @@ static int read_acpi_full_capacity (char const *dir, /* {{{ */
 
        ssnprintf (filename, sizeof (filename), "%s/%s/info", dir, power_supply);
        fh = fopen (filename, "r");
-       if ((fh = fopen (filename, "r")) == NULL)
+       if (fh == NULL)
                return (errno);
 
        /* last full capacity:      40090 mWh */
@@ -615,7 +615,7 @@ static int read_acpi_callback (char const *dir, /* {{{ */
 
        ssnprintf (filename, sizeof (filename), "%s/%s/state", dir, power_supply);
        fh = fopen (filename, "r");
-       if ((fh = fopen (filename, "r")) == NULL)
+       if (fh == NULL)
        {
                if ((errno == EAGAIN) || (errno == EINTR) || (errno == ENOENT))
                        return (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 ab3bbf8..9412ed3 100644 (file)
@@ -1565,7 +1565,7 @@ setting accordingly to prevent this from blocking other plugins.
 =head2 Plugin C<curl_json>
 
 The B<curl_json plugin> collects values from JSON data to be parsed by
-B<libyajl> (L<http://www.lloydforge.org/projects/yajl/>) retrieved via
+B<libyajl> (L<https://lloyd.github.io/yajl/>) retrieved via
 either B<libcurl> (L<http://curl.haxx.se/>) or read directly from a
 unix socket. The former can be used, for example, to collect values
 from CouchDB documents (which are stored JSON notation), and the
@@ -4513,6 +4513,16 @@ The following options are accepted within each B<Instance> block:
 Sets the URL to use to connect to the I<OpenLDAP> server. This option is
 I<mandatory>.
 
+=item B<BindDN> I<BindDN>
+
+Name in the form of an LDAP distinguished name intended to be used for 
+authentication. Defaults to empty string to establish an anonymous authorization.
+
+=item B<Password> I<Password>
+
+Password for simple bind authentication. If this option is not set, 
+unauthenticated bind operation is used.
+
 =item B<StartTLS> B<true|false>
 
 Defines whether TLS must be used when connecting to the I<OpenLDAP> server.
index 6c50cf1..33f02b4 100644 (file)
@@ -317,7 +317,10 @@ int main (int argc, char **argv)
        openlog ("collectdmon", LOG_CONS | LOG_PID, LOG_DAEMON);
 
        if (-1 == daemonize ())
+       {
+               free (collectd_argv);
                return 1;
+       }
 
        sa.sa_handler = sig_int_term_handler;
        sa.sa_flags   = 0;
@@ -325,11 +328,13 @@ int main (int argc, char **argv)
 
        if (0 != sigaction (SIGINT, &sa, NULL)) {
                syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno));
+               free (collectd_argv);
                return 1;
        }
 
        if (0 != sigaction (SIGTERM, &sa, NULL)) {
                syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno));
+               free (collectd_argv);
                return 1;
        }
 
@@ -337,6 +342,7 @@ int main (int argc, char **argv)
 
        if (0 != sigaction (SIGHUP, &sa, NULL)) {
                syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno));
+               free (collectd_argv);
                return 1;
        }
 
index b750f80..ac4cc51 100644 (file)
@@ -327,7 +327,10 @@ static int cc_config_add_match (web_page_t *page, /* {{{ */
   } /* while (status == 0) */
 
   if (status != 0)
+  {
+    cc_web_match_free (match);
     return (status);
+  }
 
   match->match = match_create_simple (match->regex, match->exclude_regex,
       match->dstype);
index 937a237..00993c0 100644 (file)
@@ -503,6 +503,7 @@ static int cj_config_add_key (cj_t *db, /* {{{ */
   {
     ERROR ("curl_json plugin: cj_config: "
            "Invalid key: %s", ci->key);
+    cj_key_free (key);
     return (-1);
   }
 
@@ -552,7 +553,6 @@ static int cj_config_add_key (cj_t *db, /* {{{ */
       db->tree = cj_avl_create();
 
     tree = db->tree;
-    name = key->path;
     ptr = key->path;
     if (*ptr == '/')
       ++ptr;
@@ -697,6 +697,7 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */
   {
     ERROR ("curl_json plugin: cj_config: "
            "Invalid key: %s", ci->key);
+    cj_free (db);
     return (-1);
   }
   if (status != 0)
index 97b964b..21f1b5b 100644 (file)
@@ -941,6 +941,7 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */
   {
     ERROR ("curl_xml plugin: cx_config: "
            "Invalid key: %s", ci->key);
+    cx_free (db);
     return (-1);
   }
 
index a708665..46e13b3 100644 (file)
@@ -408,8 +408,9 @@ static int pidfile_create (void)
 static int pidfile_remove (void)
 {
        const char *file = global_option_get ("PIDFile");
+       if (file == NULL)
+               return 0;
 
-       DEBUG ("unlink (%s)", (file != NULL) ? file : "<null>");
        return (unlink (file));
 } /* static int pidfile_remove (const char *file) */
 #endif /* COLLECT_DAEMON */
index e396b79..4720399 100644 (file)
@@ -312,44 +312,51 @@ int strsplit (char *string, char **fields, size_t size)
        return ((int) i);
 }
 
-int strjoin (char *dst, size_t dst_len,
+int strjoin (char *buffer, size_t buffer_size,
                char **fields, size_t fields_num,
                const char *sep)
 {
-       size_t field_len;
+       size_t avail;
+       char *ptr;
        size_t sep_len;
-       int i;
-
-       memset (dst, '\0', dst_len);
+       size_t i;
 
-       if (fields_num <= 0)
+       if ((buffer_size < 1) || (fields_num <= 0))
                return (-1);
 
+       memset (buffer, 0, buffer_size);
+       ptr = buffer;
+       avail = buffer_size - 1;
+
        sep_len = 0;
        if (sep != NULL)
                sep_len = strlen (sep);
 
-       for (i = 0; i < (int)fields_num; i++)
+       for (i = 0; i < fields_num; i++)
        {
+               size_t field_len;
+
                if ((i > 0) && (sep_len > 0))
                {
-                       if (dst_len <= sep_len)
+                       if (avail < sep_len)
                                return (-1);
 
-                       strncat (dst, sep, dst_len);
-                       dst_len -= sep_len;
+                       memcpy (ptr, sep, sep_len);
+                       ptr += sep_len;
+                       avail -= sep_len;
                }
 
                field_len = strlen (fields[i]);
-
-               if (dst_len <= field_len)
+               if (avail < field_len)
                        return (-1);
 
-               strncat (dst, fields[i], dst_len);
-               dst_len -= field_len;
+               memcpy (ptr, fields[i], field_len);
+               ptr += field_len;
+               avail -= field_len;
        }
 
-       return (strlen (dst));
+       assert (buffer[buffer_size - 1] == 0);
+       return (strlen (buffer));
 }
 
 int strsubstitute (char *str, char c_from, char c_to)
index da7ed5f..f367ee9 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);
 
@@ -154,9 +156,12 @@ static int cf_dispatch (const char *type, const char *orig_key,
        int ret;
        int i;
 
+       if (orig_key == NULL)
+               return (EINVAL);
+
        DEBUG ("type = %s, key = %s, value = %s",
                        ESCAPE_NULL(type),
-                       ESCAPE_NULL(orig_key),
+                       orig_key,
                        ESCAPE_NULL(orig_value));
 
        if ((cf_cb = cf_search (type)) == NULL)
@@ -197,8 +202,6 @@ static int cf_dispatch (const char *type, const char *orig_key,
        free (key);
        free (value);
 
-       DEBUG ("cf_dispatch: return (%i)", ret);
-
        return (ret);
 } /* int cf_dispatch */
 
@@ -225,7 +228,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 +254,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 +267,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 +356,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;
@@ -757,6 +760,9 @@ static oconfig_item_t *cf_read_dir (const char *dir,
                filenames[filenames_num - 1] = sstrdup (name);
        }
 
+       if (filenames == NULL)
+               return (root);
+
        qsort ((void *) filenames, filenames_num, sizeof (*filenames),
                        cf_compare_string);
 
index 0fd4a73..5042913 100644 (file)
@@ -392,7 +392,6 @@ static int fc_config_add_rule (fc_chain_t *chain, /* {{{ */
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *option = ci->children + i;
-    status = 0;
 
     if (strcasecmp ("Match", option->key) == 0)
       status = fc_config_add_match (&rule->matches, option);
@@ -486,7 +485,6 @@ static int fc_config_add_chain (const oconfig_item_t *ci) /* {{{ */
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *option = ci->children + i;
-    status = 0;
 
     if (strcasecmp ("Rule", option->key) == 0)
       status = fc_config_add_rule (chain, option);
index 04e5403..e251975 100644 (file)
@@ -146,6 +146,9 @@ static c_avl_node_t *rotate_right (c_avl_tree_t *t, c_avl_node_t *x)
        c_avl_node_t *y;
        c_avl_node_t *b;
 
+       assert (x != NULL);
+       assert (x->left != NULL);
+
        p = x->parent;
        y = x->left;
        b = y->right;
@@ -170,7 +173,7 @@ static c_avl_node_t *rotate_right (c_avl_tree_t *t, c_avl_node_t *x)
        y->height = calc_height (y);
 
        return (y);
-} /* void rotate_left */
+} /* void rotate_right */
 
 /*
  *    (x)                   (y)
@@ -187,6 +190,9 @@ static c_avl_node_t *rotate_left (c_avl_tree_t *t, c_avl_node_t *x)
        c_avl_node_t *y;
        c_avl_node_t *b;
 
+       assert (x != NULL);
+       assert (x->right != NULL);
+
        p = x->parent;
        y = x->right;
        b = y->left;
@@ -617,10 +623,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 fe22f21..7b2f958 100644 (file)
@@ -303,7 +303,13 @@ int uc_check_timeout (void)
   pthread_mutex_unlock (&cache_lock);
 
   if (keys_len == 0)
+  {
+    /* realloc() may have been called for these. */
+    sfree (keys);
+    sfree (keys_time);
+    sfree (keys_interval);
     return (0);
+  }
 
   /* Call the "missing" callback for each value. Do this before removing the
    * value from the cache, so that callbacks can still access the data stored,
@@ -322,7 +328,6 @@ int uc_check_timeout (void)
     if (status != 0)
     {
       ERROR ("uc_check_timeout: parse_identifier_vl (\"%s\") failed.", keys[i]);
-      cache_free (ce);
       continue;
     }
 
@@ -648,12 +653,13 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number)
   if (status != 0)
   {
     size_t i;
-    
+
     for (i = 0; i < number; i++)
     {
       sfree (names[i]);
     }
     sfree (names);
+    sfree (times);
 
     return (-1);
   }
@@ -661,6 +667,8 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number)
   *ret_names = names;
   if (ret_times != NULL)
     *ret_times = times;
+  else
+    sfree (times);
   *ret_number = number;
 
   return (0);
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 a6fa526..61964f3 100644 (file)
--- a/src/df.c
+++ b/src/df.c
@@ -208,10 +208,11 @@ static int df_read (void)
                uint64_t blk_reserved;
                uint64_t blk_used;
 
-               if (ignorelist_match (il_device,
-                                       (mnt_ptr->spec_device != NULL)
-                                       ? mnt_ptr->spec_device
-                                       : mnt_ptr->device))
+               char const *dev = (mnt_ptr->spec_device != NULL)
+                       ? mnt_ptr->spec_device
+                       : mnt_ptr->device;
+
+               if (ignorelist_match (il_device, dev))
                        continue;
                if (ignorelist_match (il_mountpoint, mnt_ptr->dir))
                        continue;
@@ -234,10 +235,10 @@ static int df_read (void)
                if (by_device)
                {
                        /* eg, /dev/hda1  -- strip off the "/dev/" */
-                       if (strncmp (mnt_ptr->spec_device, "/dev/", strlen ("/dev/")) == 0)
-                               sstrncpy (disk_name, mnt_ptr->spec_device + strlen ("/dev/"), sizeof (disk_name));
+                       if (strncmp (dev, "/dev/", strlen ("/dev/")) == 0)
+                               sstrncpy (disk_name, dev + strlen ("/dev/"), sizeof (disk_name));
                        else
-                               sstrncpy (disk_name, mnt_ptr->spec_device, sizeof (disk_name));
+                               sstrncpy (disk_name, dev, sizeof (disk_name));
 
                        if (strlen(disk_name) < 1)
                        {
index 8830403..1c3dd98 100644 (file)
@@ -395,169 +395,112 @@ static int disk_read (void)
        io_registry_entry_t     disk;
        io_registry_entry_t     disk_child;
        io_iterator_t           disk_list;
-       CFDictionaryRef         props_dict;
+       CFMutableDictionaryRef  props_dict, child_dict;
        CFDictionaryRef         stats_dict;
-       CFDictionaryRef         child_dict;
        CFStringRef             tmp_cf_string_ref;
        kern_return_t           status;
 
-       signed long long read_ops;
-       signed long long read_byt;
-       signed long long read_tme;
-       signed long long write_ops;
-       signed long long write_byt;
-       signed long long write_tme;
+       signed long long read_ops, read_byt, read_tme;
+       signed long long write_ops, write_byt, write_tme;
 
-       int  disk_major;
-       int  disk_minor;
+       int  disk_major, disk_minor;
        char disk_name[DATA_MAX_NAME_LEN];
-       char disk_name_bsd[DATA_MAX_NAME_LEN];
+       char child_disk_name_bsd[DATA_MAX_NAME_LEN], props_disk_name_bsd[DATA_MAX_NAME_LEN];
 
        /* Get the list of all disk objects. */
-       if (IOServiceGetMatchingServices (io_master_port,
-                               IOServiceMatching (kIOBlockStorageDriverClass),
-                               &disk_list) != kIOReturnSuccess)
-       {
+       if (IOServiceGetMatchingServices (io_master_port, IOServiceMatching (kIOBlockStorageDriverClass), &disk_list) != kIOReturnSuccess) {
                ERROR ("disk plugin: IOServiceGetMatchingServices failed.");
                return (-1);
        }
 
-       while ((disk = IOIteratorNext (disk_list)) != 0)
-       {
+       while ((disk = IOIteratorNext (disk_list)) != 0) {
                props_dict = NULL;
                stats_dict = NULL;
                child_dict = NULL;
 
-               /* `disk_child' must be released */
-               if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child))
-                               != kIOReturnSuccess)
-               {
-                       /* This fails for example for DVD/CD drives.. */
+               /* get child of disk entry and corresponding property dictionary */
+               if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child)) != kIOReturnSuccess) {
+                       /* This fails for example for DVD/CD drives, which we want to ignore anyway */
                        DEBUG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status);
                        IOObjectRelease (disk);
                        continue;
                }
-
-               /* We create `props_dict' => we need to release it later */
-               if (IORegistryEntryCreateCFProperties (disk,
-                                       (CFMutableDictionaryRef *) &props_dict,
-                                       kCFAllocatorDefault,
-                                       kNilOptions)
-                               != kIOReturnSuccess)
-               {
-                       ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed.");
+               if (IORegistryEntryCreateCFProperties (disk_child, (CFMutableDictionaryRef *) &child_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess || child_dict == NULL) {
+                       ERROR ("disk plugin: IORegistryEntryCreateCFProperties (disk_child) failed.");
                        IOObjectRelease (disk_child);
                        IOObjectRelease (disk);
                        continue;
                }
 
-               if (props_dict == NULL)
-               {
-                       DEBUG ("IORegistryEntryCreateCFProperties (disk) failed.");
-                       IOObjectRelease (disk_child);
-                       IOObjectRelease (disk);
-                       continue;
+               /* extract name and major/minor numbers */
+               memset (child_disk_name_bsd, 0, sizeof (child_disk_name_bsd));
+               tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (child_dict, CFSTR(kIOBSDNameKey));
+               if (tmp_cf_string_ref) {
+                       assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
+                       CFStringGetCString (tmp_cf_string_ref, child_disk_name_bsd, sizeof (child_disk_name_bsd), kCFStringEncodingUTF8);
                }
+               disk_major = (int) dict_get_value (child_dict, kIOBSDMajorKey);
+               disk_minor = (int) dict_get_value (child_dict, kIOBSDMinorKey);
+               DEBUG ("disk plugin: child_disk_name_bsd=\"%s\" major=%d minor=%d", child_disk_name_bsd, disk_major, disk_minor);
+               CFRelease (child_dict);
+               IOObjectRelease (disk_child);
 
-               /* tmp_cf_string_ref doesn't need to be released. */
-               tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (props_dict,
-                               CFSTR(kIOBSDNameKey));
-               if (!tmp_cf_string_ref)
-               {
-                       DEBUG ("disk plugin: CFDictionaryGetValue("
-                                       "kIOBSDNameKey) failed.");
-                       CFRelease (props_dict);
-                       IOObjectRelease (disk_child);
+               /* get property dictionary of the disk entry itself */
+               if (IORegistryEntryCreateCFProperties (disk, (CFMutableDictionaryRef *) &props_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess || props_dict == NULL) {
+                       ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed.");
                        IOObjectRelease (disk);
                        continue;
                }
-               assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
 
-               memset (disk_name_bsd, 0, sizeof (disk_name_bsd));
-               CFStringGetCString (tmp_cf_string_ref,
-                               disk_name_bsd, sizeof (disk_name_bsd),
-                               kCFStringEncodingUTF8);
-               if (disk_name_bsd[0] == 0)
-               {
-                       ERROR ("disk plugin: CFStringGetCString() failed.");
-                       CFRelease (props_dict);
-                       IOObjectRelease (disk_child);
-                       IOObjectRelease (disk);
-                       continue;
+               /* extract name and stats dictionary */
+               memset (props_disk_name_bsd, 0, sizeof (props_disk_name_bsd));
+               tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (props_dict, CFSTR(kIOBSDNameKey));
+               if (tmp_cf_string_ref) {
+                       assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
+                       CFStringGetCString (tmp_cf_string_ref, props_disk_name_bsd, sizeof (props_disk_name_bsd), kCFStringEncodingUTF8);
                }
-               DEBUG ("disk plugin: disk_name_bsd = \"%s\"", disk_name_bsd);
-
-               stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict,
-                               CFSTR (kIOBlockStorageDriverStatisticsKey));
-
-               if (stats_dict == NULL)
-               {
-                       DEBUG ("disk plugin: CFDictionaryGetValue ("
-                                       "%s) failed.",
-                                       kIOBlockStorageDriverStatisticsKey);
+               stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict, CFSTR (kIOBlockStorageDriverStatisticsKey));
+               if (stats_dict == NULL) {
+                       ERROR ("disk plugin: CFDictionaryGetValue (%s) failed.", kIOBlockStorageDriverStatisticsKey);
                        CFRelease (props_dict);
-                       IOObjectRelease (disk_child);
                        IOObjectRelease (disk);
                        continue;
                }
-
-               if (IORegistryEntryCreateCFProperties (disk_child,
-                                       (CFMutableDictionaryRef *) &child_dict,
-                                       kCFAllocatorDefault,
-                                       kNilOptions)
-                               != kIOReturnSuccess)
-               {
-                       DEBUG ("disk plugin: IORegistryEntryCreateCFProperties ("
-                                       "disk_child) failed.");
-                       IOObjectRelease (disk_child);
-                       CFRelease (props_dict);
-                       IOObjectRelease (disk);
-                       continue;
+               DEBUG ("disk plugin: props_disk_name_bsd=\"%s\"", props_disk_name_bsd);
+
+               /* choose name */
+               if (use_bsd_name) {
+                       if (child_disk_name_bsd[0] != 0)
+                               sstrncpy (disk_name, child_disk_name_bsd, sizeof (disk_name));
+                       else if (props_disk_name_bsd[0] != 0)
+                               sstrncpy (disk_name, props_disk_name_bsd, sizeof (disk_name));
+                       else {
+                               ERROR ("disk plugin: can't find bsd disk name.");
+                               ssnprintf (disk_name, sizeof (disk_name), "%i-%i", disk_major, disk_minor);
+                       }
                }
-
-               /* kIOBSDNameKey */
-               disk_major = (int) dict_get_value (child_dict,
-                               kIOBSDMajorKey);
-               disk_minor = (int) dict_get_value (child_dict,
-                               kIOBSDMinorKey);
-               read_ops  = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsReadsKey);
-               read_byt  = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsBytesReadKey);
-               read_tme  = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsTotalReadTimeKey);
-               write_ops = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsWritesKey);
-               write_byt = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsBytesWrittenKey);
-               /* This property describes the number of nanoseconds spent
-                * performing writes since the block storage driver was
-                * instantiated. It is one of the statistic entries listed
-                * under the top-level kIOBlockStorageDriverStatisticsKey
-                * property table. It has an OSNumber value. */
-               write_tme = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsTotalWriteTimeKey);
-
-               if (use_bsd_name)
-                       sstrncpy (disk_name, disk_name_bsd, sizeof (disk_name));
                else
-                       ssnprintf (disk_name, sizeof (disk_name), "%i-%i",
-                                       disk_major, disk_minor);
-               DEBUG ("disk plugin: disk_name = \"%s\"", disk_name);
+                       ssnprintf (disk_name, sizeof (disk_name), "%i-%i", disk_major, disk_minor);
+
+               /* extract the stats */
+               read_ops  = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsReadsKey);
+               read_byt  = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsBytesReadKey);
+               read_tme  = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsTotalReadTimeKey);
+               write_ops = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsWritesKey);
+               write_byt = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsBytesWrittenKey);
+               write_tme = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsTotalWriteTimeKey);
+               CFRelease (props_dict);
+               IOObjectRelease (disk);
 
+               /* and submit */
+               DEBUG ("disk plugin: disk_name = \"%s\"", disk_name);
                if ((read_byt != -1LL) || (write_byt != -1LL))
                        disk_submit (disk_name, "disk_octets", read_byt, write_byt);
                if ((read_ops != -1LL) || (write_ops != -1LL))
                        disk_submit (disk_name, "disk_ops", read_ops, write_ops);
                if ((read_tme != -1LL) || (write_tme != -1LL))
-                       disk_submit (disk_name, "disk_time",
-                                       read_tme / 1000,
-                                       write_tme / 1000);
+                       disk_submit (disk_name, "disk_time", read_tme / 1000, write_tme / 1000);
 
-               CFRelease (child_dict);
-               IOObjectRelease (disk_child);
-               CFRelease (props_dict);
-               IOObjectRelease (disk);
        }
        IOObjectRelease (disk_list);
 /* #endif HAVE_IOKIT_IOKITLIB_H */
index d1a8719..365af27 100644 (file)
@@ -256,8 +256,6 @@ static void *collect (void *arg)
        collector_t *this = (collector_t *)arg;
 
        while (1) {
-               int loop = 1;
-
                conn_t *connection;
 
                pthread_mutex_lock (&conns_mutex);
@@ -282,15 +280,13 @@ static void *collect (void *arg)
                log_debug ("collect: handling connection on fd #%i",
                                fileno (this->socket));
 
-               while (loop) {
+               while (42) {
                        /* 256 bytes ought to be enough for anybody ;-) */
                        char line[256 + 1]; /* line + '\0' */
                        int  len = 0;
 
                        errno = 0;
                        if (NULL == fgets (line, sizeof (line), this->socket)) {
-                               loop = 0;
-
                                if (0 != errno) {
                                        char errbuf[1024];
                                        log_err ("collect: reading from socket (fd #%i) "
@@ -363,7 +359,7 @@ static void *collect (void *arg)
                        else {
                                log_err ("collect: unknown type '%c'", line[0]);
                        }
-               } /* while (loop) */
+               } /* while (42) */
 
                log_debug ("Shutting down connection on fd #%i",
                                fileno (this->socket));
@@ -575,10 +571,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 +631,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 3f68e8b..8d737ce 100644 (file)
@@ -339,7 +339,7 @@ static void exec_child (program_list_t *pl, int uid, int gid, int egid) /* {{{ *
     exit (-1);
   }
 
-  status = execvp (pl->exec, pl->argv);
+  execvp (pl->exec, pl->argv);
 
   ERROR ("exec plugin: Failed to execute ``%s'': %s",
       pl->exec, sstrerror (errno, errbuf, sizeof (errbuf)));
index a00b26d..09d7137 100644 (file)
@@ -222,13 +222,13 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */
   struct addrinfo *ai_ptr;
   int              ai_return;
 
-  socket_entry_t *sockets;
-  size_t          sockets_num;
+  socket_entry_t *sockets = NULL;
+  size_t          sockets_num = 0;
 
   int status;
-    
-  sockets     = *ret_sockets;
-  sockets_num = *ret_sockets_num;
+
+  if (*ret_sockets != NULL)
+    return (EINVAL);
 
   memset (&ai_hints, 0, sizeof (ai_hints));
   ai_hints.ai_flags    = 0;
@@ -360,8 +360,11 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */
 
   freeaddrinfo (ai_list);
 
-  if ((*ret_sockets_num) >= sockets_num)
+  if (sockets_num == 0)
+  {
+    sfree (sockets);
     return (-1);
+  }
 
   *ret_sockets = sockets;
   *ret_sockets_num = sockets_num;
@@ -665,7 +668,7 @@ static int mc_handle_value_msg (Ganglia_value_msg *msg) /* {{{ */
     if ((map->ds_type == DS_TYPE_COUNTER)
         || (map->ds_type == DS_TYPE_ABSOLUTE))
       val_copy = value_counter;
-    if (map->ds_type == DS_TYPE_GAUGE)
+    else if (map->ds_type == DS_TYPE_GAUGE)
       val_copy = value_gauge;
     else if (map->ds_type == DS_TYPE_DERIVE)
       val_copy = value_derive;
index fa89489..cbb5542 100644 (file)
@@ -295,7 +295,10 @@ static void cipvs_submit_service (struct ip_vs_service_entry *se)
        int i = 0;
 
        if (0 != get_pi (se, pi, sizeof (pi)))
+       {
+               free (dests);
                return;
+       }
 
        cipvs_submit_connections (pi, NULL, stats.conns);
        cipvs_submit_if (pi, "if_packets", NULL, stats.inpkts, stats.outpkts);
index 56a39d4..a6b8022 100644 (file)
@@ -1817,6 +1817,7 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
     pthread_mutex_unlock (&java_callbacks_lock);
     ERROR ("java plugin: cjni_callback_info_create: strdup failed.");
     (*jvm_env)->ReleaseStringUTFChars (jvm_env, o_name, c_name);
+    sfree (cbi);
     return (NULL);
   }
 
@@ -1826,7 +1827,8 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
   if (cbi->object == NULL)
   {
     ERROR ("java plugin: cjni_callback_info_create: NewGlobalRef failed.");
-    free (cbi);
+    sfree (cbi->name);
+    sfree (cbi);
     return (NULL);
   }
 
@@ -1834,7 +1836,9 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
   if (cbi->class == NULL)
   {
     ERROR ("java plugin: cjni_callback_info_create: GetObjectClass failed.");
-    free (cbi);
+    (*jvm_env)->DeleteGlobalRef (jvm_env, cbi->object);
+    sfree (cbi->name);
+    sfree (cbi);
     return (NULL);
   }
 
@@ -1845,7 +1849,9 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
     ERROR ("java plugin: cjni_callback_info_create: "
         "Cannot find the `%s' method with signature `%s'.",
         method_name, method_signature);
-    free (cbi);
+    (*jvm_env)->DeleteGlobalRef (jvm_env, cbi->object);
+    sfree (cbi->name);
+    sfree (cbi);
     return (NULL);
   }
 
index 9ad61f6..a97dc50 100644 (file)
@@ -500,7 +500,6 @@ static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */
     if (fd < 0)
     {
       status = errno;
-      fd = -1;
       continue;
     }
 
@@ -509,7 +508,6 @@ static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */
     {
       status = errno;
       close (fd);
-      fd = -1;
       continue;
     }
 
@@ -518,7 +516,6 @@ static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */
     {
       status = errno;
       close (fd);
-      fd = -1;
       continue;
     }
 
index c3de92c..b5162cc 100644 (file)
@@ -6,5 +6,5 @@ AM_YFLAGS = -d
 
 noinst_LTLIBRARIES = liboconfig.la
 
-liboconfig_la_LDFLAGS = -version-info 0:0:0 $(LEXLIB)
+liboconfig_la_LDFLAGS = -avoid-version $(LEXLIB)
 liboconfig_la_SOURCES = oconfig.c oconfig.h aux_types.h scanner.l parser.y
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 37f1894..013b6c4 100644 (file)
@@ -263,7 +263,10 @@ static int cmc_config_add_match (web_page_t *page, /* {{{ */
   } /* while (status == 0) */
 
   if (status != 0)
+  {
+    cmc_web_match_free (match);
     return (status);
+  }
 
   match->match = match_create_simple (match->regex, match->exclude_regex,
       match->dstype);
index 97840fd..04abe04 100644 (file)
@@ -426,7 +426,7 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */
   uint16_t values[2];
   int values_num;
   const data_set_t *ds;
-  int status;
+  int status = 0;
 
   if ((host == NULL) || (slave == NULL) || (data == NULL))
     return (EINVAL);
@@ -463,7 +463,6 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */
   else
     values_num = 1;
 
-  status = 0;
   if (host->connection == NULL)
   {
     status = EBADF;
@@ -733,7 +732,6 @@ static int mb_config_add_data (oconfig_item_t *ci) /* {{{ */
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *child = ci->children + i;
-    status = 0;
 
     if (strcasecmp ("Type", child->key) == 0)
       status = cf_util_get_string_buffer (child,
@@ -894,7 +892,6 @@ static int mb_config_add_slave (mb_host_t *host, oconfig_item_t *ci) /* {{{ */
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *child = ci->children + i;
-    status = 0;
 
     if (strcasecmp ("Instance", child->key) == 0)
       status = cf_util_get_string_buffer (child,
index bf77a2f..a8a8e86 100644 (file)
@@ -815,7 +815,7 @@ static int mysql_read (user_data_t *ud)
                        else if (strcmp (key, "Innodb_buffer_pool_pages_dirty") == 0)
                                gauge_submit ("mysql_bpool_pages", "dirty", val, db);
                        else if (strcmp (key, "Innodb_buffer_pool_pages_flushed") == 0)
-                               counter_submit ("mysql_bpool_pages", "flushed", val, db);
+                               counter_submit ("mysql_bpool_counters", "pages_flushed", val, db);
                        else if (strcmp (key, "Innodb_buffer_pool_pages_free") == 0)
                                gauge_submit ("mysql_bpool_pages", "free", val, db);
                        else if (strcmp (key, "Innodb_buffer_pool_pages_misc") == 0)
index e58d1dc..e90bb39 100644 (file)
@@ -283,8 +283,8 @@ typedef struct receive_list_entry_s receive_list_entry_t;
 static int network_config_ttl = 0;
 /* Ethernet - (IPv6 + UDP) = 1500 - (40 + 8) = 1452 */
 static size_t network_config_packet_size = 1452;
-static int network_config_forward = 0;
-static int network_config_stats = 0;
+static _Bool network_config_forward = 0;
+static _Bool network_config_stats = 0;
 
 static sockent_t *sending_sockets = NULL;
 
@@ -354,7 +354,7 @@ static _Bool check_send_okay (const value_list_t *vl) /* {{{ */
   _Bool received = 0;
   int status;
 
-  if (network_config_forward != 0)
+  if (network_config_forward)
     return (1);
 
   if (vl->meta == NULL)
@@ -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. */
@@ -2557,15 +2567,11 @@ static int network_receive (void) /* {{{ */
                receive_list_tail = private_list_tail;
                receive_list_length += private_list_length;
 
-               private_list_head = NULL;
-               private_list_tail = NULL;
-               private_list_length = 0;
-
                pthread_cond_signal (&receive_list_cond);
                pthread_mutex_unlock (&receive_list_lock);
        }
 
-       return (0);
+       return (status);
 } /* }}} int network_receive */
 
 static void *receive_thread (void __attribute__((unused)) *arg)
@@ -2955,58 +2961,13 @@ static int network_write (const data_set_t *ds, const value_list_t *vl,
        return ((status < 0) ? -1 : 0);
 } /* int network_write */
 
-static int network_config_set_boolean (const oconfig_item_t *ci, /* {{{ */
-    int *retval)
-{
-  if ((ci->values_num != 1)
-      || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN)
-        && (ci->values[0].type != OCONFIG_TYPE_STRING)))
-  {
-    ERROR ("network plugin: The `%s' config option needs "
-        "exactly one boolean argument.", ci->key);
-    return (-1);
-  }
-
-  if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
-  {
-    if (ci->values[0].value.boolean)
-      *retval = 1;
-    else
-      *retval = 0;
-  }
-  else
-  {
-    char *str = ci->values[0].value.string;
-
-    if (IS_TRUE (str))
-      *retval = 1;
-    else if (IS_FALSE (str))
-      *retval = 0;
-    else
-    {
-      ERROR ("network plugin: Cannot parse string value `%s' of the `%s' "
-          "option as boolean value.",
-          str, ci->key);
-      return (-1);
-    }
-  }
-
-  return (0);
-} /* }}} int network_config_set_boolean */
-
 static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */
 {
-  int tmp;
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
-  {
-    WARNING ("network plugin: The `TimeToLive' config option needs exactly "
-        "one numeric argument.");
-    return (-1);
-  }
+  int tmp = 0;
 
-  tmp = (int) ci->values[0].value.number;
-  if ((tmp > 0) && (tmp <= 255))
+  if (cf_util_get_int (ci, &tmp) != 0)
+    return (-1);
+  else if ((tmp > 0) && (tmp <= 255))
     network_config_ttl = tmp;
   else {
     WARNING ("network plugin: The `TimeToLive' must be between 1 and 255.");
@@ -3019,63 +2980,30 @@ static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */
 static int network_config_set_interface (const oconfig_item_t *ci, /* {{{ */
     int *interface)
 {
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("network plugin: The `Interface' config option needs exactly "
-        "one string argument.");
-    return (-1);
-  }
+  char if_name[256];
 
-  if (interface == NULL)
+  if (cf_util_get_string_buffer (ci, if_name, sizeof (if_name)) != 0)
     return (-1);
 
-  *interface = if_nametoindex (ci->values[0].value.string);
-
+  *interface = if_nametoindex (if_name);
   return (0);
 } /* }}} int network_config_set_interface */
 
 static int network_config_set_buffer_size (const oconfig_item_t *ci) /* {{{ */
 {
-  int tmp;
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
-  {
-    WARNING ("network plugin: The `MaxPacketSize' config option needs exactly "
-        "one numeric argument.");
-    return (-1);
-  }
+  int tmp = 0;
 
-  tmp = (int) ci->values[0].value.number;
-  if ((tmp >= 1024) && (tmp <= 65535))
+  if (cf_util_get_int (ci, &tmp) != 0)
+    return (-1);
+  else if ((tmp >= 1024) && (tmp <= 65535))
     network_config_packet_size = tmp;
-
-  return (0);
-} /* }}} int network_config_set_buffer_size */
-
-#if HAVE_LIBGCRYPT
-static int network_config_set_string (const oconfig_item_t *ci, /* {{{ */
-    char **ret_string)
-{
-  char *tmp;
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("network plugin: The `%s' config option needs exactly "
-        "one string argument.", ci->key);
+  else {
+    WARNING ("network plugin: The `MaxPacketSize' must be between 1024 and 65535.");
     return (-1);
   }
 
-  tmp = strdup (ci->values[0].value.string);
-  if (tmp == NULL)
-    return (-1);
-
-  sfree (*ret_string);
-  *ret_string = tmp;
-
   return (0);
-} /* }}} int network_config_set_string */
-#endif /* HAVE_LIBGCRYPT */
+} /* }}} int network_config_set_buffer_size */
 
 #if HAVE_LIBGCRYPT
 static int network_config_set_security_level (oconfig_item_t *ci, /* {{{ */
@@ -3139,15 +3067,14 @@ static int network_config_add_listen (const oconfig_item_t *ci) /* {{{ */
 
 #if HAVE_LIBGCRYPT
     if (strcasecmp ("AuthFile", child->key) == 0)
-      network_config_set_string (child, &se->data.server.auth_file);
+      cf_util_get_string (child, &se->data.server.auth_file);
     else if (strcasecmp ("SecurityLevel", child->key) == 0)
       network_config_set_security_level (child,
           &se->data.server.security_level);
     else
 #endif /* HAVE_LIBGCRYPT */
     if (strcasecmp ("Interface", child->key) == 0)
-      network_config_set_interface (child,
-          &se->interface);
+      network_config_set_interface (child, &se->interface);
     else
     {
       WARNING ("network plugin: Option `%s' is not allowed here.",
@@ -3226,19 +3153,18 @@ static int network_config_add_server (const oconfig_item_t *ci) /* {{{ */
 
 #if HAVE_LIBGCRYPT
     if (strcasecmp ("Username", child->key) == 0)
-      network_config_set_string (child, &se->data.client.username);
+      cf_util_get_string (child, &se->data.client.username);
     else if (strcasecmp ("Password", child->key) == 0)
-      network_config_set_string (child, &se->data.client.password);
+      cf_util_get_string (child, &se->data.client.password);
     else if (strcasecmp ("SecurityLevel", child->key) == 0)
       network_config_set_security_level (child,
           &se->data.client.security_level);
     else
 #endif /* HAVE_LIBGCRYPT */
     if (strcasecmp ("Interface", child->key) == 0)
-      network_config_set_interface (child,
-          &se->interface);
-               else if (strcasecmp ("ResolveInterval", child->key) == 0)
-                       cf_util_get_cdtime(child, &se->data.client.resolve_interval);
+      network_config_set_interface (child, &se->interface);
+    else if (strcasecmp ("ResolveInterval", child->key) == 0)
+      cf_util_get_cdtime(child, &se->data.client.resolve_interval);
     else
     {
       WARNING ("network plugin: Option `%s' is not allowed here.",
@@ -3307,9 +3233,9 @@ static int network_config (oconfig_item_t *ci) /* {{{ */
     else if (strcasecmp ("MaxPacketSize", child->key) == 0)
       network_config_set_buffer_size (child);
     else if (strcasecmp ("Forward", child->key) == 0)
-      network_config_set_boolean (child, &network_config_forward);
+      cf_util_get_boolean (child, &network_config_forward);
     else if (strcasecmp ("ReportStats", child->key) == 0)
-      network_config_set_boolean (child, &network_config_stats);
+      cf_util_get_boolean (child, &network_config_stats);
     else
     {
       WARNING ("network plugin: Option `%s' is not allowed here.",
@@ -3530,7 +3456,7 @@ static int network_init (void)
        network_init_gcrypt ();
 #endif
 
-       if (network_config_stats != 0)
+       if (network_config_stats)
                plugin_register_read ("network", network_stats_read);
 
        plugin_register_shutdown ("network", network_shutdown);
index 4285d76..be82372 100644 (file)
--- a/src/nfs.c
+++ b/src/nfs.c
@@ -506,6 +506,7 @@ static int nfs_submit_nfs4_client (const char *instance, char **fields,
                case 42:
                case 44:
                        proc40_names_num = 36;
+                       break;
                case 46:
                case 47:
                case 51:
index 15b12f9..5fdfef3 100644 (file)
@@ -670,7 +670,6 @@ static int ntpd_receive_response (int *res_items, int *res_size,
                                (items_num + pkt_item_num) * res_item_size);
                if (items == NULL)
                {
-                       items = *res_data;
                        ERROR ("ntpd plugin: realloc failed.");
                        continue;
                }
index 6cfea0e..58c35e1 100644 (file)
@@ -384,7 +384,6 @@ static int cow_read_values (const char *path, const char *name,
     if (endptr == NULL)
     {
       ERROR ("onewire plugin: Buffer is not a number: %s", buffer);
-      status = -1;
       continue;
     }
 
@@ -528,7 +527,6 @@ static int cow_simple_read (void)
       if (endptr == NULL)
       {
           ERROR ("onewire plugin: Buffer is not a number: %s", buffer);
-          status = -1;
           continue;
       }
 
index bd989e4..ffcdb94 100644 (file)
@@ -38,6 +38,8 @@ struct cldap_s /* {{{ */
 {
        char *name;
 
+       char *binddn;
+       char *password;
        char *cacert;
        char *host;
        int   state;
@@ -56,6 +58,8 @@ static void cldap_free (cldap_t *st) /* {{{ */
        if (st == NULL)
                return;
 
+       sfree (st->binddn);
+       sfree (st->password);
        sfree (st->cacert);
        sfree (st->host);
        sfree (st->name);
@@ -110,10 +114,19 @@ static int cldap_init_host (cldap_t *st) /* {{{ */
        }
 
        struct berval cred;
-       cred.bv_val = "";
-       cred.bv_len = 0;
+       if (st->password != NULL)
+       {
+               cred.bv_val = st->password;
+               cred.bv_len = strlen (st->password);
+       }
+       else
+       {
+               cred.bv_val = "";
+               cred.bv_len = 0;
+       }
 
-       rc = ldap_sasl_bind_s (st->ld, NULL, NULL, &cred, NULL, NULL, NULL);
+       rc = ldap_sasl_bind_s (st->ld, st->binddn, LDAP_SASL_SIMPLE, &cred, 
+                       NULL, NULL, NULL);
        if (rc != LDAP_SUCCESS)
        {
                ERROR ("openldap plugin: Failed to bind to %s: %s",
@@ -559,7 +572,11 @@ static int cldap_config_add (oconfig_item_t *ci) /* {{{ */
        {
                oconfig_item_t *child = ci->children + i;
 
-               if (strcasecmp ("CACert", child->key) == 0)
+               if (strcasecmp ("BindDN", child->key) == 0)
+                       status = cf_util_get_string (child, &st->binddn);
+               else if (strcasecmp ("Password", child->key) == 0)
+                       status = cf_util_get_string (child, &st->password);
+               else if (strcasecmp ("CACert", child->key) == 0)
                        status = cf_util_get_string (child, &st->cacert);
                else if (strcasecmp ("StartTLS", child->key) == 0)
                        status = cf_util_get_boolean (child, &st->starttls);
@@ -604,7 +621,8 @@ static int cldap_config_add (oconfig_item_t *ci) /* {{{ */
                                st->name, st->url);
                        status = -1;
                }
-               else
+
+               if ((status == 0) && (ludpp->lud_host != NULL))
                {
                        st->host = strdup (ludpp->lud_host);
                }
index 0fd9405..663a82d 100644 (file)
@@ -189,8 +189,6 @@ static int single_read (char *name, FILE *fh)
        post_compress = 0;
        pre_decompress = 0;
        post_decompress = 0;
-       overhead_rx = 0;
-       overhead_tx = 0;
 
        while (fgets (buffer, sizeof (buffer), fh) != NULL)
        {
@@ -520,13 +518,15 @@ static int multi4_read (char *name, FILE *fh)
 static int openvpn_read (void)
 {
        FILE *fh;
-       int  i, vpn_read, read;
+       int  i, read;
 
-       vpn_read = read = 0;
+       read = 0;
 
        /* call the right read function for every status entry in the list */
        for (i = 0; i < vpn_num; i++)
        {
+               int vpn_read = 0;
+
                fh = fopen (vpn_list[i]->file, "r");
                if (fh == NULL)
                {
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 216feda..d669aa9 100644 (file)
@@ -359,7 +359,7 @@ static void *ping_thread (void *arg) /* {{{ */
      * `ts_wait'. */
     time_calc (&ts_wait, &ts_int, &tv_begin, &tv_end);
 
-    status = pthread_cond_timedwait (&ping_cond, &ping_lock, &ts_wait);
+    pthread_cond_timedwait (&ping_cond, &ping_lock, &ts_wait);
     if (ping_thread_loop <= 0)
       break;
   } /* while (ping_thread_loop > 0) */
index ec337bf..f9f291a 100644 (file)
@@ -462,6 +462,12 @@ static int powerdns_get_data_stream (list_item_t *item, /* {{{ */
   timeout.tv_sec=5;
   timeout.tv_usec=0;
   status = setsockopt (sd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof (timeout));
+  if (status != 0)
+  {
+    FUNC_ERROR ("setsockopt");
+    close (sd);
+    return (-1);
+  }
 
   status = connect (sd, (struct sockaddr *) &item->sockaddr,
       sizeof (item->sockaddr));
@@ -509,7 +515,6 @@ static int powerdns_get_data_stream (list_item_t *item, /* {{{ */
     buffer[buffer_size] = 0;
   } /* while (42) */
   close (sd);
-  sd = -1;
 
   if (status < 0)
   {
@@ -732,25 +737,6 @@ static int powerdns_read_recursor (list_item_t *item) /* {{{ */
   return (0);
 } /* }}} int powerdns_read_recursor */
 
-static int powerdns_config_add_string (const char *name, /* {{{ */
-    char **dest,
-    oconfig_item_t *ci)
-{
-  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("powerdns plugin: `%s' needs exactly one string argument.",
-       name);
-    return (-1);
-  }
-
-  sfree (*dest);
-  *dest = strdup (ci->values[0].value.string);
-  if (*dest == NULL)
-    return (-1);
-
-  return (0);
-} /* }}} int powerdns_config_add_string */
-
 static int powerdns_config_add_collect (list_item_t *li, /* {{{ */
     oconfig_item_t *ci)
 {
@@ -861,7 +847,7 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */
     if (strcasecmp ("Collect", option->key) == 0)
       status = powerdns_config_add_collect (item, option);
     else if (strcasecmp ("Socket", option->key) == 0)
-      status = powerdns_config_add_string ("Socket", &socket_temp, option);
+      status = cf_util_get_string (option, &socket_temp);
     else
     {
       ERROR ("powerdns plugin: Option `%s' not allowed here.", option->key);
@@ -901,12 +887,14 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */
 
   if (status != 0)
   {
+    sfree (socket_temp);
     sfree (item);
     return (-1);
   }
 
   DEBUG ("powerdns plugin: Add server: instance = %s;", item->instance);
 
+  sfree (socket_temp);
   return (0);
 } /* }}} int powerdns_config_add_server */
 
index bebf468..8497a24 100644 (file)
@@ -743,6 +743,7 @@ static int rrd_cache_insert (const char *filename,
                new_rc = 1;
        }
 
+       assert (value_time > 0); /* plugin_dispatch() ensures this. */
        if (rc->last_value >= value_time)
        {
                pthread_mutex_unlock (&cache_lock);
index 51afea1..3acadd2 100644 (file)
@@ -402,7 +402,6 @@ static int csnmp_config_add_data (oconfig_item_t *ci)
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *option = ci->children + i;
-    status = 0;
 
     if (strcasecmp ("Type", option->key) == 0)
       status = cf_util_get_string(option, &dd->type);
@@ -1232,16 +1231,17 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat
     return (-1);
   }
   assert (ds->ds_num == data->values_len);
+  assert (data->values_len > 0);
 
   instance_list_ptr = instance_list;
 
-  value_table_ptr = malloc (sizeof (*value_table_ptr) * data->values_len);
+  value_table_ptr = calloc ((size_t) data->values_len, sizeof (*value_table_ptr));
   if (value_table_ptr == NULL)
     return (-1);
   for (i = 0; i < data->values_len; i++)
     value_table_ptr[i] = value_table[i];
 
-  vl.values_len = ds->ds_num;
+  vl.values_len = data->values_len;
   vl.values = malloc (sizeof (*vl.values) * vl.values_len);
   if (vl.values == NULL)
   {
@@ -1420,6 +1420,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
         data->type, ds->ds_num, data->values_len);
     return (-1);
   }
+  assert (data->values_len > 0);
 
   /* We need a copy of all the OIDs, because GETNEXT will destroy them. */
   memcpy (oid_list, data->values, data->values_len * sizeof (oid_t));
@@ -1519,7 +1520,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
     for (vb = res->variables, i = 0; (vb != NULL); vb = vb->next_variable, i++)
     {
       /* Calculate value index from todo list */
-      while (!oid_list_todo[i] && (i < oid_list_len))
+      while ((i < oid_list_len) && !oid_list_todo[i])
         i++;
 
       /* An instance is configured and the res variable we process is the
index c6b5bad..beded1a 100644 (file)
@@ -283,8 +283,9 @@ static int tbl_config_table (oconfig_item_t *ci)
        if (NULL == tbl->sep) {
                log_err ("Table \"%s\" does not specify any separator.", tbl->file);
                status = 1;
+       } else {
+               strunescape (tbl->sep, strlen (tbl->sep) + 1);
        }
-       strunescape (tbl->sep, strlen (tbl->sep) + 1);
 
        if (NULL == tbl->instance) {
                tbl->instance = sstrdup (tbl->file);
index 480715f..751243b 100644 (file)
@@ -224,7 +224,6 @@ static int ctail_config_add_file (oconfig_item_t *ci)
   cdtime_t interval = 0;
   char *plugin_instance = NULL;
   int num_matches = 0;
-  int status;
   int i;
 
   if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
@@ -241,10 +240,10 @@ static int ctail_config_add_file (oconfig_item_t *ci)
     return (-1);
   }
 
-  status = 0;
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *option = ci->children + i;
+    int status = 0;
 
     if (strcasecmp ("Instance", option->key) == 0)
       status = cf_util_get_string (option, &plugin_instance);
index 41ed980..a1ee249 100644 (file)
@@ -312,7 +312,6 @@ static int tcsv_config_add_metric(oconfig_item_t *ci){
 
     for (i = 0; i < ci->children_num; ++i){
         oconfig_item_t *option = ci->children + i;
-        status = 0;
 
         if (strcasecmp("Type", option->key) == 0)
             status = cf_util_get_string(option, &md->type);
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 bf519bb..5dd75bc 100644 (file)
--- a/src/ted.c
+++ b/src/ted.c
@@ -104,7 +104,6 @@ static int ted_read_value(double *ret_power, double *ret_voltage)
 
     /* Loop until we find the end of the package */
     end_flag = 0;
-    escape_flag = 0;
     package_buffer_pos = 0;
     while (end_flag == 0)
     {
index 8815a00..8dcb711 100644 (file)
@@ -251,7 +251,6 @@ static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci)
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *option = ci->children + i;
-    status = 0;
 
     if (strcasecmp ("Instance", option->key) == 0)
       status = ut_config_type_instance (&th, option);
@@ -339,7 +338,6 @@ static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci)
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *option = ci->children + i;
-    status = 0;
 
     if (strcasecmp ("Type", option->key) == 0)
       status = ut_config_type (&th, option);
@@ -386,7 +384,6 @@ static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci)
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *option = ci->children + i;
-    status = 0;
 
     if (strcasecmp ("Type", option->key) == 0)
       status = ut_config_type (&th, option);
@@ -515,15 +512,12 @@ static int ut_report_state (const data_set_t *ds,
   if (state == STATE_OKAY)
   {
     if (state_old == STATE_MISSING)
-      status = ssnprintf (buf, bufsize,
-          ": Value is no longer missing.");
+      ssnprintf (buf, bufsize, ": Value is no longer missing.");
     else
-      status = ssnprintf (buf, bufsize,
+      ssnprintf (buf, bufsize,
           ": All data sources are within range again. "
           "Current value of \"%s\" is %f.",
           ds->ds[ds_index].name, values[ds_index]);
-    buf += status;
-    bufsize -= status;
   }
   else
   {
@@ -537,7 +531,7 @@ static int ut_report_state (const data_set_t *ds,
     {
       if (!isnan (min) && !isnan (max))
       {
-        status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+        ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
             "%f. That is within the %s region of %f%s and %f%s.",
             ds->ds[ds_index].name, values[ds_index],
             (state == STATE_ERROR) ? "failure" : "warning",
@@ -546,13 +540,13 @@ static int ut_report_state (const data_set_t *ds,
       }
       else
       {
-       status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
-           "%f. That is %s the %s threshold of %f%s.",
-           ds->ds[ds_index].name, values[ds_index],
-           isnan (min) ? "below" : "above",
-           (state == STATE_ERROR) ? "failure" : "warning",
-           isnan (min) ? max : min,
-           ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
+        ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+            "%f. That is %s the %s threshold of %f%s.",
+            ds->ds[ds_index].name, values[ds_index],
+            isnan (min) ? "below" : "above",
+            (state == STATE_ERROR) ? "failure" : "warning",
+            isnan (min) ? max : min,
+            ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
       }
     }
     else if (th->flags & UT_FLAG_PERCENTAGE)
@@ -575,7 +569,7 @@ static int ut_report_state (const data_set_t *ds,
       else
         value = 100.0 * values[ds_index] / sum;
 
-      status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+      ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
           "%g (%.2f%%). That is %s the %s threshold of %.2f%%.",
           ds->ds[ds_index].name, values[ds_index], value,
           (value < min) ? "below" : "above",
@@ -584,15 +578,13 @@ static int ut_report_state (const data_set_t *ds,
     }
     else /* is not inverted */
     {
-      status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
-         "%f. That is %s the %s threshold of %f.",
-         ds->ds[ds_index].name, values[ds_index],
-         (values[ds_index] < min) ? "below" : "above",
-         (state == STATE_ERROR) ? "failure" : "warning",
-         (values[ds_index] < min) ? min : max);
+      ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+          "%f. That is %s the %s threshold of %f.",
+          ds->ds[ds_index].name, values[ds_index],
+          (values[ds_index] < min) ? "below" : "above",
+          (state == STATE_ERROR) ? "failure" : "warning",
+          (values[ds_index] < min) ? min : max);
     }
-    buf += status;
-    bufsize -= status;
   }
 
   plugin_dispatch_notification (&n);
@@ -906,7 +898,6 @@ int ut_config (oconfig_item_t *ci)
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *option = ci->children + i;
-    status = 0;
 
     if (strcasecmp ("Type", option->key) == 0)
       status = ut_config_type (&th, option);
index 80650df..42fed52 100644 (file)
@@ -1253,10 +1253,22 @@ allocate_counters(struct thread_data **threads, struct core_data **cores, struct
        unsigned int i;
        unsigned int total_threads, total_cores;
 
+       if ((topology.num_threads == 0)
+           || (topology.num_cores == 0)
+           || (topology.num_packages == 0))
+       {
+               ERROR ("turbostat plugin: Invalid topology: %u threads, %u cores, %u packages",
+                      topology.num_threads, topology.num_cores, topology.num_packages);
+               return -1;
+       }
+
        total_threads = topology.num_threads * topology.num_cores * topology.num_packages;
        *threads = calloc(total_threads, sizeof(struct thread_data));
        if (*threads == NULL)
-               goto err;
+       {
+               ERROR ("turbostat plugin: calloc failed");
+               return -1;
+       }
 
        for (i = 0; i < total_threads; ++i)
                (*threads)[i].cpu_id = topology.max_cpu_id + 1;
@@ -1264,21 +1276,22 @@ allocate_counters(struct thread_data **threads, struct core_data **cores, struct
        total_cores = topology.num_cores * topology.num_packages;
        *cores = calloc(total_cores, sizeof(struct core_data));
        if (*cores == NULL)
-               goto err_clean_threads;
+       {
+               ERROR ("turbostat plugin: calloc failed");
+               sfree (threads);
+               return -1;
+       }
 
        *packages = calloc(topology.num_packages, sizeof(struct pkg_data));
        if (*packages == NULL)
-               goto err_clean_cores;
+       {
+               ERROR ("turbostat plugin: calloc failed");
+               sfree (cores);
+               sfree (threads);
+               return -1;
+       }
 
        return 0;
-
-err_clean_cores:
-       free(*cores);
-err_clean_threads:
-       free(*threads);
-err:
-       ERROR("turbostat plugin: Failled to allocate memory for counters");
-       return -1;
 }
 
 static void
index 089ab70..f19835e 100644 (file)
 #include "plugin.h"
 #include "utils_parse_option.h"
 
-#define print_to_socket(fh, ...) \
-       do { \
-               if (fprintf (fh, __VA_ARGS__) < 0) { \
-                       char errbuf[1024]; \
-                       WARNING ("handle_flush: failed to write to socket #%i: %s", \
-                                       fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
-                       return -1; \
-               } \
-               fflush(fh); \
-       } while (0)
-
-static int add_to_array (char ***array, int *array_num, char *value)
-{
-       char **temp;
-
-       temp = (char **) realloc (*array, sizeof (char *) * (*array_num + 1));
-       if (temp == NULL)
-               return (-1);
-
-       *array = temp;
-       (*array)[*array_num] = value;
-       (*array_num)++;
-
-       return (0);
-} /* int add_to_array */
-
 int handle_flush (FILE *fh, char *buffer)
 {
        int success = 0;
@@ -64,11 +38,24 @@ int handle_flush (FILE *fh, char *buffer)
 
        double timeout = 0.0;
        char **plugins = NULL;
-       int plugins_num = 0;
+       size_t plugins_num = 0;
        char **identifiers = NULL;
-       int identifiers_num = 0;
+       size_t identifiers_num = 0;
 
-       int i;
+       size_t i;
+
+#define PRINT_TO_SOCK(fh, ...) \
+       do { \
+               if (fprintf (fh, __VA_ARGS__) < 0) { \
+                       char errbuf[1024]; \
+                       WARNING ("handle_flush: failed to write to socket #%i: %s", \
+                                       fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
+                       strarray_free (plugins, plugins_num); \
+                       strarray_free (identifiers, identifiers_num); \
+                       return -1; \
+               } \
+               fflush(fh); \
+       } while (0)
 
        if ((fh == NULL) || (buffer == NULL))
                return (-1);
@@ -78,7 +65,7 @@ int handle_flush (FILE *fh, char *buffer)
 
        if (strncasecmp ("FLUSH", buffer, strlen ("FLUSH")) != 0)
        {
-               print_to_socket (fh, "-1 Cannot parse command.\n");
+               PRINT_TO_SOCK (fh, "-1 Cannot parse command.\n");
                return (-1);
        }
        buffer += strlen ("FLUSH");
@@ -94,34 +81,30 @@ int handle_flush (FILE *fh, char *buffer)
                status = parse_option (&buffer, &opt_key, &opt_value);
                if (status != 0)
                {
-                       print_to_socket (fh, "-1 Parsing options failed.\n");
-                       sfree (plugins);
-                       sfree (identifiers);
+                       PRINT_TO_SOCK (fh, "-1 Parsing options failed.\n");
+                       strarray_free (plugins, plugins_num);
+                       strarray_free (identifiers, identifiers_num);
                        return (-1);
                }
 
                if (strcasecmp ("plugin", opt_key) == 0)
-               {
-                       add_to_array (&plugins, &plugins_num, opt_value);
-               }
+                       strarray_add (&plugins, &plugins_num, opt_value);
                else if (strcasecmp ("identifier", opt_key) == 0)
-               {
-                       add_to_array (&identifiers, &identifiers_num, opt_value);
-               }
+                       strarray_add (&identifiers, &identifiers_num, opt_value);
                else if (strcasecmp ("timeout", opt_key) == 0)
                {
                        char *endptr;
-                       
+
                        errno = 0;
                        endptr = NULL;
                        timeout = strtod (opt_value, &endptr);
 
                        if ((endptr == opt_value) || (errno != 0) || (!isfinite (timeout)))
                        {
-                               print_to_socket (fh, "-1 Invalid value for option `timeout': "
+                               PRINT_TO_SOCK (fh, "-1 Invalid value for option `timeout': "
                                                "%s\n", opt_value);
-                               sfree (plugins);
-                               sfree (identifiers);
+                               strarray_free (plugins, plugins_num);
+                               strarray_free (identifiers, identifiers_num);
                                return (-1);
                        }
                        else if (timeout < 0.0)
@@ -131,34 +114,29 @@ int handle_flush (FILE *fh, char *buffer)
                }
                else
                {
-                       print_to_socket (fh, "-1 Cannot parse option %s\n", opt_key);
-                       sfree (plugins);
-                       sfree (identifiers);
+                       PRINT_TO_SOCK (fh, "-1 Cannot parse option %s\n", opt_key);
+                       strarray_free (plugins, plugins_num);
+                       strarray_free (identifiers, identifiers_num);
                        return (-1);
                }
        } /* while (*buffer != 0) */
 
-       /* Add NULL entries for `any plugin' and/or `any value' if nothing was
-        * specified. */
-       if (plugins_num == 0)
-               add_to_array (&plugins, &plugins_num, NULL);
-
-       if (identifiers_num == 0)
-               add_to_array (&identifiers, &identifiers_num, NULL);
-
-       for (i = 0; i < plugins_num; i++)
+       for (i = 0; (i == 0) || (i < plugins_num); i++)
        {
-               char *plugin;
+               char *plugin = NULL;
                int j;
 
-               plugin = plugins[i];
+               if (plugins_num != 0)
+                       plugin = plugins[i];
 
-               for (j = 0; j < identifiers_num; j++)
+               for (j = 0; (j == 0) || (j < identifiers_num); j++)
                {
-                       char *identifier;
+                       char *identifier = NULL;
                        int status;
 
-                       identifier = identifiers[j];
+                       if (identifiers_num != 0)
+                               identifier = identifiers[j];
+
                        status = plugin_flush (plugin,
                                        DOUBLE_TO_CDTIME_T (timeout),
                                        identifier);
@@ -169,20 +147,13 @@ int handle_flush (FILE *fh, char *buffer)
                }
        }
 
-       if ((success + error) > 0)
-       {
-               print_to_socket (fh, "0 Done: %i successful, %i errors\n",
-                               success, error);
-       }
-       else
-       {
-               plugin_flush (NULL, DOUBLE_TO_CDTIME_T (timeout), NULL);
-               print_to_socket (fh, "0 Done\n");
-       }
+       PRINT_TO_SOCK (fh, "0 Done: %i successful, %i errors\n",
+                       success, error);
 
-       sfree (plugins);
-       sfree (identifiers);
+       strarray_free (plugins, plugins_num);
+       strarray_free (identifiers, identifiers_num);
        return (0);
+#undef PRINT_TO_SOCK
 } /* int handle_flush */
 
 /* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index c717f0b..7b0258c 100644 (file)
             char errbuf[1024]; \
             WARNING ("handle_putval: failed to write to socket #%i: %s", \
                     fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
+            sfree (vl.values); \
             return -1; \
         } \
         fflush(fh); \
     } while (0)
 
-static int dispatch_values (const data_set_t *ds, value_list_t *vl,
-               FILE *fh, char *buffer)
-{
-       int status;
-
-       status = parse_values (buffer, vl, ds);
-       if (status != 0)
-       {
-               print_to_socket (fh, "-1 Parsing the values string failed.\n");
-               return (-1);
-       }
-
-       plugin_dispatch_values (vl);
-       return (0);
-} /* int dispatch_values */
-
 static int set_option (value_list_t *vl, const char *key, const char *value)
 {
        if ((vl == NULL) || (key == NULL) || (value == NULL))
@@ -97,6 +82,7 @@ int handle_putval (FILE *fh, char *buffer)
 
        const data_set_t *ds;
        value_list_t vl = VALUE_LIST_INIT;
+       vl.values = NULL;
 
        DEBUG ("utils_cmd_putval: handle_putval (fh = %p, buffer = %s);",
                        (void *) fh, buffer);
@@ -196,6 +182,7 @@ int handle_putval (FILE *fh, char *buffer)
                        /* parse_option failed, buffer has been modified.
                         * => we need to abort */
                        print_to_socket (fh, "-1 Misformatted option.\n");
+                       sfree (vl.values);
                        return (-1);
                }
                else if (status == 0)
@@ -212,16 +199,20 @@ int handle_putval (FILE *fh, char *buffer)
                if (status != 0)
                {
                        print_to_socket (fh, "-1 Misformatted value.\n");
+                       sfree (vl.values);
                        return (-1);
                }
                assert (string != NULL);
 
-               status = dispatch_values (ds, &vl, fh, string);
+               status = parse_values (string, &vl, ds);
                if (status != 0)
                {
-                       /* An error has already been printed. */
+                       print_to_socket (fh, "-1 Parsing the values string failed.\n");
+                       sfree (vl.values);
                        return (-1);
                }
+
+               plugin_dispatch_values (&vl);
                values_submitted++;
        } /* while (*buffer != 0) */
        /* Done parsing the options. */
@@ -230,8 +221,7 @@ int handle_putval (FILE *fh, char *buffer)
                        values_submitted,
                        (values_submitted == 1) ? "value has" : "values have");
 
-       sfree (vl.values); 
-
+       sfree (vl.values);
        return (0);
 } /* int handle_putval */
 
index 893d590..9c84937 100644 (file)
@@ -202,8 +202,9 @@ static int udb_result_submit (udb_result_t *r, /* {{{ */
   assert (r != NULL);
   assert (r_area->ds != NULL);
   assert (((size_t) r_area->ds->ds_num) == r->values_num);
+  assert (r->values_num > 0);
 
-  vl.values = (value_t *) calloc (r_area->ds->ds_num, sizeof (value_t));
+  vl.values = (value_t *) calloc (r->values_num, sizeof (value_t));
   if (vl.values == NULL)
   {
     ERROR ("db query utils: malloc failed.");
@@ -1071,10 +1072,9 @@ udb_query_allocate_preparation_area (udb_query_t *q) /* {{{ */
   udb_result_preparation_area_t **next_r_area;
   udb_result_t *r;
 
-  q_area = (udb_query_preparation_area_t *)malloc (sizeof (*q_area));
+  q_area = malloc (sizeof (*q_area));
   if (q_area == NULL)
     return NULL;
-
   memset (q_area, 0, sizeof (*q_area));
 
   next_r_area = &q_area->result_prep_areas;
@@ -1082,14 +1082,18 @@ udb_query_allocate_preparation_area (udb_query_t *q) /* {{{ */
   {
     udb_result_preparation_area_t *r_area;
 
-    r_area = (udb_result_preparation_area_t *)malloc (sizeof (*r_area));
+    r_area = malloc (sizeof (*r_area));
     if (r_area == NULL)
     {
-      for (r_area = q_area->result_prep_areas;
-          r_area != NULL; r_area = r_area->next)
+      udb_result_preparation_area_t *a = q_area->result_prep_areas;
+
+      while (a != NULL)
       {
-        free (r_area);
+        udb_result_preparation_area_t *next = a->next;
+        sfree (a);
+        a = next;
       }
+
       free (q_area);
       return NULL;
     }
index 0ad252b..7b1c7d2 100644 (file)
@@ -131,6 +131,7 @@ static int ignorelist_append_regex(ignorelist_t *il, const char *entry)
                if (errsize)
                        sfree (regerr);
                regfree (regtemp);
+               sfree (regtemp);
                return (1);
        }
        DEBUG("regex compiled: %s - %i", entry, rcompile);
@@ -140,6 +141,7 @@ static int ignorelist_append_regex(ignorelist_t *il, const char *entry)
        {
                ERROR ("cannot allocate new config entry");
                regfree (regtemp);
+               sfree (regtemp);
                return (1);
        }
        memset (new, '\0', sizeof(ignorelist_item_t));
@@ -248,6 +250,7 @@ void ignorelist_free (ignorelist_t *il)
                if (this->rmatch != NULL)
                {
                        regfree (this->rmatch);
+                       sfree (this->rmatch);
                        this->rmatch = NULL;
                }
 #endif
index 7f60e11..c6a1ff6 100644 (file)
@@ -117,6 +117,7 @@ latency_counter_t *latency_counter_create () /* {{{ */
   lc = malloc (sizeof (*lc));
   if (lc == NULL)
     return (NULL);
+  memset (lc, 0, sizeof (*lc));
 
   latency_counter_reset (lc);
   lc->bin_width = HISTOGRAM_DEFAULT_BIN_WIDTH;
index 0e2d86c..5add323 100644 (file)
@@ -171,14 +171,10 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */
 
   int rra_max;
 
-  int span;
-
   int cdp_num;
   int cdp_len;
   int i, j;
 
-  char buffer[128];
-
   /* The stepsize we use here: If it is user-set, use it. If not, use the
    * interval of the value-list. */
   int ss;
@@ -218,16 +214,17 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */
   }
 
   rra_max = rts_num * rra_types_num;
+  assert (rra_max > 0);
 
-  if ((rra_def = (char **) malloc ((rra_max + 1) * sizeof (char *))) == NULL)
+  if ((rra_def = malloc ((rra_max + 1) * sizeof (*rra_def))) == NULL)
     return (-1);
-  memset (rra_def, '\0', (rra_max + 1) * sizeof (char *));
+  memset (rra_def, 0, (rra_max + 1) * sizeof (*rra_def));
   rra_num = 0;
 
   cdp_len = 0;
   for (i = 0; i < rts_num; i++)
   {
-    span = rts[i];
+    int span = rts[i];
 
     if ((span / ss) < cfg->rrarows)
       span = ss * cfg->rrarows;
@@ -243,6 +240,7 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */
 
     for (j = 0; j < rra_types_num; j++)
     {
+      char buffer[128];
       int status;
 
       if (rra_num >= rra_max)
@@ -261,6 +259,12 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */
     }
   }
 
+  if (rra_num <= 0)
+  {
+    sfree (rra_def);
+    return (0);
+  }
+
   *ret = rra_def;
   return (rra_num);
 } /* }}} int rra_get */
@@ -286,7 +290,9 @@ static int ds_get (char ***ret, /* {{{ */
   char max[32];
   char buffer[128];
 
-  ds_def = (char **) malloc (ds->ds_num * sizeof (char *));
+  assert (ds->ds_num > 0);
+
+  ds_def = malloc (ds->ds_num * sizeof (*ds_def));
   if (ds_def == NULL)
   {
     char errbuf[1024];
@@ -294,7 +300,7 @@ static int ds_get (char ***ret, /* {{{ */
         sstrerror (errno, errbuf, sizeof (errbuf)));
     return (-1);
   }
-  memset (ds_def, '\0', ds->ds_num * sizeof (char *));
+  memset (ds_def, 0, ds->ds_num * sizeof (*ds_def));
 
   for (ds_num = 0; ds_num < ds->ds_num; ds_num++)
   {
@@ -352,6 +358,12 @@ static int ds_get (char ***ret, /* {{{ */
     return (-1);
   }
 
+  if (ds_num <= 0)
+  {
+    sfree (ds_def);
+    return (0);
+  }
+
   *ret = ds_def;
   return (ds_num);
 } /* }}} int ds_get */
@@ -651,9 +663,9 @@ int cu_rrd_create_file (const char *filename, /* {{{ */
 {
   char **argv;
   int argc;
-  char **rra_def;
+  char **rra_def = NULL;
   int rra_num;
-  char **ds_def;
+  char **ds_def = NULL;
   int ds_num;
   int status = 0;
   time_t last_up;
@@ -671,6 +683,7 @@ int cu_rrd_create_file (const char *filename, /* {{{ */
   if ((ds_num = ds_get (&ds_def, ds, vl, cfg)) < 1)
   {
     ERROR ("cu_rrd_create_file failed: Could not calculate DSes");
+    rra_free (rra_num, rra_def);
     return (-1);
   }
 
@@ -681,6 +694,8 @@ int cu_rrd_create_file (const char *filename, /* {{{ */
     char errbuf[1024];
     ERROR ("cu_rrd_create_file failed: %s",
         sstrerror (errno, errbuf, sizeof (errbuf)));
+    rra_free (rra_num, rra_def);
+    ds_free (ds_num, ds_def);
     return (-1);
   }
 
@@ -709,18 +724,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);
     }
   }
 
index b6fedf5..dff8f71 100644 (file)
@@ -926,6 +926,9 @@ add_interface_device (virDomainPtr dom, const char *path, const char *address, u
     int new_size = sizeof (interface_devices[0]) * (nr_interface_devices+1);
     char *path_copy, *address_copy, number_string[15];
 
+    if ((path == NULL) || (address == NULL))
+        return EINVAL;
+
     path_copy = strdup (path);
     if (!path_copy) return -1;
 
@@ -961,6 +964,9 @@ ignore_device_match (ignorelist_t *il, const char *domname, const char *devpath)
     char *name;
     int n, r;
 
+    if ((domname == NULL) || (devpath == NULL))
+        return 0;
+
     n = sizeof (char) * (strlen (domname) + strlen (devpath) + 2);
     name = malloc (n);
     if (name == NULL) {
index dfa031c..24bcfc8 100644 (file)
@@ -112,7 +112,10 @@ static int wr_write (const data_set_t *ds, /* {{{ */
 
 #undef APPEND
 
+  status = format_values (value_ptr, value_size, ds, vl, /* store rates = */ 0);
   pthread_mutex_lock (&node->lock);
+  if (status != 0)
+    return (status);
 
   if (node->conn == NULL)
   {
index 7a3e4f4..f7803e8 100644 (file)
@@ -113,8 +113,8 @@ struct sensu_host {
        int                          reference_count;
 };
 
-static char    *sensu_tags;
-static char    **sensu_attrs;
+static char    *sensu_tags = NULL;
+static char    **sensu_attrs = NULL;
 static size_t sensu_attrs_num;
 
 static int add_str_to_list(struct str_list *strs,
@@ -558,7 +558,7 @@ char *replace_str(const char *str, const char *old, /* {{{ */
        const char *p, *q;
        size_t oldlen = strlen(old);
        size_t count = strlen(new);
-       size_t retlen = count;
+       size_t retlen;
        size_t newlen = count;
        int samesize = (oldlen == newlen);
 
@@ -1160,12 +1160,6 @@ static int sensu_config(oconfig_item_t *ci) /* {{{ */
 
        sensu_tags_arr.nb_strs = 0;
        sensu_tags_arr.strs = NULL;
-       sensu_tags = malloc(sizeof(char));
-       if (sensu_tags == NULL) {
-               ERROR("write_sensu plugin: Unable to alloc memory");
-               return -1;
-       }
-       sensu_tags[0] = '\0';
 
        for (i = 0; i < ci->children_num; i++)  {
                child = &ci->children[i];
@@ -1173,36 +1167,22 @@ static int sensu_config(oconfig_item_t *ci) /* {{{ */
                if (strcasecmp("Node", child->key) == 0) {
                        sensu_config_node(child);
                } else if (strcasecmp(child->key, "attribute") == 0) {
-                       char *key = NULL;
-                       char *val = NULL;
-
                        if (child->values_num != 2) {
                                WARNING("sensu attributes need both a key and a value.");
-                               free(sensu_tags);
-                               return -1;
+                               continue;
                        }
                        if (child->values[0].type != OCONFIG_TYPE_STRING ||
-                           child->values[1].type != OCONFIG_TYPE_STRING) {
+                                       child->values[1].type != OCONFIG_TYPE_STRING) {
                                WARNING("sensu attribute needs string arguments.");
-                               free(sensu_tags);
-                               return -1;
-                       }
-                       if ((key = strdup(child->values[0].value.string)) == NULL) {
-                               ERROR("write_sensu plugin: Unable to alloc memory");
-                               free(sensu_tags);
-                               return -1;
-                       }
-                       if ((val = strdup(child->values[1].value.string)) == NULL) {
-                               free(sensu_tags);
-                               free(key);
-                               ERROR("write_sensu plugin: Unable to alloc memory");
-                               return -1;
+                               continue;
                        }
-                       strarray_add(&sensu_attrs, &sensu_attrs_num, key);
-                       strarray_add(&sensu_attrs, &sensu_attrs_num, val);
-                       DEBUG("write_sensu: got attr: %s => %s", key, val);
-                       sfree(key);
-                       sfree(val);
+
+                       strarray_add(&sensu_attrs, &sensu_attrs_num, child->values[0].value.string);
+                       strarray_add(&sensu_attrs, &sensu_attrs_num, child->values[1].value.string);
+
+                       DEBUG("write_sensu plugin: New attribute: %s => %s",
+                                       child->values[0].value.string,
+                                       child->values[1].value.string);
                } else if (strcasecmp(child->key, "tag") == 0) {
                        char *tmp = NULL;
                        status = cf_util_get_string(child, &tmp);
@@ -1221,7 +1201,7 @@ static int sensu_config(oconfig_item_t *ci) /* {{{ */
                }
        }
        if (sensu_tags_arr.nb_strs > 0) {
-               free(sensu_tags);
+               sfree (sensu_tags);
                sensu_tags = build_json_str_list("tags", &sensu_tags_arr);
                free_str_list(&sensu_tags_arr);
                if (sensu_tags == NULL) {