src/plugin.[ch]: Provide unregister-functions for plugins to remove certain functions.
[collectd.git] / src / plugin.c
index 2cf5968..df2eb6b 100644 (file)
@@ -39,6 +39,8 @@ static llist_t *list_data_set;
 
 static char *plugindir = NULL;
 
+char hostname[DATA_MAX_NAME_LEN] = "localhost";
+
 /*
  * Static functions
  */
@@ -75,6 +77,20 @@ static int register_callback (llist_t **list, const char *name, void *callback)
        return (0);
 } /* int register_callback */
 
+static int plugin_unregister (llist_t *list, const char *name)
+{
+       llentry_t *e;
+
+       e = llist_search (list, name);
+
+       if (e == NULL)
+               return (-1);
+
+       llist_remove (list, e);
+
+       return (0);
+} /* int plugin_unregister */
+
 /*
  * (Try to) load the shared object `file'. Won't complain if it isn't a shared
  * object, but it will bitch about a shared object not having a
@@ -233,11 +249,38 @@ int plugin_register_data_set (const data_set_t *ds)
        return (register_callback (&list_data_set, ds->type, (void *) ds));
 } /* int plugin_register_data_set */
 
+int plugin_unregister_init (const char *name)
+{
+       return (plugin_unregister (list_init, name));
+}
+
+int plugin_unregister_read (const char *name)
+{
+       return (plugin_unregister (list_read, name));
+}
+
+int plugin_unregister_write (const char *name)
+{
+       return (plugin_unregister (list_write, name));
+}
+
+int plugin_unregister_shutdown (const char *name)
+{
+       return (plugin_unregister (list_shutdown, name));
+}
+
+int plugin_unregister_data_set (const char *name)
+{
+       return (plugin_unregister (list_data_set, name));
+}
+
 void plugin_init_all (void)
 {
        int (*callback) (void);
        llentry_t *le;
 
+       gethostname (hostname, sizeof (hostname));
+
        if (list_init == NULL)
                return;
 
@@ -298,10 +341,20 @@ int plugin_dispatch_values (const char *name, const value_list_t *vl)
 
        le = llist_search (list_data_set, name);
        if (le == NULL)
+       {
+               DBG ("No such dataset registered: %s", name);
                return (-1);
+       }
 
        ds = (data_set_t *) le->value;
 
+       DBG ("time = %u; host = %s; "
+                       "plugin = %s; plugin_instance = %s; "
+                       "type = %s; type_instance = %s;",
+                       (unsigned int) vl->time, vl->host,
+                       vl->plugin, vl->plugin_instance,
+                       ds->type, vl->type_instance);
+
        le = llist_head (list_write);
        while (le != NULL)
        {