Merge branch 'collectd-4.3' into collectd-4.4
[collectd.git] / src / plugin.c
index 1aad97c..e611b8c 100644 (file)
@@ -580,22 +580,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)
        {
@@ -608,12 +601,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)