[Asterisk-code-review] Prevent unload of modules which implement an Optional API. (asterisk[13])

Jenkins2 asteriskteam at digium.com
Mon Nov 6 09:41:30 CST 2017


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/6959 )

Change subject: Prevent unload of modules which implement an Optional API.
......................................................................

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
---
M funcs/func_periodic_hook.c
M res/res_agi.c
M res/res_http_websocket.c
M res/res_monitor.c
M res/res_pktccops.c
M res/res_smdi.c
M res/res_statsd.c
7 files changed, 26 insertions(+), 0 deletions(-)

Approvals:
  George Joseph: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/funcs/func_periodic_hook.c b/funcs/func_periodic_hook.c
index f459e35..0e260c9 100644
--- a/funcs/func_periodic_hook.c
+++ b/funcs/func_periodic_hook.c
@@ -490,6 +490,11 @@
 
 	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;
 }
 
diff --git a/res/res_agi.c b/res/res_agi.c
index d7ea351..d104c43 100644
--- a/res/res_agi.c
+++ b/res/res_agi.c
@@ -4715,6 +4715,10 @@
 		unload_module();
 		return AST_MODULE_LOAD_DECLINE;
 	}
+
+	/* For Optional API. */
+	ast_module_shutdown_ref(ast_module_info->self);
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c
index f49a357..2baccc0 100644
--- a/res/res_http_websocket.c
+++ b/res/res_http_websocket.c
@@ -1439,6 +1439,9 @@
 	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;
 }
 
diff --git a/res/res_monitor.c b/res/res_monitor.c
index c4ee674..b7ef2ea 100644
--- a/res/res_monitor.c
+++ b/res/res_monitor.c
@@ -987,6 +987,9 @@
 	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;
 }
 
diff --git a/res/res_pktccops.c b/res/res_pktccops.c
index 837e0f5..037e533 100644
--- a/res/res_pktccops.c
+++ b/res/res_pktccops.c
@@ -1474,6 +1474,10 @@
 	}
 	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;
 }
 
diff --git a/res/res_smdi.c b/res/res_smdi.c
index 9a40227..7b4c42b 100644
--- a/res/res_smdi.c
+++ b/res/res_smdi.c
@@ -1407,6 +1407,10 @@
 	}
 
 	smdi_loaded = 0;
+
+	/* For Optional API. */
+	ast_module_shutdown_ref(ast_module_info->self);
+
 	return 0;
 }
 
diff --git a/res/res_statsd.c b/res/res_statsd.c
index eb0dc67..b8e4d04 100644
--- a/res/res_statsd.c
+++ b/res/res_statsd.c
@@ -355,6 +355,9 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
+	/* For Optional API. */
+	ast_module_shutdown_ref(ast_module_info->self);
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 

-- 
To view, visit https://gerrit.asterisk.org/6959
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia07786fe655681aec49cc8d3d96e06483b11f5e6
Gerrit-Change-Number: 6959
Gerrit-PatchSet: 2
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171106/39738f98/attachment.html>


More information about the asterisk-code-review mailing list