From: Florian Forster Date: Wed, 3 Aug 2016 20:27:26 +0000 (+0200) Subject: src/plugin.c: Stop write threads before calling shutdown callbacks. X-Git-Tag: collectd-5.6.0~3^2~8^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=924bfe28d5be1058ccf50931d77639212fb28346;p=collectd.git src/plugin.c: Stop write threads before calling shutdown callbacks. Issue: #1110 --- diff --git a/src/network.c b/src/network.c index 71eb1f25..9d33acd6 100644 --- a/src/network.c +++ b/src/network.c @@ -2893,6 +2893,11 @@ static int network_write (const data_set_t *ds, const value_list_t *vl, { int status; + /* listen_loop is set to non-zero in the shutdown callback, which is + * guaranteed to be called *after* all the write threads have been shut + * down. */ + assert (listen_loop == 0); + if (!check_send_okay (vl)) { #if COLLECT_DEBUG diff --git a/src/plugin.c b/src/plugin.c index 73ec77ab..d42493b9 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -1731,10 +1731,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; @@ -1742,6 +1742,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); @@ -1771,8 +1775,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