exec plugin: Change the input format so it's identical to the one used in unixsock.
[collectd.git] / src / plugin.c
index ee1240c..da66204 100644 (file)
@@ -420,7 +420,8 @@ int plugin_register_data_set (const data_set_t *ds)
        data_set_t *ds_copy;
        int i;
 
-       if (llist_search (list_data_set, ds->type) != NULL)
+       if ((list_data_set != NULL)
+                       && (llist_search (list_data_set, ds->type) != NULL))
        {
                NOTICE ("Replacing DS `%s' with another version.", ds->type);
                plugin_unregister_data_set (ds->type);
@@ -493,6 +494,9 @@ int plugin_unregister_data_set (const char *name)
        llentry_t  *e;
        data_set_t *ds;
 
+       if (list_data_set == NULL)
+               return (-1);
+
        e = llist_search (list_data_set, name);
 
        if (e == NULL)
@@ -603,19 +607,24 @@ void plugin_shutdown_all (void)
        while (le != NULL)
        {
                callback = (int (*) (void)) le->value;
-               (*callback) ();
 
+               /* Advance the pointer before calling the callback allows
+                * shutdown functions to unregister themselves. If done the
+                * other way around the memory `le' points to will be freed
+                * after callback returns. */
                le = le->next;
+
+               (*callback) ();
        }
 } /* void plugin_shutdown_all */
 
-int plugin_dispatch_values (const char *name, const value_list_t *vl)
+int plugin_dispatch_values (const char *name, value_list_t *vl)
 {
        int (*callback) (const data_set_t *, const value_list_t *);
        data_set_t *ds;
        llentry_t *le;
 
-       if (list_write == NULL)
+       if ((list_write == NULL) || (list_data_set == NULL))
                return (-1);
 
        le = llist_search (list_data_set, name);
@@ -634,6 +643,23 @@ int plugin_dispatch_values (const char *name, const value_list_t *vl)
                        vl->plugin, vl->plugin_instance,
                        ds->type, vl->type_instance);
 
+#if COLLECT_DEBUG
+       assert (ds->ds_num == vl->values_len);
+#else
+       if (ds->ds_num != vl->values_len)
+       {
+               ERROR ("plugin: ds->type = %s: (ds->ds_num = %i) != "
+                               "(vl->values_len = %i)",
+                               ds->type, ds->ds_num, vl->values_len);
+               return (-1);
+       }
+#endif
+
+       escape_slashes (vl->host, sizeof (vl->host));
+       escape_slashes (vl->plugin, sizeof (vl->plugin));
+       escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
+       escape_slashes (vl->type_instance, sizeof (vl->type_instance));
+
        le = llist_head (list_write);
        while (le != NULL)
        {
@@ -644,7 +670,7 @@ int plugin_dispatch_values (const char *name, const value_list_t *vl)
        }
 
        return (0);
-}
+} /* int plugin_dispatch_values */
 
 void plugin_log (int level, const char *format, ...)
 {