summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2007-08-16 21:09:46 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2007-08-16 21:09:46 +0000
commit56b9568164b694a42e88f1f8a31012078b833203 (patch)
tree8fda811f62cb6ffb99847befb7b74b1519ea95ba /main
parentc0060cd99a0a318b504da4c13eee85f3b9043fdc (diff)
Don't reload a configuration file if nothing has changed.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@79747 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r--main/asterisk.c5
-rw-r--r--main/cdr.c12
-rw-r--r--main/config.c219
-rw-r--r--main/dnsmgr.c6
-rw-r--r--main/enum.c14
-rw-r--r--main/http.c5
-rw-r--r--main/loader.c3
-rw-r--r--main/logger.c12
-rw-r--r--main/manager.c28
-rw-r--r--main/rtp.c14
-rw-r--r--main/udptl.c15
11 files changed, 257 insertions, 76 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index 118dd2982..052bf629d 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2290,13 +2290,14 @@ static void ast_readconfig(void)
struct ast_variable *v;
char *config = AST_CONFIG_FILE;
char hostname[MAXHOSTNAMELEN] = "";
+ struct ast_flags config_flags = { 0 };
if (ast_opt_override_config) {
- cfg = ast_config_load(ast_config_AST_CONFIG_FILE);
+ cfg = ast_config_load(ast_config_AST_CONFIG_FILE, config_flags);
if (!cfg)
ast_log(LOG_WARNING, "Unable to open specified master config file '%s', using built-in defaults\n", ast_config_AST_CONFIG_FILE);
} else
- cfg = ast_config_load(config);
+ cfg = ast_config_load(config, config_flags);
/* init with buildtime config */
ast_copy_string(ast_config_AST_CONFIG_DIR, AST_CONFIG_DIR, sizeof(ast_config_AST_CONFIG_DIR));
diff --git a/main/cdr.c b/main/cdr.c
index 6f0d75aab..6cbb52f7e 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -1281,7 +1281,7 @@ static struct ast_cli_entry cli_status = {
" Displays the Call Detail Record engine system status.\n"
};
-static int do_reload(void)
+static int do_reload(int reload)
{
struct ast_config *config;
const char *enabled_value;
@@ -1296,6 +1296,10 @@ static int do_reload(void)
int was_enabled;
int was_batchmode;
int res=0;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+
+ if ((config = ast_config_load("cdr.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ return 0;
ast_mutex_lock(&cdr_batch_lock);
@@ -1312,7 +1316,7 @@ static int do_reload(void)
if (cdr_sched > -1)
ast_sched_del(sched, cdr_sched);
- if ((config = ast_config_load("cdr.conf"))) {
+ if (config) {
if ((enabled_value = ast_variable_retrieve(config, "general", "enable"))) {
enabled = ast_true(enabled_value);
}
@@ -1405,7 +1409,7 @@ int ast_cdr_engine_init(void)
ast_cli_register(&cli_status);
- res = do_reload();
+ res = do_reload(0);
if (res) {
ast_mutex_lock(&cdr_batch_lock);
res = init_batch();
@@ -1424,6 +1428,6 @@ void ast_cdr_engine_term(void)
int ast_cdr_engine_reload(void)
{
- return do_reload();
+ return do_reload(1);
}
diff --git a/main/config.c b/main/config.c
index 01c9c9a0c..1405423c4 100644
--- a/main/config.c
+++ b/main/config.c
@@ -65,12 +65,27 @@ static char *extconfig_conf = "extconfig.conf";
/*! \brief Structure to keep comments for rewriting configuration files */
-/*! \brief Structure to keep comments for rewriting configuration files */
struct ast_comment {
struct ast_comment *next;
char cmt[0];
};
+/*! \brief Hold the mtime for config files, so if we don't need to reread our config, don't. */
+struct cache_file_include {
+ AST_LIST_ENTRY(cache_file_include) list;
+ char include[0];
+};
+
+struct cache_file_mtime {
+ AST_LIST_ENTRY(cache_file_mtime) list;
+ AST_LIST_HEAD(includes, cache_file_include) includes;
+ unsigned int has_exec:1;
+ time_t mtime;
+ char filename[0];
+};
+
+static AST_LIST_HEAD_STATIC(cfmtime_head, cache_file_mtime);
+
#define CB_INCR 250
static void CB_INIT(char **comment_buffer, int *comment_buffer_size, char **lline_buffer, int *lline_buffer_size)
@@ -590,7 +605,58 @@ void ast_config_set_current_category(struct ast_config *cfg, const struct ast_ca
cfg->current = (struct ast_category *) cat;
}
-static int process_text_line(struct ast_config *cfg, struct ast_category **cat, char *buf, int lineno, const char *configfile, int withcomments,
+enum config_cache_attribute_enum {
+ ATTRIBUTE_INCLUDE = 0,
+ ATTRIBUTE_EXEC = 1,
+};
+
+static void config_cache_attribute(const char *configfile, enum config_cache_attribute_enum attrtype, const char *filename)
+{
+ struct cache_file_mtime *cfmtime;
+ struct cache_file_include *cfinclude;
+ struct stat statbuf = { 0, };
+
+ /* Find our cached entry for this configuration file */
+ AST_LIST_LOCK(&cfmtime_head);
+ AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
+ if (!strcmp(cfmtime->filename, configfile))
+ break;
+ }
+ if (!cfmtime) {
+ cfmtime = ast_calloc(1, sizeof(*cfmtime) + strlen(configfile) + 1);
+ if (!cfmtime) {
+ AST_LIST_UNLOCK(&cfmtime_head);
+ return;
+ }
+ AST_LIST_HEAD_INIT(&cfmtime->includes);
+ strcpy(cfmtime->filename, configfile);
+ /* Note that the file mtime is initialized to 0, i.e. 1970 */
+ AST_LIST_INSERT_TAIL(&cfmtime_head, cfmtime, list);
+ }
+
+ if (!stat(configfile, &statbuf))
+ cfmtime->mtime = 0;
+ else
+ cfmtime->mtime = statbuf.st_mtime;
+
+ switch (attrtype) {
+ case ATTRIBUTE_INCLUDE:
+ cfinclude = ast_calloc(1, sizeof(*cfinclude) + strlen(filename) + 1);
+ if (!cfinclude) {
+ AST_LIST_UNLOCK(&cfmtime_head);
+ return;
+ }
+ strcpy(cfinclude->include, filename);
+ AST_LIST_INSERT_TAIL(&cfmtime->includes, cfinclude, list);
+ break;
+ case ATTRIBUTE_EXEC:
+ cfmtime->has_exec = 1;
+ break;
+ }
+ AST_LIST_UNLOCK(&cfmtime_head);
+}
+
+static int process_text_line(struct ast_config *cfg, struct ast_category **cat, char *buf, int lineno, const char *configfile, struct ast_flags flags,
char **comment_buffer, int *comment_buffer_size, char **lline_buffer, int *lline_buffer_size)
{
char *c;
@@ -619,13 +685,13 @@ static int process_text_line(struct ast_config *cfg, struct ast_category **cat,
return -1;
}
/* add comments */
- if (withcomments && *comment_buffer && (*comment_buffer)[0] ) {
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && *comment_buffer && (*comment_buffer)[0] ) {
newcat->precomments = ALLOC_COMMENT(*comment_buffer);
}
- if (withcomments && *lline_buffer && (*lline_buffer)[0] ) {
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && *lline_buffer && (*lline_buffer)[0] ) {
newcat->sameline = ALLOC_COMMENT(*lline_buffer);
}
- if ( withcomments )
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS))
CB_RESET(comment_buffer, lline_buffer);
/* If there are options or categories to inherit from, process them now */
@@ -702,15 +768,20 @@ static int process_text_line(struct ast_config *cfg, struct ast_category **cat,
}
/* #exec </path/to/executable>
We create a tmp file, then we #include it, then we delete it. */
- if (do_exec) {
+ if (do_exec) {
+ if (!ast_test_flag(&flags, CONFIG_FLAG_NOCACHE))
+ config_cache_attribute(configfile, ATTRIBUTE_EXEC, NULL);
snprintf(exec_file, sizeof(exec_file), "/var/tmp/exec.%d.%ld", (int)time(NULL), (long)pthread_self());
snprintf(cmd, sizeof(cmd), "%s > %s 2>&1", cur, exec_file);
ast_safe_system(cmd);
cur = exec_file;
- } else
+ } else {
+ if (!ast_test_flag(&flags, CONFIG_FLAG_NOCACHE))
+ config_cache_attribute(configfile, ATTRIBUTE_INCLUDE, cur);
exec_file[0] = '\0';
+ }
/* A #include */
- do_include = ast_config_internal_load(cur, cfg, withcomments) ? 1 : 0;
+ do_include = ast_config_internal_load(cur, cfg, flags) ? 1 : 0;
if (!ast_strlen_zero(exec_file))
unlink(exec_file);
if (!do_include)
@@ -750,13 +821,13 @@ static int process_text_line(struct ast_config *cfg, struct ast_category **cat,
v->blanklines = 0;
ast_variable_append(*cat, v);
/* add comments */
- if (withcomments && *comment_buffer && (*comment_buffer)[0] ) {
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && *comment_buffer && (*comment_buffer)[0] ) {
v->precomments = ALLOC_COMMENT(*comment_buffer);
}
- if (withcomments && *lline_buffer && (*lline_buffer)[0] ) {
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && *lline_buffer && (*lline_buffer)[0] ) {
v->sameline = ALLOC_COMMENT(*lline_buffer);
}
- if ( withcomments )
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS))
CB_RESET(comment_buffer, lline_buffer);
} else {
@@ -769,7 +840,7 @@ static int process_text_line(struct ast_config *cfg, struct ast_category **cat,
return 0;
}
-static struct ast_config *config_text_file_load(const char *database, const char *table, const char *filename, struct ast_config *cfg, int withcomments)
+static struct ast_config *config_text_file_load(const char *database, const char *table, const char *filename, struct ast_config *cfg, struct ast_flags flags)
{
char fn[256];
char buf[8192];
@@ -780,6 +851,8 @@ static struct ast_config *config_text_file_load(const char *database, const char
struct ast_category *cat = NULL;
int count = 0;
struct stat statbuf;
+ struct cache_file_mtime *cfmtime = NULL;
+ struct cache_file_include *cfinclude;
/*! Growable string buffer */
char *comment_buffer=0; /*!< this will be a comment collector.*/
int comment_buffer_size=0; /*!< the amount of storage so far alloc'd for the comment_buffer */
@@ -787,8 +860,8 @@ static struct ast_config *config_text_file_load(const char *database, const char
char *lline_buffer=0; /*!< A buffer for stuff behind the ; */
int lline_buffer_size=0;
-
- cat = ast_config_get_current_category(cfg);
+ if (cfg)
+ cat = ast_config_get_current_category(cfg);
if (filename[0] == '/') {
ast_copy_string(fn, filename, sizeof(fn));
@@ -796,7 +869,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, filename);
}
- if (withcomments) {
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
CB_INIT(&comment_buffer, &comment_buffer_size, &lline_buffer, &lline_buffer_size);
if (!lline_buffer || !comment_buffer) {
ast_log(LOG_ERROR, "Failed to initialize the comment buffer!\n");
@@ -833,6 +906,77 @@ static struct ast_config *config_text_file_load(const char *database, const char
ast_log(LOG_WARNING, "'%s' is not a regular file, ignoring\n", fn);
continue;
}
+
+ if (!ast_test_flag(&flags, CONFIG_FLAG_NOCACHE)) {
+ /* Find our cached entry for this configuration file */
+ AST_LIST_LOCK(&cfmtime_head);
+ AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
+ if (!strcmp(cfmtime->filename, fn))
+ break;
+ }
+ if (!cfmtime) {
+ cfmtime = ast_calloc(1, sizeof(*cfmtime) + strlen(fn) + 1);
+ if (!cfmtime)
+ continue;
+ AST_LIST_HEAD_INIT(&cfmtime->includes);
+ strcpy(cfmtime->filename, fn);
+ /* Note that the file mtime is initialized to 0, i.e. 1970 */
+ AST_LIST_INSERT_TAIL(&cfmtime_head, cfmtime, list);
+ }
+ }
+
+ if (cfmtime && (!cfmtime->has_exec) && (cfmtime->mtime == statbuf.st_mtime) && ast_test_flag(&flags, CONFIG_FLAG_FILEUNCHANGED)) {
+ /* File is unchanged, what about the (cached) includes (if any)? */
+ int unchanged = 1;
+ AST_LIST_TRAVERSE(&cfmtime->includes, cfinclude, list) {
+ /* We must glob here, because if we did not, then adding a file to globbed directory would
+ * incorrectly cause no reload to be necessary. */
+ char fn2[256];
+#ifdef AST_INCLUDE_GLOB
+ int glob_ret;
+ glob_t globbuf = { .gl_offs = 0 };
+#ifdef SOLARIS
+ glob_ret = glob(cfinclude->include, GLOB_NOCHECK, NULL, &globbuf);
+#else
+ glob_ret = glob(cfinclude->include, GLOB_NOMAGIC|GLOB_BRACE, NULL, &globbuf);
+#endif
+ /* On error, we reparse */
+ if (glob_ret == GLOB_NOSPACE || glob_ret == GLOB_ABORTED)
+ unchanged = 0;
+ else {
+ /* loop over expanded files */
+ int j;
+ for (j = 0; j < globbuf.gl_pathc; j++) {
+ ast_copy_string(fn2, globbuf.gl_pathv[j], sizeof(fn2));
+#else
+ ast_copy_string(fn2, cfinclude->include);
+#endif
+ if (config_text_file_load(NULL, NULL, fn2, NULL, flags) == NULL) {
+ unchanged = 0;
+ /* One change is enough to short-circuit and reload the whole shebang */
+ break;
+ }
+#ifdef AST_INCLUDE_GLOB
+ }
+ }
+#endif
+ }
+
+ if (unchanged) {
+ AST_LIST_UNLOCK(&cfmtime_head);
+ return CONFIG_STATUS_FILEUNCHANGED;
+ }
+ }
+ if (cfmtime)
+ AST_LIST_UNLOCK(&cfmtime_head);
+
+ /* If cfg is NULL, then we just want an answer */
+ if (cfg == NULL)
+ return NULL;
+
+ if (cfmtime)
+ cfmtime->mtime = statbuf.st_mtime;
+
ast_verb(2, "Parsing '%s': ", fn);
fflush(stdout);
if (!(f = fopen(fn, "r"))) {
@@ -846,7 +990,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
while (!feof(f)) {
lineno++;
if (fgets(buf, sizeof(buf), f)) {
- if ( withcomments ) {
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
CB_ADD(&comment_buffer, &comment_buffer_size, lline_buffer); /* add the current lline buffer to the comment buffer */
lline_buffer[0] = 0; /* erase the lline buffer */
}
@@ -883,7 +1027,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
/* Actually have to move what's left over the top, then continue */
char *oldptr;
oldptr = process_buf + strlen(process_buf);
- if ( withcomments ) {
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
CB_ADD(&comment_buffer, &comment_buffer_size, ";");
CB_ADD_LEN(&comment_buffer, &comment_buffer_size, oldptr+1, new_buf-oldptr-1);
}
@@ -897,7 +1041,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
if (!comment) {
/* If ; is found, and we are not nested in a comment,
we immediately stop all comment processing */
- if ( withcomments ) {
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
LLB_ADD(&lline_buffer, &lline_buffer_size, comment_p);
}
*comment_p = '\0';
@@ -906,7 +1050,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
new_buf = comment_p + 1;
}
}
- if ( withcomments && comment && !process_buf )
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment && !process_buf )
{
CB_ADD(&comment_buffer, &comment_buffer_size, buf); /* the whole line is a comment, store it */
}
@@ -914,7 +1058,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
if (process_buf) {
char *buf = ast_strip(process_buf);
if (!ast_strlen_zero(buf)) {
- if (process_text_line(cfg, &cat, buf, lineno, fn, withcomments, &comment_buffer, &comment_buffer_size, &lline_buffer, &lline_buffer_size)) {
+ if (process_text_line(cfg, &cat, buf, lineno, fn, flags, &comment_buffer, &comment_buffer_size, &lline_buffer, &lline_buffer_size)) {
cfg = NULL;
break;
}
@@ -928,7 +1072,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
ast_log(LOG_WARNING,"Unterminated comment detected beginning on line %d\n", nest[comment - 1]);
}
#ifdef AST_INCLUDE_GLOB
- if (!cfg)
+ if (cfg == NULL || cfg == CONFIG_STATUS_FILEUNCHANGED)
break;
}
globfree(&globbuf);
@@ -936,7 +1080,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
}
#endif
- if (cfg && cfg->include_level == 1 && withcomments && comment_buffer) {
+ if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg->include_level == 1 && ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment_buffer) {
ast_free(comment_buffer);
ast_free(lline_buffer);
comment_buffer = NULL;
@@ -1090,12 +1234,13 @@ int read_config_maps(void)
struct ast_config *config, *configtmp;
struct ast_variable *v;
char *driver, *table, *database, *stringp, *tmp;
+ struct ast_flags flags = { 0 };
clear_config_maps();
configtmp = ast_config_new();
configtmp->max_include_level = 1;
- config = ast_config_internal_load(extconfig_conf, configtmp, 0);
+ config = ast_config_internal_load(extconfig_conf, configtmp, flags);
if (!config) {
ast_config_destroy(configtmp);
return 0;
@@ -1234,7 +1379,7 @@ static struct ast_config_engine text_file_engine = {
.load_func = config_text_file_load,
};
-struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg, int withcomments)
+struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg, struct ast_flags flags)
{
char db[256];
char table[256];
@@ -1263,9 +1408,9 @@ struct ast_config *ast_config_internal_load(const char *filename, struct ast_con
}
}
- result = loader->load_func(db, table, filename, cfg, withcomments);
+ result = loader->load_func(db, table, filename, cfg, flags);
- if (result)
+ if (result && result != CONFIG_STATUS_FILEUNCHANGED)
result->include_level--;
else
cfg->include_level--;
@@ -1273,23 +1418,7 @@ struct ast_config *ast_config_internal_load(const char *filename, struct ast_con
return result;
}
-struct ast_config *ast_config_load(const char *filename)
-{
- struct ast_config *cfg;
- struct ast_config *result;
-
- cfg = ast_config_new();
- if (!cfg)
- return NULL;
-
- result = ast_config_internal_load(filename, cfg, 0);
- if (!result)
- ast_config_destroy(cfg);
-
- return result;
-}
-
-struct ast_config *ast_config_load_with_comments(const char *filename)
+struct ast_config *ast_config_load(const char *filename, struct ast_flags flags)
{
struct ast_config *cfg;
struct ast_config *result;
@@ -1298,8 +1427,8 @@ struct ast_config *ast_config_load_with_comments(const char *filename)
if (!cfg)
return NULL;
- result = ast_config_internal_load(filename, cfg, 1);
- if (!result)
+ result = ast_config_internal_load(filename, cfg, flags);
+ if (!result || result == CONFIG_STATUS_FILEUNCHANGED)
ast_config_destroy(cfg);
return result;
diff --git a/main/dnsmgr.c b/main/dnsmgr.c
index d3eb9a50f..d1e5dd30b 100644
--- a/main/dnsmgr.c
+++ b/main/dnsmgr.c
@@ -349,12 +349,16 @@ int dnsmgr_reload(void)
static int do_reload(int loading)
{
struct ast_config *config;
+ struct ast_flags config_flags = { loading ? 0 : CONFIG_FLAG_FILEUNCHANGED };
const char *interval_value;
const char *enabled_value;
int interval;
int was_enabled;
int res = -1;
+ if ((config = ast_config_load("dnsmgr.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ return 0;
+
/* ensure that no refresh cycles run while the reload is in progress */
ast_mutex_lock(&refresh_lock);
@@ -366,7 +370,7 @@ static int do_reload(int loading)
if (refresh_sched > -1)
ast_sched_del(sched, refresh_sched);
- if ((config = ast_config_load("dnsmgr.conf"))) {
+ if (config) {
if ((enabled_value = ast_variable_retrieve(config, "general", "enable"))) {
enabled = ast_true(enabled_value);
}
diff --git a/main/enum.c b/main/enum.c
index cf298a655..9e771b948 100644
--- a/main/enum.c
+++ b/main/enum.c
@@ -605,11 +605,15 @@ static struct enum_search *enum_newtoplev(char *s)
}
/*! \brief Initialize the ENUM support subsystem */
-int ast_enum_init(void)
+static int private_enum_init(int reload)
{
struct ast_config *cfg;
struct enum_search *s, *sl;
struct ast_variable *v;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+
+ if ((cfg = ast_config_load("enum.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ return 0;
/* Destroy existing list */
ast_mutex_lock(&enumlock);
@@ -620,7 +624,6 @@ int ast_enum_init(void)
ast_free(sl);
}
toplevs = NULL;
- cfg = ast_config_load("enum.conf");
if (cfg) {
sl = NULL;
v = ast_variable_browse(cfg, "general");
@@ -646,7 +649,12 @@ int ast_enum_init(void)
return 0;
}
+int ast_enum_init(void)
+{
+ return private_enum_init(0);
+}
+
int ast_enum_reload(void)
{
- return ast_enum_init();
+ return private_enum_init(1);
}
diff --git a/main/http.c b/main/http.c
index b61858cde..b4aac2636 100644
--- a/main/http.c
+++ b/main/http.c
@@ -1134,6 +1134,10 @@ static int __ast_http_load(int reload)
char newprefix[MAX_PREFIX];
int have_sslbindaddr = 0;
struct http_uri_redirect *redirect;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+
+ if ((cfg = ast_config_load("http.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ return 0;
/* default values */
memset(&http_desc.sin, 0, sizeof(http_desc.sin));
@@ -1159,7 +1163,6 @@ static int __ast_http_load(int reload)
destroy_post_mappings();
- cfg = ast_config_load("http.conf");
if (cfg) {
v = ast_variable_browse(cfg, "general");
for (; v; v = v->next) {
diff --git a/main/loader.c b/main/loader.c
index f3db6841c..359d7323c 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -731,6 +731,7 @@ int load_modules(unsigned int preload_only)
unsigned int load_count;
struct load_order load_order;
int res = 0;
+ struct ast_flags config_flags = { 0 };
#if LOADABLE_MODULES
struct dirent *dirent;
DIR *dir;
@@ -745,7 +746,7 @@ int load_modules(unsigned int preload_only)
AST_LIST_LOCK(&module_list);
- if (!(cfg = ast_config_load(AST_MODULE_CONFIG))) {
+ if (!(cfg = ast_config_load(AST_MODULE_CONFIG, config_flags))) {
ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG);
goto done;
}
diff --git a/main/logger.c b/main/logger.c
index 209da2167..fff798aee 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -305,12 +305,16 @@ static struct logchannel *make_logchannel(char *channel, char *components, int l
return chan;
}
-static void init_logger_chain(void)
+static void init_logger_chain(int reload)
{
struct logchannel *chan;
struct ast_config *cfg;
struct ast_variable *var;
const char *s;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+
+ if ((cfg = ast_config_load("logger.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ return;
/* delete our list of log channels */
AST_RWLIST_WRLOCK(&logchannels);
@@ -323,8 +327,6 @@ static void init_logger_chain(void)
/* close syslog */
closelog();
- cfg = ast_config_load("logger.conf");
-
/* If no config file, we're fine, set default options. */
if (!cfg) {
if (errno)
@@ -454,7 +456,7 @@ int reload_logger(int rotate)
filesize_reload_needed = 0;
- init_logger_chain();
+ init_logger_chain(1);
if (logfiles.event_log) {
snprintf(old, sizeof(old), "%s/%s", ast_config_AST_LOG_DIR, EVENTLOG);
@@ -802,7 +804,7 @@ int init_logger(void)
ast_mkdir(ast_config_AST_LOG_DIR, 0777);
/* create log channels */
- init_logger_chain();
+ init_logger_chain(0);
/* create the eventlog */
if (logfiles.event_log) {
diff --git a/main/manager.c b/main/manager.c
index 69c809204..9abb6c5b1 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -954,6 +954,7 @@ static int authenticate(struct mansession *s, const struct message *m)
struct ast_ha *ha = NULL;
char *password = NULL;
int readperm = 0, writeperm = 0;
+ struct ast_flags config_flags = { 0 };
if (ast_strlen_zero(user)) /* missing username */
return -1;
@@ -964,7 +965,7 @@ static int authenticate(struct mansession *s, const struct message *m)
* suffices to call get_manager_by_name_locked() to fetch
* the user's entry.
*/
- struct ast_config *cfg = ast_config_load("manager.conf");
+ struct ast_config *cfg = ast_config_load("manager.conf", config_flags);
char *cat = NULL;
struct ast_variable *v;
@@ -1001,7 +1002,7 @@ static int authenticate(struct mansession *s, const struct message *m)
if (!cat) {
/* Didn't find the user in manager.conf, check users.conf */
int hasmanager = 0;
- cfg = ast_config_load("users.conf");
+ cfg = ast_config_load("users.conf", config_flags);
if (!cfg)
return -1;
while ( (cat = ast_category_browse(cfg, cat)) ) {
@@ -1117,12 +1118,13 @@ static int action_getconfig(struct mansession *s, const struct message *m)
int lineno = 0;
char *category=NULL;
struct ast_variable *v;
+ struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
if (ast_strlen_zero(fn)) {
astman_send_error(s, m, "Filename not specified");
return 0;
}
- if (!(cfg = ast_config_load_with_comments(fn))) {
+ if (!(cfg = ast_config_load(fn, config_flags))) {
astman_send_error(s, m, "Config file not found");
return 0;
}
@@ -1167,13 +1169,14 @@ static int action_getconfigjson(struct mansession *s, const struct message *m)
int comma1 = 0;
char *buf = NULL;
unsigned int buf_len = 0;
+ struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
if (ast_strlen_zero(fn)) {
astman_send_error(s, m, "Filename not specified");
return 0;
}
- if (!(cfg = ast_config_load_with_comments(fn))) {
+ if (!(cfg = ast_config_load(fn, config_flags))) {
astman_send_error(s, m, "Config file not found");
return 0;
}
@@ -1302,12 +1305,13 @@ static int action_updateconfig(struct mansession *s, const struct message *m)
const char *dfn = astman_get_header(m, "DstFilename");
int res;
const char *rld = astman_get_header(m, "Reload");
+ struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
if (ast_strlen_zero(sfn) || ast_strlen_zero(dfn)) {
astman_send_error(s, m, "Filename not specified");
return 0;
}
- if (!(cfg = ast_config_load_with_comments(sfn))) {
+ if (!(cfg = ast_config_load(sfn, config_flags))) {
astman_send_error(s, m, "Config file not found");
return 0;
}
@@ -3246,7 +3250,7 @@ static struct server_args amis_desc = {
.worker_fn = session_do, /* thread handling the session */
};
-int init_manager(void)
+static int __init_manager(int reload)
{
struct ast_config *cfg = NULL;
const char *val;
@@ -3257,6 +3261,7 @@ int init_manager(void)
struct ast_hostent ahp;
struct ast_manager_user *user = NULL;
struct ast_variable *var;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
if (!registered) {
/* Register default actions */
@@ -3292,8 +3297,10 @@ int init_manager(void)
/* Append placeholder event so master_eventq never runs dry */
append_event("Event: Placeholder\r\n\r\n", 0);
}
+ if ((cfg = ast_config_load("manager.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ return 0;
+
displayconnects = 1;
- cfg = ast_config_load("manager.conf");
if (!cfg) {
ast_log(LOG_NOTICE, "Unable to open management configuration manager.conf. Call management disabled.\n");
return 0;
@@ -3474,8 +3481,13 @@ int init_manager(void)
return 0;
}
+int init_manager(void)
+{
+ return __init_manager(0);
+}
+
int reload_manager(void)
{
manager_event(EVENT_FLAG_SYSTEM, "Reload", "Message: Reload Requested\r\n");
- return init_manager();
+ return __init_manager(1);
}
diff --git a/main/rtp.c b/main/rtp.c
index 7f81ed7cf..2ff4440f0 100644
--- a/main/rtp.c
+++ b/main/rtp.c
@@ -3997,15 +3997,18 @@ static struct ast_cli_entry cli_rtp[] = {
stun_no_debug_usage },
};
-int ast_rtp_reload(void)
+static int __ast_rtp_reload(int reload)
{
struct ast_config *cfg;
const char *s;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+
+ if ((cfg = ast_config_load("rtp.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ return 0;
rtpstart = 5000;
rtpend = 31000;
dtmftimeout = DEFAULT_DTMF_TIMEOUT;
- cfg = ast_config_load("rtp.conf");
if (cfg) {
if ((s = ast_variable_retrieve(cfg, "general", "rtpstart"))) {
rtpstart = atoi(s);
@@ -4060,10 +4063,15 @@ int ast_rtp_reload(void)
return 0;
}
+int ast_rtp_reload(void)
+{
+ return __ast_rtp_reload(1);
+}
+
/*! \brief Initialize the RTP system in Asterisk */
void ast_rtp_init(void)
{
ast_cli_register_multiple(cli_rtp, sizeof(cli_rtp) / sizeof(struct ast_cli_entry));
- ast_rtp_reload();
+ __ast_rtp_reload(0);
}
diff --git a/main/udptl.c b/main/udptl.c
index 2385679a8..d3c6163e7 100644
--- a/main/udptl.c
+++ b/main/udptl.c
@@ -1183,10 +1183,14 @@ static struct ast_cli_entry cli_udptl[] = {
nodebug_usage },
};
-void ast_udptl_reload(void)
+static void __ast_udptl_reload(int reload)
{
struct ast_config *cfg;
const char *s;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+
+ if ((cfg = ast_config_load("udptl.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ return;
udptlstart = 4500;
udptlend = 4999;
@@ -1195,7 +1199,7 @@ void ast_udptl_reload(void)
udptlfecspan = 0;
udptlmaxdatagram = 0;
- if ((cfg = ast_config_load("udptl.conf"))) {
+ if (cfg) {
if ((s = ast_variable_retrieve(cfg, "general", "udptlstart"))) {
udptlstart = atoi(s);
if (udptlstart < 1024)
@@ -1258,8 +1262,13 @@ void ast_udptl_reload(void)
ast_verb(2, "UDPTL allocating from port range %d -> %d\n", udptlstart, udptlend);
}
+void ast_udptl_reload(void)
+{
+ __ast_udptl_reload(1);
+}
+
void ast_udptl_init(void)
{
ast_cli_register_multiple(cli_udptl, sizeof(cli_udptl) / sizeof(struct ast_cli_entry));
- ast_udptl_reload();
+ __ast_udptl_reload(0);
}