From: Sebastian Harl Date: Tue, 22 Apr 2014 17:49:02 +0000 (+0200) Subject: plugin: Added sdb_plugin_shutdown_all(). X-Git-Tag: sysdb-0.1.0~101 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a90a18a7947c8803f7049551bedc81a669a07834;p=sysdb.git plugin: Added sdb_plugin_shutdown_all(). This function calls all registered "shutdown" callbacks. --- diff --git a/src/core/plugin.c b/src/core/plugin.c index a73faa0..d1f7541 100644 --- a/src/core/plugin.c +++ b/src/core/plugin.c @@ -933,6 +933,36 @@ sdb_plugin_init_all(void) return ret; } /* sdb_plugin_init_all */ +int +sdb_plugin_shutdown_all(void) +{ + sdb_llist_iter_t *iter; + int ret = 0; + + iter = sdb_llist_get_iter(shutdown_list); + while (sdb_llist_iter_has_next(iter)) { + sdb_plugin_cb_t *cb; + sdb_plugin_shutdown_cb callback; + ctx_t *old_ctx; + + sdb_object_t *obj = sdb_llist_iter_get_next(iter); + assert(obj); + cb = SDB_PLUGIN_CB(obj); + + callback = (sdb_plugin_shutdown_cb)cb->cb_callback; + + old_ctx = ctx_set(cb->cb_ctx); + if (callback(cb->cb_user_data)) { + sdb_log(SDB_LOG_ERR, "core: Failed to shutdown plugin '%s'.", + obj->name); + ++ret; + } + ctx_set(old_ctx); + } + sdb_llist_iter_destroy(iter); + return ret; +} /* sdb_plugin_shutdown_all */ + int sdb_plugin_collector_loop(sdb_plugin_loop_t *loop) { diff --git a/src/include/core/plugin.h b/src/include/core/plugin.h index 9701d60..e5e222f 100644 --- a/src/include/core/plugin.h +++ b/src/include/core/plugin.h @@ -273,6 +273,16 @@ sdb_plugin_reconfigure_finish(void); int sdb_plugin_init_all(void); +/* + * sdb_plugin_shutdown_all: + * Shutdown all plugins using their registered "shutdown" function. + * + * Returns: + * The number of failed shutdowns. + */ +int +sdb_plugin_shutdown_all(void); + /* * sdb_plugin_collector_loop: * Loop until loop->do_loop is false, calling the next collector function on