]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_sorcery_config: Always reload configuration on errors.
authorJoshua C. Colp <jcolp@sangoma.com>
Tue, 19 May 2020 12:55:32 +0000 (09:55 -0300)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Wed, 20 May 2020 15:02:00 +0000 (10:02 -0500)
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

res/res_sorcery_config.c

index b9ccc15960506cfaf61e29bcc211000dc167f5da..1a60f853345ab7aa390fb5c45cdfc80d59dc8071 100644 (file)
@@ -64,6 +64,9 @@ struct sorcery_config {
        /*! \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[];
 };
@@ -312,7 +315,7 @@ static int sorcery_is_configuration_met(const struct ast_sorcery *sorcery, const
 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);
@@ -330,6 +333,9 @@ static void sorcery_config_internal_load(void *data, const struct ast_sorcery *s
                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))) {
 
@@ -363,6 +369,7 @@ static void sorcery_config_internal_load(void *data, const struct ast_sorcery *s
                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;
        }
 
@@ -375,6 +382,7 @@ static void sorcery_config_internal_load(void *data, const struct ast_sorcery *s
                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;
        }
 
@@ -395,6 +403,7 @@ static void sorcery_config_internal_load(void *data, const struct ast_sorcery *s
                        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;
                }
 
@@ -405,10 +414,12 @@ static void sorcery_config_internal_load(void *data, const struct ast_sorcery *s
                                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);