X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Fplugin.c;h=3da8eccbb3b2b147f8042c866ded54ee788fe127;hb=dab48f284f9d4bb6ae98244310c5cdb6c5d91bf3;hp=3a95f362a319e176c3ce87ced0fce37216964794;hpb=60786de4e8280a109077ab5ecc293f74b3b9bce3;p=collectd.git diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index 3a95f362..3da8eccb 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -235,13 +235,13 @@ static void destroy_read_heap (void) /* {{{ */ while (42) { - callback_func_t *cf; + read_func_t *rf; - cf = c_heap_get_root (read_heap); - if (cf == NULL) + rf = c_heap_get_root (read_heap); + if (rf == NULL) break; - - destroy_callback (cf); + sfree (rf->rf_name); + destroy_callback ((callback_func_t *) rf); } c_heap_destroy (read_heap); @@ -307,6 +307,56 @@ static int register_callback (llist_t **list, /* {{{ */ return (0); } /* }}} int register_callback */ +static void log_list_callbacks (llist_t **list, /* {{{ */ + const char *comment) +{ + char *str; + int len; + llentry_t *le; + int i; + int n; + char **keys; + + n = llist_size(*list); + if (n == 0) + { + INFO("%s [none]", comment); + return; + } + + keys = calloc(n, sizeof(char*)); + + if (keys == NULL) + { + ERROR("%s: failed to allocate memory for list of callbacks", + comment); + + return; + } + + for (le = llist_head (*list), i = 0, len = 0; + le != NULL; + le = le->next, i++) + { + keys[i] = le->key; + len += strlen(le->key) + 6; + } + str = malloc(len + 10); + if (str == NULL) + { + ERROR("%s: failed to allocate memory for list of callbacks", + comment); + } + else + { + *str = '\0'; + strjoin(str, len, keys, n, "', '"); + INFO("%s ['%s']", comment, str); + free(str); + } + free(keys); +} /* }}} void log_list_callbacks */ + static int create_register_callback (llist_t **list, /* {{{ */ const char *name, void *callback, user_data_t *ud) { @@ -949,7 +999,6 @@ int plugin_load (char const *plugin_name, uint32_t flags) const char *dir; char filename[BUFSIZE] = ""; char typename[BUFSIZE]; - int typename_len; int ret; struct stat statbuf; struct dirent *de; @@ -989,7 +1038,6 @@ int plugin_load (char const *plugin_name, uint32_t flags) WARNING ("plugin_load: Filename too long: \"%s.so\"", plugin_name); return (-1); } - typename_len = strlen (typename); if ((dh = opendir (dir)) == NULL) { @@ -1001,7 +1049,7 @@ int plugin_load (char const *plugin_name, uint32_t flags) while ((de = readdir (dh)) != NULL) { - if (strncasecmp (de->d_name, typename, typename_len)) + if (strcasecmp (de->d_name, typename)) continue; status = ssnprintf (filename, sizeof (filename), @@ -1189,8 +1237,10 @@ int plugin_register_read (const char *name, rf->rf_interval = plugin_get_interval (); status = plugin_insert_read (rf); - if (status != 0) + if (status != 0) { + sfree (rf->rf_name); sfree (rf); + } return (status); } /* int plugin_register_read */ @@ -1237,8 +1287,10 @@ int plugin_register_complex_read (const char *group, const char *name, rf->rf_ctx = plugin_get_ctx (); status = plugin_insert_read (rf); - if (status != 0) + if (status != 0) { + sfree (rf->rf_name); sfree (rf); + } return (status); } /* int plugin_register_complex_read */ @@ -1400,6 +1452,11 @@ int plugin_unregister_read (const char *name) /* {{{ */ return (0); } /* }}} int plugin_unregister_read */ +void plugin_log_available_writers (void) +{ + log_list_callbacks (&list_write, "Available write targets:"); +} + static int compare_read_func_group (llentry_t *e, void *ud) /* {{{ */ { read_func_t *rf = e->value; @@ -1667,6 +1724,7 @@ int plugin_read_all_once (void) return_status = -1; } + sfree (rf->rf_name); destroy_callback ((void *) rf); }