]> 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 01:07:15 +0000 (21:07 -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 f459e357683e7306e00b986034f987c4a0e97b1e..0e260c9cad3849a0580548ba7ebbefdb593ceb29 100644 (file)
@@ -490,6 +490,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_info->self);
+       }
+
        return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
 }
 
index d7ea3510c28d0d397ffc059bc46e3cad311d0b44..d104c4362907c5bbdcf9a85677a0314fd2415f53 100644 (file)
@@ -4715,6 +4715,10 @@ static int load_module(void)
                unload_module();
                return AST_MODULE_LOAD_DECLINE;
        }
+
+       /* For Optional API. */
+       ast_module_shutdown_ref(ast_module_info->self);
+
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index f49a3573e59c2d55a29c2e4a39a3202df95db652..2baccc052734d91078d7d60cc33e550048ff5297 100644 (file)
@@ -1439,6 +1439,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_info->self);
+
        return 0;
 }
 
index c4ee674f91f55b4d642b34e00d34654fb55d1725..b7ef2ea888cbf60c507dac56f139814347be3fe5 100644 (file)
@@ -987,6 +987,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_info->self);
+
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index 837e0f5e194783ea993502df92fa5c20b83a10ff..037e533d3caa5742a663a5aa16aac9de684daf3b 100644 (file)
@@ -1474,6 +1474,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_info->self);
+
        return 0;
 }
 
index 9a40227f2db7c203d4fb88e2fc01ae09bb43d846..7b4c42b176ceca75fe4d1d04f96239bb4b4f6ec5 100644 (file)
@@ -1407,6 +1407,10 @@ static int _unload_module(int fromload)
        }
 
        smdi_loaded = 0;
+
+       /* For Optional API. */
+       ast_module_shutdown_ref(ast_module_info->self);
+
        return 0;
 }
 
index eb0dc670296b1869f08628a0b8c2cf6f42c5a80f..b8e4d04758b34bb496839ca08884ac2268e704d2 100644 (file)
@@ -355,6 +355,9 @@ static int load_module(void)
                return AST_MODULE_LOAD_DECLINE;
        }
 
+       /* For Optional API. */
+       ast_module_shutdown_ref(ast_module_info->self);
+
        return AST_MODULE_LOAD_SUCCESS;
 }