From: Corey Farrell Date: Thu, 2 Nov 2017 00:46:11 +0000 (-0400) Subject: Prevent unload of modules which implement an Optional API. X-Git-Tag: 15.2.0-rc1~184^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec9245174871a7117289e94a07693a07544c5ba0;p=thirdparty%2Fasterisk.git Prevent unload of modules which implement an Optional API. Once an Optional API module is loaded it should stay loaded. Unloading an optional API module runs the risk of a crash if something else is using it. This patch causes all optional API providers to tell the module loader not to unload except at shutdown. ASTERISK-27389 Change-Id: Ia07786fe655681aec49cc8d3d96e06483b11f5e6 --- diff --git a/funcs/func_periodic_hook.c b/funcs/func_periodic_hook.c index f8e79b326a..0ab3d6b8b6 100644 --- a/funcs/func_periodic_hook.c +++ b/funcs/func_periodic_hook.c @@ -488,6 +488,11 @@ static int load_module(void) res = ast_custom_function_register_escalating(&hook_function, AST_CFE_BOTH); + if (!res) { + /* For Optional API. */ + ast_module_shutdown_ref(AST_MODULE_SELF); + } + return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS; } diff --git a/res/res_agi.c b/res/res_agi.c index 466063557b..91f270cd9b 100644 --- a/res/res_agi.c +++ b/res/res_agi.c @@ -4713,6 +4713,10 @@ static int load_module(void) unload_module(); return AST_MODULE_LOAD_DECLINE; } + + /* For Optional API. */ + ast_module_shutdown_ref(AST_MODULE_SELF); + return AST_MODULE_LOAD_SUCCESS; } diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c index 60332f591d..8e9aae9dde 100644 --- a/res/res_http_websocket.c +++ b/res/res_http_websocket.c @@ -1446,6 +1446,9 @@ static int load_module(void) ast_http_uri_link(&websocketuri); websocket_add_protocol_internal("echo", websocket_echo_callback); + /* For Optional API. */ + ast_module_shutdown_ref(AST_MODULE_SELF); + return 0; } diff --git a/res/res_monitor.c b/res/res_monitor.c index 3e3611b361..aed5a26b97 100644 --- a/res/res_monitor.c +++ b/res/res_monitor.c @@ -984,6 +984,9 @@ static int load_module(void) ast_manager_register_xml("PauseMonitor", EVENT_FLAG_CALL, pause_monitor_action); ast_manager_register_xml("UnpauseMonitor", EVENT_FLAG_CALL, unpause_monitor_action); + /* For Optional API. */ + ast_module_shutdown_ref(AST_MODULE_SELF); + return AST_MODULE_LOAD_SUCCESS; } diff --git a/res/res_pktccops.c b/res/res_pktccops.c index 4f69448754..e8d266cdad 100644 --- a/res/res_pktccops.c +++ b/res/res_pktccops.c @@ -1472,6 +1472,10 @@ static int load_module(void) } ast_cli_register_multiple(cli_pktccops, sizeof(cli_pktccops) / sizeof(struct ast_cli_entry)); restart_pktc_thread(); + + /* For Optional API. */ + ast_module_shutdown_ref(AST_MODULE_SELF); + return 0; } diff --git a/res/res_smdi.c b/res/res_smdi.c index 4d72401042..0edabb83c5 100644 --- a/res/res_smdi.c +++ b/res/res_smdi.c @@ -1405,6 +1405,10 @@ static int _unload_module(int fromload) } smdi_loaded = 0; + + /* For Optional API. */ + ast_module_shutdown_ref(AST_MODULE_SELF); + return 0; } diff --git a/res/res_statsd.c b/res/res_statsd.c index 3d7dd16840..aee0bcd5a0 100644 --- a/res/res_statsd.c +++ b/res/res_statsd.c @@ -353,6 +353,9 @@ static int load_module(void) return AST_MODULE_LOAD_DECLINE; } + /* For Optional API. */ + ast_module_shutdown_ref(AST_MODULE_SELF); + return AST_MODULE_LOAD_SUCCESS; }