[Asterisk-code-review] Fix shutdown crash caused by modules being left open. (asterisk[13])
Corey Farrell
asteriskteam at digium.com
Fri Oct 28 00:13:42 CDT 2016
Corey Farrell has uploaded a new change for review. ( https://gerrit.asterisk.org/4214 )
Change subject: Fix shutdown crash caused by modules being left open.
......................................................................
Fix shutdown crash caused by modules being left open.
It is only safe to run ast_register_cleanup callbacks when all modules
have been unloaded. Previously these callbacks were run during graceful
shutdown, making it possible to crash during shutdown.
ASTERISK-26513 #close
Change-Id: Ibfa635bb688d1227ec54aa211d90d6bd45052e21
---
M include/asterisk/_private.h
M include/asterisk/module.h
M main/asterisk.c
M main/loader.c
4 files changed, 8 insertions(+), 10 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/14/4214/1
diff --git a/include/asterisk/_private.h b/include/asterisk/_private.h
index 9255dc1..d4a0d72 100644
--- a/include/asterisk/_private.h
+++ b/include/asterisk/_private.h
@@ -16,6 +16,7 @@
#define _ASTERISK__PRIVATE_H
int load_modules(unsigned int); /*!< Provided by loader.c */
+int modules_shutdown(void); /*!< Provided by loader.c */
int load_pbx(void); /*!< Provided by pbx.c */
int load_pbx_builtins(void); /*!< Provided by pbx_builtins.c */
int load_pbx_functions_cli(void); /*!< Provided by pbx_functions.c */
diff --git a/include/asterisk/module.h b/include/asterisk/module.h
index 35ee8bb..b92043b 100644
--- a/include/asterisk/module.h
+++ b/include/asterisk/module.h
@@ -228,13 +228,6 @@
*/
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
diff --git a/main/asterisk.c b/main/asterisk.c
index 92993d3..de00f4f 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2140,8 +2140,9 @@
struct ast_json *json_object = NULL;
int run_cleanups = niceness >= SHUTDOWN_NICE;
- if (run_cleanups) {
- ast_module_shutdown();
+ if (run_cleanups && modules_shutdown()) {
+ ast_verb(0, "Some modules could not be unloaded, switching to fast shutdown\n");
+ run_cleanups = 0;
}
if (!restart) {
diff --git a/main/loader.c b/main/loader.c
index 85aeb24..74254b4 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -613,7 +613,7 @@
#endif
-void ast_module_shutdown(void)
+int modules_shutdown(void)
{
struct ast_module *mod;
int somethingchanged = 1, final = 0;
@@ -663,7 +663,10 @@
}
} while (somethingchanged && !final);
+ final = AST_DLLIST_EMPTY(&module_list);
AST_DLLIST_UNLOCK(&module_list);
+
+ return !final;
}
int ast_unload_resource(const char *resource_name, enum ast_module_unload_mode force)
--
To view, visit https://gerrit.asterisk.org/4214
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibfa635bb688d1227ec54aa211d90d6bd45052e21
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Corey Farrell <git at cfware.com>
More information about the asterisk-code-review
mailing list