<p>Joshua Colp has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14419">View Change</a></p><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;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/19/14419/1</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 b9ccc15..1a60f85 100644</span><br><span>--- a/res/res_sorcery_config.c</span><br><span>+++ b/res/res_sorcery_config.c</span><br><span>@@ -64,6 +64,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>@@ -312,7 +315,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>@@ -330,6 +333,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>@@ -363,6 +369,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>@@ -375,6 +382,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>@@ -395,6 +403,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>@@ -405,10 +414,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/+/14419">change 14419</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/+/14419"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: If2e05a017570f1f5f4f49120da09601e9ecdf9ed </div>
<div style="display:none"> Gerrit-Change-Number: 14419 </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>