Merge branch 'pull/collectd-4' into collectd-4
authorFlorian Forster <octo@huhu.verplant.org>
Fri, 20 Apr 2007 14:16:27 +0000 (16:16 +0200)
committerFlorian Forster <octo@huhu.verplant.org>
Fri, 20 Apr 2007 14:16:27 +0000 (16:16 +0200)
configure.in
src/Makefile.am
src/perl.c
src/rrdtool.c
src/unixsock.c

index 3d8cf40..2cb067b 100644 (file)
@@ -1073,12 +1073,14 @@ AC_DEFINE_UNQUOTED(COLLECT_LIBPCAP, [$collect_libpcap],
        [Wether or not to use the pcap library])
 AM_CONDITIONAL(BUILD_WITH_LIBPCAP, test "x$with_libpcap" = "xyes")
 
+perl_interpreter="perl"
 AC_ARG_WITH(libperl, [AS_HELP_STRING([--with-libperl@<:@=PREFIX@:>@], [Path to libperl.])],
 [
        if test "x$withval" != "xno" && test "x$withval" != "xyes"
        then
                LDFLAGS="$LDFLAGS -L$withval/lib"
                CPPFLAGS="$CPPFLAGS -I$withval/include"
+               perl_interpreter="$withval/bin/perl"
                with_libperl="yes"
        fi
 ],
@@ -1089,8 +1091,10 @@ if test "x$with_libperl" = "xyes"
 then
   SAVE_CFLAGS=$CFLAGS
   SAVE_LDFLAGS=$LDFLAGS
-  CFLAGS="$CFLAGS `perl -MExtUtils::Embed -e ccopts`"
-  LDFLAGS="$LDFLAGS `perl -MExtUtils::Embed -e ldopts`"
+  PERL_CFLAGS=`$perl_interpreter -MExtUtils::Embed -e ccopts`
+  PERL_LDFLAGS=`$perl_interpreter -MExtUtils::Embed -e ldopts`
+  CFLAGS="$CFLAGS $PERL_CFLAGS"
+  LDFLAGS="$LDFLAGS $PERL_LDFLAGS"
 
   AC_CACHE_CHECK([for libperl],
     [have_libperl],
@@ -1104,7 +1108,7 @@ then
       [[
        PerlInterpreter *perl = NULL;
        Perl_load_module (perl, PERL_LOADMOD_NOIMPORT,
-                        Perl_newSVpvf (perl, "Collectd::Plugin::%s", "foo"),
+                        newSVpv ("Collectd::Plugin::FooBar", 24),
                         Nullsv);
       ]]),
       [have_libperl="yes"],
@@ -1115,6 +1119,8 @@ then
   if test "x$have_libperl" = "xyes"
   then
          AC_DEFINE(HAVE_LIBPERL, 1, [Define if libperl is present and usable.])
+         AC_SUBST(PERL_CFLAGS)
+         AC_SUBST(PERL_LDFLAGS)
   else
          with_libperl="no"
   fi
index 99a8de2..72d67b3 100644 (file)
@@ -401,10 +401,10 @@ if BUILD_MODULE_PERL
 pkglib_LTLIBRARIES += perl.la
 perl_la_SOURCES = perl.c
 perl_la_CFLAGS  = $(AM_CFLAGS) \
-                 $(shell perl -MExtUtils::Embed -e ccopts) \
+                 $(PERL_CFLAGS) \
                  -DXS_VERSION=\"$(VERSION)\" -DVERSION=\"$(VERSION)\"
 perl_la_LDFLAGS = -module -avoid-version \
-                 $(shell perl -MExtUtils::Embed -e ldopts)
+                 $(PERL_LDFLAGS)
 collectd_LDADD += "-dlopen" perl.la
 collectd_DEPENDENCIES += perl.la
 endif
index ebdacb8..d8f294f 100644 (file)
@@ -965,7 +965,7 @@ static int perl_config (const char *key, const char *value)
 
                log_debug ("perl_config: loading perl plugin \"%s\"", value);
                Perl_load_module (perl, PERL_LOADMOD_NOIMPORT,
-                               newSVpv (module_name, strlen (module_name)),
+                               Perl_newSVpv (perl, module_name, strlen (module_name)),
                                Nullsv);
        }
        else if (0 == strcasecmp (key, "BaseName")) {
index 814b3e3..b4bb3fb 100644 (file)
@@ -772,9 +772,14 @@ static int rrd_config (const char *key, const char *value)
                char *saveptr = NULL;
                char *dummy;
                char *ptr;
+               char *value_copy;
                int *tmp_alloc;
 
-               dummy = value;
+               value_copy = strdup (value);
+               if (value_copy == NULL)
+                       return (1);
+
+               dummy = value_copy;
                while ((ptr = strtok_r (dummy, ", \t", &saveptr)) != NULL)
                {
                        dummy = NULL;
@@ -784,6 +789,7 @@ static int rrd_config (const char *key, const char *value)
                        if (tmp_alloc == NULL)
                        {
                                fprintf (stderr, "rrdtool: realloc failed.\n");
+                               free (value_copy);
                                return (1);
                        }
                        rra_timespans_custom = tmp_alloc;
@@ -791,7 +797,7 @@ static int rrd_config (const char *key, const char *value)
                        if (rra_timespans_custom[rra_timespans_custom_num] != 0)
                                rra_timespans_custom_num++;
                } /* while (strtok_r) */
-
+               free (value_copy);
        }
        else if (strcasecmp ("XFF", key) == 0)
        {
index 8524bea..1ddd03c 100644 (file)
@@ -243,12 +243,24 @@ static int cache_update (const data_set_t *ds, const value_list_t *vl)
 
        vc = cache_search (name);
 
+       /* pthread_mutex_lock is called by cache_insert. */
        if (vc == NULL)
                return (cache_insert (ds, vl));
 
        assert (vc->values_num == ds->ds_num);
        assert (vc->values_num == vl->values_len);
 
+       /* Avoid floating-point exceptions due to division by zero. */
+       if (vc->time >= vl->time)
+       {
+               pthread_mutex_unlock (&cache_lock);
+               ERROR ("unixsock plugin: vc->time >= vl->time. vc->time = %u; "
+                               "vl->time = %u; vl = %s;",
+                               (unsigned int) vc->time, (unsigned int) vl->time,
+                               name);
+               return (-1);
+       } /* if (vc->time >= vl->time) */
+
        /*
         * Update the values. This is possibly a lot more that you'd expect
         * because we honor min and max values and handle counter overflows here.