[Asterisk-code-review] res_sorcery_config: Always reload configuration on errors. (asterisk[16])

Joshua Colp asteriskteam at digium.com
Wed May 20 10:49:50 CDT 2020


Joshua Colp has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14436 )

Change subject: res_sorcery_config: Always reload configuration on errors.
......................................................................

res_sorcery_config: Always reload configuration on errors.

When a configuration file in Asterisk is loaded
information about it is stored such that on a
reload it is not reloaded if nothing has changed.
This can be problematic when an error exists in
a configuration file in PJSIP since the error
will be output at start and not subsequently on
reload if the file is unchanged.

This change makes it so that if an error is
encountered when res_sorcery_config is loading
a configuration file a reload will always read
in the configuration file, allowing the error
to be seen easier.

Change-Id: If2e05a017570f1f5f4f49120da09601e9ecdf9ed
---
M res/res_sorcery_config.c
1 file changed, 12 insertions(+), 1 deletion(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Joshua Colp: Approved for Submit



diff --git a/res/res_sorcery_config.c b/res/res_sorcery_config.c
index 6029789..67679a2 100644
--- a/res/res_sorcery_config.c
+++ b/res/res_sorcery_config.c
@@ -62,6 +62,9 @@
 	/*! \brief Enable enforcement of a single configuration object of this type */
 	unsigned int single_object:1;
 
+	/*! \brief Configuration is invalid in some way, force reload */
+	unsigned int configuration_invalid:1;
+
 	/*! \brief Filename of the configuration file */
 	char filename[];
 };
@@ -310,7 +313,7 @@
 static void sorcery_config_internal_load(void *data, const struct ast_sorcery *sorcery, const char *type, unsigned int reload)
 {
 	struct sorcery_config *config = data;
-	struct ast_flags flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+	struct ast_flags flags = { reload && !config->configuration_invalid ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 	struct ast_config *cfg = ast_config_load2(config->filename, config->uuid, flags);
 	struct ast_category *category = NULL;
 	RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);
@@ -328,6 +331,9 @@
 		return;
 	}
 
+	/* When parsing the configuration assume it is valid until proven otherwise */
+	config->configuration_invalid = 0;
+
 	if (!config->buckets) {
 		while ((category = ast_category_browse_filtered(cfg, NULL, category, NULL))) {
 
@@ -361,6 +367,7 @@
 		ast_log(LOG_ERROR, "Config file '%s' could not be loaded; configuration contains more than one object of type '%s'\n",
 			config->filename, type);
 		ast_config_destroy(cfg);
+		config->configuration_invalid = 1;
 		return;
 	}
 
@@ -373,6 +380,7 @@
 		ast_log(LOG_ERROR, "Could not create bucket for new objects from '%s', keeping existing objects\n",
 			config->filename);
 		ast_config_destroy(cfg);
+		config->configuration_invalid = 1; /* Not strictly invalid but we want to try next time */
 		return;
 	}
 
@@ -393,6 +401,7 @@
 			ast_log(LOG_ERROR, "Config file '%s' could not be loaded; configuration contains a duplicate object: '%s' of type '%s'\n",
 				config->filename, id, type);
 			ast_config_destroy(cfg);
+			config->configuration_invalid = 1;
 			return;
 		}
 
@@ -403,10 +412,12 @@
 				ast_log(LOG_ERROR, "Config file '%s' could not be loaded due to error with object '%s' of type '%s'\n",
 					config->filename, id, type);
 				ast_config_destroy(cfg);
+				config->configuration_invalid = 1;
 				return;
 			} else {
 				ast_log(LOG_ERROR, "Could not create an object of type '%s' with id '%s' from configuration file '%s'\n",
 					type, id, config->filename);
+				config->configuration_invalid = 1;
 			}
 
 			ao2_cleanup(obj);

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: If2e05a017570f1f5f4f49120da09601e9ecdf9ed
Gerrit-Change-Number: 14436
Gerrit-PatchSet: 2
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200520/2827c385/attachment-0001.html>


More information about the asterisk-code-review mailing list