src/utils_llist.[ch]: Changed the semantic so module doesn't copy the `key'.
[collectd.git] / src / plugin.c
index 67d6188..44bdc8f 100644 (file)
@@ -32,6 +32,7 @@
 #include "configfile.h"
 #include "utils_llist.h"
 #include "utils_cache.h"
+#include "utils_threshold.h"
 
 /*
  * Private structures
@@ -78,6 +79,7 @@ static const char *plugin_get_dir (void)
 static int register_callback (llist_t **list, const char *name, void *callback)
 {
        llentry_t *le;
+       char *key;
 
        if ((*list == NULL)
                        && ((*list = llist_create ()) == NULL))
@@ -86,9 +88,16 @@ static int register_callback (llist_t **list, const char *name, void *callback)
        le = llist_search (*list, name);
        if (le == NULL)
        {
-               le = llentry_create (name, callback);
+               key = strdup (name);
+               if (key == NULL)
+                       return (-1);
+
+               le = llentry_create (key, callback);
                if (le == NULL)
+               {
+                       free (key);
                        return (-1);
+               }
 
                llist_append (*list, le);
        }
@@ -110,6 +119,7 @@ static int plugin_unregister (llist_t *list, const char *name)
                return (-1);
 
        llist_remove (list, e);
+       free (e->key);
        llentry_destroy (e);
 
        return (0);
@@ -498,6 +508,7 @@ int plugin_unregister_read (const char *name)
 
        llist_remove (list_read, e);
        free (e->value);
+       free (e->key);
        llentry_destroy (e);
 
        return (0);
@@ -528,6 +539,7 @@ int plugin_unregister_data_set (const char *name)
 
        llist_remove (list_data_set, e);
        ds = (data_set_t *) e->value;
+       free (e->key);
        llentry_destroy (e);
 
        sfree (ds->ds);
@@ -696,6 +708,7 @@ int plugin_dispatch_values (const char *name, value_list_t *vl)
 
        /* Update the value cache */
        uc_update (ds, vl);
+       ut_check_threshold (ds, vl);
 
        le = llist_head (list_write);
        while (le != NULL)
@@ -715,6 +728,11 @@ int plugin_dispatch_notification (const notification_t *notif)
        llentry_t *le;
        /* Possible TODO: Add flap detection here */
 
+       DEBUG ("plugin_dispatch_notification: severity = %i; message = %s; "
+                       "time = %u; host = %s;",
+                       notif->severity, notif->message,
+                       (unsigned int) notif->time, notif->host);
+
        /* Nobody cares for notifications */
        if (list_notification == NULL)
                return (-1);