Merge pull request #2348 from maryamtahhan/feat_dpdkevents_fixes
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Thu, 6 Jul 2017 16:54:45 +0000 (18:54 +0200)
committerGitHub <noreply@github.com>
Thu, 6 Jul 2017 16:54:45 +0000 (18:54 +0200)
Feat dpdkevents fixes

15 files changed:
ChangeLog
Makefile.am
configure.ac
src/apcups.c
src/collectd-snmp.pod
src/email.c
src/exec.c
src/ipvs.c
src/openldap.c
src/snmp_agent.c
src/tcpconns.c
src/unixsock.c
src/write_mongodb.c
src/write_riemann.c
version-gen.sh

index 9f1b639..b8755d9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,50 @@
+2017-06-06, Version 5.7.2
+       * Build system: The Notify Email plugin is no longer linked with
+         indirect dependencies. Thanks to Marc Fournier.
+       * collectd: A race condition when calculating a metric's rate has been
+         fixed. Thanks to Florian Forster. #1193
+       * AMQP, Exec, UnixSock, Write Kafka plugins: Parsing of the PUTVAL
+         command with multiple values has been fixed. Thanks to Florian
+         Forster. #2274
+       * AMQP plugin: The "ExchangeType" option is now also valid for
+         publishers. Thanks to Florian Forster. #2286
+       * BIND plugin: Fix parsing of the sample time provided by BIND.
+         Previously, the time was assumed to be in the local timezone when in
+         fact it was in UTC. Thanks to Ed Ravin. #1268
+       * BIND plugin: Memory leaks have been fixed. Thanks to Ruben Kerkhof.
+         #2303
+       * cURL-JSON plugin: Handling of arrays has been fixed. Thanks to Florian
+         Forster. #2266
+       * DPDKStat plugin: Error handling during initialization has been
+         improved. Thanks to Ruben Kerkhof.
+       * DPDKStat plugin: Handling of a number of metrics has been improved,
+         for example "rx_q0bytes". Thanks to Przemyslaw Szczerbik. #2167
+       * Intel RDT plugin: Configuration handling has been changed to be more
+         graceful. Thanks to Maryam Tahhan. #2165
+       * Log Logstash plugin: If writing the log entry fails, print it to
+         "STDERR" instead. Thanks to Marc Fournier.
+       * LogFile plugin: If writing to the file fails, print log messages on
+         "STDERR" instead. Thanks to Marc Fournier.
+       * memcachec, Tail plugins: A resource leak in the matching
+         infrastructure has been fixed. Thanks to Krzysztof Matczak. #2192
+       * MQTT plugin: Invalid symbols in topic names are now replaced and a
+         resource leak has been fixed. Thanks to Denys Fedoryshchenko. #2123
+       * Network plugin: A potential endless-loop has been fixed. This can be
+         triggered remotely by sending a signed network packet to a server
+         which is not set up to check signatures. Thanks to Marcin Kozlowski
+         and Pavel Rochnyack. #2174, #2233, CVE-2017-7401
+       * Perl plugin: A potential double-free has been fixed. Thanks to Florian
+         Forster. #2278
+       * Processes plugin: A compilation error on AIX has been fixed. Thanks to
+         Pavel Rochnyack. #2210
+       * SMART plugin: A check for the "CAP_SYS_RAWIO" capability has been
+         added. Thanks to Marc Fournier.
+       * Write Graphite plugin: Error handling in the case that calculating a
+         metric's rate fails has been improved. Previously, the raw counter
+         values were sent to Graphite. Thanks to Iain Buclaw. #2209
+       * Write Prometheus plugin: An incorrect use of "realloc(3)" has been
+         fixed. Thanks to Florian Forster. #2275
+
 2017-01-23, Version 5.7.1
        * collectd: Handling of boolean configuration options has been unified.
          Thanks to Sebastian Harl. #2083, #2098
index 529d4a9..f927399 100644 (file)
@@ -119,7 +119,10 @@ noinst_LTLIBRARIES = \
        liblookup.la \
        libmetadata.la \
        libmount.la \
-       liboconfig.la \
+       liboconfig.la
+
+
+check_LTLIBRARIES = \
        libplugin_mock.la
 
 
@@ -940,10 +943,6 @@ endif
 if BUILD_PLUGIN_IPVS
 pkglib_LTLIBRARIES += ipvs.la
 ipvs_la_SOURCES = src/ipvs.c
-ipvs_la_CFLAGS = $(AM_CFLAGS)
-if IP_VS_H_NEEDS_KERNEL_CFLAGS
-ipvs_la_CFLAGS += $(KERNEL_CFLAGS)
-endif
 ipvs_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
index 5f56385..3357375 100644 (file)
@@ -112,15 +112,6 @@ AM_CONDITIONAL([BUILD_LINUX], [test "x$ac_system" = "xLinux"])
 AM_CONDITIONAL([BUILD_OPENBSD], [test "x$ac_system" = "xOpenBSD"])
 AM_CONDITIONAL([BUILD_SOLARIS], [test "x$ac_system" = "xSolaris"])
 
-if test "x$ac_system" = "xLinux"; then
-  AC_ARG_VAR([KERNEL_DIR], [path to Linux kernel sources])
-  if test "x$KERNEL_DIR" = "x"; then
-    KERNEL_DIR="/lib/modules/`uname -r`/source"
-  fi
-  KERNEL_CFLAGS="-I$KERNEL_DIR/include"
-  AC_SUBST([KERNEL_CFLAGS])
-fi
-
 if test "x$ac_system" = "xSolaris"; then
   AC_DEFINE([_POSIX_PTHREAD_SEMANTICS], [1], [Define to enforce POSIX thread semantics under Solaris.])
   AC_DEFINE([_REENTRANT], [1], [Define to enable reentrancy interfaces.])
@@ -461,7 +452,7 @@ if test "x$ac_system" = "xLinux"; then
       #endif
     ]]
   )
-  
+
   AC_CHECK_HEADERS([linux/inet_diag.h], [], [],
     [[
       #if HAVE_SYS_TYPES_H
@@ -472,7 +463,7 @@ if test "x$ac_system" = "xLinux"; then
       #endif
     ]]
   )
-  
+
   AC_CHECK_HEADERS([linux/netdevice.h], [], [],
     [[
       #if HAVE_SYS_TYPES_H
@@ -486,7 +477,7 @@ if test "x$ac_system" = "xLinux"; then
       #endif
     ]]
   )
-  
+
   # For ethstat module
   AC_CHECK_HEADERS([linux/sockios.h],
     [have_linux_sockios_h="yes"],
@@ -500,7 +491,7 @@ if test "x$ac_system" = "xLinux"; then
       #endif
     ]]
   )
-  
+
   AC_CHECK_HEADERS([linux/ethtool.h],
     [have_linux_ethtool_h="yes"],
     [have_linux_ethtool_h="no"],
@@ -518,28 +509,7 @@ if test "x$ac_system" = "xLinux"; then
   )
 
   # For ipvs module
-  AC_CHECK_HEADERS([linux/ip_vs.h], [have_linux_ip_vs_h="yes"], [have_linux_ip_vs="no"])
-  AC_CHECK_HEADERS([net/ip_vs.h], [have_net_ip_vs_h="yes"], [have_net_ip_vs_h="no"])
-  AC_CHECK_HEADERS([ip_vs.h], [have_ip_vs_h="yes"], [have_ip_vs_h="no"])
-
-  ip_vs_h_needs_kernel_cflags="no"
-  
-  if test "x$have_linux_ip_vs_h$have_net_ip_vs_h$have_ip_vs_h" = "xnonono" && test -d "$KERNEL_DIR"; then
-    SAVE_CFLAGS="$CFLAGS"
-    CFLAGS="$CFLAGS $KERNEL_CFLAGS"
-    
-    AC_MSG_NOTICE([Did not find ip_vs.h. Trying again using headers from $KERNEL_DIR.])
-    
-    AC_CHECK_HEADERS([linux/ip_vs.h], [have_linux_ip_vs_h="yes"])
-    AC_CHECK_HEADERS([net/ip_vs.h], [have_net_ip_vs_h="yes"])
-    AC_CHECK_HEADERS([ip_vs.h], [have_ip_vs_h="yes"])
-    
-    if test "x$have_linux_ip_vs_h" = "xyes" || test "x$have_net_ip_vs_h" = "xyes" || test "x$have_ip_vs_h" = "xyes"; then
-      ip_vs_h_needs_kernel_cflags="yes"
-    fi
-    
-    CFLAGS="$SAVE_CFLAGS"
-  fi
+  AC_CHECK_HEADERS_ONCE([linux/ip_vs.h])
 
   # For the email plugin
   AC_CHECK_HEADERS([linux/un.h], [], [],
@@ -554,7 +524,7 @@ if test "x$ac_system" = "xLinux"; then
     [have_asm_msrindex_h="yes"],
     [have_asm_msrindex_h="no"]
   )
-  
+
   if test "x$have_asm_msrindex_h" = "xyes"; then
     AC_CACHE_CHECK([whether asm/msr-index.h has MSR_PKG_C10_RESIDENCY],
       [c_cv_have_usable_asm_msrindex_h],
@@ -575,12 +545,12 @@ if test "x$ac_system" = "xLinux"; then
       ]
     )
   fi
-  
+
   AC_CHECK_HEADERS([cpuid.h],
     [have_cpuid_h="yes"],
     [have_cpuid_h="no (cpuid.h not found)"]
   )
-  
+
   AC_CHECK_HEADERS([sys/capability.h],
     [have_capability="yes"],
     [have_capability="no (<sys/capability.h> not found)"]
@@ -610,7 +580,6 @@ else
   have_linux_wireless_h="no"
 fi
 
-AM_CONDITIONAL([IP_VS_H_NEEDS_KERNEL_CFLAGS], [test "x$ip_vs_h_needs_kernel_cflags" = "xyes"])
 AM_CONDITIONAL([BUILD_WITH_CAPABILITY], [test "x$have_capability" = "xyes"])
 
 # For the swap module
@@ -1445,13 +1414,13 @@ if test "x$fp_layout_type" = "xunknown"; then
               uint64_t i1;
               uint8_t c[8];
               double d;
-              
+
               d = 8.642135e130;
               memcpy ((void *) &i0, (void *) &d, 8);
-              
+
               i1 = endianflip (i0);
               memcpy ((void *) c, (void *) &i1, 8);
-              
+
               if ((c[0] == 0x2f) && (c[1] == 0x25)
                   && (c[2] == 0xc0) && (c[3] == 0xc7)
                   && (c[4] == 0x43) && (c[5] == 0x2b)
@@ -1494,13 +1463,13 @@ if test "x$fp_layout_type" = "xunknown"; then
               uint64_t i1;
               uint8_t c[8];
               double d;
-              
+
               d = 8.642135e130;
               memcpy ((void *) &i0, (void *) &d, 8);
-              
+
               i1 = intswap (i0);
               memcpy ((void *) c, (void *) &i1, 8);
-              
+
               if ((c[0] == 0x2f) && (c[1] == 0x25)
                   && (c[2] == 0xc0) && (c[3] == 0xc7)
                   && (c[4] == 0x43) && (c[5] == 0x2b)
@@ -6185,14 +6154,14 @@ if test "x$ac_system" = "xLinux"; then
   plugin_wireless="yes"
   plugin_zfs_arc="yes"
 
-  if test "x$have_linux_ip_vs_h" = "xyes" || test "x$have_net_ip_vs_h" = "xyes" || test "x$have_ip_vs_h" = "xyes"; then
+  if test "x$ac_cv_header_linux_ip_vs_h" = "xyes"; then
     plugin_ipvs="yes"
   fi
 
   if test "x$c_cv_have_usable_asm_msrindex_h" = "xyes" && test "x$have_cpuid_h" = "xyes"; then
     plugin_turbostat="yes"
   fi
-  
+
   if test "x$c_cv_have_clock_boottime_monotonic" = "xyes"; then
     plugin_cpusleep="yes"
   fi
@@ -6667,8 +6636,7 @@ AC_SUBST([LOAD_PLUGIN_SYSLOG])
 AC_SUBST([LOAD_PLUGIN_LOGFILE])
 AC_SUBST([LOAD_PLUGIN_LOG_LOGSTASH])
 
-if test "x$enable_debug" = "xyes"
-then
+if test "x$enable_debug" = "xyes"; then
   DEFAULT_LOG_LEVEL="debug"
 else
   DEFAULT_LOG_LEVEL="info"
@@ -6713,21 +6681,11 @@ AC_SUBST([LOAD_PLUGIN_RRDTOOL])
 AC_SUBST([LOAD_PLUGIN_NETWORK])
 AC_SUBST([LOAD_PLUGIN_CSV])
 
-dnl ip_vs.h
-if test "x$ac_system" = "xLinux" && test "x$have_linux_ip_vs_h" = "xno" && "x$have_net_ip_vs_h" = "xno" && "x$have_ip_vs_h" = "xno"; then
-  enable_ipvs="$enable_ipvs (ip_vs.h not found)"
-fi
-
-if test "x$ip_vs_h_needs_kernel_cflags" = "xyes"; then
-  enable_ipvs="$enable_ipvs (needs $KERNEL_CFLAGS)"
-fi
-
 dnl Perl bindings
 PERL_BINDINGS_OPTIONS="PREFIX=${prefix}"
 AC_ARG_WITH(perl-bindings, [AS_HELP_STRING([--with-perl-bindings@<:@=OPTIONS@:>@], [Options passed to "perl Makefile.PL".])],
 [
-  if test "x$withval" != "xno" && test "x$withval" != "xyes"
-  then
+  if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
     PERL_BINDINGS_OPTIONS="$withval"
     with_perl_bindings="yes"
   else
@@ -6735,8 +6693,7 @@ AC_ARG_WITH(perl-bindings, [AS_HELP_STRING([--with-perl-bindings@<:@=OPTIONS@:>@
   fi
 ],
 [
-  if test "x$PERL" != "x"
-  then
+  if test "x$PERL" != "x"; then
     with_perl_bindings="yes"
   else
     with_perl_bindings="no (no perl interpreter found)"
@@ -6753,8 +6710,7 @@ if test "x$with_perl_bindings" = "xyes"; then
   fi
 fi
 
-if test "x$with_perl_bindings" = "xyes"
-then
+if test "x$with_perl_bindings" = "xyes"; then
   PERL_BINDINGS="perl"
 else
   PERL_BINDINGS=""
index f6ee2db..7c6a47c 100644 (file)
@@ -240,7 +240,7 @@ static int apc_query_server(char const *node, char const *service,
   char recvline[1024];
   char *tokptr;
   char *toksaveptr;
-  _Bool retry = 1;
+  int try = 0;
   int status;
 
 #if APCMAIN
@@ -250,7 +250,7 @@ static int apc_query_server(char const *node, char const *service,
 #define PRINT_VALUE(name, val) /**/
 #endif
 
-  while (retry) {
+  while (1) {
     if (global_sockfd < 0) {
       global_sockfd = net_open(node, service);
       if (global_sockfd < 0) {
@@ -262,10 +262,10 @@ static int apc_query_server(char const *node, char const *service,
 
     status = net_send(&global_sockfd, "status", strlen("status"));
     if (status != 0) {
-      /* net_send is closing the socket on error. */
+      /* net_send closes the socket on error. */
       assert(global_sockfd < 0);
-      if (retry) {
-        retry = 0;
+      if (try == 0) {
+        try++;
         count_retries++;
         continue;
       }
@@ -275,7 +275,7 @@ static int apc_query_server(char const *node, char const *service,
     }
 
     break;
-  } /* while (retry) */
+  } /* while (1) */
 
   /* When collectd's collection interval is larger than apcupsd's
    * timeout, we would have to retry / re-connect each iteration. Try to
index c246f1d..edb9506 100644 (file)
@@ -44,7 +44,7 @@ collectd-snmp - Documentation of collectd's C<snmp plugin>
       Collect "std_traffic" "hr_users"
     </Host>
     <Host "secure.router.mydomain.org">
-      Address "192.168.0.7"
+      Address "192.168.0.7:165"
       Version 3
       SecurityLevel "authPriv"
       Username "cosmo"
@@ -55,7 +55,7 @@ collectd-snmp - Documentation of collectd's C<snmp plugin>
       Collect "std_traffic"
     </Host>
     <Host "some.ups.mydomain.org">
-      Address "192.168.0.3"
+      Address "tcp:192.168.0.3"
       Version 1
       Community "more_communities"
       Collect "powerplus_voltge_input"
@@ -228,7 +228,8 @@ stored by collectd.
 
 =item B<Address> I<IP-Address>|I<Hostname>
 
-Set the address to connect to.
+Set the address to connect to. Address may include transport specifier and/or
+port number.
 
 =item B<Version> B<1>|B<2>|B<3>
 
index 871ddf8..e5f015b 100644 (file)
@@ -159,18 +159,18 @@ static type_list_t list_check_copy;
  * Private functions
  */
 static int email_config(const char *key, const char *value) {
-  if (0 == strcasecmp(key, "SocketFile")) {
-    if (NULL != sock_file)
+  if (strcasecmp(key, "SocketFile") == 0) {
+    if (sock_file != NULL)
       free(sock_file);
     sock_file = sstrdup(value);
-  } else if (0 == strcasecmp(key, "SocketGroup")) {
-    if (NULL != sock_group)
+  } else if (strcasecmp(key, "SocketGroup") == 0) {
+    if (sock_group != NULL)
       free(sock_group);
     sock_group = sstrdup(value);
-  } else if (0 == strcasecmp(key, "SocketPerms")) {
+  } else if (strcasecmp(key, "SocketPerms") == 0) {
     /* the user is responsible for providing reasonable values */
     sock_perms = (int)strtol(value, NULL, 8);
-  } else if (0 == strcasecmp(key, "MaxConns")) {
+  } else if (strcasecmp(key, "MaxConns") == 0) {
     long int tmp = strtol(value, NULL, 0);
 
     if (tmp < 1) {
@@ -200,7 +200,7 @@ static int email_config(const char *key, const char *value) {
 
 /* Increment the value of the given name in the given list by incr. */
 static void type_list_incr(type_list_t *list, char *name, int incr) {
-  if (NULL == list->head) {
+  if (list->head == NULL) {
     list->head = smalloc(sizeof(*list->head));
 
     list->head->name = sstrdup(name);
@@ -212,11 +212,11 @@ static void type_list_incr(type_list_t *list, char *name, int incr) {
     type_t *ptr;
 
     for (ptr = list->head; NULL != ptr; ptr = ptr->next) {
-      if (0 == strcmp(name, ptr->name))
+      if (strcmp(name, ptr->name) == 0)
         break;
     }
 
-    if (NULL == ptr) {
+    if (ptr == NULL) {
       list->tail->next = smalloc(sizeof(*list->tail->next));
       list->tail = list->tail->next;
 
@@ -238,14 +238,14 @@ static void *collect(void *arg) {
 
     pthread_mutex_lock(&conns_mutex);
 
-    while (NULL == conns.head) {
+    while (conns.head == NULL) {
       pthread_cond_wait(&conn_available, &conns_mutex);
     }
 
     connection = conns.head;
     conns.head = conns.head->next;
 
-    if (NULL == conns.head) {
+    if (conns.head == NULL) {
       conns.tail = NULL;
     }
 
@@ -263,8 +263,8 @@ static void *collect(void *arg) {
       int len = 0;
 
       errno = 0;
-      if (NULL == fgets(line, sizeof(line), this->socket)) {
-        if (0 != errno) {
+      if (fgets(line, sizeof(line), this->socket) == NULL) {
+        if (errno != 0) {
           char errbuf[1024];
           log_err("collect: reading from socket (fd #%i) "
                   "failed: %s",
@@ -275,13 +275,13 @@ static void *collect(void *arg) {
       }
 
       len = strlen(line);
-      if (('\n' != line[len - 1]) && ('\r' != line[len - 1])) {
+      if ((line[len - 1] != '\n') && (line[len - 1] != '\r')) {
         log_warn("collect: line too long (> %zu characters): "
                  "'%s' (truncated)",
                  sizeof(line) - 1, line);
 
-        while (NULL != fgets(line, sizeof(line), this->socket))
-          if (('\n' == line[len - 1]) || ('\r' == line[len - 1]))
+        while (fgets(line, sizeof(line), this->socket) != NULL)
+          if ((line[len - 1] == '\n') || (line[len - 1] == '\r'))
             break;
         continue;
       }
@@ -293,18 +293,18 @@ static void *collect(void *arg) {
 
       log_debug("collect: line = '%s'", line);
 
-      if (':' != line[1]) {
+      if (line[1] != ':') {
         log_err("collect: syntax error in line '%s'", line);
         continue;
       }
 
-      if ('e' == line[0]) { /* e:<type>:<bytes> */
+      if (line[0] == 'e') { /* e:<type>:<bytes> */
         char *ptr = NULL;
         char *type = strtok_r(line + 2, ":", &ptr);
         char *tmp = strtok_r(NULL, ":", &ptr);
         int bytes = 0;
 
-        if (NULL == tmp) {
+        if (tmp == NULL) {
           log_err("collect: syntax error in line '%s'", line);
           continue;
         }
@@ -320,13 +320,13 @@ static void *collect(void *arg) {
           type_list_incr(&list_size, type, /* increment = */ bytes);
           pthread_mutex_unlock(&size_mutex);
         }
-      } else if ('s' == line[0]) { /* s:<value> */
+      } else if (line[0] == 's') { /* s:<value> */
         pthread_mutex_lock(&score_mutex);
         score = (score * (double)score_count + atof(line + 2)) /
                 (double)(score_count + 1);
         ++score_count;
         pthread_mutex_unlock(&score_mutex);
-      } else if ('c' == line[0]) { /* c:<type1>[,<type2>,...] */
+      } else if (line[0] == 'c') { /* c:<type1>[,<type2>,...] */
         char *dummy = line + 2;
         char *endptr = NULL;
         char *type;
@@ -366,7 +366,7 @@ static void *open_connection(void __attribute__((unused)) * arg) {
 
   /* create UNIX socket */
   errno = 0;
-  if (-1 == (connector_socket = socket(PF_UNIX, SOCK_STREAM, 0))) {
+  if ((connector_socket = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
     char errbuf[1024];
     disabled = 1;
     log_err("socket() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
@@ -379,9 +379,8 @@ static void *open_connection(void __attribute__((unused)) * arg) {
   sstrncpy(addr.sun_path, path, (size_t)(UNIX_PATH_MAX - 1));
 
   errno = 0;
-  if (-1 ==
-      bind(connector_socket, (struct sockaddr *)&addr,
-           offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path))) {
+  if (bind(connector_socket, (struct sockaddr *)&addr,
+           offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)) == -1) {
     char errbuf[1024];
     disabled = 1;
     close(connector_socket);
@@ -391,7 +390,7 @@ static void *open_connection(void __attribute__((unused)) * arg) {
   }
 
   errno = 0;
-  if (-1 == listen(connector_socket, 5)) {
+  if (listen(connector_socket, 5) == -1) {
     char errbuf[1024];
     disabled = 1;
     close(connector_socket);
@@ -403,7 +402,7 @@ static void *open_connection(void __attribute__((unused)) * arg) {
   {
     struct group sg;
     struct group *grp;
-    char grbuf[2048];
+    char grbuf[4096];
     int status;
 
     grp = NULL;
@@ -411,7 +410,7 @@ static void *open_connection(void __attribute__((unused)) * arg) {
     if (status != 0) {
       char errbuf[1024];
       log_warn("getgrnam_r (%s) failed: %s", group,
-               sstrerror(errno, errbuf, sizeof(errbuf)));
+               sstrerror(status, errbuf, sizeof(errbuf)));
     } else if (grp == NULL) {
       log_warn("No such group: `%s'", group);
     } else {
@@ -425,7 +424,7 @@ static void *open_connection(void __attribute__((unused)) * arg) {
   }
 
   errno = 0;
-  if (0 != chmod(path, sock_perms)) {
+  if (chmod(path, sock_perms) != 0) {
     char errbuf[1024];
     log_warn("chmod() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
   }
@@ -466,7 +465,7 @@ static void *open_connection(void __attribute__((unused)) * arg) {
 
     pthread_mutex_lock(&available_mutex);
 
-    while (0 == available_collectors) {
+    while (available_collectors == 0) {
       pthread_cond_wait(&collector_available, &available_mutex);
     }
 
@@ -505,7 +504,7 @@ static void *open_connection(void __attribute__((unused)) * arg) {
     connection->socket = fdopen(remote, "r");
     connection->next = NULL;
 
-    if (NULL == connection->socket) {
+    if (connection->socket == NULL) {
       close(remote);
       sfree(connection);
       continue;
@@ -513,7 +512,7 @@ static void *open_connection(void __attribute__((unused)) * arg) {
 
     pthread_mutex_lock(&conns_mutex);
 
-    if (NULL == conns.head) {
+    if (conns.head == NULL) {
       conns.head = connection;
       conns.tail = connection;
     } else {
@@ -605,7 +604,7 @@ static int email_shutdown(void) {
   type_list_free(&list_check);
   type_list_free(&list_check_copy);
 
-  unlink((NULL == sock_file) ? SOCK_PATH : sock_file);
+  unlink((sock_file == NULL) ? SOCK_PATH : sock_file);
 
   sfree(sock_file);
   sfree(sock_group);
@@ -632,14 +631,14 @@ static void email_submit(const char *type, const char *type_instance,
 static void copy_type_list(type_list_t *l1, type_list_t *l2) {
   type_t *last = NULL;
 
-  for (type_t *ptr1 = l1->head, *ptr2 = l2->head; NULL != ptr1;
+  for (type_t *ptr1 = l1->head, *ptr2 = l2->head; ptr1 != NULL;
        ptr1 = ptr1->next, last = ptr2, ptr2 = ptr2->next) {
-    if (NULL == ptr2) {
+    if (ptr2 == NULL) {
       ptr2 = smalloc(sizeof(*ptr2));
       ptr2->name = NULL;
       ptr2->next = NULL;
 
-      if (NULL == last) {
+      if (last == NULL) {
         l2->head = ptr2;
       } else {
         last->next = ptr2;
@@ -648,7 +647,7 @@ static void copy_type_list(type_list_t *l1, type_list_t *l2) {
       l2->tail = ptr2;
     }
 
-    if (NULL == ptr2->name) {
+    if (ptr2->name == NULL) {
       ptr2->name = sstrdup(ptr1->name);
     }
 
@@ -672,7 +671,7 @@ static int email_read(void) {
 
   pthread_mutex_unlock(&count_mutex);
 
-  for (type_t *ptr = list_count_copy.head; NULL != ptr; ptr = ptr->next) {
+  for (type_t *ptr = list_count_copy.head; ptr != NULL; ptr = ptr->next) {
     email_submit("email_count", ptr->name, ptr->value);
   }
 
@@ -683,7 +682,7 @@ static int email_read(void) {
 
   pthread_mutex_unlock(&size_mutex);
 
-  for (type_t *ptr = list_size_copy.head; NULL != ptr; ptr = ptr->next) {
+  for (type_t *ptr = list_size_copy.head; ptr != NULL; ptr = ptr->next) {
     email_submit("email_size", ptr->name, ptr->value);
   }
 
@@ -707,7 +706,7 @@ static int email_read(void) {
 
   pthread_mutex_unlock(&check_mutex);
 
-  for (type_t *ptr = list_check_copy.head; NULL != ptr; ptr = ptr->next)
+  for (type_t *ptr = list_check_copy.head; ptr != NULL; ptr = ptr->next)
     email_submit("spam_check", ptr->name, ptr->value);
 
   return 0;
index f10b816..3d12a2d 100644 (file)
@@ -369,7 +369,7 @@ static int fork_child(program_list_t *pl, int *fd_in, int *fd_out,
 
   struct passwd *sp_ptr;
   struct passwd sp;
-  char nambuf[2048];
+  char nambuf[4096];
 
   if (pl->pid != 0)
     return -1;
@@ -382,7 +382,7 @@ static int fork_child(program_list_t *pl, int *fd_in, int *fd_out,
   status = getpwnam_r(pl->user, &sp, nambuf, sizeof(nambuf), &sp_ptr);
   if (status != 0) {
     ERROR("exec plugin: Failed to get user information for user ``%s'': %s",
-          pl->user, sstrerror(errno, errbuf, sizeof(errbuf)));
+          pl->user, sstrerror(status, errbuf, sizeof(errbuf)));
     goto failed;
   }
 
@@ -401,19 +401,19 @@ static int fork_child(program_list_t *pl, int *fd_in, int *fd_out,
   /* The group configured in the configfile is set as effective group, because
    * this way the forked process can (re-)gain the user's primary group. */
   egid = -1;
-  if (NULL != pl->group) {
-    if ('\0' != *pl->group) {
+  if (pl->group != NULL) {
+    if (*pl->group != '\0') {
       struct group *gr_ptr = NULL;
       struct group gr;
 
       status = getgrnam_r(pl->group, &gr, nambuf, sizeof(nambuf), &gr_ptr);
-      if (0 != status) {
+      if (status != 0) {
         ERROR("exec plugin: Failed to get group information "
               "for group ``%s'': %s",
-              pl->group, sstrerror(errno, errbuf, sizeof(errbuf)));
+              pl->group, sstrerror(status, errbuf, sizeof(errbuf)));
         goto failed;
       }
-      if (NULL == gr_ptr) {
+      if (gr_ptr == NULL) {
         ERROR("exec plugin: No such group: `%s'", pl->group);
         goto failed;
       }
index e614b93..da67970 100644 (file)
 #include <netinet/in.h>
 #endif /* HAVE_NETINET_IN_H */
 
-/* this can probably only be found in the kernel sources */
-#if HAVE_LINUX_IP_VS_H
 #include <linux/ip_vs.h>
-#elif HAVE_NET_IP_VS_H
-#include <net/ip_vs.h>
-#elif HAVE_IP_VS_H
-#include <ip_vs.h>
-#endif /* HAVE_IP_VS_H */
 
 #define log_err(...) ERROR("ipvs: " __VA_ARGS__)
 #define log_info(...) INFO("ipvs: " __VA_ARGS__)
@@ -64,68 +57,67 @@ static int sockfd = -1;
  */
 static struct ip_vs_get_services *ipvs_get_services(void) {
   struct ip_vs_getinfo ipvs_info;
-  struct ip_vs_get_services *ret;
+  struct ip_vs_get_services *services;
 
-  socklen_t len;
+  socklen_t len = sizeof(ipvs_info);
 
-  len = sizeof(ipvs_info);
-
-  if (0 != getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_INFO, (void *)&ipvs_info,
-                      &len)) {
+  if (getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_INFO, &ipvs_info, &len) ==
+      -1) {
     char errbuf[1024];
     log_err("ip_vs_get_services: getsockopt() failed: %s",
             sstrerror(errno, errbuf, sizeof(errbuf)));
     return NULL;
   }
 
-  len = sizeof(*ret) +
+  len = sizeof(*services) +
         sizeof(struct ip_vs_service_entry) * ipvs_info.num_services;
 
-  if (NULL == (ret = malloc(len))) {
+  services = malloc(len);
+  if (services == NULL) {
     log_err("ipvs_get_services: Out of memory.");
-    exit(3);
+    return NULL;
   }
 
-  ret->num_services = ipvs_info.num_services;
+  services->num_services = ipvs_info.num_services;
 
-  if (0 != getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_SERVICES, (void *)ret,
-                      &len)) {
+  if (getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_SERVICES, services, &len) ==
+      -1) {
     char errbuf[1024];
     log_err("ipvs_get_services: getsockopt failed: %s",
             sstrerror(errno, errbuf, sizeof(errbuf)));
 
-    free(ret);
+    free(services);
     return NULL;
   }
-  return ret;
+  return services;
 } /* ipvs_get_services */
 
 static struct ip_vs_get_dests *ipvs_get_dests(struct ip_vs_service_entry *se) {
-  struct ip_vs_get_dests *ret;
-  socklen_t len;
+  struct ip_vs_get_dests *dests;
 
-  len = sizeof(*ret) + sizeof(struct ip_vs_dest_entry) * se->num_dests;
+  socklen_t len =
+      sizeof(*dests) + sizeof(struct ip_vs_dest_entry) * se->num_dests;
 
-  if (NULL == (ret = malloc(len))) {
+  dests = malloc(len);
+  if (dests == NULL) {
     log_err("ipvs_get_dests: Out of memory.");
-    exit(3);
+    return NULL;
   }
 
-  ret->fwmark = se->fwmark;
-  ret->protocol = se->protocol;
-  ret->addr = se->addr;
-  ret->port = se->port;
-  ret->num_dests = se->num_dests;
+  dests->fwmark = se->fwmark;
+  dests->protocol = se->protocol;
+  dests->addr = se->addr;
+  dests->port = se->port;
+  dests->num_dests = se->num_dests;
 
-  if (0 !=
-      getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_DESTS, (void *)ret, &len)) {
+  if (getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_DESTS, dests, &len) == -1) {
     char errbuf[1024];
     log_err("ipvs_get_dests: getsockopt() failed: %s",
             sstrerror(errno, errbuf, sizeof(errbuf)));
-    free(ret);
+    free(dests);
     return NULL;
   }
-  return ret;
+  return dests;
 } /* ip_vs_get_dests */
 
 /*
@@ -134,19 +126,17 @@ static struct ip_vs_get_dests *ipvs_get_dests(struct ip_vs_service_entry *se) {
 static int cipvs_init(void) {
   struct ip_vs_getinfo ipvs_info;
 
-  socklen_t len;
-
-  if (-1 == (sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
+  if ((sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) == -1) {
     char errbuf[1024];
     log_err("cipvs_init: socket() failed: %s",
             sstrerror(errno, errbuf, sizeof(errbuf)));
     return -1;
   }
 
-  len = sizeof(ipvs_info);
+  socklen_t len = sizeof(ipvs_info);
 
-  if (0 != getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_INFO, (void *)&ipvs_info,
-                      &len)) {
+  if (getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_INFO, &ipvs_info, &len) ==
+      -1) {
     char errbuf[1024];
     log_err("cipvs_init: getsockopt() failed: %s",
             sstrerror(errno, errbuf, sizeof(errbuf)));
@@ -176,21 +166,16 @@ static int cipvs_init(void) {
 
 /* plugin instance */
 static int get_pi(struct ip_vs_service_entry *se, char *pi, size_t size) {
-  struct in_addr addr;
-  int len = 0;
-
-  if ((NULL == se) || (NULL == pi))
+  if ((se == NULL) || (pi == NULL))
     return 0;
 
-  addr.s_addr = se->addr;
+  struct in_addr addr = {.s_addr = se->addr};
 
-  /* inet_ntoa() returns a pointer to a statically allocated buffer
-   * I hope non-glibc systems behave the same */
-  len =
+  int len =
       ssnprintf(pi, size, "%s_%s%u", inet_ntoa(addr),
                 (se->protocol == IPPROTO_TCP) ? "TCP" : "UDP", ntohs(se->port));
 
-  if ((0 > len) || (size <= ((size_t)len))) {
+  if ((len < 0) || (size <= ((size_t)len))) {
     log_err("plugin instance truncated: %s", pi);
     return -1;
   }
@@ -199,19 +184,14 @@ static int get_pi(struct ip_vs_service_entry *se, char *pi, size_t size) {
 
 /* type instance */
 static int get_ti(struct ip_vs_dest_entry *de, char *ti, size_t size) {
-  struct in_addr addr;
-  int len = 0;
-
-  if ((NULL == de) || (NULL == ti))
+  if ((de == NULL) || (ti == NULL))
     return 0;
 
-  addr.s_addr = de->addr;
+  struct in_addr addr = {.s_addr = de->addr};
 
-  /* inet_ntoa() returns a pointer to a statically allocated buffer
-   * I hope non-glibc systems behave the same */
-  len = ssnprintf(ti, size, "%s_%u", inet_ntoa(addr), ntohs(de->port));
+  int len = ssnprintf(ti, size, "%s_%u", inet_ntoa(addr), ntohs(de->port));
 
-  if ((0 > len) || (size <= ((size_t)len))) {
+  if ((len < 0) || (size <= ((size_t)len))) {
     log_err("type instance truncated: %s", ti);
     return -1;
   }
@@ -228,11 +208,10 @@ static void cipvs_submit_connections(const char *pi, const char *ti,
   sstrncpy(vl.plugin, "ipvs", sizeof(vl.plugin));
   sstrncpy(vl.plugin_instance, pi, sizeof(vl.plugin_instance));
   sstrncpy(vl.type, "connections", sizeof(vl.type));
-  sstrncpy(vl.type_instance, (NULL != ti) ? ti : "total",
+  sstrncpy(vl.type_instance, (ti != NULL) ? ti : "total",
            sizeof(vl.type_instance));
 
   plugin_dispatch_values(&vl);
-  return;
 } /* cipvs_submit_connections */
 
 static void cipvs_submit_if(const char *pi, const char *t, const char *ti,
@@ -248,11 +227,10 @@ static void cipvs_submit_if(const char *pi, const char *t, const char *ti,
   sstrncpy(vl.plugin, "ipvs", sizeof(vl.plugin));
   sstrncpy(vl.plugin_instance, pi, sizeof(vl.plugin_instance));
   sstrncpy(vl.type, t, sizeof(vl.type));
-  sstrncpy(vl.type_instance, (NULL != ti) ? ti : "total",
+  sstrncpy(vl.type_instance, (ti != NULL) ? ti : "total",
            sizeof(vl.type_instance));
 
   plugin_dispatch_values(&vl);
-  return;
 } /* cipvs_submit_if */
 
 static void cipvs_submit_dest(const char *pi, struct ip_vs_dest_entry *de) {
@@ -260,13 +238,12 @@ static void cipvs_submit_dest(const char *pi, struct ip_vs_dest_entry *de) {
 
   char ti[DATA_MAX_NAME_LEN];
 
-  if (0 != get_ti(de, ti, sizeof(ti)))
+  if (get_ti(de, ti, sizeof(ti)) != 0)
     return;
 
   cipvs_submit_connections(pi, ti, stats.conns);
   cipvs_submit_if(pi, "if_packets", ti, stats.inpkts, stats.outpkts);
   cipvs_submit_if(pi, "if_octets", ti, stats.inbytes, stats.outbytes);
-  return;
 } /* cipvs_submit_dest */
 
 static void cipvs_submit_service(struct ip_vs_service_entry *se) {
@@ -275,7 +252,7 @@ static void cipvs_submit_service(struct ip_vs_service_entry *se) {
 
   char pi[DATA_MAX_NAME_LEN];
 
-  if (0 != get_pi(se, pi, sizeof(pi))) {
+  if (get_pi(se, pi, sizeof(pi)) != 0) {
     free(dests);
     return;
   }
@@ -292,12 +269,11 @@ static void cipvs_submit_service(struct ip_vs_service_entry *se) {
 } /* cipvs_submit_service */
 
 static int cipvs_read(void) {
-  struct ip_vs_get_services *services = NULL;
-
   if (sockfd < 0)
     return -1;
 
-  if (NULL == (services = ipvs_get_services()))
+  struct ip_vs_get_services *services = ipvs_get_services();
+  if (services == NULL)
     return -1;
 
   for (size_t i = 0; i < services->num_services; ++i)
index 1156169..8053929 100644 (file)
@@ -92,8 +92,9 @@ static int cldap_init_host(cldap_t *st) /* {{{ */
   if (rc != LDAP_SUCCESS) {
     ERROR("openldap plugin: ldap_initialize failed: %s", ldap_err2string(rc));
     st->state = 0;
-    ldap_unbind_ext_s(ld, NULL, NULL);
-    return -1;
+    if (ld != NULL)
+      ldap_unbind_ext_s(ld, NULL, NULL);
+    return (-1);
   }
 
   st->ld = ld;
@@ -119,8 +120,9 @@ static int cldap_init_host(cldap_t *st) /* {{{ */
       ERROR("openldap plugin: Failed to start tls on %s: %s", st->url,
             ldap_err2string(rc));
       st->state = 0;
-      ldap_unbind_ext_s(st->ld, NULL, NULL);
-      return -1;
+      if (st->ld != NULL)
+        ldap_unbind_ext_s(st->ld, NULL, NULL);
+      return (-1);
     }
   }
 
@@ -139,8 +141,9 @@ static int cldap_init_host(cldap_t *st) /* {{{ */
     ERROR("openldap plugin: Failed to bind to %s: %s", st->url,
           ldap_err2string(rc));
     st->state = 0;
-    ldap_unbind_ext_s(st->ld, NULL, NULL);
-    return -1;
+    if (st->ld != NULL)
+      ldap_unbind_ext_s(st->ld, NULL, NULL);
+    return (-1);
   } else {
     DEBUG("openldap plugin: Successfully connected to %s", st->url);
     st->state = 1;
@@ -214,8 +217,9 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */
     ERROR("openldap plugin: Failed to execute search: %s", ldap_err2string(rc));
     ldap_msgfree(result);
     st->state = 0;
-    ldap_unbind_ext_s(st->ld, NULL, NULL);
-    return -1;
+    if (st->ld != NULL)
+      ldap_unbind_ext_s(st->ld, NULL, NULL);
+    return (-1);
   }
 
   for (LDAPMessage *e = ldap_first_entry(st->ld, result); e != NULL;
index 6cbe881..d7aea2d 100644 (file)
@@ -163,7 +163,7 @@ static void snmp_agent_dump_data(void) {
         DEBUG(PLUGIN_NAME ":     Type: %s", dd->type);
       if (dd->type_instance)
         DEBUG(PLUGIN_NAME ":     TypeInstance: %s", dd->type_instance);
-      for (int i = 0; i < dd->oids_len; i++) {
+      for (size_t i = 0; i < dd->oids_len; i++) {
         snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]);
         DEBUG(PLUGIN_NAME ":     OID[%d]: %s", i, oid_str);
       }
@@ -187,7 +187,7 @@ static void snmp_agent_dump_data(void) {
       DEBUG(PLUGIN_NAME ":   Type: %s", dd->type);
     if (dd->type_instance)
       DEBUG(PLUGIN_NAME ":   TypeInstance: %s", dd->type_instance);
-    for (int i = 0; i < dd->oids_len; i++) {
+    for (size_t i = 0; i < dd->oids_len; i++) {
       snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]);
       DEBUG(PLUGIN_NAME ":   OID[%d]: %s", i, oid_str);
     }
@@ -282,7 +282,7 @@ static int snmp_agent_validate_data(void) {
   return 0;
 }
 
-static void snmp_agent_generate_oid2string(oid_t *oid, int offset, char *key) {
+static void snmp_agent_generate_oid2string(oid_t *oid, size_t offset, char *key) {
   int key_len = oid->oid[offset];
   int i;
 
@@ -352,7 +352,7 @@ static int snmp_agent_table_row_remove(table_definition_t *td,
   for (llentry_t *de = llist_head(td->columns); de != NULL; de = de->next) {
     data_definition_t *dd = de->value;
 
-    for (int i = 0; i < dd->oids_len; i++)
+    for (size_t i = 0; i < dd->oids_len; i++)
       if (td->index_oid.oid_len)
         snmp_agent_unregister_oid_index(&dd->oids[i], *index);
       else
@@ -417,7 +417,7 @@ static void snmp_agent_free_data(data_definition_t **dd) {
 
   /* unregister scalar type OID */
   if ((*dd)->table == NULL) {
-    for (int i = 0; i < (*dd)->oids_len; i++)
+    for (size_t i = 0; i < (*dd)->oids_len; i++)
       unregister_mib((*dd)->oids[i].oid, (*dd)->oids[i].oid_len);
   }
   if (!(*dd)->table->index_oid.oid_len) {
@@ -426,7 +426,7 @@ static void snmp_agent_free_data(data_definition_t **dd) {
     c_avl_iterator_t *iter = c_avl_get_iterator((*dd)->table->instance_index);
     while (c_avl_iterator_next(iter, (void *)&instance, (void *)&instance) ==
            0) {
-      for (int i = 0; i < (*dd)->oids_len; i++)
+      for (size_t i = 0; i < (*dd)->oids_len; i++)
         snmp_agent_unregister_oid_string(&(*dd)->oids[i], instance);
     }
     c_avl_iterator_destroy(iter);
@@ -437,7 +437,7 @@ static void snmp_agent_free_data(data_definition_t **dd) {
 
     c_avl_iterator_t *iter = c_avl_get_iterator((*dd)->table->index_instance);
     while (c_avl_iterator_next(iter, (void *)&index, (void *)&value) == 0) {
-      for (int i = 0; i < (*dd)->oids_len; i++)
+      for (size_t i = 0; i < (*dd)->oids_len; i++)
         snmp_agent_unregister_oid_index(&(*dd)->oids[i], *index);
     }
     c_avl_iterator_destroy(iter);
@@ -529,7 +529,7 @@ static int snmp_agent_form_reply(struct netsnmp_request_info_s *requests,
   }
 
   assert(ds->ds_num == values_num);
-  assert(oid_index < values_num);
+  assert(oid_index < (int)values_num);
 
   char data[DATA_MAX_NAME_LEN];
   size_t data_len = sizeof(data);
@@ -545,8 +545,8 @@ static int snmp_agent_form_reply(struct netsnmp_request_info_s *requests,
   }
 
   requests->requestvb->type = dd->oids[oid_index].type;
-  snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type, data,
-                           data_len);
+  snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type,
+                           (const u_char *)data, data_len);
 
   return SNMP_ERR_NOERROR;
 }
@@ -581,7 +581,7 @@ snmp_agent_table_oid_handler(struct netsnmp_mib_handler_s *handler,
     for (llentry_t *de = llist_head(td->columns); de != NULL; de = de->next) {
       data_definition_t *dd = de->value;
 
-      for (int i = 0; i < dd->oids_len; i++) {
+      for (size_t i = 0; i < dd->oids_len; i++) {
         int ret = snmp_oid_ncompare(oid.oid, oid.oid_len, dd->oids[i].oid,
                                     dd->oids[i].oid_len,
                                     MIN(oid.oid_len, dd->oids[i].oid_len));
@@ -617,7 +617,7 @@ snmp_agent_table_oid_handler(struct netsnmp_mib_handler_s *handler,
         if (dd->is_instance) {
           requests->requestvb->type = ASN_OCTET_STR;
           snmp_set_var_typed_value(requests->requestvb,
-                                   requests->requestvb->type, instance,
+                                   requests->requestvb->type, (const u_char *)instance,
                                    strlen((instance)));
 
           pthread_mutex_unlock(&g_agent->lock);
@@ -678,7 +678,7 @@ static int snmp_agent_table_index_oid_handler(
 
       requests->requestvb->type = ASN_INTEGER;
       snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type,
-                               &index, sizeof(index));
+                               (const u_char *)&index, sizeof(index));
 
       pthread_mutex_unlock(&g_agent->lock);
 
@@ -724,7 +724,7 @@ static int snmp_agent_table_size_oid_handler(
 
       requests->requestvb->type = td->size_oid.type;
       snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type,
-                               &size, sizeof(size));
+                               (const u_char *)&size, sizeof(size));
 
       pthread_mutex_unlock(&g_agent->lock);
 
@@ -765,7 +765,7 @@ snmp_agent_scalar_oid_handler(struct netsnmp_mib_handler_s *handler,
        de = de->next) {
     data_definition_t *dd = de->value;
 
-    for (int i = 0; i < dd->oids_len; i++) {
+    for (size_t i = 0; i < dd->oids_len; i++) {
 
       int ret = snmp_oid_compare(oid.oid, oid.oid_len, dd->oids[i].oid,
                                  dd->oids[i].oid_len);
@@ -803,7 +803,7 @@ static int snmp_agent_register_table_oids(void) {
     for (llentry_t *de = llist_head(td->columns); de != NULL; de = de->next) {
       data_definition_t *dd = de->value;
 
-      for (int i = 0; i < dd->oids_len; i++) {
+      for (size_t i = 0; i < dd->oids_len; i++) {
         dd->oids[i].type =
             snmp_agent_get_asn_type(dd->oids[i].oid, dd->oids[i].oid_len);
       }
@@ -818,7 +818,7 @@ static int snmp_agent_register_scalar_oids(void) {
   for (llentry_t *e = llist_head(g_agent->scalars); e != NULL; e = e->next) {
     data_definition_t *dd = e->value;
 
-    for (int i = 0; i < dd->oids_len; i++) {
+    for (size_t i = 0; i < dd->oids_len; i++) {
 
       dd->oids[i].type =
           snmp_agent_get_asn_type(dd->oids[i].oid, dd->oids[i].oid_len);
@@ -1284,7 +1284,7 @@ static int snmp_agent_update_index(table_definition_t *td,
   for (llentry_t *de = llist_head(td->columns); de != NULL; de = de->next) {
     data_definition_t *dd = de->value;
 
-    for (int i = 0; i < dd->oids_len; i++) {
+    for (size_t i = 0; i < dd->oids_len; i++) {
       if (td->index_oid.oid_len) {
         ret = snmp_agent_register_oid_index(&dd->oids[i], *index,
                                             snmp_agent_table_oid_handler);
index 419d8c1..f12ce5c 100644 (file)
@@ -774,9 +774,15 @@ static int conn_read(void) {
   for (in_ptr = (struct xinpgen *)(((char *)in_orig) + in_orig->xig_len);
        in_ptr->xig_len > sizeof(struct xinpgen);
        in_ptr = (struct xinpgen *)(((char *)in_ptr) + in_ptr->xig_len)) {
+#if __FreeBSD_version >= 1200026
+    struct xtcpcb *tp = (struct xtcpcb *)in_ptr;
+    struct xinpcb *inp = &tp->xt_inp;
+    struct xsocket *so = &inp->xi_socket;
+#else
     struct tcpcb *tp = &((struct xtcpcb *)in_ptr)->xt_tp;
     struct inpcb *inp = &((struct xtcpcb *)in_ptr)->xt_inp;
     struct xsocket *so = &((struct xtcpcb *)in_ptr)->xt_socket;
+#endif
 
     /* Ignore non-TCP sockets */
     if (so->xso_protocol != IPPROTO_TCP)
index 8ccde80..00b930e 100644 (file)
@@ -134,7 +134,7 @@ static int us_open_socket(void) {
     const char *grpname;
     struct group *g;
     struct group sg;
-    char grbuf[2048];
+    char grbuf[4096];
 
     grpname = (sock_group != NULL) ? sock_group : COLLECTD_GRP_NAME;
     g = NULL;
@@ -143,7 +143,7 @@ static int us_open_socket(void) {
     if (status != 0) {
       char errbuf[1024];
       WARNING("unixsock plugin: getgrnam_r (%s) failed: %s", grpname,
-              sstrerror(errno, errbuf, sizeof(errbuf)));
+              sstrerror(status, errbuf, sizeof(errbuf)));
       break;
     }
     if (g == NULL) {
index 33f9bd5..e90900e 100644 (file)
@@ -144,7 +144,8 @@ static bson_t *wm_create_bson(const data_set_t *ds, /* {{{ */
   size_t error_location;
   if (!bson_validate(ret, BSON_VALIDATE_UTF8, &error_location)) {
     ERROR("write_mongodb plugin: Error in generated BSON document "
-        "at byte %zu", error_location);
+          "at byte %zu",
+          error_location);
     bson_destroy(ret);
     return NULL;
   }
@@ -155,23 +156,16 @@ static bson_t *wm_create_bson(const data_set_t *ds, /* {{{ */
 static int wm_initialize(wm_node_t *node) /* {{{ */
 {
   char *uri;
-  size_t uri_length;
-  char const *format_string;
 
-  if (node->connected) {
+  if (node->connected)
     return 0;
-  }
 
-  INFO("write_mongodb plugin: Connecting to [%s]:%i",
-       (node->host != NULL) ? node->host : "localhost",
-       (node->port != 0) ? node->port : MONGOC_DEFAULT_PORT);
+  INFO("write_mongodb plugin: Connecting to [%s]:%d", node->host, node->port);
 
   if ((node->db != NULL) && (node->user != NULL) && (node->passwd != NULL)) {
-    format_string = "mongodb://%s:%s@%s:%d/?authSource=%s";
-    uri_length = strlen(format_string) + strlen(node->user) +
-                 strlen(node->passwd) + strlen(node->host) + 5 +
-                 strlen(node->db) + 1;
-    if ((uri = calloc(1, uri_length)) == NULL) {
+    uri = ssnprintf_alloc("mongodb://%s:%s@%s:%d/?authSource=%s", node->user,
+                          node->passwd, node->host, node->port, node->db);
+    if (uri == NULL) {
       ERROR("write_mongodb plugin: Not enough memory to assemble "
             "authentication string.");
       mongoc_client_destroy(node->client);
@@ -179,24 +173,19 @@ static int wm_initialize(wm_node_t *node) /* {{{ */
       node->connected = 0;
       return -1;
     }
-    ssnprintf(uri, uri_length, format_string, node->user, node->passwd,
-              node->host, node->port, node->db);
 
     node->client = mongoc_client_new(uri);
     if (!node->client) {
-      ERROR("write_mongodb plugin: Authenticating to [%s]%i for database "
+      ERROR("write_mongodb plugin: Authenticating to [%s]:%d for database "
             "\"%s\" as user \"%s\" failed.",
-            (node->host != NULL) ? node->host : "localhost",
-            (node->port != 0) ? node->port : MONGOC_DEFAULT_PORT, node->db,
-            node->user);
+            node->host, node->port, node->db, node->user);
       node->connected = 0;
       sfree(uri);
       return -1;
     }
   } else {
-    format_string = "mongodb://%s:%d";
-    uri_length = strlen(format_string) + strlen(node->host) + 5 + 1;
-    if ((uri = calloc(1, uri_length)) == NULL) {
+    uri = ssnprintf_alloc("mongodb://%s:%d", node->host, node->port);
+    if (uri == NULL) {
       ERROR("write_mongodb plugin: Not enough memory to assemble "
             "authentication string.");
       mongoc_client_destroy(node->client);
@@ -204,19 +193,17 @@ static int wm_initialize(wm_node_t *node) /* {{{ */
       node->connected = 0;
       return -1;
     }
-    snprintf(uri, uri_length, format_string, node->host, node->port);
 
     node->client = mongoc_client_new(uri);
     if (!node->client) {
-      ERROR("write_mongodb plugin: Connecting to [%s]:%i failed.",
-            (node->host != NULL) ? node->host : "localhost",
-            (node->port != 0) ? node->port : MONGOC_DEFAULT_PORT);
+      ERROR("write_mongodb plugin: Connecting to [%s]:%d failed.", node->host,
+            node->port);
       node->connected = 0;
       sfree(uri);
       return -1;
     }
+    sfree(uri);
   }
-  sfree(uri);
 
   node->database = mongoc_client_get_database(node->client, "collectd");
   if (!node->database) {
@@ -319,13 +306,19 @@ static int wm_config_node(oconfig_item_t *ci) /* {{{ */
   if (node == NULL)
     return ENOMEM;
   mongoc_init();
-  node->host = NULL;
+  node->host = strdup("localhost");
+  if (node->host == NULL) {
+    sfree(node);
+    return ENOMEM;
+  }
+  node->port = MONGOC_DEFAULT_PORT;
   node->store_rates = 1;
   pthread_mutex_init(&node->lock, /* attr = */ NULL);
 
   status = cf_util_get_string_buffer(ci, node->name, sizeof(node->name));
 
   if (status != 0) {
+    sfree(node->host);
     sfree(node);
     return status;
   }
@@ -377,10 +370,11 @@ static int wm_config_node(oconfig_item_t *ci) /* {{{ */
 
     ssnprintf(cb_name, sizeof(cb_name), "write_mongodb/%s", node->name);
 
-    status = plugin_register_write(
-        cb_name, wm_write, &(user_data_t){
-                               .data = node, .free_func = wm_config_free,
-                           });
+    status =
+        plugin_register_write(cb_name, wm_write,
+                              &(user_data_t){
+                                  .data = node, .free_func = wm_config_free,
+                              });
     INFO("write_mongodb plugin: registered write plugin %s %d", cb_name,
          status);
   }
index 9e07e75..5bd0cf4 100644 (file)
@@ -214,6 +214,11 @@ wrr_notification_to_message(struct riemann_host *host, /* {{{ */
       RIEMANN_EVENT_FIELD_SERVICE, &service_buffer[1],
       RIEMANN_EVENT_FIELD_NONE);
 
+#if RCC_VERSION_NUMBER >= 0x010A00
+  riemann_event_set(event, RIEMANN_EVENT_FIELD_TIME_MICROS,
+                    (int64_t)CDTIME_T_TO_US(n->time));
+#endif
+
   if (n->host[0] != 0)
     riemann_event_string_attribute_add(event, "host", n->host);
   if (n->plugin[0] != 0)
@@ -310,6 +315,11 @@ wrr_value_to_event(struct riemann_host const *host, /* {{{ */
       vl->type, "ds_name", ds->ds[index].name, NULL,
       RIEMANN_EVENT_FIELD_SERVICE, service_buffer, RIEMANN_EVENT_FIELD_NONE);
 
+#if RCC_VERSION_NUMBER >= 0x010A00
+  riemann_event_set(event, RIEMANN_EVENT_FIELD_TIME_MICROS,
+                    (int64_t)CDTIME_T_TO_US(vl->time));
+#endif
+
   if (host->check_thresholds) {
     const char *state = NULL;
 
index bdbb847..2c7a2e5 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-DEFAULT_VERSION="5.7.1.git"
+DEFAULT_VERSION="5.7.2.git"
 
 if [ -d .git ]; then
        VERSION="`git describe --dirty=+ --abbrev=7 2> /dev/null | grep collectd | sed -e 's/^collectd-//' -e 's/-/./g'`"