]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Prevent unload of modules which implement an Optional API.
authorCorey Farrell <git@cfware.com>
Thu, 2 Nov 2017 00:46:11 +0000 (20:46 -0400)
committerCorey Farrell <git@cfware.com>
Thu, 2 Nov 2017 00:46:11 +0000 (20:46 -0400)
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

funcs/func_periodic_hook.c
res/res_agi.c
res/res_http_websocket.c
res/res_monitor.c
res/res_pktccops.c
res/res_smdi.c
res/res_statsd.c

index f8e79b326af091b45d1706c158a5e145aca87302..0ab3d6b8b6f6480a5c51266194cd7da5ffd55c44 100644 (file)
@@ -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;
 }
 
index 466063557b32a08549e5e2cc4a1e8ec2d8093a3c..91f270cd9b169f3abac81c74575d34439cf5739c 100644 (file)
@@ -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;
 }
 
index 60332f591dc63f8077c2d40706d41cac549bb361..8e9aae9dded13b7e66a9f8ff283b8178e15f2b9d 100644 (file)
@@ -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;
 }
 
index 3e3611b3615ff1fc80ac14ae61dcd89b2c5337bd..aed5a26b97e295716fe8db7da241d04b6e70611d 100644 (file)
@@ -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;
 }
 
index 4f694487543f2b0e11fee23a8723d61237bc8ebf..e8d266cdadeee300759718f7ef49636a988e5c9f 100644 (file)
@@ -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;
 }
 
index 4d7240104273c8de55744ae0876e2eb4049977f3..0edabb83c516a894e33ccdb2ffe1d72de11451f4 100644 (file)
@@ -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;
 }
 
index 3d7dd168400f980c1a80c90ddeff599e746712e9..aee0bcd5a00a97df4525d20a8c25cd1a09f4e7ed 100644 (file)
@@ -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;
 }