From 9f704b5d59a91879ba30b90b817090b71ca36afe Mon Sep 17 00:00:00 2001 From: Terry Wilson Date: Thu, 7 Jun 2012 20:32:07 +0000 Subject: 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/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@368673 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/config_options.c | 49 ++++++++++++++++++++++++++++++------------------- main/udptl.c | 2 +- 2 files changed, 31 insertions(+), 20 deletions(-) (limited to 'main') diff --git a/main/config_options.c b/main/config_options.c index de89d8ddb..c8fb4ffad 100644 --- a/main/config_options.c +++ b/main/config_options.c @@ -368,7 +368,7 @@ static int apply_config(struct aco_info *info) 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 @@ static int internal_process_ast_config(struct aco_info *info, struct aco_file *f 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 ACO_PROCESS_ERROR; } } - return 0; + return ACO_PROCESS_OK; } -int aco_process_ast_config(struct aco_info *info, struct aco_file *file, struct ast_config *cfg) +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 @@ int aco_process_ast_config(struct aco_info *info, struct aco_file *file, struct }; ao2_cleanup(info->internal->pending); - return 0; + return ACO_PROCESS_OK; error: ao2_cleanup(info->internal->pending); - return -1; + return ACO_PROCESS_ERROR; } -int aco_process_config(struct aco_info *info, int reload) +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; + return ACO_PROCESS_ERROR; } - while (!res && (file = info->files[x++])) { + 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 @@ int aco_process_config(struct aco_info *info, int reload) 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; } diff --git a/main/udptl.c b/main/udptl.c index a550ff16f..e31d9f81c 100644 --- a/main/udptl.c +++ b/main/udptl.c @@ -1411,7 +1411,7 @@ static int removed_options_handler(const struct aco_option *opt, struct ast_vari 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"); } } -- cgit v1.2.3