Merge branch 'master' into ff/java
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Tue, 24 Feb 2009 09:16:19 +0000 (10:16 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Tue, 24 Feb 2009 09:16:19 +0000 (10:16 +0100)
bindings/perl/Collectd.pm
contrib/cussh.pl
src/common.c
src/cpu.c
src/perl.c
src/plugin.c

index 007367d..557950c 100644 (file)
@@ -1,5 +1,5 @@
 # collectd - Collectd.pm
-# Copyright (C) 2007, 2008  Sebastian Harl
+# Copyright (C) 2007-2009  Sebastian Harl
 #
 # 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
index c143aea..3f1f7c8 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 #
 # collectd - contrib/cussh.pl
-# Copyright (C) 2007-2008  Sebastian Harl
+# Copyright (C) 2007-2009  Sebastian Harl
 #
 # 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
index 2286088..4aa0ebe 100644 (file)
@@ -18,6 +18,8 @@
  * Authors:
  *   Florian octo Forster <octo at verplant.org>
  *   Niki W. Waibel <niki.waibel@gmx.net>
+ *   Sebastian Harl <sh at tokkee.org>
+ *   Michał Mirosław <mirq-linux at rere.qmqm.pl>
 **/
 
 #if HAVE_CONFIG_H
index 1f1284a..8a4e10e 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -1,6 +1,7 @@
 /**
  * collectd - src/cpu.c
- * Copyright (C) 2005-2007  Florian octo Forster
+ * Copyright (C) 2005-2009  Florian octo Forster
+ * Copyright (C) 2009 Simon Kuhnle
  *
  * 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
@@ -17,6 +18,7 @@
  *
  * Authors:
  *   Florian octo Forster <octo at verplant.org>
+ *   Simon Kuhnle <simon at blarzwurst.de>
  **/
 
 #include "collectd.h"
index 96ba802..b6e7b22 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/perl.c
- * Copyright (C) 2007, 2008  Sebastian Harl
+ * Copyright (C) 2007-2009  Sebastian Harl
  *
  * 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
index 856ec1a..d185ef2 100644 (file)
@@ -1036,9 +1036,14 @@ int plugin_dispatch_values (value_list_t *vl)
        int status;
        static c_complain_t no_write_complaint = C_COMPLAIN_INIT_STATIC;
 
+       value_t *saved_values;
+       int      saved_values_len;
+
        data_set_t *ds;
 
-       if ((vl == NULL) || (*vl->type == '\0')) {
+       if ((vl == NULL) || (vl->type[0] == 0)
+                       || (vl->values == NULL) || (vl->values_len < 1))
+       {
                ERROR ("plugin_dispatch_values: Invalid value list.");
                return (-1);
        }
@@ -1102,6 +1107,31 @@ int plugin_dispatch_values (value_list_t *vl)
        escape_slashes (vl->type, sizeof (vl->type));
        escape_slashes (vl->type_instance, sizeof (vl->type_instance));
 
+       /* Copy the values. This way, we can assure `targets' that they get
+        * dynamically allocated values, which they can free and replace if
+        * they like. */
+       if ((pre_cache_chain != NULL) || (post_cache_chain != NULL))
+       {
+               saved_values     = vl->values;
+               saved_values_len = vl->values_len;
+
+               vl->values = (value_t *) calloc (vl->values_len,
+                               sizeof (*vl->values));
+               if (vl->values == NULL)
+               {
+                       ERROR ("plugin_dispatch_values: calloc failed.");
+                       vl->values = saved_values;
+                       return (-1);
+               }
+               memcpy (vl->values, saved_values,
+                               vl->values_len * sizeof (*vl->values));
+       }
+       else /* if ((pre == NULL) && (post == NULL)) */
+       {
+               saved_values     = NULL;
+               saved_values_len = 0;
+       }
+
        if (pre_cache_chain != NULL)
        {
                status = fc_process_chain (ds, vl, pre_cache_chain);
@@ -1113,7 +1143,17 @@ int plugin_dispatch_values (value_list_t *vl)
                                        status, status);
                }
                else if (status == FC_TARGET_STOP)
+               {
+                       /* Restore the state of the value_list so that plugins
+                        * don't get confused.. */
+                       if (saved_values != NULL)
+                       {
+                               free (vl->values);
+                               vl->values     = saved_values;
+                               vl->values_len = saved_values_len;
+                       }
                        return (0);
+               }
        }
 
        /* Update the value cache */
@@ -1133,6 +1173,15 @@ int plugin_dispatch_values (value_list_t *vl)
        else
                fc_default_action (ds, vl);
 
+       /* Restore the state of the value_list so that plugins don't get
+        * confused.. */
+       if (saved_values != NULL)
+       {
+               free (vl->values);
+               vl->values     = saved_values;
+               vl->values_len = saved_values_len;
+       }
+
        return (0);
 } /* int plugin_dispatch_values */