[asterisk-commits] dlee: branch dlee/shutdown-deux r389546 - in /team/dlee/shutdown-deux: includ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu May 23 09:04:36 CDT 2013
Author: dlee
Date: Thu May 23 09:04:32 2013
New Revision: 389546
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389546
Log:
A shutdown fix that doesn't suck
Modified:
team/dlee/shutdown-deux/include/asterisk.h
team/dlee/shutdown-deux/include/asterisk/stasis.h
team/dlee/shutdown-deux/main/app.c
team/dlee/shutdown-deux/main/asterisk.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.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/include/asterisk.h?view=diff&rev=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/include/asterisk.h (original)
+++ team/dlee/shutdown-deux/include/asterisk.h Thu May 23 09:04:32 2013
@@ -90,6 +90,22 @@
int ast_register_atexit(void (*func)(void));
/*!
+ * \since 12
+ * \brief Register a function to be executed before Asterisk gracefully exits.
+ *
+ * If Asterisk is immediately shutdown (core stop now, or sending the TERM
+ * signal), the callback is not run. When the callbacks are run, they are run in
+ * sequence with ast_register_atexit() callbacks, in the reverse order of
+ * registration.
+ *
+ * \param func The callback function to use.
+ *
+ * \retval 0 on success.
+ * \retval -1 on error.
+ */
+int ast_register_cleanup(void (*func)(void));
+
+/*!
* \brief Unregister a function registered with ast_register_atexit().
* \param func The callback function to unregister.
*/
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=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/include/asterisk/stasis.h (original)
+++ team/dlee/shutdown-deux/include/asterisk/stasis.h Thu May 23 09:04:32 2013
@@ -633,12 +633,6 @@
/*! @{ */
/*!
- * \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.
@@ -647,9 +641,7 @@
#define STASIS_MESSAGE_TYPE_DEFN(name) \
static struct stasis_message_type *_priv_ ## name; \
struct stasis_message_type *name(void) { \
- if (_priv_ ## name == NULL) { \
- stasis_log_bad_type_access(#name); \
- } \
+ ast_assert(_priv_ ## name != NULL); \
return _priv_ ## name; \
}
@@ -701,25 +693,6 @@
*/
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/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/shutdown-deux/main/app.c?view=diff&rev=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/main/app.c (original)
+++ team/dlee/shutdown-deux/main/app.c Thu May 23 09:04:32 2013
@@ -2723,24 +2723,19 @@
return NULL;
}
-static void topic_shutdown(void)
+static void app_cleanup(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);
+ ast_register_cleanup(app_cleanup);
if (STASIS_MESSAGE_TYPE_INIT(stasis_mwi_state_type) != 0) {
return -1;
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=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/main/asterisk.c (original)
+++ team/dlee/shutdown-deux/main/asterisk.c Thu May 23 09:04:32 2013
@@ -314,6 +314,7 @@
struct ast_atexit {
void (*func)(void);
+ int is_cleanup;
AST_LIST_ENTRY(ast_atexit) list;
};
@@ -1065,22 +1066,17 @@
}
/*! \brief Cleanup the \ref stasis system level items */
-static void topic_shutdown(void)
-{
- ao2_cleanup(system_topic);
+static void stasis_system_topic_cleanup(void)
+{
+ ao2_ref(system_topic, -1);
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(topic_shutdown);
- stasis_register_atexit(message_shutdown);
+ ast_register_cleanup(stasis_system_topic_cleanup);
system_topic = stasis_topic_create("ast_system");
if (!system_topic) {
@@ -1093,13 +1089,13 @@
return 0;
}
-static void ast_run_atexits(void)
+static void ast_run_atexits(int run_cleanups)
{
struct ast_atexit *ae;
AST_LIST_LOCK(&atexits);
while ((ae = AST_LIST_REMOVE_HEAD(&atexits, list))) {
- if (ae->func) {
+ if (ae->func && (!ae->is_cleanup || run_cleanups)) {
ae->func();
}
ast_free(ae);
@@ -1121,7 +1117,7 @@
AST_LIST_TRAVERSE_SAFE_END;
}
-int ast_register_atexit(void (*func)(void))
+static int register_atexit(void (*func)(void), int is_cleanup)
{
struct ast_atexit *ae;
@@ -1130,6 +1126,7 @@
return -1;
}
ae->func = func;
+ ae->is_cleanup = is_cleanup;
AST_LIST_LOCK(&atexits);
__ast_unregister_atexit(func);
@@ -1137,6 +1134,16 @@
AST_LIST_UNLOCK(&atexits);
return 0;
+}
+
+int ast_register_atexit(void (*func)(void))
+{
+ return register_atexit(func, 0);
+}
+
+int ast_register_cleanup(void (*func)(void))
+{
+ return register_atexit(func, 1);
}
void ast_unregister_atexit(void (*func)(void))
@@ -1902,8 +1909,9 @@
static void really_quit(int num, shutdown_nice_t niceness, int restart)
{
int active_channels;
-
- if (niceness >= SHUTDOWN_NICE) {
+ int run_cleanups = niceness >= SHUTDOWN_NICE;
+
+ if (run_cleanups) {
ast_module_shutdown();
}
@@ -1961,7 +1969,7 @@
active_channels ? "uncleanly" : "cleanly", num);
ast_verb(0, "Executing last minute cleanups\n");
- ast_run_atexits();
+ ast_run_atexits(run_cleanups);
ast_debug(1, "Asterisk ending (%d).\n", num);
if (ast_socket > -1) {
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=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/main/channel.c (original)
+++ team/dlee/shutdown-deux/main/channel.c Thu May 23 09:04:32 2013
@@ -8572,7 +8572,6 @@
static void channels_shutdown(void)
{
-
free_channelvars();
ast_data_unregister(NULL);
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=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/main/devicestate.c (original)
+++ team/dlee/shutdown-deux/main/devicestate.c Thu May 23 09:04:32 2013
@@ -772,24 +772,19 @@
return device_state->cache_id;
}
-static void topic_shutdown(void)
+static void devstate_cleanup(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);
+ ast_register_cleanup(devstate_cleanup);
device_state_topic_all = stasis_topic_create("ast_device_state_topic");
if (!device_state_topic_all) {
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=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/main/named_acl.c (original)
+++ team/dlee/shutdown-deux/main/named_acl.c Thu May 23 09:04:32 2013
@@ -360,7 +360,7 @@
/*! \brief Message type for named ACL changes */
STASIS_MESSAGE_TYPE_DEFN(ast_named_acl_change_type);
-static void message_shutdown(void)
+static void acl_stasis_cleanup(void)
{
STASIS_MESSAGE_TYPE_CLEANUP(ast_named_acl_change_type);
}
@@ -371,7 +371,7 @@
*/
static void ast_acl_stasis_init(void)
{
- stasis_register_atexit(message_shutdown);
+ ast_register_cleanup(acl_stasis_cleanup);
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=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/main/presencestate.c (original)
+++ team/dlee/shutdown-deux/main/presencestate.c Thu May 23 09:04:32 2013
@@ -310,23 +310,18 @@
return presence_state->provider;
}
-static void topic_cleanup(void)
+static void presence_state_engine_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);
+ ast_register_cleanup(presence_state_engine_cleanup);
if (STASIS_MESSAGE_TYPE_INIT(ast_presence_state_message_type) != 0) {
return -1;
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=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/main/security_events.c (original)
+++ team/dlee/shutdown-deux/main/security_events.c Thu May 23 09:04:32 2013
@@ -54,21 +54,17 @@
/*! \brief Message type for security events */
STASIS_MESSAGE_TYPE_DEFN(ast_security_event_type);
-static void topic_cleanup(void)
+static void security_stasis_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);
+ ast_register_cleanup(security_stasis_cleanup);
security_topic = stasis_topic_create("ast_security");
if (!security_topic) {
@@ -78,6 +74,7 @@
if (STASIS_MESSAGE_TYPE_INIT(ast_security_event_type)) {
return -1;
}
+
return 0;
}
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=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/main/stasis.c (original)
+++ team/dlee/shutdown-deux/main/stasis.c Thu May 23 09:04:32 2013
@@ -32,10 +32,9 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/astobj2.h"
-#include "asterisk/linkedlists.h"
#include "asterisk/stasis.h"
+#include "asterisk/threadpool.h"
#include "asterisk/taskprocessor.h"
-#include "asterisk/threadpool.h"
#include "asterisk/utils.h"
#include "asterisk/uuid.h"
@@ -49,14 +48,6 @@
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 {
@@ -628,50 +619,17 @@
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;
+}
+
+/*! \brief Cleanup function for graceful shutdowns */
+static void stasis_cleanup(void)
+{
STASIS_MESSAGE_TYPE_CLEANUP(stasis_subscription_change_type);
-
- run_atexits();
}
int stasis_init(void)
@@ -688,6 +646,7 @@
};
ast_register_atexit(stasis_exit);
+ ast_register_cleanup(stasis_cleanup);
if (pool) {
ast_log(LOG_ERROR, "Stasis double-initialized\n");
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=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/main/stasis_bridging.c (original)
+++ team/dlee/shutdown-deux/main/stasis_bridging.c Thu May 23 09:04:32 2013
@@ -319,7 +319,7 @@
return ast_json_ref(json_chan);
}
-static void topic_shutdown(void)
+static void stasis_bridging_cleanup(void)
{
ao2_cleanup(bridge_topic_all);
bridge_topic_all = NULL;
@@ -327,10 +327,7 @@
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);
@@ -350,8 +347,7 @@
int ast_stasis_bridging_init(void)
{
- ast_register_atexit(topic_shutdown);
- stasis_register_atexit(message_shutdown);
+ ast_register_cleanup(stasis_bridging_cleanup);
STASIS_MESSAGE_TYPE_INIT(ast_bridge_snapshot_type);
STASIS_MESSAGE_TYPE_INIT(ast_bridge_merge_message_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=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/main/stasis_cache.c (original)
+++ team/dlee/shutdown-deux/main/stasis_cache.c Thu May 23 09:04:32 2013
@@ -446,7 +446,7 @@
return caching_topic;
}
-static void message_shutdown(void)
+static void stasis_cache_cleanup(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)
{
- stasis_register_atexit(message_shutdown);
+ ast_register_cleanup(stasis_cache_cleanup);
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=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/main/stasis_channels.c (original)
+++ team/dlee/shutdown-deux/main/stasis_channels.c Thu May 23 09:04:32 2013
@@ -501,15 +501,11 @@
strcmp(old_snapshot->caller_name, new_snapshot->caller_name) == 0;
}
-static void topic_shutdown(void)
+static void stasis_channels_cleanup(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);
@@ -521,8 +517,7 @@
void ast_stasis_channels_init(void)
{
- ast_register_atexit(topic_shutdown);
- stasis_register_atexit(message_shutdown);
+ ast_register_cleanup(stasis_channels_cleanup);
STASIS_MESSAGE_TYPE_INIT(ast_channel_snapshot_type);
STASIS_MESSAGE_TYPE_INIT(ast_channel_dial_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=389546&r1=389545&r2=389546
==============================================================================
--- team/dlee/shutdown-deux/main/test.c (original)
+++ team/dlee/shutdown-deux/main/test.c Thu May 23 09:04:32 2013
@@ -993,14 +993,10 @@
#ifdef TEST_FRAMEWORK
-static void topic_cleanup(void)
+static void test_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);
}
@@ -1009,8 +1005,7 @@
int ast_test_init(void)
{
#ifdef TEST_FRAMEWORK
- ast_register_atexit(topic_cleanup);
- stasis_register_atexit(message_cleanup);
+ ast_register_cleanup(test_cleanup);
/* Create stasis topic */
test_suite_topic = stasis_topic_create("test_suite_topic");
More information about the asterisk-commits
mailing list