[asterisk-commits] rmudgett: trunk r399352 - /trunk/main/config_options.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 18 12:15:58 CDT 2013


Author: rmudgett
Date: Wed Sep 18 12:15:53 2013
New Revision: 399352

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=399352
Log:
Make config framework able to reload module configs with multiple config files.

The config framework is supposed to be able to load configs that come from
multiple config files.  The principle example is chan_sip's sip.conf and
users.conf.  Unfortunately, it only does this correctly on initial load.
This patch causes the module's config to be reloaded entirely if any of
the config files change.

(closes issue ASTERISK-22009)
Reported by: Richard Mudgett

Review: https://reviewboard.asterisk.org/r/2859/

Modified:
    trunk/main/config_options.c

Modified: trunk/main/config_options.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/config_options.c?view=diff&rev=399352&r1=399351&r2=399352
==============================================================================
--- trunk/main/config_options.c (original)
+++ trunk/main/config_options.c Wed Sep 18 12:15:53 2013
@@ -184,7 +184,7 @@
 		}
 		if (!ao2_link(type->internal->opts, opt)
 #ifdef AST_XML_DOCS
-				|| (!info->hidden && 
+				|| (!info->hidden &&
 					!opt->no_doc &&
 					xmldoc_update_config_option(types, info->module, opt->name, type->name, opt->default_val, opt->match_type == ACO_REGEX, opt->type))
 #endif /* AST_XML_DOCS */
@@ -592,34 +592,31 @@
 {
 	struct ast_config *cfg;
 	struct ast_flags cfg_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0, };
-	int res = ACO_PROCESS_OK, x = 0;
+	int res = ACO_PROCESS_OK;
+	int file_count = 0;
 	struct aco_file *file;
+
+	if (!info->internal) {
+		ast_log(LOG_ERROR, "Attempting to process uninitialized aco_info\n");
+		return ACO_PROCESS_ERROR;
+	}
 
 	if (!(info->files[0])) {
 		ast_log(LOG_ERROR, "No filename given, cannot proceed!\n");
 		return ACO_PROCESS_ERROR;
 	}
 
-	if (!info->internal) {
-		ast_log(LOG_ERROR, "Attempting to process uninitialized aco_info\n");
-		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 ACO_PROCESS_ERROR;
 	}
 
-/*
- * XXX ASTERISK-22009 must fix config framework loading of multiple files.
- *
- * A reload with multiple files must reload all files if any
- * file has been touched.
- */
-	while (res != ACO_PROCESS_ERROR && (file = info->files[x++])) {
+	while (res != ACO_PROCESS_ERROR && (file = info->files[file_count++])) {
 		const char *filename = file->filename;
+
 try_alias:
-		if (!(cfg = ast_config_load(filename, cfg_flags))) {
+		cfg = ast_config_load(filename, cfg_flags);
+		if (!cfg || cfg == CONFIG_STATUS_FILEMISSING) {
 			if (file->alias && strcmp(file->alias, filename)) {
 				filename = file->alias;
 				goto try_alias;
@@ -632,20 +629,30 @@
 			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);
+			ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed\n",
+				file->filename);
 			res = ACO_PROCESS_ERROR;
 			break;
-		} else if (cfg == CONFIG_STATUS_FILEMISSING) {
-			if (file->alias && strcmp(file->alias, filename)) {
-				filename = file->alias;
-				goto try_alias;
-			}
-			ast_log(LOG_ERROR, "%s is missing! Cannot load %s\n", file->filename, info->module);
-			res = ACO_PROCESS_ERROR;
-			break;
-		}
-
-		res = internal_process_ast_config(info, file, cfg);
+		}
+
+		/* A file got loaded. */
+		if (reload) {
+			/* Must do any subsequent file loads unconditionally. */
+			reload = 0;
+			ast_clear_flag(&cfg_flags, CONFIG_FLAG_FILEUNCHANGED);
+
+			if (file_count != 1) {
+				/*
+				 * Must restart loading to load all config files since a file
+				 * after the first one changed.
+				 */
+				file_count = 0;
+			} else {
+				res = internal_process_ast_config(info, file, cfg);
+			}
+		} else {
+			res = internal_process_ast_config(info, file, cfg);
+		}
 		ast_config_destroy(cfg);
 	}
 
@@ -653,7 +660,7 @@
 		goto end;
 	}
 
-	if (info->pre_apply_config && (info->pre_apply_config())) {
+	if (info->pre_apply_config && info->pre_apply_config()) {
 		res = ACO_PROCESS_ERROR;
 		goto end;
 	}




More information about the asterisk-commits mailing list