Merge branch 'collectd-5.1' into collectd-5.2
authorFlorian Forster <octo@collectd.org>
Sun, 7 Apr 2013 03:54:24 +0000 (05:54 +0200)
committerFlorian Forster <octo@collectd.org>
Sun, 7 Apr 2013 03:54:24 +0000 (05:54 +0200)
Conflicts:
configure.in

1  2 
configure.in
src/network.c
src/rrdcached.c

diff --combined configure.in
@@@ -535,22 -535,6 +535,22 @@@ AC_CHECK_HEADERS(netinet/if_ether.h, []
  
  AC_CHECK_HEADERS(netinet/ip_compat.h)
  
 +have_net_pfvar_h="no"
 +AC_CHECK_HEADERS(net/pfvar.h,
 +               [have_net_pfvar_h="yes"],
 +               [have_net_pfvar_h="no"],
 +[
 +#if HAVE_SYS_IOCTL_H
 +# include <sys/ioctl.h>
 +#endif
 +#if HAVE_SYS_SOCKET_H
 +# include <sys/socket.h>
 +#endif
 +#if HAVE_NET_IF_H
 +# include <net/if.h>
 +#endif
 +])
 +
  # For the multimeter plugin
  have_termios_h="no"
  AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"])
@@@ -598,7 -582,7 +598,7 @@@ AC_CACHE_CHECK([for strtok_r]
        saveptr = NULL;
        while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
        {
-       dummy = NULL;
+         dummy = NULL;
          printf ("token = %s;\n", token);
        }
  ]]]
@@@ -631,7 -615,7 +631,7 @@@ the
          saveptr = NULL;
          while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
          {
-         dummy = NULL;
+           dummy = NULL;
            printf ("token = %s;\n", token);
          }
  ]]]
        if test -d "$with_java_home"
        then
                AC_MSG_CHECKING([for jni.h])
-               TMPDIR=`find "$with_java_home" -name jni.h -type f -exec 'dirname' '{}' ';' 2>/dev/null | head -n 1`
-               if test "x$TMPDIR" != "x"
 -              TMPVAR=`find "$with_java_home" -name jni.h -type f -exec 'dirname' '{}' ';' | head -n 1`
++              TMPVAR=`find "$with_java_home" -name jni.h -type f -exec 'dirname' '{}' ';' 2>/dev/null | head -n 1`
+               if test "x$TMPVAR" != "x"
                then
-                       AC_MSG_RESULT([found in $TMPDIR])
-                       JAVA_CPPFLAGS="$JAVA_CPPFLAGS -I$TMPDIR"
+                       AC_MSG_RESULT([found in $TMPVAR])
+                       JAVA_CPPFLAGS="$JAVA_CPPFLAGS -I$TMPVAR"
                else
                        AC_MSG_RESULT([not found])
                fi
  
                AC_MSG_CHECKING([for jni_md.h])
-               TMPDIR=`find "$with_java_home" -name jni_md.h -type f -exec 'dirname' '{}' ';' 2>/dev/null | head -n 1`
-               if test "x$TMPDIR" != "x"
 -              TMPVAR=`find "$with_java_home" -name jni_md.h -type f -exec 'dirname' '{}' ';' | head -n 1`
++              TMPVAR=`find "$with_java_home" -name jni_md.h -type f -exec 'dirname' '{}' ';' 2>/dev/null | head -n 1`
+               if test "x$TMPVAR" != "x"
                then
-                       AC_MSG_RESULT([found in $TMPDIR])
-                       JAVA_CPPFLAGS="$JAVA_CPPFLAGS -I$TMPDIR"
+                       AC_MSG_RESULT([found in $TMPVAR])
+                       JAVA_CPPFLAGS="$JAVA_CPPFLAGS -I$TMPVAR"
                else
                        AC_MSG_RESULT([not found])
                fi
  
                AC_MSG_CHECKING([for libjvm.so])
-               TMPDIR=`find "$with_java_home" -name libjvm.so -type f -exec 'dirname' '{}' ';' 2>/dev/null | head -n 1`
-               if test "x$TMPDIR" != "x"
 -              TMPVAR=`find "$with_java_home" -name libjvm.so -type f -exec 'dirname' '{}' ';' | head -n 1`
++              TMPVAR=`find "$with_java_home" -name libjvm.so -type f -exec 'dirname' '{}' ';' 2>/dev/null | head -n 1`
+               if test "x$TMPVAR" != "x"
                then
-                       AC_MSG_RESULT([found in $TMPDIR])
-                       JAVA_LDFLAGS="$JAVA_LDFLAGS -L$TMPDIR -Wl,-rpath -Wl,$TMPDIR"
+                       AC_MSG_RESULT([found in $TMPVAR])
+                       JAVA_LDFLAGS="$JAVA_LDFLAGS -L$TMPVAR -Wl,-rpath -Wl,$TMPVAR"
                else
                        AC_MSG_RESULT([not found])
                fi
                if test "x$JAVAC" = "x"
                then
                        AC_MSG_CHECKING([for javac])
-                       TMPDIR=`find "$with_java_home" -name javac -type f 2>/dev/null | head -n 1`
-                       if test "x$TMPDIR" != "x"
 -                      TMPVAR=`find "$with_java_home" -name javac -type f | head -n 1`
++                      TMPVAR=`find "$with_java_home" -name javac -type f 2>/dev/null | head -n 1`
+                       if test "x$TMPVAR" != "x"
                        then
-                               JAVAC="$TMPDIR"
+                               JAVAC="$TMPVAR"
                                AC_MSG_RESULT([$JAVAC])
                        else
                                AC_MSG_RESULT([not found])
                if test "x$JAR" = "x"
                then
                        AC_MSG_CHECKING([for jar])
-                       TMPDIR=`find "$with_java_home" -name jar -type f 2>/dev/null | head -n 1`
-                       if test "x$TMPDIR" != "x"
 -                      TMPVAR=`find "$with_java_home" -name jar -type f | head -n 1`
++                      TMPVAR=`find "$with_java_home" -name jar -type f 2>/dev/null | head -n 1`
+                       if test "x$TMPVAR" != "x"
                        then
-                               JAR="$TMPDIR"
+                               JAR="$TMPVAR"
                                AC_MSG_RESULT([$JAR])
                        else
                                AC_MSG_RESULT([not found])
  if test "x$with_perfstat" = "xyes"
  then
        plugin_cpu="yes"
 +      plugin_contextswitch="yes"
        plugin_disk="yes"
        plugin_memory="yes"
        plugin_swap="yes"
        plugin_interface="yes"
        plugin_load="yes"
 +      plugin_uptime="yes"
  fi
  
  if test "x$with_procinfo" = "xyes"
@@@ -4877,7 -4859,6 +4877,7 @@@ AC_ARG_ENABLE([all-plugins]
  
  m4_divert_once([HELP_ENABLE], [])
  
 +AC_PLUGIN([aggregation], [yes],                [Aggregation plugin])
  AC_PLUGIN([amqp],        [$with_librabbitmq],  [AMQP output plugin])
  AC_PLUGIN([apache],      [$with_libcurl],      [Apache httpd statistics])
  AC_PLUGIN([apcups],      [yes],                [Statistics of UPSes by APC])
@@@ -4944,7 -4925,6 +4944,7 @@@ AC_PLUGIN([onewire],     [$with_libowca
  AC_PLUGIN([openvpn],     [yes],                [OpenVPN client statistics])
  AC_PLUGIN([oracle],      [$with_oracle],       [Oracle plugin])
  AC_PLUGIN([perl],        [$plugin_perl],       [Embed a Perl interpreter])
 +AC_PLUGIN([pf],          [$have_net_pfvar_h],  [BSD packet filter (PF) statistics])
  # FIXME: Check for libevent, too.
  AC_PLUGIN([pinba],       [$have_protoc_c],     [Pinba statistics])
  AC_PLUGIN([ping],        [$with_liboping],     [Network latency statistics])
@@@ -5084,7 -5064,6 +5084,7 @@@ the
  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"
                PERL_BINDINGS_OPTIONS="$withval"
                with_perl_bindings="yes"
        else
 -              PERL_BINDINGS_OPTIONS=""
                with_perl_bindings="$withval"
        fi
  ],
  [
 -      PERL_BINDINGS_OPTIONS=""
        if test -n "$perl_interpreter"
        then
                with_perl_bindings="yes"
@@@ -5127,7 -5108,7 +5127,7 @@@ AC_SUBST(LCC_VERSION_PATCH
  AC_SUBST(LCC_VERSION_EXTRA)
  AC_SUBST(LCC_VERSION_STRING)
  
 -AC_CONFIG_FILES(src/libcollectdclient/lcc_features.h)
 +AC_CONFIG_FILES(src/libcollectdclient/collectd/lcc_features.h)
  
  AC_OUTPUT(Makefile src/Makefile src/collectd.conf src/libcollectdclient/Makefile src/libcollectdclient/libcollectdclient.pc src/liboconfig/Makefile bindings/Makefile bindings/java/Makefile)
  
@@@ -5210,7 -5191,6 +5210,7 @@@ Configuration
      perl  . . . . . . . . $with_perl_bindings
  
    Modules:
 +    aggregation . . . . . $enable_aggregation
      amqp    . . . . . . . $enable_amqp
      apache  . . . . . . . $enable_apache
      apcups  . . . . . . . $enable_apcups
      openvpn . . . . . . . $enable_openvpn
      oracle  . . . . . . . $enable_oracle
      perl  . . . . . . . . $enable_perl
 +    pf  . . . . . . . . . $enable_pf
      pinba . . . . . . . . $enable_pinba
      ping  . . . . . . . . $enable_ping
      postgresql  . . . . . $enable_postgresql
diff --combined src/network.c
@@@ -1,6 -1,6 +1,6 @@@
  /**
   * collectd - src/network.c
-  * Copyright (C) 2005-2010  Florian octo Forster
+  * Copyright (C) 2005-2013  Florian octo Forster
   * Copyright (C) 2009       Aman Gupta
   *
   * This program is free software; you can redistribute it and/or modify it
@@@ -18,7 -18,7 +18,7 @@@
   * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   *
   * Authors:
-  *   Florian octo Forster <octo at verplant.org>
+  *   Florian octo Forster <octo at collectd.org>
   *   Aman Gupta <aman at tmm1.net>
   **/
  
@@@ -493,6 -493,20 +493,20 @@@ static int network_dispatch_notificatio
  } /* }}} int network_dispatch_notification */
  
  #if HAVE_LIBGCRYPT
+ static void network_init_gcrypt (void) /* {{{ */
+ {
+   /* http://lists.gnupg.org/pipermail/gcrypt-devel/2003-August/000458.html
+    * Because you can't know in a library whether another library has
+    * already initialized the library */
+   if (gcry_control (GCRYCTL_ANY_INITIALIZATION_P))
+     return;
+   gcry_check_version (NULL); /* before calling any other functions */
+   gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
+   gcry_control (GCRYCTL_INIT_SECMEM, 32768);
+   gcry_control (GCRYCTL_INITIALIZATION_FINISHED);
+ } /* }}} void network_init_gcrypt */
  static gcry_cipher_hd_t network_get_aes256_cypher (sockent_t *se, /* {{{ */
      const void *iv, size_t iv_size, const char *username)
  {
@@@ -2029,6 -2043,8 +2043,8 @@@ static int sockent_open (sockent_t *se
        {
                if (se->data.client.security_level > SECURITY_LEVEL_NONE)
                {
+                       network_init_gcrypt ();
                        if ((se->data.client.username == NULL)
                                        || (se->data.client.password == NULL))
                        {
        {
                if (se->data.server.security_level > SECURITY_LEVEL_NONE)
                {
+                       network_init_gcrypt ();
                        if (se->data.server.auth_file == NULL)
                        {
                                ERROR ("network plugin: Server socket with "
@@@ -3311,6 -3329,7 +3329,6 @@@ static int network_stats_read (void) /
        vl.values = values;
        vl.values_len = 2;
        vl.time = 0;
 -      vl.interval = interval_g;
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "network", sizeof (vl.plugin));
  
@@@ -3370,17 -3389,7 +3388,7 @@@ static int network_init (void
        have_init = 1;
  
  #if HAVE_LIBGCRYPT
-     /* http://lists.gnupg.org/pipermail/gcrypt-devel/2003-August/000458.html
-      * Because you can't know in a library whether another library has
-      * already initialized the library
-      */
-     if (!gcry_control (GCRYCTL_ANY_INITIALIZATION_P))
-     {
-         gcry_check_version(NULL); /* before calling any other functions */
-         gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
-         gcry_control (GCRYCTL_INIT_SECMEM, 32768, 0);
-         gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
-     }
+       network_init_gcrypt ();
  #endif
  
        if (network_config_stats != 0)
        if (dispatch_thread_running == 0)
        {
                int status;
 -              status = pthread_create (&dispatch_thread_id,
 +              status = plugin_thread_create (&dispatch_thread_id,
                                NULL /* no attributes */,
                                dispatch_thread,
                                NULL /* no argument */);
        if (receive_thread_running == 0)
        {
                int status;
 -              status = pthread_create (&receive_thread_id,
 +              status = plugin_thread_create (&receive_thread_id,
                                NULL /* no attributes */,
                                receive_thread,
                                NULL /* no argument */);
diff --combined src/rrdcached.c
@@@ -1,6 -1,6 +1,6 @@@
  /**
   * collectd - src/rrdcached.c
-  * Copyright (C) 2008-2012  Florian octo Forster
+  * Copyright (C) 2008-2013  Florian octo Forster
   *
   * This program is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License as published by the
@@@ -33,8 -33,8 +33,8 @@@
   */
  static char *datadir = NULL;
  static char *daemon_address = NULL;
 -static int config_create_files = 1;
 -static int config_collect_stats = 1;
 +static _Bool config_create_files = 1;
 +static _Bool config_collect_stats = 1;
  static rrdcreate_config_t rrdcreate_config =
  {
        /* stepsize = */ 0,
@@@ -161,130 -161,89 +161,130 @@@ static int value_list_to_filename (cha
    return (0);
  } /* int value_list_to_filename */
  
 -static const char *config_get_string (oconfig_item_t *ci)
 +static int rc_config_get_int_positive (oconfig_item_t const *ci, int *ret)
  {
 -  if ((ci->children_num != 0) || (ci->values_num != 1)
 -      || ((ci->values[0].type != OCONFIG_TYPE_STRING)
 -        && (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)))
 +  int status;
 +  int tmp = 0;
 +
 +  status = cf_util_get_int (ci, &tmp);
 +  if (status != 0)
 +    return (status);
 +  if (tmp < 0)
 +    return (EINVAL);
 +
 +  *ret = tmp;
 +  return (0);
 +} /* int rc_config_get_int_positive */
 +
 +static int rc_config_get_xff (oconfig_item_t const *ci, double *ret)
 +{
 +  double value;
 +
 +  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
    {
 -    ERROR ("rrdcached plugin: %s expects a single string argument.",
 -        ci->key);
 -    return (NULL);
 +    ERROR ("rrdcached plugin: The \"%s\" needs exactly one numeric argument "
 +        "in the range [0.0, 1.0)", ci->key);
 +    return (EINVAL);
    }
  
 -  if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN) {
 -    if (ci->values[0].value.boolean)
 -      return "true";
 -    else
 -      return "false";
 +  value = ci->values[0].value.number;
 +  if ((value >= 0.0) && (value < 1.0))
 +  {
 +    *ret = value;
 +    return (0);
    }
 -  return (ci->values[0].value.string);
 -} /* const char *config_get_string */
 +
 +  ERROR ("rrdcached plugin: The \"%s\" needs exactly one numeric argument "
 +      "in the range [0.0, 1.0)", ci->key);
 +  return (EINVAL);
 +} /* int rc_config_get_xff */
 +
 +static int rc_config_add_timespan (int timespan)
 +{
 +  int *tmp;
 +
 +  if (timespan <= 0)
 +    return (EINVAL);
 +
 +  tmp = realloc (rrdcreate_config.timespans,
 +      sizeof (*rrdcreate_config.timespans)
 +      * (rrdcreate_config.timespans_num + 1));
 +  if (tmp == NULL)
 +    return (ENOMEM);
 +  rrdcreate_config.timespans = tmp;
 +
 +  rrdcreate_config.timespans[rrdcreate_config.timespans_num] = timespan;
 +  rrdcreate_config.timespans_num++;
 +
 +  return (0);
 +} /* int rc_config_add_timespan */
  
  static int rc_config (oconfig_item_t *ci)
  {
    int i;
  
 -  for (i = 0; i < ci->children_num; ++i) {
 -    const char *key = ci->children[i].key;
 -    const char *value = config_get_string (ci->children + i);
 -
 -    if (value == NULL) /* config_get_strings prints error message */
 -      continue;
 +  for (i = 0; i < ci->children_num; i++)
 +  {
 +    oconfig_item_t const *child = ci->children + i;
 +    const char *key = child->key;
 +    int status = 0;
  
      if (strcasecmp ("DataDir", key) == 0)
      {
 -      if (datadir != NULL)
 -        free (datadir);
 -      datadir = strdup (value);
 -      if (datadir != NULL)
 +      status = cf_util_get_string (child, &datadir);
 +      if (status == 0)
        {
          int len = strlen (datadir);
 +
          while ((len > 0) && (datadir[len - 1] == '/'))
          {
            len--;
 -          datadir[len] = '\0';
 +          datadir[len] = 0;
          }
 +
          if (len <= 0)
 -        {
 -          free (datadir);
 -          datadir = NULL;
 -        }
 +          sfree (datadir);
        }
      }
      else if (strcasecmp ("DaemonAddress", key) == 0)
 -    {
 -      sfree (daemon_address);
 -      daemon_address = strdup (value);
 -      if (daemon_address == NULL)
 -      {
 -        ERROR ("rrdcached plugin: strdup failed.");
 -        continue;
 -      }
 -    }
 +      status = cf_util_get_string (child, &daemon_address);
      else if (strcasecmp ("CreateFiles", key) == 0)
 +      status = cf_util_get_boolean (child, &config_create_files);
 +    else if (strcasecmp ("CollectStatistics", key) == 0)
 +      status = cf_util_get_boolean (child, &config_collect_stats);
 +    else if (strcasecmp ("StepSize", key) == 0)
      {
 -      if (IS_FALSE (value))
 -        config_create_files = 0;
 -      else
 -        config_create_files = 1;
 +      int tmp = -1;
 +
 +      status = rc_config_get_int_positive (child, &tmp);
 +      if (status == 0)
 +        rrdcreate_config.stepsize = (unsigned long) tmp;
      }
 -    else if (strcasecmp ("CollectStatistics", key) == 0)
 +    else if (strcasecmp ("HeartBeat", key) == 0)
 +      status = rc_config_get_int_positive (child, &rrdcreate_config.heartbeat);
 +    else if (strcasecmp ("RRARows", key) == 0)
 +      status = rc_config_get_int_positive (child, &rrdcreate_config.rrarows);
 +    else if (strcasecmp ("RRATimespan", key) == 0)
      {
 -      if (IS_FALSE (value))
 -        config_collect_stats = 0;
 -      else
 -        config_collect_stats = 1;
 +      int tmp = -1;
 +      status = rc_config_get_int_positive (child, &tmp);
 +      if (status == 0)
 +        status = rc_config_add_timespan (tmp);
      }
 +    else if (strcasecmp ("XFF", key) == 0)
 +      status = rc_config_get_xff (child, &rrdcreate_config.xff);
      else
      {
        WARNING ("rrdcached plugin: Ignoring invalid option %s.", key);
        continue;
      }
 +
 +    if (status != 0)
 +      WARNING ("rrdcached plugin: Handling the \"%s\" option failed.", key);
    }
  
 -  if (daemon_address != NULL) {
 +  if (daemon_address != NULL)
 +  {
      plugin_register_write ("rrdcached", rc_write, /* user_data = */ NULL);
      plugin_register_flush ("rrdcached", rc_flush, /* user_data = */ NULL);
    }
@@@ -303,7 -262,7 +303,7 @@@ static int rc_read (void
    if (daemon_address == NULL)
      return (-1);
  
 -  if (config_collect_stats == 0)
 +  if (!config_collect_stats)
      return (-1);
  
    vl.values = values;
      sstrncpy (vl.host, daemon_address, sizeof (vl.host));
    sstrncpy (vl.plugin, "rrdcached", sizeof (vl.plugin));
  
+   status = rrdc_connect (daemon_address);
+   if (status != 0)
+   {
+     ERROR ("rrdcached plugin: rrdc_connect (%s) failed with status %i.",
+         daemon_address, status);
+     return (-1);
+   }
    head = NULL;
    status = rrdc_stats_get (&head);
    if (status != 0)
  
  static int rc_init (void)
  {
 -  if (config_collect_stats != 0)
 +  if (config_collect_stats)
      plugin_register_read ("rrdcached", rc_read);
  
    return (0);
@@@ -437,7 -404,7 +445,7 @@@ static int rc_write (const data_set_t *
    values_array[0] = values;
    values_array[1] = NULL;
  
 -  if (config_create_files != 0)
 +  if (config_create_files)
    {
      struct stat statbuf;