[asterisk-commits] dlee: branch dlee/shutdown-deux r389540 - in /team/dlee/shutdown-deux: includ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed May 22 22:14:32 CDT 2013
Author: dlee
Date: Wed May 22 22:14:28 2013
New Revision: 389540
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389540
Log:
Another attempt at fixing the shutdown problem
Modified:
team/dlee/shutdown-deux/include/asterisk/security_events.h
team/dlee/shutdown-deux/include/asterisk/stasis.h
team/dlee/shutdown-deux/include/asterisk/stasis_bridging.h
team/dlee/shutdown-deux/include/asterisk/stasis_channels.h
team/dlee/shutdown-deux/main/app.c
team/dlee/shutdown-deux/main/asterisk.c
team/dlee/shutdown-deux/main/bridging.c
team/dlee/shutdown-deux/main/channel.c
team/dlee/shutdown-deux/main/devicestate.c
team/dlee/shutdown-deux/main/named_acl.c
team/dlee/shutdown-deux/main/presencestate.c
team/dlee/shutdown-deux/main/security_events.c
team/dlee/shutdown-deux/main/stasis.c
team/dlee/shutdown-deux/main/stasis_bridging.c
team/dlee/shutdown-deux/main/stasis_cache.c
team/dlee/shutdown-deux/main/stasis_channels.c
team/dlee/shutdown-deux/main/test.c
Modified: team/dlee/shutdown-deux/include/asterisk/security_events.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/include/asterisk/security_events.h?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/include/asterisk/security_events.h (original)
+++ team/dlee/shutdown-deux/include/asterisk/security_events.h Wed May 22 22:14:28 2013
@@ -87,12 +87,6 @@
int ast_security_stasis_init(void);
/*!
- * \brief removes stasis topic/event types for \ref ast_security_topic and \ref ast_security_event_type
- * \since 12
- */
-void ast_security_stasis_cleanup(void);
-
-/*!
* \brief Get the list of required IEs for a given security event sub-type
*
* \param[in] event_type security event sub-type
Modified: team/dlee/shutdown-deux/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/include/asterisk/stasis.h?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/include/asterisk/stasis.h (original)
+++ team/dlee/shutdown-deux/include/asterisk/stasis.h Wed May 22 22:14:28 2013
@@ -633,6 +633,12 @@
/*! @{ */
/*!
+ * \internal
+ * \brief Log a message about invalid attempt to access a type.
+ */
+void stasis_log_bad_type_access(const char *name);
+
+/*!
* \brief Boiler-plate removing macro for defining message types.
*
* \param name Name of message type.
@@ -641,7 +647,9 @@
#define STASIS_MESSAGE_TYPE_DEFN(name) \
static struct stasis_message_type *_priv_ ## name; \
struct stasis_message_type *name(void) { \
- ast_assert(_priv_ ## name != NULL); \
+ if (_priv_ ## name == NULL) { \
+ stasis_log_bad_type_access(#name); \
+ } \
return _priv_ ## name; \
}
@@ -693,6 +701,25 @@
*/
int stasis_cache_init(void);
+/*!
+ * \brief Register a function to be called after the message bus has been
+ * shut down.
+ *
+ * This is specifically to handle shutdown ordering issues when the use of
+ * objects cannot normally be stopped before stopping the message bus itself.
+ *
+ * Specifically, this happens with the core message types during a 'core stop
+ * now', since the modules that use those types are not unloaded. The cleanup
+ * of those types must be deferred until after the message bus has been shut
+ * down.
+ *
+ * \param func Function to call after shutting down the bus.
+ * \return 0 on success.
+ * \return Non-zero on error.
+ * \since 12
+ */
+int stasis_register_atexit(void (*func)(void));
+
/*! @} */
/*!
Modified: team/dlee/shutdown-deux/include/asterisk/stasis_bridging.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/include/asterisk/stasis_bridging.h?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/include/asterisk/stasis_bridging.h (original)
+++ team/dlee/shutdown-deux/include/asterisk/stasis_bridging.h Wed May 22 22:14:28 2013
@@ -220,11 +220,6 @@
struct ast_json *ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot);
/*!
- * \brief Dispose of the stasis bridging topics and message types
- */
-void ast_stasis_bridging_shutdown(void);
-
-/*!
* \brief Initialize the stasis bridging topic and message types
* \retval 0 on success
* \retval -1 on failure
Modified: team/dlee/shutdown-deux/include/asterisk/stasis_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/include/asterisk/stasis_channels.h?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/include/asterisk/stasis_channels.h (original)
+++ team/dlee/shutdown-deux/include/asterisk/stasis_channels.h Wed May 22 22:14:28 2013
@@ -344,11 +344,6 @@
const struct ast_channel_snapshot *new_snapshot);
/*!
- * \brief Dispose of the stasis channel topics and message types
- */
-void ast_stasis_channels_shutdown(void);
-
-/*!
* \brief Initialize the stasis channel topic and message types
*/
void ast_stasis_channels_init(void);
Modified: team/dlee/shutdown-deux/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/app.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/app.c (original)
+++ team/dlee/shutdown-deux/main/app.c Wed May 22 22:14:28 2013
@@ -2723,18 +2723,25 @@
return NULL;
}
-static void app_exit(void)
+static void topic_shutdown(void)
{
ao2_cleanup(mwi_topic_all);
mwi_topic_all = NULL;
mwi_topic_cached = stasis_caching_unsubscribe_and_join(mwi_topic_cached);
- STASIS_MESSAGE_TYPE_CLEANUP(stasis_mwi_state_type);
ao2_cleanup(mwi_topic_pool);
mwi_topic_pool = NULL;
}
+static void message_shutdown(void)
+{
+ STASIS_MESSAGE_TYPE_CLEANUP(stasis_mwi_state_type);
+}
+
int app_init(void)
{
+ ast_register_atexit(topic_shutdown);
+ stasis_register_atexit(message_shutdown);
+
if (STASIS_MESSAGE_TYPE_INIT(stasis_mwi_state_type) != 0) {
return -1;
}
@@ -2751,7 +2758,6 @@
return -1;
}
- ast_register_atexit(app_exit);
return 0;
}
Modified: team/dlee/shutdown-deux/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/asterisk.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/asterisk.c (original)
+++ team/dlee/shutdown-deux/main/asterisk.c Wed May 22 22:14:28 2013
@@ -1065,17 +1065,22 @@
}
/*! \brief Cleanup the \ref stasis system level items */
-static void stasis_system_topic_cleanup(void)
-{
- ao2_ref(system_topic, -1);
+static void topic_shutdown(void)
+{
+ ao2_cleanup(system_topic);
system_topic = NULL;
+}
+
+static void message_shutdown(void)
+{
STASIS_MESSAGE_TYPE_CLEANUP(ast_network_change_type);
}
/*! \brief Initialize the system level items for \ref stasis */
static int stasis_system_topic_init(void)
{
- ast_register_atexit(stasis_system_topic_cleanup);
+ ast_register_atexit(topic_shutdown);
+ stasis_register_atexit(message_shutdown);
system_topic = stasis_topic_create("ast_system");
if (!system_topic) {
@@ -4265,7 +4270,6 @@
}
if (ast_security_stasis_init()) { /* Initialize Security Stasis Topic and Events */
- ast_security_stasis_cleanup();
printf("%s", term_quit());
exit(1);
}
Modified: team/dlee/shutdown-deux/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/bridging.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/bridging.c (original)
+++ team/dlee/shutdown-deux/main/bridging.c Wed May 22 22:14:28 2013
@@ -5810,26 +5810,24 @@
bridges = NULL;
ao2_cleanup(bridge_manager);
bridge_manager = NULL;
- ast_stasis_bridging_shutdown();
}
int ast_bridging_init(void)
{
+ ast_register_atexit(bridge_shutdown);
+
if (ast_stasis_bridging_init()) {
- bridge_shutdown();
return -1;
}
bridge_manager = bridge_manager_create();
if (!bridge_manager) {
- bridge_shutdown();
return -1;
}
bridges = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_MUTEX,
AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE, bridge_sort_cmp, NULL);
if (!bridges) {
- bridge_shutdown();
return -1;
}
@@ -5838,6 +5836,5 @@
/* BUGBUG need AMI action equivalents to the CLI commands. */
ast_cli_register_multiple(bridge_cli, ARRAY_LEN(bridge_cli));
- ast_register_atexit(bridge_shutdown);
return 0;
}
Modified: team/dlee/shutdown-deux/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/channel.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/channel.c (original)
+++ team/dlee/shutdown-deux/main/channel.c Wed May 22 22:14:28 2013
@@ -8572,8 +8572,6 @@
static void channels_shutdown(void)
{
-
- ast_stasis_channels_shutdown();
free_channelvars();
Modified: team/dlee/shutdown-deux/main/devicestate.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/devicestate.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/devicestate.c (original)
+++ team/dlee/shutdown-deux/main/devicestate.c Wed May 22 22:14:28 2013
@@ -772,18 +772,25 @@
return device_state->cache_id;
}
-static void devstate_exit(void)
+static void topic_shutdown(void)
{
ao2_cleanup(device_state_topic_all);
device_state_topic_all = NULL;
device_state_topic_cached = stasis_caching_unsubscribe_and_join(device_state_topic_cached);
- STASIS_MESSAGE_TYPE_CLEANUP(ast_device_state_message_type);
ao2_cleanup(device_state_topic_pool);
device_state_topic_pool = NULL;
}
+static void message_shutdown(void)
+{
+ STASIS_MESSAGE_TYPE_CLEANUP(ast_device_state_message_type);
+}
+
int devstate_init(void)
{
+ ast_register_atexit(topic_shutdown);
+ stasis_register_atexit(message_shutdown);
+
device_state_topic_all = stasis_topic_create("ast_device_state_topic");
if (!device_state_topic_all) {
return -1;
@@ -807,6 +814,5 @@
return -1;
}
- ast_register_atexit(devstate_exit);
return 0;
}
Modified: team/dlee/shutdown-deux/main/named_acl.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/named_acl.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/named_acl.c (original)
+++ team/dlee/shutdown-deux/main/named_acl.c Wed May 22 22:14:28 2013
@@ -360,7 +360,7 @@
/*! \brief Message type for named ACL changes */
STASIS_MESSAGE_TYPE_DEFN(ast_named_acl_change_type);
-static void acl_stasis_shutdown(void)
+static void message_shutdown(void)
{
STASIS_MESSAGE_TYPE_CLEANUP(ast_named_acl_change_type);
}
@@ -371,7 +371,7 @@
*/
static void ast_acl_stasis_init(void)
{
- ast_register_atexit(acl_stasis_shutdown);
+ stasis_register_atexit(message_shutdown);
STASIS_MESSAGE_TYPE_INIT(ast_named_acl_change_type);
}
Modified: team/dlee/shutdown-deux/main/presencestate.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/presencestate.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/presencestate.c (original)
+++ team/dlee/shutdown-deux/main/presencestate.c Wed May 22 22:14:28 2013
@@ -310,17 +310,24 @@
return presence_state->provider;
}
-static void presence_state_engine_cleanup(void)
+static void topic_cleanup(void)
{
ao2_cleanup(presence_state_topic_all);
presence_state_topic_all = NULL;
ao2_cleanup(presence_state_topic_cached);
presence_state_topic_cached = NULL;
+}
+
+static void message_cleanup(void)
+{
STASIS_MESSAGE_TYPE_CLEANUP(ast_presence_state_message_type);
}
int ast_presence_state_engine_init(void)
{
+ ast_register_atexit(topic_cleanup);
+ stasis_register_atexit(message_cleanup);
+
if (STASIS_MESSAGE_TYPE_INIT(ast_presence_state_message_type) != 0) {
return -1;
}
@@ -334,7 +341,6 @@
if (!presence_state_topic_cached) {
return -1;
}
- ast_register_atexit(presence_state_engine_cleanup);
return 0;
}
Modified: team/dlee/shutdown-deux/main/security_events.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/security_events.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/security_events.c (original)
+++ team/dlee/shutdown-deux/main/security_events.c Wed May 22 22:14:28 2013
@@ -54,8 +54,22 @@
/*! \brief Message type for security events */
STASIS_MESSAGE_TYPE_DEFN(ast_security_event_type);
+static void topic_cleanup(void)
+{
+ ao2_cleanup(security_topic);
+ security_topic = NULL;
+}
+
+static void message_cleanup(void)
+{
+ STASIS_MESSAGE_TYPE_CLEANUP(ast_security_event_type);
+}
+
int ast_security_stasis_init(void)
{
+ ast_register_atexit(topic_cleanup);
+ stasis_register_atexit(message_cleanup);
+
security_topic = stasis_topic_create("ast_security");
if (!security_topic) {
return -1;
@@ -65,19 +79,7 @@
return -1;
}
- if (ast_register_atexit(ast_security_stasis_cleanup)) {
- return -1;
- }
-
return 0;
-}
-
-void ast_security_stasis_cleanup(void)
-{
- STASIS_MESSAGE_TYPE_CLEANUP(ast_security_event_type);
-
- ao2_cleanup(security_topic);
- security_topic = NULL;
}
static const struct {
Modified: team/dlee/shutdown-deux/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/stasis.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/stasis.c (original)
+++ team/dlee/shutdown-deux/main/stasis.c Wed May 22 22:14:28 2013
@@ -32,9 +32,10 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/astobj2.h"
+#include "asterisk/linkedlists.h"
#include "asterisk/stasis.h"
+#include "asterisk/taskprocessor.h"
#include "asterisk/threadpool.h"
-#include "asterisk/taskprocessor.h"
#include "asterisk/utils.h"
#include "asterisk/uuid.h"
@@ -48,6 +49,14 @@
static struct ast_threadpool *pool;
STASIS_MESSAGE_TYPE_DEFN(stasis_subscription_change_type);
+
+struct stasis_atexit {
+ void (*func)(void);
+ AST_LIST_ENTRY(stasis_atexit) list;
+};
+
+/*! List of function to run after the message bus has been shutdown */
+static AST_LIST_HEAD_STATIC(atexits, stasis_atexit);
/*! \internal */
struct stasis_topic {
@@ -619,12 +628,50 @@
return topic_pool_entry->topic;
}
+void stasis_log_bad_type_access(const char *name)
+{
+ ast_log(LOG_ERROR, "Use of %s() before init/after destruction\n", name);
+}
+
+int stasis_register_atexit(void (*func)(void))
+{
+ struct stasis_atexit *ae;
+
+ ast_assert(func != NULL);
+
+ ae = ast_calloc(1, sizeof(*ae));
+ if (!ae) {
+ return -1;
+ }
+ ae->func = func;
+
+ AST_LIST_LOCK(&atexits);
+ AST_LIST_INSERT_HEAD(&atexits, ae, list);
+ AST_LIST_UNLOCK(&atexits);
+
+ return 0;
+}
+
+static void run_atexits(void)
+{
+ struct stasis_atexit *ae;
+
+ AST_LIST_LOCK(&atexits);
+ while ((ae = AST_LIST_REMOVE_HEAD(&atexits, list))) {
+ ae->func();
+ ast_free(ae);
+ }
+ AST_LIST_UNLOCK(&atexits);
+}
+
/*! \brief Cleanup function */
static void stasis_exit(void)
{
ast_threadpool_shutdown(pool);
pool = NULL;
STASIS_MESSAGE_TYPE_CLEANUP(stasis_subscription_change_type);
+
+ run_atexits();
}
int stasis_init(void)
Modified: team/dlee/shutdown-deux/main/stasis_bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/stasis_bridging.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/stasis_bridging.c (original)
+++ team/dlee/shutdown-deux/main/stasis_bridging.c Wed May 22 22:14:28 2013
@@ -319,7 +319,7 @@
return ast_json_ref(json_chan);
}
-void ast_stasis_bridging_shutdown(void)
+static void topic_shutdown(void)
{
ao2_cleanup(bridge_topic_all);
bridge_topic_all = NULL;
@@ -327,7 +327,10 @@
bridge_topic_all_cached);
ao2_cleanup(bridge_topic_pool);
bridge_topic_pool = NULL;
-
+}
+
+static void message_shutdown(void)
+{
STASIS_MESSAGE_TYPE_CLEANUP(ast_bridge_snapshot_type);
STASIS_MESSAGE_TYPE_CLEANUP(ast_bridge_merge_message_type);
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_entered_bridge_type);
@@ -347,6 +350,9 @@
int ast_stasis_bridging_init(void)
{
+ ast_register_atexit(topic_shutdown);
+ stasis_register_atexit(message_shutdown);
+
STASIS_MESSAGE_TYPE_INIT(ast_bridge_snapshot_type);
STASIS_MESSAGE_TYPE_INIT(ast_bridge_merge_message_type);
STASIS_MESSAGE_TYPE_INIT(ast_channel_entered_bridge_type);
Modified: team/dlee/shutdown-deux/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/stasis_cache.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/stasis_cache.c (original)
+++ team/dlee/shutdown-deux/main/stasis_cache.c Wed May 22 22:14:28 2013
@@ -446,7 +446,7 @@
return caching_topic;
}
-static void stasis_cache_exit(void)
+static void message_shutdown(void)
{
STASIS_MESSAGE_TYPE_CLEANUP(stasis_cache_clear_type);
STASIS_MESSAGE_TYPE_CLEANUP(stasis_cache_update_type);
@@ -454,7 +454,7 @@
int stasis_cache_init(void)
{
- ast_register_atexit(stasis_cache_exit);
+ stasis_register_atexit(message_shutdown);
if (STASIS_MESSAGE_TYPE_INIT(stasis_cache_clear_type) != 0) {
return -1;
Modified: team/dlee/shutdown-deux/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/stasis_channels.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/stasis_channels.c (original)
+++ team/dlee/shutdown-deux/main/stasis_channels.c Wed May 22 22:14:28 2013
@@ -501,11 +501,15 @@
strcmp(old_snapshot->caller_name, new_snapshot->caller_name) == 0;
}
-void ast_stasis_channels_shutdown(void)
+static void topic_shutdown(void)
{
channel_topic_all_cached = stasis_caching_unsubscribe_and_join(channel_topic_all_cached);
ao2_cleanup(channel_topic_all);
channel_topic_all = NULL;
+}
+
+static void message_shutdown(void)
+{
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_snapshot_type);
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dial_type);
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_varset_type);
@@ -517,6 +521,9 @@
void ast_stasis_channels_init(void)
{
+ ast_register_atexit(topic_shutdown);
+ stasis_register_atexit(message_shutdown);
+
STASIS_MESSAGE_TYPE_INIT(ast_channel_snapshot_type);
STASIS_MESSAGE_TYPE_INIT(ast_channel_dial_type);
STASIS_MESSAGE_TYPE_INIT(ast_channel_varset_type);
Modified: team/dlee/shutdown-deux/main/test.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/test.c?view=diff&rev=389540&r1=389539&r2=389540
==============================================================================
--- team/dlee/shutdown-deux/main/test.c (original)
+++ team/dlee/shutdown-deux/main/test.c Wed May 22 22:14:28 2013
@@ -993,10 +993,14 @@
#ifdef TEST_FRAMEWORK
-static void test_cleanup(void)
+static void topic_cleanup(void)
{
ao2_cleanup(test_suite_topic);
test_suite_topic = NULL;
+}
+
+static void message_cleanup(void)
+{
STASIS_MESSAGE_TYPE_CLEANUP(ast_test_suite_message_type);
}
@@ -1005,6 +1009,9 @@
int ast_test_init(void)
{
#ifdef TEST_FRAMEWORK
+ ast_register_atexit(topic_cleanup);
+ stasis_register_atexit(message_cleanup);
+
/* Create stasis topic */
test_suite_topic = stasis_topic_create("test_suite_topic");
if (!test_suite_topic) {
@@ -1017,7 +1024,6 @@
/* Register cli commands */
ast_cli_register_multiple(test_cli, ARRAY_LEN(test_cli));
- ast_register_atexit(test_cleanup);
#endif
return 0;
More information about the asterisk-commits
mailing list