[asterisk-commits] russell: trunk r67310 - in /trunk: ./ include/asterisk/ main/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jun 5 08:54:37 MST 2007


Author: russell
Date: Tue Jun  5 10:54:36 2007
New Revision: 67310

URL: http://svn.digium.com/view/asterisk?view=rev&rev=67310
Log:
Merged revisions 67308 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r67308 | russell | 2007-06-05 10:51:53 -0500 (Tue, 05 Jun 2007) | 5 lines

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)

........

Modified:
    trunk/   (props changed)
    trunk/include/asterisk/module.h
    trunk/main/asterisk.c
    trunk/main/loader.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/include/asterisk/module.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/module.h?view=diff&rev=67310&r1=67309&r2=67310
==============================================================================
--- trunk/include/asterisk/module.h (original)
+++ trunk/include/asterisk/module.h Tue Jun  5 10:54:36 2007
@@ -141,6 +141,13 @@
  */
 int ast_loader_unregister(int (*updater)(void));
 
+/*!
+ * \brief Run the unload() callback for all loaded modules
+ *
+ * This function should be called when Asterisk is shutting down gracefully.
+ */
+void ast_module_shutdown(void);
+
 /*! 
  * \brief Match modules names for the Asterisk cli.
  * \param line Unused by this function, but this should be the line we are

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=67310&r1=67309&r2=67310
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Tue Jun  5 10:54:36 2007
@@ -126,6 +126,7 @@
 #include "asterisk/version.h"
 #include "asterisk/linkedlists.h"
 #include "asterisk/devicestate.h"
+#include "asterisk/module.h"
 
 #include "asterisk/doxyref.h"		/* Doxygen documentation */
 
@@ -1244,6 +1245,9 @@
 				ast_verbose("Asterisk %s cancelled.\n", restart ? "restart" : "shutdown");
 			return;
 		}
+
+		if (nice)
+			ast_module_shutdown();
 	}
 	if (ast_opt_console || ast_opt_remote) {
 		if (getenv("HOME")) 

Modified: trunk/main/loader.c
URL: http://svn.digium.com/view/asterisk/trunk/main/loader.c?view=diff&rev=67310&r1=67309&r2=67310
==============================================================================
--- trunk/main/loader.c (original)
+++ trunk/main/loader.c Tue Jun  5 10:54:36 2007
@@ -428,6 +428,31 @@
 }
 #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;



More information about the asterisk-commits mailing list