[svn-commits] twilson: trunk r368673 - in /trunk: apps/ include/asterisk/ main/ tests/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Thu Jun 7 15:32:13 CDT 2012
Author: twilson
Date: Thu Jun 7 15:32:07 2012
New Revision: 368673
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=368673
Log:
Fix reloading an unchanged file with the Config Options API
Adding multiple file support broke reloading an unchanged file. This
adds an enum for return values for the aco_process_* functions and
ensures that the config is not applied if res is not ACO_PROCESS_OK.
Review: https://reviewboard.asterisk.org/r/1979/
Modified:
trunk/apps/app_skel.c
trunk/include/asterisk/config_options.h
trunk/main/config_options.c
trunk/main/udptl.c
trunk/tests/test_config.c
Modified: trunk/apps/app_skel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_skel.c?view=diff&rev=368673&r1=368672&r2=368673
==============================================================================
--- trunk/apps/app_skel.c (original)
+++ trunk/apps/app_skel.c Thu Jun 7 15:32:07 2012
@@ -633,7 +633,7 @@
static int reload_module(void)
{
- if (aco_process_config(&cfg_info, 1)) {
+ if (aco_process_config(&cfg_info, 1) == ACO_PROCESS_ERROR) {
return AST_MODULE_LOAD_DECLINE;
}
@@ -673,7 +673,7 @@
aco_option_register(&cfg_info, "max_number", ACO_EXACT, level_options, NULL, OPT_UINT_T, 0, FLDSET(struct skel_level, max_num));
aco_option_register(&cfg_info, "max_guesses", ACO_EXACT, level_options, NULL, OPT_UINT_T, 1, FLDSET(struct skel_level, max_guesses));
- if (aco_process_config(&cfg_info, 0)) {
+ if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
goto error;
}
Modified: trunk/include/asterisk/config_options.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/config_options.h?view=diff&rev=368673&r1=368672&r2=368673
==============================================================================
--- trunk/include/asterisk/config_options.h (original)
+++ trunk/include/asterisk/config_options.h Thu Jun 7 15:32:07 2012
@@ -386,15 +386,24 @@
/*! \brief Allocate a container to hold config options */
struct ao2_container *aco_option_container_alloc(void);
+/*! \brief Return values for the aco_process functions
+ */
+enum aco_process_status {
+ ACO_PROCESS_OK, /*!< \brief The config was processed and applied */
+ ACO_PROCESS_UNCHANGED, /*!< \brief The config had not been edited and no changes applied */
+ ACO_PROCESS_ERROR, /*!< \brief Their was an error and no changes were applied */
+};
+
/*! \brief Process a config info via the options registered with an aco_info
*
* \param info The config_options_info to be used for handling the config
* \param reload Whether or not this is a reload
*
- * \retval 0 Success
- * \retval -1 Failure
- */
-int aco_process_config(struct aco_info *info, int reload);
+ * \retval ACO_PROCESS_OK Success
+ * \retval ACO_PROCESS_ERROR Failure
+ * \retval ACO_PROCESS_UNCHANGED No change due to unedited config file
+ */
+enum aco_process_status aco_process_config(struct aco_info *info, int reload);
/*! \brief Process config info from an ast_config via options registered with an aco_info
*
@@ -403,10 +412,10 @@
* \param cfg A pointer to a loaded ast_config to parse
* \param reload Whether or not this is a reload
*
- * \retval 0 Success
- * \retval -1 Failure
- */
-int aco_process_ast_config(struct aco_info *info, struct aco_file *file, struct ast_config *cfg);
+ * \retval ACO_PROCESS_OK Success
+ * \retval ACO_PROCESS_ERROR Failure
+ */
+enum aco_process_status aco_process_ast_config(struct aco_info *info, struct aco_file *file, struct ast_config *cfg);
/*! \brief Parse each option defined in a config category
* \param type The aco_type with the options for parsing
Modified: trunk/main/config_options.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/config_options.c?view=diff&rev=368673&r1=368672&r2=368673
==============================================================================
--- trunk/main/config_options.c (original)
+++ trunk/main/config_options.c Thu Jun 7 15:32:07 2012
@@ -368,7 +368,7 @@
return 0;
}
-static int internal_process_ast_config(struct aco_info *info, struct aco_file *file, struct ast_config *cfg)
+static enum aco_process_status internal_process_ast_config(struct aco_info *info, struct aco_file *file, struct ast_config *cfg)
{
const char *cat = NULL;
@@ -376,20 +376,20 @@
int i;
for (i = 0; !ast_strlen_zero(file->preload[i]); i++) {
if (process_category(cfg, info, file, file->preload[i], 1)) {
- return -1;
+ return ACO_PROCESS_ERROR;
}
}
}
while ((cat = ast_category_browse(cfg, cat))) {
if (process_category(cfg, info, file, cat, 0)) {
- return -1;
- }
- }
- return 0;
-}
-
-int aco_process_ast_config(struct aco_info *info, struct aco_file *file, struct ast_config *cfg)
+ return ACO_PROCESS_ERROR;
+ }
+ }
+ return ACO_PROCESS_OK;
+}
+
+enum aco_process_status aco_process_ast_config(struct aco_info *info, struct aco_file *file, struct ast_config *cfg)
{
if (!(info->internal->pending = info->snapshot_alloc())) {
ast_log(LOG_ERROR, "In %s: Could not allocate temporary objects\n", file->filename);
@@ -409,46 +409,46 @@
};
ao2_cleanup(info->internal->pending);
- return 0;
+ return ACO_PROCESS_OK;
error:
ao2_cleanup(info->internal->pending);
- return -1;
-}
-
-int aco_process_config(struct aco_info *info, int reload)
+ return ACO_PROCESS_ERROR;
+}
+
+enum aco_process_status aco_process_config(struct aco_info *info, int reload)
{
struct ast_config *cfg;
struct ast_flags cfg_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0, };
- int res = 0, x = 0;
+ int res = ACO_PROCESS_OK, x = 0;
struct aco_file *file;
if (!(info->files[0])) {
ast_log(LOG_ERROR, "No filename given, cannot proceed!\n");
- return -1;
+ return ACO_PROCESS_ERROR;
}
if (!(info->internal->pending = info->snapshot_alloc())) {
ast_log(LOG_ERROR, "In %s: Could not allocate temporary objects\n", info->module);
- return -1;
- }
-
- while (!res && (file = info->files[x++])) {
+ return ACO_PROCESS_ERROR;
+ }
+
+ while (res != ACO_PROCESS_ERROR && (file = info->files[x++])) {
if (!(cfg = ast_config_load(file->filename, cfg_flags))) {
ast_log(LOG_ERROR, "Unable to load config file '%s'\n", file->filename);
- res = -1;
+ res = ACO_PROCESS_ERROR;
break;
} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
ast_debug(1, "%s was unchanged\n", file->filename);
- res = 0;
+ res = ACO_PROCESS_UNCHANGED;
continue;
} else if (cfg == CONFIG_STATUS_FILEINVALID) {
ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed\n", file->filename);
- res = -1;
+ res = ACO_PROCESS_ERROR;
break;
} else if (cfg == CONFIG_STATUS_FILEMISSING) {
ast_log(LOG_ERROR, "%s is missing! Cannot load %s\n", file->filename, info->module);
- res = -1;
+ res = ACO_PROCESS_ERROR;
break;
}
@@ -456,10 +456,21 @@
ast_config_destroy(cfg);
}
- if (res || (res = ((info->pre_apply_config && info->pre_apply_config()) || apply_config(info)))) {
- ;
- };
-
+ if (res != ACO_PROCESS_OK) {
+ goto end;
+ }
+
+ if (info->pre_apply_config && (info->pre_apply_config())) {
+ res = ACO_PROCESS_ERROR;
+ goto end;
+ }
+
+ if (apply_config(info)) {
+ res = ACO_PROCESS_ERROR;
+ goto end;
+ }
+
+end:
ao2_cleanup(info->internal->pending);
return res;
}
Modified: trunk/main/udptl.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/udptl.c?view=diff&rev=368673&r1=368672&r2=368673
==============================================================================
--- trunk/main/udptl.c (original)
+++ trunk/main/udptl.c Thu Jun 7 15:32:07 2012
@@ -1411,7 +1411,7 @@
static void __ast_udptl_reload(int reload)
{
- if (aco_process_config(&cfg_info, reload)) {
+ if (aco_process_config(&cfg_info, reload) == ACO_PROCESS_ERROR) {
ast_log(LOG_WARNING, "Could not reload udptl config\n");
}
}
Modified: trunk/tests/test_config.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_config.c?view=diff&rev=368673&r1=368672&r2=368673
==============================================================================
--- trunk/tests/test_config.c (original)
+++ trunk/tests/test_config.c Thu Jun 7 15:32:07 2012
@@ -811,7 +811,7 @@
aco_option_register(&cfg_info, "stropt", ACO_EXACT, config_test_conf.types, STR_DEFAULT, OPT_STRINGFIELD_T, 0, STRFLDSET(struct test_item, stropt));
aco_option_register_custom(&cfg_info, "customopt", ACO_EXACT, config_test_conf.types, CUSTOM_DEFAULT, customopt_handler, 0);
- if (aco_process_config(&cfg_info, 0)) {
+ if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
ast_test_status_update(test, "Could not parse config\n");
return AST_TEST_FAIL;
}
More information about the svn-commits
mailing list