[Asterisk-code-review] loader: Allow declined modules to be unloaded. (asterisk[master])

N A asteriskteam at digium.com
Thu Dec 8 15:47:06 CST 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19657 )


Change subject: loader: Allow declined modules to be unloaded.
......................................................................

loader: Allow declined modules to be unloaded.

Currently, if a module declines to load, dlopen is called
to register the module but dlclose never gets called.
Furthermore, loader.c currently doesn't allow dlclose
to ever get called on the module, since it declined to
load and the unload function bails early in this case.

This can be problematic if a module is updated, since the
new module cannot be loaded into memory since we haven't
closed all references to it. To fix this, we now allow
modules to be unloaded, even if they never "loaded" in
Asterisk itself, so that dlclose is called and the module
can be properly cleaned up, allowing the updated module
to be loaded from scratch next time.

ASTERISK-30345 #close

Change-Id: Ifc743aadfa85ebe3284e02a63e124dafa64988d5
---
M main/loader.c
1 file changed, 36 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/19657/1

diff --git a/main/loader.c b/main/loader.c
index 549e3f0..2b69075 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -1241,8 +1241,16 @@
 	}
 
 	if (!mod->flags.running || mod->flags.declined) {
-		ast_log(LOG_WARNING, "Unload failed, '%s' is not loaded.\n", resource_name);
-		error = 1;
+		/* If the user asks to unload a module that didn't load, obey.
+		 * Otherwise, we never dlclose() modules that fail to load,
+		 * which means if the module (shared object) is updated,
+		 * we can't load the updated module since we never dlclose()'d it.
+		 * Accordingly, obey the unload request so we can load the module
+		 * from scratch next time.
+		 */
+		ast_log(LOG_WARNING, "Unloading module '%s' that was never loaded\n", resource_name);
+		error = 0;
+		goto exit; /* Skip all the intervening !error checks, only the last one is relevant. */
 	}
 
 	if (!error && (mod->usecount > 0)) {
@@ -1284,6 +1292,7 @@
 	if (!error)
 		mod->flags.running = mod->flags.declined = 0;
 
+exit:
 	AST_DLLIST_UNLOCK(&module_list);
 
 	if (!error) {

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19657
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ifc743aadfa85ebe3284e02a63e124dafa64988d5
Gerrit-Change-Number: 19657
Gerrit-PatchSet: 1
Gerrit-Owner: N A <asterisk at phreaknet.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20221208/3c26a9ea/attachment.html>


More information about the asterisk-code-review mailing list