src/plugin.c: Initialize plugins before checking if read callbacks are available.
authorSebastian Harl <sh@tokkee.org>
Wed, 2 Jul 2008 14:26:46 +0000 (16:26 +0200)
committerFlorian Forster <octo@huhu.verplant.org>
Sun, 6 Jul 2008 12:27:18 +0000 (14:27 +0200)
plugin_init_all() checks if any read callbacks are available before starting
the read threads. A few plugins register their read callback from their
init callback though. By initializing the plugins before that the read
threads are still started correctly if all plugins register the read
callback in the init callback.

Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/plugin.c

index 8b2803d..f1333f1 100644 (file)
@@ -568,22 +568,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)
        {
@@ -596,12 +589,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)