X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Fplugin.c;h=1deabba3dde599a3c203258e1b26200519d6951c;hb=7bfda8d327240ac73297e4449663814dd0594be5;hp=b69e65b6a75b2413b6f777694fd9f73fb92ace12;hpb=809a89739bd92a5432deb6230a68dd6e6bbb72b3;p=collectd.git diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index b69e65b6..1deabba3 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); @@ -974,7 +974,7 @@ static int plugin_mark_loaded (char const *name) return (status); } -static void plugin_free_loaded () +static void plugin_free_loaded (void) { void *key; void *value; @@ -1237,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 */ @@ -1285,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 */ @@ -1448,9 +1452,9 @@ int plugin_unregister_read (const char *name) /* {{{ */ return (0); } /* }}} int plugin_unregister_read */ -void plugin_log_available_writers () +void plugin_log_available_writers (void) { - log_list_callbacks (&list_write, "Available writers:"); + log_list_callbacks (&list_write, "Available write targets:"); } static int compare_read_func_group (llentry_t *e, void *ud) /* {{{ */ @@ -1563,7 +1567,6 @@ int plugin_unregister_notification (const char *name) void plugin_init_all (void) { char const *chain_name; - long write_threads_num; llentry_t *le; int status; @@ -1609,8 +1612,6 @@ void plugin_init_all (void) write_threads_num = 5; } - start_write_threads ((size_t) write_threads_num); - if ((list_init == NULL) && (read_heap == NULL)) return; @@ -1646,6 +1647,8 @@ void plugin_init_all (void) le = le->next; } + start_write_threads ((size_t) write_threads_num); + max_read_interval = global_option_get_time ("MaxReadInterval", DEFAULT_MAX_READ_INTERVAL); @@ -1720,6 +1723,7 @@ int plugin_read_all_once (void) return_status = -1; } + sfree (rf->rf_name); destroy_callback ((void *) rf); } @@ -1846,10 +1850,10 @@ void plugin_shutdown_all (void) { llentry_t *le; - stop_read_threads (); - destroy_all_callbacks (&list_init); + stop_read_threads (); + pthread_mutex_lock (&read_lock); llist_destroy (read_list); read_list = NULL; @@ -1857,6 +1861,10 @@ void plugin_shutdown_all (void) destroy_read_heap (); + /* blocks until all write threads have shut down. */ + stop_write_threads (); + + /* ask all plugins to write out the state they kept. */ plugin_flush (/* plugin = */ NULL, /* timeout = */ 0, /* identifier = */ NULL); @@ -1886,8 +1894,6 @@ void plugin_shutdown_all (void) plugin_set_ctx (old_ctx); } - stop_write_threads (); - /* Write plugins which use the `user_data' pointer usually need the * same data available to the flush callback. If this is the case, set * the free_function to NULL when registering the flush callback and to @@ -2267,7 +2273,7 @@ int plugin_dispatch_multivalue (value_list_t const *template, /* {{{ */ case DS_TYPE_GAUGE: vl->values[0].gauge = va_arg (ap, gauge_t); if (store_percentage) - vl->values[0].gauge *= 100.0 / sum; + vl->values[0].gauge *= sum ? (100.0 / sum) : 0; break; case DS_TYPE_ABSOLUTE: vl->values[0].absolute = va_arg (ap, absolute_t);