[Asterisk-code-review] loader: Output warnings for deprecated modules. (asterisk[16])

Joshua Colp asteriskteam at digium.com
Wed Mar 10 09:05:25 CST 2021


Joshua Colp has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15625 )


Change subject: loader: Output warnings for deprecated modules.
......................................................................

loader: Output warnings for deprecated modules.

Using the information from the MODULEINFO XML we can
now output useful information at the end of module
loading for deprecated modules. This includes the
version it was deprecated in, the version it will be
removed in, and the replacement if available.

ASTERISK-29339

Change-Id: I2080dab97d2186be94c421b41dabf6d79a11611a
---
M main/loader.c
1 file changed, 92 insertions(+), 31 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/25/15625/1

diff --git a/main/loader.c b/main/loader.c
index 033693e..d93d6f0 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -153,37 +153,7 @@
 static struct ast_vector_string startup_errors;
 static struct ast_str *startup_error_builder;
 
-#if defined(HAVE_PERMANENT_DLOPEN)
-#define FIRST_DLOPEN 999
-
-struct ao2_container *info_list = NULL;
-
-struct info_list_obj {
-	const struct ast_module_info *info;
-	int dlopened;
-	char name[0];
-};
-
-static struct info_list_obj *info_list_obj_alloc(const char *name,
-	const struct ast_module_info *info)
-{
-	struct info_list_obj *new_entry;
-
-	new_entry = ao2_alloc(sizeof(*new_entry) + strlen(name) + 1, NULL);
-
-	if (!new_entry) {
-		return NULL;
-	}
-
-	strcpy(new_entry->name, name); /* SAFE */
-	new_entry->info = info;
-	new_entry->dlopened = FIRST_DLOPEN;
-
-	return new_entry;
-}
-
-AO2_STRING_FIELD_CMP_FN(info_list_obj, name)
-
+#if defined(HAVE_PERMANENT_DLOPEN) || defined(AST_XML_DOCS)
 static char *get_name_from_resource(const char *resource)
 {
 	int len;
@@ -219,6 +189,38 @@
 	/* Unable to allocate memory. */
 	return NULL;
 }
+#endif
+
+#if defined(HAVE_PERMANENT_DLOPEN)
+#define FIRST_DLOPEN 999
+
+struct ao2_container *info_list = NULL;
+
+struct info_list_obj {
+	const struct ast_module_info *info;
+	int dlopened;
+	char name[0];
+};
+
+static struct info_list_obj *info_list_obj_alloc(const char *name,
+	const struct ast_module_info *info)
+{
+	struct info_list_obj *new_entry;
+
+	new_entry = ao2_alloc(sizeof(*new_entry) + strlen(name) + 1, NULL);
+
+	if (!new_entry) {
+		return NULL;
+	}
+
+	strcpy(new_entry->name, name); /* SAFE */
+	new_entry->info = info;
+	new_entry->dlopened = FIRST_DLOPEN;
+
+	return new_entry;
+}
+
+AO2_STRING_FIELD_CMP_FN(info_list_obj, name)
 
 static void manual_mod_reg(const void *lib, const char *resource)
 {
@@ -2341,6 +2343,10 @@
 	int res = 0;
 	int modulecount = 0;
 	int i;
+	struct ast_module *cur;
+#ifdef AST_XML_DOCS
+	struct ast_str *warning_msg;
+#endif
 
 	ast_verb(1, "Asterisk Dynamic Loader Starting:\n");
 
@@ -2388,6 +2394,61 @@
 		ast_free(order);
 	}
 
+#ifdef AST_XML_DOCS
+	warning_msg = ast_str_create(512);
+#endif
+
+	AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
+#ifdef AST_XML_DOCS
+		char *mod_name = NULL;
+		struct ast_xml_xpath_results *results;
+#endif
+
+		if (!cur->flags.running || cur->flags.declined ||
+			cur->info->support_level != AST_MODULE_SUPPORT_DEPRECATED) {
+			continue;
+		}
+
+#ifdef AST_XML_DOCS
+		mod_name = get_name_from_resource(cur->resource);
+		if (!warning_msg || !mod_name) {
+			ast_log(LOG_WARNING, "The deprecated module '%s' has been loaded and is running, it may be removed in a future version\n", cur->resource);
+			ast_free(mod_name);
+			continue;
+		}
+
+		ast_str_reset(warning_msg);
+
+		ast_str_set(&warning_msg, -1, "The deprecated module '%s' has been loaded and is running", cur->resource);
+
+		results = ast_xmldoc_query("/docs/module[@name='%s']/deprecated_in", mod_name);
+		if (results && !ast_strlen_zero(ast_xml_get_text(ast_xml_xpath_get_first_result(results)))) {
+			ast_str_append(&warning_msg, -1, ", it was deprecated in version '%s'", ast_xml_get_text(ast_xml_xpath_get_first_result(results)));
+		}
+		ast_xml_xpath_results_free(results);
+
+		results = ast_xmldoc_query("/docs/module[@name='%s']/removed_in", mod_name);
+		if (results && !ast_strlen_zero(ast_xml_get_text(ast_xml_xpath_get_first_result(results)))) {
+			ast_str_append(&warning_msg, -1, ", it will be removed in version '%s'", ast_xml_get_text(ast_xml_xpath_get_first_result(results)));
+		}
+		ast_xml_xpath_results_free(results);
+
+		results = ast_xmldoc_query("/docs/module[@name='%s']/replacement", mod_name);
+		if (results && !ast_strlen_zero(ast_xml_get_text(ast_xml_xpath_get_first_result(results)))) {
+			ast_str_append(&warning_msg, -1, ", it has been replaced by '%s'", ast_xml_get_text(ast_xml_xpath_get_first_result(results)));
+		}
+		ast_xml_xpath_results_free(results);
+
+		ast_str_append(&warning_msg, -1, ", it is recommended to move away from using this module if you are doing so.");
+		ast_log(LOG_WARNING, "%s\n", ast_str_buffer(warning_msg));
+
+		ast_free(mod_name);
+#else
+		ast_log(LOG_WARNING, "The deprecated module '%s' has been loaded and is running, it may be removed in a future version\n", cur->resource);
+#endif
+	}
+
+
 	AST_DLLIST_UNLOCK(&module_list);
 
 	for (i = 0; i < AST_VECTOR_SIZE(&startup_errors); i++) {

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I2080dab97d2186be94c421b41dabf6d79a11611a
Gerrit-Change-Number: 15625
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210310/c2130032/attachment-0001.html>


More information about the asterisk-code-review mailing list