<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14437">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_sorcery_config: Always reload configuration on errors.<br><br>When a configuration file in Asterisk is loaded<br>information about it is stored such that on a<br>reload it is not reloaded if nothing has changed.<br>This can be problematic when an error exists in<br>a configuration file in PJSIP since the error<br>will be output at start and not subsequently on<br>reload if the file is unchanged.<br><br>This change makes it so that if an error is<br>encountered when res_sorcery_config is loading<br>a configuration file a reload will always read<br>in the configuration file, allowing the error<br>to be seen easier.<br><br>Change-Id: If2e05a017570f1f5f4f49120da09601e9ecdf9ed<br>---<br>M res/res_sorcery_config.c<br>1 file changed, 12 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_sorcery_config.c b/res/res_sorcery_config.c</span><br><span>index 6029789..67679a2 100644</span><br><span>--- a/res/res_sorcery_config.c</span><br><span>+++ b/res/res_sorcery_config.c</span><br><span>@@ -62,6 +62,9 @@</span><br><span> /*! \brief Enable enforcement of a single configuration object of this type */</span><br><span> unsigned int single_object:1;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /*! \brief Configuration is invalid in some way, force reload */</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int configuration_invalid:1;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \brief Filename of the configuration file */</span><br><span> char filename[];</span><br><span> };</span><br><span>@@ -310,7 +313,7 @@</span><br><span> static void sorcery_config_internal_load(void *data, const struct ast_sorcery *sorcery, const char *type, unsigned int reload)</span><br><span> {</span><br><span> struct sorcery_config *config = data;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_flags flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_flags flags = { reload && !config->configuration_invalid ? CONFIG_FLAG_FILEUNCHANGED : 0 };</span><br><span> struct ast_config *cfg = ast_config_load2(config->filename, config->uuid, flags);</span><br><span> struct ast_category *category = NULL;</span><br><span> RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);</span><br><span>@@ -328,6 +331,9 @@</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* When parsing the configuration assume it is valid until proven otherwise */</span><br><span style="color: hsl(120, 100%, 40%);">+ config->configuration_invalid = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (!config->buckets) {</span><br><span> while ((category = ast_category_browse_filtered(cfg, NULL, category, NULL))) {</span><br><span> </span><br><span>@@ -361,6 +367,7 @@</span><br><span> ast_log(LOG_ERROR, "Config file '%s' could not be loaded; configuration contains more than one object of type '%s'\n",</span><br><span> config->filename, type);</span><br><span> ast_config_destroy(cfg);</span><br><span style="color: hsl(120, 100%, 40%);">+ config->configuration_invalid = 1;</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span>@@ -373,6 +380,7 @@</span><br><span> ast_log(LOG_ERROR, "Could not create bucket for new objects from '%s', keeping existing objects\n",</span><br><span> config->filename);</span><br><span> ast_config_destroy(cfg);</span><br><span style="color: hsl(120, 100%, 40%);">+ config->configuration_invalid = 1; /* Not strictly invalid but we want to try next time */</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span>@@ -393,6 +401,7 @@</span><br><span> ast_log(LOG_ERROR, "Config file '%s' could not be loaded; configuration contains a duplicate object: '%s' of type '%s'\n",</span><br><span> config->filename, id, type);</span><br><span> ast_config_destroy(cfg);</span><br><span style="color: hsl(120, 100%, 40%);">+ config->configuration_invalid = 1;</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span>@@ -403,10 +412,12 @@</span><br><span> ast_log(LOG_ERROR, "Config file '%s' could not be loaded due to error with object '%s' of type '%s'\n",</span><br><span> config->filename, id, type);</span><br><span> ast_config_destroy(cfg);</span><br><span style="color: hsl(120, 100%, 40%);">+ config->configuration_invalid = 1;</span><br><span> return;</span><br><span> } else {</span><br><span> ast_log(LOG_ERROR, "Could not create an object of type '%s' with id '%s' from configuration file '%s'\n",</span><br><span> type, id, config->filename);</span><br><span style="color: hsl(120, 100%, 40%);">+ config->configuration_invalid = 1;</span><br><span> }</span><br><span> </span><br><span> ao2_cleanup(obj);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14437">change 14437</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/+/14437"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 17 </div>
<div style="display:none"> Gerrit-Change-Id: If2e05a017570f1f5f4f49120da09601e9ecdf9ed </div>
<div style="display:none"> Gerrit-Change-Number: 14437 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>