aboutsummaryrefslogtreecommitdiffstats
path: root/main/loader.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-06-05 15:51:53 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-06-05 15:51:53 +0000
commiteb02aa69b9a111b1bcd63c170a2048dc67560b81 (patch)
tree2b99d894a46c9f12785e2e840661614cb0913938 /main/loader.c
parent57a489abfdcdbf55b611feac52794e0ad9e953fb (diff)
When shutting down "gracefully", go through and run the unload() callbacks for
all of the modules. "stop now" is considered a non-graceful shutdown and will not go through this process. (issue #9804, reported by chrisost, patch by me) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@67308 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/loader.c')
-rw-r--r--main/loader.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/main/loader.c b/main/loader.c
index 012f0e810..69d0be52c 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -427,6 +427,31 @@ static struct ast_module *load_dynamic_module(const char *resource_in, unsigned
}
#endif
+void ast_module_shutdown(void)
+{
+ struct ast_module *mod;
+ AST_LIST_HEAD_NOLOCK_STATIC(local_module_list, ast_module);
+
+ /* We have to call the unload() callbacks in reverse order that the modules
+ * exist in the module list so it is the reverse order of how they were
+ * loaded. */
+
+ AST_LIST_LOCK(&module_list);
+ while ((mod = AST_LIST_REMOVE_HEAD(&module_list, entry)))
+ AST_LIST_INSERT_HEAD(&local_module_list, mod, entry);
+ AST_LIST_UNLOCK(&module_list);
+
+ while ((mod = AST_LIST_REMOVE_HEAD(&local_module_list, entry))) {
+ if (mod->info->unload)
+ mod->info->unload();
+ /* Since this should only be called when shutting down "gracefully",
+ * all channels should be down before we get to this point, meaning
+ * there will be no module users left. */
+ AST_LIST_HEAD_DESTROY(&mod->users);
+ free(mod);
+ }
+}
+
int ast_unload_resource(const char *resource_name, enum ast_module_unload_mode force)
{
struct ast_module *mod;