<p>Joshua Colp has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15625">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">loader: Output warnings for deprecated modules.<br><br>Using the information from the MODULEINFO XML we can<br>now output useful information at the end of module<br>loading for deprecated modules. This includes the<br>version it was deprecated in, the version it will be<br>removed in, and the replacement if available.<br><br>ASTERISK-29339<br><br>Change-Id: I2080dab97d2186be94c421b41dabf6d79a11611a<br>---<br>M main/loader.c<br>1 file changed, 92 insertions(+), 31 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/25/15625/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/loader.c b/main/loader.c</span><br><span>index 033693e..d93d6f0 100644</span><br><span>--- a/main/loader.c</span><br><span>+++ b/main/loader.c</span><br><span>@@ -153,37 +153,7 @@</span><br><span> static struct ast_vector_string startup_errors;</span><br><span> static struct ast_str *startup_error_builder;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#if defined(HAVE_PERMANENT_DLOPEN)</span><br><span style="color: hsl(0, 100%, 40%);">-#define FIRST_DLOPEN 999</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-struct ao2_container *info_list = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-struct info_list_obj {</span><br><span style="color: hsl(0, 100%, 40%);">- const struct ast_module_info *info;</span><br><span style="color: hsl(0, 100%, 40%);">- int dlopened;</span><br><span style="color: hsl(0, 100%, 40%);">- char name[0];</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static struct info_list_obj *info_list_obj_alloc(const char *name,</span><br><span style="color: hsl(0, 100%, 40%);">- const struct ast_module_info *info)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- struct info_list_obj *new_entry;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- new_entry = ao2_alloc(sizeof(*new_entry) + strlen(name) + 1, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!new_entry) {</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- strcpy(new_entry->name, name); /* SAFE */</span><br><span style="color: hsl(0, 100%, 40%);">- new_entry->info = info;</span><br><span style="color: hsl(0, 100%, 40%);">- new_entry->dlopened = FIRST_DLOPEN;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return new_entry;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-AO2_STRING_FIELD_CMP_FN(info_list_obj, name)</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+#if defined(HAVE_PERMANENT_DLOPEN) || defined(AST_XML_DOCS)</span><br><span> static char *get_name_from_resource(const char *resource)</span><br><span> {</span><br><span> int len;</span><br><span>@@ -219,6 +189,38 @@</span><br><span> /* Unable to allocate memory. */</span><br><span> return NULL;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#if defined(HAVE_PERMANENT_DLOPEN)</span><br><span style="color: hsl(120, 100%, 40%);">+#define FIRST_DLOPEN 999</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct ao2_container *info_list = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct info_list_obj {</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_module_info *info;</span><br><span style="color: hsl(120, 100%, 40%);">+ int dlopened;</span><br><span style="color: hsl(120, 100%, 40%);">+ char name[0];</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct info_list_obj *info_list_obj_alloc(const char *name,</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_module_info *info)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct info_list_obj *new_entry;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ new_entry = ao2_alloc(sizeof(*new_entry) + strlen(name) + 1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!new_entry) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ strcpy(new_entry->name, name); /* SAFE */</span><br><span style="color: hsl(120, 100%, 40%);">+ new_entry->info = info;</span><br><span style="color: hsl(120, 100%, 40%);">+ new_entry->dlopened = FIRST_DLOPEN;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return new_entry;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+AO2_STRING_FIELD_CMP_FN(info_list_obj, name)</span><br><span> </span><br><span> static void manual_mod_reg(const void *lib, const char *resource)</span><br><span> {</span><br><span>@@ -2341,6 +2343,10 @@</span><br><span> int res = 0;</span><br><span> int modulecount = 0;</span><br><span> int i;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_module *cur;</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef AST_XML_DOCS</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *warning_msg;</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span> </span><br><span> ast_verb(1, "Asterisk Dynamic Loader Starting:\n");</span><br><span> </span><br><span>@@ -2388,6 +2394,61 @@</span><br><span> ast_free(order);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef AST_XML_DOCS</span><br><span style="color: hsl(120, 100%, 40%);">+ warning_msg = ast_str_create(512);</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_DLLIST_TRAVERSE(&module_list, cur, entry) {</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef AST_XML_DOCS</span><br><span style="color: hsl(120, 100%, 40%);">+ char *mod_name = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_xml_xpath_results *results;</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!cur->flags.running || cur->flags.declined ||</span><br><span style="color: hsl(120, 100%, 40%);">+ cur->info->support_level != AST_MODULE_SUPPORT_DEPRECATED) {</span><br><span style="color: hsl(120, 100%, 40%);">+ continue;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef AST_XML_DOCS</span><br><span style="color: hsl(120, 100%, 40%);">+ mod_name = get_name_from_resource(cur->resource);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!warning_msg || !mod_name) {</span><br><span style="color: hsl(120, 100%, 40%);">+ 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);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(mod_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ continue;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_reset(warning_msg);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_set(&warning_msg, -1, "The deprecated module '%s' has been loaded and is running", cur->resource);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ results = ast_xmldoc_query("/docs/module[@name='%s']/deprecated_in", mod_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (results && !ast_strlen_zero(ast_xml_get_text(ast_xml_xpath_get_first_result(results)))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&warning_msg, -1, ", it was deprecated in version '%s'", ast_xml_get_text(ast_xml_xpath_get_first_result(results)));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_xpath_results_free(results);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ results = ast_xmldoc_query("/docs/module[@name='%s']/removed_in", mod_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (results && !ast_strlen_zero(ast_xml_get_text(ast_xml_xpath_get_first_result(results)))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&warning_msg, -1, ", it will be removed in version '%s'", ast_xml_get_text(ast_xml_xpath_get_first_result(results)));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_xpath_results_free(results);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ results = ast_xmldoc_query("/docs/module[@name='%s']/replacement", mod_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (results && !ast_strlen_zero(ast_xml_get_text(ast_xml_xpath_get_first_result(results)))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&warning_msg, -1, ", it has been replaced by '%s'", ast_xml_get_text(ast_xml_xpath_get_first_result(results)));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_xpath_results_free(results);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&warning_msg, -1, ", it is recommended to move away from using this module if you are doing so.");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "%s\n", ast_str_buffer(warning_msg));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(mod_name);</span><br><span style="color: hsl(120, 100%, 40%);">+#else</span><br><span style="color: hsl(120, 100%, 40%);">+ 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);</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> AST_DLLIST_UNLOCK(&module_list);</span><br><span> </span><br><span> for (i = 0; i < AST_VECTOR_SIZE(&startup_errors); i++) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15625">change 15625</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/15625"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I2080dab97d2186be94c421b41dabf6d79a11611a </div>
<div style="display:none"> Gerrit-Change-Number: 15625 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>