[Asterisk-code-review] loader: Perform chained starts when missing dependencies are... (asterisk[master])

Corey Farrell asteriskteam at digium.com
Tue Oct 9 03:59:05 CDT 2018


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/10447


Change subject: loader: Perform chained starts when missing dependencies are started.
......................................................................

loader: Perform chained starts when missing dependencies are started.

After a module is manually loaded recheck the full list of declined
modules.  Determine if any modules that were previously missing
dependencies can now be started.

This is only effective for modules which are loaded but declined for
non-started dependencies.  This has no effect on modules which
previously could not be dlopen'ed due to unresolved symbols, those
modules still must be manually loaded.

Change-Id: I1cfe77a550a036b549ff5c47c05f69eead61f5e3
---
M main/loader.c
1 file changed, 48 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/47/10447/1

diff --git a/main/loader.c b/main/loader.c
index 865346f..deb9aef 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -207,6 +207,8 @@
 		unsigned int running:1;
 		/*! The module has declined to start. */
 		unsigned int declined:1;
+		/*! The module is missing a dependency. */
+		unsigned int missingdep:1;
 		/*! This module is being held open until it's time to shutdown. */
 		unsigned int keepuntilshutdown:1;
 		/*! The module is built-in. */
@@ -1552,6 +1554,8 @@
 		struct module_vector missing;
 		int i;
 
+		/* We only get here if the module is being manually loaded. */
+		mod->flags.missingdep = mod->flags.declined = 1;
 		AST_VECTOR_INIT(&missing, 0);
 		if (module_deps_missing_recursive(mod, &missing)) {
 			module_load_error("%s has one or more unknown dependencies.\n", mod->info->name);
@@ -1675,10 +1679,51 @@
 int ast_load_resource(const char *resource_name)
 {
 	int res;
+
 	AST_DLLIST_LOCK(&module_list);
 	res = load_resource(resource_name, 0, NULL, 0, 0);
-	if (!res) {
+	if (res == AST_MODULE_LOAD_SUCCESS) {
+		struct module_vector missingdeps;
+		struct ast_module *cur;
+
 		ast_test_suite_event_notify("MODULE_LOAD", "Message: %s", resource_name);
+
+		AST_VECTOR_INIT(&missingdeps, 0);
+		AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
+			if (cur->flags.declined && cur->flags.missingdep) {
+				AST_VECTOR_APPEND(&missingdeps, cur);
+			}
+		}
+
+		while (AST_VECTOR_SIZE(&missingdeps)) {
+			int didwork = 0;
+			int i = 0;
+
+			while (i < AST_VECTOR_SIZE(&missingdeps)) {
+				cur = AST_VECTOR_GET(&missingdeps, i);
+				if (!module_deps_reference(cur, NULL)) {
+					cur->flags.declined = cur->flags.missingdep = 0;
+					res = start_resource(cur);
+					if (res == AST_MODULE_LOAD_SUCCESS) {
+						AST_VECTOR_REMOVE(&missingdeps, i, 1);
+						ast_test_suite_event_notify("MODULE_LOAD", "Message: %s",
+							ast_module_name(cur));
+						didwork = 1;
+						continue;
+					}
+				}
+				i++;
+			}
+
+			if (!didwork) {
+				break;
+			}
+		}
+		AST_VECTOR_FREE(&missingdeps);
+
+		/* Report success for load of resource_name even if this cleared the
+		 * missingdep of another module which still failed to start. */
+		res = AST_MODULE_LOAD_SUCCESS;
 	}
 	AST_DLLIST_UNLOCK(&module_list);
 
@@ -1801,6 +1846,7 @@
 
 		if (AST_VECTOR_GET_CMP(&missingdeps, mod, AST_VECTOR_ELEM_DEFAULT_CMP)) {
 			dep->flags.declined = 1;
+			dep->flags.missingdep = 1;
 			if (dep->flags.required) {
 				module_load_error("Cannot load required module %s that depends on %s\n",
 					ast_module_name(dep), ast_module_name(mod));
@@ -1932,6 +1978,7 @@
 			module_load_error("Failed to load %s due to dependencies: %s.\n",
 				ast_module_name(mod),
 				printmissing ? ast_str_buffer(printmissing) : "allocation failure creating list");
+			mod->flags.missingdep = 1;
 			res = resource_list_recursive_decline(resources, mod, &printmissing);
 
 			AST_VECTOR_RESET(&missingdeps, AST_VECTOR_ELEM_CLEANUP_NOOP);

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1cfe77a550a036b549ff5c47c05f69eead61f5e3
Gerrit-Change-Number: 10447
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181009/5ee477dd/attachment.html>


More information about the asterisk-code-review mailing list