Merge branch 'collectd-4.4'
[collectd.git] / src / plugin.c
index 27074a7..bf8fb08 100644 (file)
@@ -584,22 +584,15 @@ void plugin_init_all (void)
        llentry_t *le;
        int status;
 
-       /* Start read-threads */
-       if (list_read != NULL)
-       {
-               const char *rt;
-               int num;
-               rt = global_option_get ("ReadThreads");
-               num = atoi (rt);
-               start_threads ((num > 0) ? num : 5);
-       }
-
        /* Init the value cache */
        uc_init ();
 
-       if (list_init == NULL)
+       if ((list_init == NULL) && (list_read == NULL))
                return;
 
+       /* Calling all init callbacks before checking if read callbacks
+        * are available allows the init callbacks to register the read
+        * callback. */
        le = llist_head (list_init);
        while (le != NULL)
        {
@@ -612,12 +605,25 @@ void plugin_init_all (void)
                                        "failed with status %i. "
                                        "Plugin will be unloaded.",
                                        le->key, status);
+                       /* Plugins that register read callbacks from the init
+                        * callback should take care of appropriate error
+                        * handling themselves. */
                        /* FIXME: Unload _all_ functions */
                        plugin_unregister_read (le->key);
                }
 
                le = le->next;
        }
+
+       /* Start read-threads */
+       if (list_read != NULL)
+       {
+               const char *rt;
+               int num;
+               rt = global_option_get ("ReadThreads");
+               num = atoi (rt);
+               start_threads ((num > 0) ? num : 5);
+       }
 } /* void plugin_init_all */
 
 void plugin_read_all (void)
@@ -716,6 +722,7 @@ int plugin_flush (const char *plugin, int timeout, const char *identifier)
 
     (*callback) (timeout, identifier);
   }
+  return (0);
 } /* int plugin_flush */
 
 void plugin_shutdown_all (void)
@@ -923,7 +930,6 @@ static int plugin_notification_meta_add (notification_t *n,
 
   sstrncpy (meta->name, name, sizeof (meta->name));
   meta->type = type;
-  meta->next = NULL;
 
   switch (type)
   {
@@ -966,6 +972,7 @@ static int plugin_notification_meta_add (notification_t *n,
     }
   } /* switch (type) */
 
+  meta->next = NULL;
   tail = n->meta;
   while ((tail != NULL) && (tail->next != NULL))
     tail = tail->next;
@@ -1013,6 +1020,38 @@ int plugin_notification_meta_add_boolean (notification_t *n,
   return (plugin_notification_meta_add (n, name, NM_TYPE_BOOLEAN, &value));
 }
 
+int plugin_notification_meta_copy (notification_t *dst,
+    const notification_t *src)
+{
+  notification_meta_t *meta;
+
+  assert (dst != NULL);
+  assert (src != NULL);
+  assert (dst != src);
+  assert ((src->meta == NULL) || (src->meta != dst->meta));
+
+  for (meta = src->meta; meta != NULL; meta = meta->next)
+  {
+    if (meta->type == NM_TYPE_STRING)
+      plugin_notification_meta_add_string (dst, meta->name,
+         meta->value_string);
+    else if (meta->type == NM_TYPE_SIGNED_INT)
+      plugin_notification_meta_add_signed_int (dst, meta->name,
+         meta->value_signed_int);
+    else if (meta->type == NM_TYPE_UNSIGNED_INT)
+      plugin_notification_meta_add_unsigned_int (dst, meta->name,
+         meta->value_unsigned_int);
+    else if (meta->type == NM_TYPE_DOUBLE)
+      plugin_notification_meta_add_double (dst, meta->name,
+         meta->value_double);
+    else if (meta->type == NM_TYPE_BOOLEAN)
+      plugin_notification_meta_add_boolean (dst, meta->name,
+         meta->value_boolean);
+  }
+
+  return (0);
+} /* int plugin_notification_meta_copy */
+
 int plugin_notification_meta_free (notification_t *n)
 {
   notification_meta_t *this;
@@ -1032,7 +1071,8 @@ int plugin_notification_meta_free (notification_t *n)
 
     if (this->type == NM_TYPE_STRING)
     {
-      sfree (this->value_string);
+      free ((char *)this->value_string);
+      this->value_string = NULL;
     }
     sfree (this);