X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fplugin.c;h=9ecee5cf26f5fd1b2d421d0d69a3f6476a0815b0;hb=6bd4bf7b21f84746010792b885b9b71791dccb79;hp=52a5ea088cfb9537e5d5c8f2f0b7e905413cf6b4;hpb=79a87c3315bb85a71a2e69e0abaaabbfa544d6a9;p=collectd.git diff --git a/src/plugin.c b/src/plugin.c index 52a5ea08..9ecee5cf 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -1,6 +1,6 @@ /** * collectd - src/plugin.c - * Copyright (C) 2005-2010 Florian octo Forster + * Copyright (C) 2005-2011 Florian octo Forster * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -729,35 +729,36 @@ static int plugin_insert_read (read_func_t *rf) } le = llist_search (read_list, rf->rf_name); - if (le == NULL) + if (le != NULL) { - 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); - } + pthread_mutex_unlock (&read_lock); + WARNING ("The read function \"%s\" is already registered. " + "Check for duplicate \"LoadPlugin\" lines " + "in your configuration!", + rf->rf_name); + return (EINVAL); + } - /* This does not fail. */ - llist_append (read_list, le); + le = llentry_create (rf->rf_name, rf); + if (le == NULL) + { + pthread_mutex_unlock (&read_lock); + ERROR ("plugin_insert_read: llentry_create failed."); + return (-1); } - else + + status = c_heap_insert (read_heap, rf); + if (status != 0) { - INFO ("plugin: plugin_insert_read: " - "read function for plugin `%s' already added.", - rf->rf_name); + pthread_mutex_unlock (&read_lock); + ERROR ("plugin_insert_read: c_heap_insert failed."); + llentry_destroy (le); + return (-1); } + /* This does not fail. */ + llist_append (read_list, le); + pthread_mutex_unlock (&read_lock); return (0); } /* int plugin_insert_read */ @@ -766,14 +767,13 @@ int plugin_register_read (const char *name, int (*callback) (void)) { read_func_t *rf; + int status; - rf = (read_func_t *) malloc (sizeof (read_func_t)); + rf = malloc (sizeof (*rf)); if (rf == NULL) { - char errbuf[1024]; - ERROR ("plugin_register_read: malloc failed: %s", - sstrerror (errno, errbuf, sizeof (errbuf))); - return (-1); + ERROR ("plugin_register_read: malloc failed."); + return (ENOMEM); } memset (rf, 0, sizeof (read_func_t)); @@ -787,7 +787,11 @@ int plugin_register_read (const char *name, rf->rf_interval.tv_nsec = 0; rf->rf_effective_interval = rf->rf_interval; - return (plugin_insert_read (rf)); + status = plugin_insert_read (rf); + if (status != 0) + sfree (rf); + + return (status); } /* int plugin_register_read */ int plugin_register_complex_read (const char *group, const char *name, @@ -796,12 +800,13 @@ int plugin_register_complex_read (const char *group, const char *name, user_data_t *user_data) { read_func_t *rf; + int status; - rf = (read_func_t *) malloc (sizeof (read_func_t)); + rf = malloc (sizeof (*rf)); if (rf == NULL) { ERROR ("plugin_register_complex_read: malloc failed."); - return (-1); + return (ENOMEM); } memset (rf, 0, sizeof (read_func_t)); @@ -829,7 +834,11 @@ int plugin_register_complex_read (const char *group, const char *name, rf->rf_udata = *user_data; } - return (plugin_insert_read (rf)); + status = plugin_insert_read (rf); + if (status != 0) + sfree (rf); + + return (status); } /* int plugin_register_complex_read */ int plugin_register_write (const char *name,