[asterisk-commits] dlee: branch dlee/unload-order r386989 - in /team/dlee/unload-order: apps/ in...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 30 10:59:26 CDT 2013


Author: dlee
Date: Tue Apr 30 10:59:23 2013
New Revision: 386989

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386989
Log:
Fixed unload order for res_stasis*.so

Modified:
    team/dlee/unload-order/apps/app_stasis.c
    team/dlee/unload-order/include/asterisk/stasis_app.h
    team/dlee/unload-order/main/loader.c
    team/dlee/unload-order/res/res_stasis.c
    team/dlee/unload-order/res/res_stasis_http.c
    team/dlee/unload-order/res/res_stasis_http_asterisk.c
    team/dlee/unload-order/res/res_stasis_http_bridges.c
    team/dlee/unload-order/res/res_stasis_http_channels.c
    team/dlee/unload-order/res/res_stasis_http_endpoints.c
    team/dlee/unload-order/res/res_stasis_http_events.c
    team/dlee/unload-order/res/res_stasis_http_playback.c
    team/dlee/unload-order/res/res_stasis_http_recordings.c
    team/dlee/unload-order/res/res_stasis_http_sounds.c
    team/dlee/unload-order/res/res_stasis_websocket.c
    team/dlee/unload-order/rest-api-templates/res_stasis_http_resource.c.mustache
    team/dlee/unload-order/tests/test_res_stasis.c

Modified: team/dlee/unload-order/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/apps/app_stasis.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/apps/app_stasis.c (original)
+++ team/dlee/unload-order/apps/app_stasis.c Tue Apr 30 10:59:23 2013
@@ -105,7 +105,10 @@
 	return r;
 }
 
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS,
-		"Stasis dialplan application",
-		.load = load_module,
-		.unload = unload_module);
+AST_MODULE_INFO(ASTERISK_GPL_KEY,
+	AST_MODFLAG_DEFAULT,
+	"Stasis dialplan application",
+	.load = load_module,
+	.unload = unload_module,
+	.nonoptreq = "res_stasis",
+	);

Modified: team/dlee/unload-order/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/include/asterisk/stasis_app.h?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/include/asterisk/stasis_app.h (original)
+++ team/dlee/unload-order/include/asterisk/stasis_app.h Tue Apr 30 10:59:23 2013
@@ -44,6 +44,10 @@
  * Finally, Stasis apps control channels through the use of the \ref
  * stasis_app_control object, and the family of \c stasis_app_control_*
  * functions.
+ *
+ * Since module unload order is based on reference counting, any module that
+ * uses the API defined in this file must call stasis_app_ref() when loaded,
+ * and stasis_app_unref() when unloaded.
  */
 
 #include "asterisk/channel.h"
@@ -171,6 +175,20 @@
  */
 struct ast_json *ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot);
 
+/*!
+ * \brief Increment the res_stasis reference count.
+ *
+ * This ensures graceful shutdown happens in the proper order.
+ */
+void stasis_app_ref(void);
+
+/*!
+ * \brief Decrement the res_stasis reference count.
+ *
+ * This ensures graceful shutdown happens in the proper order.
+ */
+void stasis_app_unref(void);
+
 /*! @} */
 
 #endif /* _ASTERISK_STASIS_APP_H */

Modified: team/dlee/unload-order/main/loader.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/main/loader.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/main/loader.c (original)
+++ team/dlee/unload-order/main/loader.c Tue Apr 30 10:59:23 2013
@@ -525,6 +525,7 @@
 			}
 			AST_LIST_REMOVE_CURRENT(entry);
 			if (mod->flags.running && !mod->flags.declined && mod->info->unload) {
+				ast_verb(1, "Unloading %s\n", mod->resource);
 				mod->info->unload();
 			}
 			AST_LIST_HEAD_DESTROY(&mod->users);
@@ -571,6 +572,7 @@
 		/* Request any channels attached to the module to hangup. */
 		__ast_module_user_hangup_all(mod);
 
+		ast_verb(1, "Unloading %s\n", mod->resource);
 		res = mod->info->unload();
 		if (res) {
 			ast_log(LOG_WARNING, "Firm unload failed for %s\n", resource_name);

Modified: team/dlee/unload-order/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/res/res_stasis.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/res/res_stasis.c (original)
+++ team/dlee/unload-order/res/res_stasis.c Tue Apr 30 10:59:23 2013
@@ -709,6 +709,16 @@
 	}
 }
 
+void stasis_app_ref(void)
+{
+	ast_module_ref(ast_module_info->self);
+}
+
+void stasis_app_unref(void)
+{
+	ast_module_unref(ast_module_info->self);
+}
+
 static int load_module(void)
 {
 	int r = 0;

Modified: team/dlee/unload-order/res/res_stasis_http.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/res/res_stasis_http.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/res/res_stasis_http.c (original)
+++ team/dlee/unload-order/res/res_stasis_http.c Tue Apr 30 10:59:23 2013
@@ -72,7 +72,6 @@
  */
 
 /*** MODULEINFO
-	<depend type="module">app_stasis</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -235,6 +234,7 @@
 	ao2_cleanup(root_handler);
 	ao2_ref(new_handler, +1);
 	root_handler = new_handler;
+	ast_module_ref(ast_module_info->self);
 	return 0;
 }
 
@@ -243,9 +243,7 @@
 	RAII_VAR(struct stasis_rest_handlers *, new_handler, NULL, ao2_cleanup);
 	size_t size, i, j;
 
-	if (!root_handler) {
-		return -1;
-	}
+	ast_assert(root_handler != NULL);
 
 	ast_mutex_lock(&root_handler_lock);
 	size = sizeof(*new_handler) +
@@ -259,6 +257,7 @@
 
 	for (i = 0, j = 0; i < root_handler->num_children; ++i) {
 		if (root_handler->children[i] == handler) {
+			ast_module_unref(ast_module_info->self);
 			continue;
 		}
 		new_handler->children[j++] = root_handler->children[i];
@@ -860,6 +859,7 @@
 static int load_module(void)
 {
 	ast_mutex_init(&root_handler_lock);
+
 	root_handler = root_handler_create();
 	if (!root_handler) {
 		return AST_MODULE_LOAD_FAILURE;
@@ -932,6 +932,5 @@
 	.load = load_module,
 	.unload = unload_module,
 	.reload = reload_module,
-	.nonoptreq = "app_stasis",
 	.load_pri = AST_MODPRI_APP_DEPEND,
 	);

Modified: team/dlee/unload-order/res/res_stasis_http_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/res/res_stasis_http_asterisk.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/res/res_stasis_http_asterisk.c (original)
+++ team/dlee/unload-order/res/res_stasis_http_asterisk.c Tue Apr 30 10:59:23 2013
@@ -33,6 +33,7 @@
 
 /*** MODULEINFO
 	<depend type="module">res_stasis_http</depend>
+	<depend type="module">res_stasis</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -41,6 +42,7 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/module.h"
+#include "asterisk/stasis_app.h"
 #include "stasis_http/resource_asterisk.h"
 
 /*!
@@ -86,12 +88,14 @@
 
 static int load_module(void)
 {
+	stasis_app_ref();
 	return stasis_http_add_handler(&asterisk);
 }
 
 static int unload_module(void)
 {
 	stasis_http_remove_handler(&asterisk);
+	stasis_app_unref();
 	return 0;
 }
 
@@ -99,5 +103,5 @@
 	"RESTful API module - Asterisk resources",
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis_http",
+	.nonoptreq = "res_stasis_http,res_stasis",
 	);

Modified: team/dlee/unload-order/res/res_stasis_http_bridges.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/res/res_stasis_http_bridges.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/res/res_stasis_http_bridges.c (original)
+++ team/dlee/unload-order/res/res_stasis_http_bridges.c Tue Apr 30 10:59:23 2013
@@ -33,6 +33,7 @@
 
 /*** MODULEINFO
 	<depend type="module">res_stasis_http</depend>
+	<depend type="module">res_stasis</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -41,6 +42,7 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/module.h"
+#include "asterisk/stasis_app.h"
 #include "stasis_http/resource_bridges.h"
 
 /*!
@@ -274,12 +276,14 @@
 
 static int load_module(void)
 {
+	stasis_app_ref();
 	return stasis_http_add_handler(&bridges);
 }
 
 static int unload_module(void)
 {
 	stasis_http_remove_handler(&bridges);
+	stasis_app_unref();
 	return 0;
 }
 
@@ -287,5 +291,5 @@
 	"RESTful API module - Bridge resources",
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis_http",
+	.nonoptreq = "res_stasis_http,res_stasis",
 	);

Modified: team/dlee/unload-order/res/res_stasis_http_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/res/res_stasis_http_channels.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/res/res_stasis_http_channels.c (original)
+++ team/dlee/unload-order/res/res_stasis_http_channels.c Tue Apr 30 10:59:23 2013
@@ -33,6 +33,7 @@
 
 /*** MODULEINFO
 	<depend type="module">res_stasis_http</depend>
+	<depend type="module">res_stasis</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -41,6 +42,7 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/module.h"
+#include "asterisk/stasis_app.h"
 #include "stasis_http/resource_channels.h"
 
 /*!
@@ -487,12 +489,14 @@
 
 static int load_module(void)
 {
+	stasis_app_ref();
 	return stasis_http_add_handler(&channels);
 }
 
 static int unload_module(void)
 {
 	stasis_http_remove_handler(&channels);
+	stasis_app_unref();
 	return 0;
 }
 
@@ -500,5 +504,5 @@
 	"RESTful API module - Channel resources",
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis_http",
+	.nonoptreq = "res_stasis_http,res_stasis",
 	);

Modified: team/dlee/unload-order/res/res_stasis_http_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/res/res_stasis_http_endpoints.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/res/res_stasis_http_endpoints.c (original)
+++ team/dlee/unload-order/res/res_stasis_http_endpoints.c Tue Apr 30 10:59:23 2013
@@ -33,6 +33,7 @@
 
 /*** MODULEINFO
 	<depend type="module">res_stasis_http</depend>
+	<depend type="module">res_stasis</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -41,6 +42,7 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/module.h"
+#include "asterisk/stasis_app.h"
 #include "stasis_http/resource_endpoints.h"
 
 /*!
@@ -110,12 +112,14 @@
 
 static int load_module(void)
 {
+	stasis_app_ref();
 	return stasis_http_add_handler(&endpoints);
 }
 
 static int unload_module(void)
 {
 	stasis_http_remove_handler(&endpoints);
+	stasis_app_unref();
 	return 0;
 }
 
@@ -123,5 +127,5 @@
 	"RESTful API module - Endpoint resources",
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis_http",
+	.nonoptreq = "res_stasis_http,res_stasis",
 	);

Modified: team/dlee/unload-order/res/res_stasis_http_events.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/res/res_stasis_http_events.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/res/res_stasis_http_events.c (original)
+++ team/dlee/unload-order/res/res_stasis_http_events.c Tue Apr 30 10:59:23 2013
@@ -33,6 +33,7 @@
 
 /*** MODULEINFO
 	<depend type="module">res_stasis_http</depend>
+	<depend type="module">res_stasis</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -41,6 +42,7 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/module.h"
+#include "asterisk/stasis_app.h"
 #include "stasis_http/resource_events.h"
 
 /*!
@@ -78,12 +80,14 @@
 
 static int load_module(void)
 {
+	stasis_app_ref();
 	return stasis_http_add_handler(&events);
 }
 
 static int unload_module(void)
 {
 	stasis_http_remove_handler(&events);
+	stasis_app_unref();
 	return 0;
 }
 
@@ -91,5 +95,5 @@
 	"RESTful API module - WebSocket resource",
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis_http",
+	.nonoptreq = "res_stasis_http,res_stasis",
 	);

Modified: team/dlee/unload-order/res/res_stasis_http_playback.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/res/res_stasis_http_playback.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/res/res_stasis_http_playback.c (original)
+++ team/dlee/unload-order/res/res_stasis_http_playback.c Tue Apr 30 10:59:23 2013
@@ -33,6 +33,7 @@
 
 /*** MODULEINFO
 	<depend type="module">res_stasis_http</depend>
+	<depend type="module">res_stasis</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -41,6 +42,7 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/module.h"
+#include "asterisk/stasis_app.h"
 #include "stasis_http/resource_playback.h"
 
 /*!
@@ -147,12 +149,14 @@
 
 static int load_module(void)
 {
+	stasis_app_ref();
 	return stasis_http_add_handler(&playback);
 }
 
 static int unload_module(void)
 {
 	stasis_http_remove_handler(&playback);
+	stasis_app_unref();
 	return 0;
 }
 
@@ -160,5 +164,5 @@
 	"RESTful API module - Playback control resources",
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis_http",
+	.nonoptreq = "res_stasis_http,res_stasis",
 	);

Modified: team/dlee/unload-order/res/res_stasis_http_recordings.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/res/res_stasis_http_recordings.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/res/res_stasis_http_recordings.c (original)
+++ team/dlee/unload-order/res/res_stasis_http_recordings.c Tue Apr 30 10:59:23 2013
@@ -33,6 +33,7 @@
 
 /*** MODULEINFO
 	<depend type="module">res_stasis_http</depend>
+	<depend type="module">res_stasis</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -41,6 +42,7 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/module.h"
+#include "asterisk/stasis_app.h"
 #include "stasis_http/resource_recordings.h"
 
 /*!
@@ -381,12 +383,14 @@
 
 static int load_module(void)
 {
+	stasis_app_ref();
 	return stasis_http_add_handler(&recordings);
 }
 
 static int unload_module(void)
 {
 	stasis_http_remove_handler(&recordings);
+	stasis_app_unref();
 	return 0;
 }
 
@@ -394,5 +398,5 @@
 	"RESTful API module - Recording resources",
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis_http",
+	.nonoptreq = "res_stasis_http,res_stasis",
 	);

Modified: team/dlee/unload-order/res/res_stasis_http_sounds.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/res/res_stasis_http_sounds.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/res/res_stasis_http_sounds.c (original)
+++ team/dlee/unload-order/res/res_stasis_http_sounds.c Tue Apr 30 10:59:23 2013
@@ -33,6 +33,7 @@
 
 /*** MODULEINFO
 	<depend type="module">res_stasis_http</depend>
+	<depend type="module">res_stasis</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -41,6 +42,7 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/module.h"
+#include "asterisk/stasis_app.h"
 #include "stasis_http/resource_sounds.h"
 
 /*!
@@ -113,12 +115,14 @@
 
 static int load_module(void)
 {
+	stasis_app_ref();
 	return stasis_http_add_handler(&sounds);
 }
 
 static int unload_module(void)
 {
 	stasis_http_remove_handler(&sounds);
+	stasis_app_unref();
 	return 0;
 }
 
@@ -126,5 +130,5 @@
 	"RESTful API module - Sound resources",
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis_http",
+	.nonoptreq = "res_stasis_http,res_stasis",
 	);

Modified: team/dlee/unload-order/res/res_stasis_websocket.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/res/res_stasis_websocket.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/res/res_stasis_websocket.c (original)
+++ team/dlee/unload-order/res/res_stasis_websocket.c Tue Apr 30 10:59:23 2013
@@ -301,6 +301,7 @@
 {
 	int r = 0;
 
+	stasis_app_ref();
 	oom_json = ast_json_pack("{s: s}",
 				 "error", "OutOfMemory");
 	if (!oom_json) {
@@ -315,6 +316,7 @@
 {
 	int r = 0;
 
+	stasis_app_unref();
 	ast_json_unref(oom_json);
 	oom_json = NULL;
 	r |= ast_websocket_remove_protocol(ws_protocol, websocket_callback);

Modified: team/dlee/unload-order/rest-api-templates/res_stasis_http_resource.c.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/rest-api-templates/res_stasis_http_resource.c.mustache?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/rest-api-templates/res_stasis_http_resource.c.mustache (original)
+++ team/dlee/unload-order/rest-api-templates/res_stasis_http_resource.c.mustache Tue Apr 30 10:59:23 2013
@@ -38,6 +38,7 @@
 
 /*** MODULEINFO
 	<depend type="module">res_stasis_http</depend>
+	<depend type="module">res_stasis</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -46,6 +47,7 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/module.h"
+#include "asterisk/stasis_app.h"
 #include "stasis_http/resource_{{name}}.h"
 
 {{#apis}}
@@ -98,12 +100,14 @@
 
 static int load_module(void)
 {
+	stasis_app_ref();
 	return stasis_http_add_handler(&{{root_full_name}});
 }
 
 static int unload_module(void)
 {
 	stasis_http_remove_handler(&{{root_full_name}});
+	stasis_app_unref();
 	return 0;
 }
 
@@ -111,6 +115,6 @@
 	"RESTful API module - {{{description}}}",
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis_http",
+	.nonoptreq = "res_stasis_http,res_stasis",
 	);
 {{/api_declaration}}

Modified: team/dlee/unload-order/tests/test_res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/unload-order/tests/test_res_stasis.c?view=diff&rev=386989&r1=386988&r2=386989
==============================================================================
--- team/dlee/unload-order/tests/test_res_stasis.c (original)
+++ team/dlee/unload-order/tests/test_res_stasis.c Tue Apr 30 10:59:23 2013
@@ -176,11 +176,13 @@
 	AST_TEST_UNREGISTER(app_invoke_dne);
 	AST_TEST_UNREGISTER(app_invoke_one);
 	AST_TEST_UNREGISTER(app_replaced);
+	stasis_app_unref();
 	return 0;
 }
 
 static int load_module(void)
 {
+	stasis_app_ref();
 	AST_TEST_REGISTER(app_replaced);
 	AST_TEST_REGISTER(app_invoke_one);
 	AST_TEST_REGISTER(app_invoke_dne);




More information about the asterisk-commits mailing list