plugin.c: prevent re-adding read functions
[collectd.git] / src / plugin.c
index e32c8f9..52a5ea0 100644 (file)
@@ -36,7 +36,6 @@
 #include "utils_llist.h"
 #include "utils_heap.h"
 #include "utils_cache.h"
-#include "utils_threshold.h"
 #include "filter_chain.h"
 
 /*
@@ -729,26 +728,36 @@ static int plugin_insert_read (read_func_t *rf)
                }
        }
 
-       le = llentry_create (rf->rf_name, rf);
+       le = llist_search (read_list, rf->rf_name);
        if (le == NULL)
        {
-               pthread_mutex_unlock (&read_lock);
-               ERROR ("plugin_insert_read: llentry_create failed.");
-               return (-1);
-       }
+               le = llentry_create (rf->rf_name, rf);
+               if (le == NULL)
+               {
+                       pthread_mutex_unlock (&read_lock);
+                       ERROR ("plugin_insert_read: llentry_create failed.");
+                       return (-1);
+               }
 
-       status = c_heap_insert (read_heap, rf);
-       if (status != 0)
+               status = c_heap_insert (read_heap, rf);
+               if (status != 0)
+               {
+                       pthread_mutex_unlock (&read_lock);
+                       ERROR ("plugin_insert_read: c_heap_insert failed.");
+                       llentry_destroy (le);
+                       return (-1);
+               }
+
+               /* This does not fail. */
+               llist_append (read_list, le);
+       }
+       else
        {
-               pthread_mutex_unlock (&read_lock);
-               ERROR ("plugin_insert_read: c_heap_insert failed.");
-               llentry_destroy (le);
-               return (-1);
+               INFO ("plugin: plugin_insert_read: "
+                               "read function for plugin `%s' already added.",
+                               rf->rf_name);
        }
 
-       /* This does not fail. */
-       llist_append (read_list, le);
-
        pthread_mutex_unlock (&read_lock);
        return (0);
 } /* int plugin_insert_read */
@@ -1359,7 +1368,7 @@ int plugin_dispatch_missing (const value_list_t *vl) /* {{{ */
     cf = le->value;
     callback = cf->cf_callback;
 
-    status = (*callback) (vl);
+    status = (*callback) (vl, &cf->cf_udata);
     if (status != 0)
     {
       if (status < 0)
@@ -1525,9 +1534,6 @@ int plugin_dispatch_values (value_list_t *vl)
        /* Update the value cache */
        uc_update (ds, vl);
 
-       /* Initiate threshold checking */
-       ut_check_threshold (ds, vl);
-
        if (post_cache_chain != NULL)
        {
                status = fc_process_chain (ds, vl, post_cache_chain);