summaryrefslogtreecommitdiff
path: root/include/asterisk.h
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2013-05-30 17:05:53 +0000
committerDavid M. Lee <dlee@digium.com>2013-05-30 17:05:53 +0000
commitd81c846724f4131e63ded19ae2749ea19ccfe7bc (patch)
tree4629bf19b6b206ba3b6bd894e8cc91eb44ebd9b0 /include/asterisk.h
parentf069ee9681b2def71d211ad3ca65db66b7072eef (diff)
Avoid unnecessary cleanups during immediate shutdown
This patch addresses issues during immediate shutdowns, where modules are not unloaded, but Asterisk atexit handlers are run. In the typical case, this usually isn't a big deal. But the introduction of the Stasis message bus makes it much more likely for asynchronous activity to be happening off in some thread during shutdown. During an immediate shutdown, Asterisk skips unloading modules. But while it is processing the atexit handlers, there is a window of time where some of the core message types have been cleaned up, but the message bus is still running. Specifically, it's still running module subscriptions that might be using the core message types. If a message is received by that subscription in that window, it will attempt to use a message type that has been cleaned up. To solve this problem, this patch introduces ast_register_cleanup(). This function operates identically to ast_register_atexit(), except that cleanup calls are not invoked on an immediate shutdown. All of the core message type and topic cleanup was moved from atexit handlers to cleanup handlers. This ensures that core type and topic cleanup only happens if the modules that used them are first unloaded. This patch also changes the ast_assert() when accessing a cleaned up or uninitialized message type to an error log message. Message type functions are actually NULL safe across the board, so the assert was a bit heavy handed. Especially for anyone with DO_CRASH enabled. Review: https://reviewboard.asterisk.org/r/2562/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@390122 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk.h')
-rw-r--r--include/asterisk.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/asterisk.h b/include/asterisk.h
index 58d2df89c..87ebec032 100644
--- a/include/asterisk.h
+++ b/include/asterisk.h
@@ -90,6 +90,22 @@ int ast_pbx_init(void); /*!< Provided by pbx.c */
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.
*/