plugin.c: prevent re-adding read functions
authorBlaise Tarr <blaise.tarr@gmail.com>
Mon, 10 Jan 2011 22:15:47 +0000 (17:15 -0500)
committerFlorian Forster <octo@huhu.verplant.org>
Tue, 11 Jan 2011 07:48:15 +0000 (08:48 +0100)
When multiple LoadPlugin options are used with a plugin, the plugin is
only loaded once, however the plugin's read function is invoked
multiple times at every interval. This in turn causes undesired
redundant data to be sent to the write plugins.

This patch prevents a plugin's read function from being re-added to
the read_heap and read_list during plugin registration.

Signed-off-by: Blaise Tarr <blaise.tarr@gmail.com>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/plugin.c

index 0f360c0..52a5ea0 100644 (file)
@@ -728,26 +728,36 @@ static int plugin_insert_read (read_func_t *rf)
                }
        }
 
-       le = llentry_create (rf->rf_name, rf);
+       le = llist_search (read_list, rf->rf_name);
        if (le == NULL)
        {
-               pthread_mutex_unlock (&read_lock);
-               ERROR ("plugin_insert_read: llentry_create failed.");
-               return (-1);
-       }
+               le = llentry_create (rf->rf_name, rf);
+               if (le == NULL)
+               {
+                       pthread_mutex_unlock (&read_lock);
+                       ERROR ("plugin_insert_read: llentry_create failed.");
+                       return (-1);
+               }
+
+               status = c_heap_insert (read_heap, rf);
+               if (status != 0)
+               {
+                       pthread_mutex_unlock (&read_lock);
+                       ERROR ("plugin_insert_read: c_heap_insert failed.");
+                       llentry_destroy (le);
+                       return (-1);
+               }
 
-       status = c_heap_insert (read_heap, rf);
-       if (status != 0)
+               /* This does not fail. */
+               llist_append (read_list, le);
+       }
+       else
        {
-               pthread_mutex_unlock (&read_lock);
-               ERROR ("plugin_insert_read: c_heap_insert failed.");
-               llentry_destroy (le);
-               return (-1);
+               INFO ("plugin: plugin_insert_read: "
+                               "read function for plugin `%s' already added.",
+                               rf->rf_name);
        }
 
-       /* This does not fail. */
-       llist_append (read_list, le);
-
        pthread_mutex_unlock (&read_lock);
        return (0);
 } /* int plugin_insert_read */