summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2008-09-12 23:30:03 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2008-09-12 23:30:03 +0000
commit08af5bb31222c39739b8ec216b403756fb250924 (patch)
tree790035cc6aca2440080bd357a68a09fdbbb2624c /main
parent5d39c767c12477610cf13f5c2e00e7eed7839352 (diff)
Create a new config file status, CONFIG_STATUS_FILEINVALID for differentiating
when a file is invalid from when a file is missing. This is most important when we have two configuration files. Consider the following example: Old system: sip.conf users.conf Old result New result ======== ========== ========== ========== Missing Missing SIP doesn't load SIP doesn't load Missing OK SIP doesn't load SIP doesn't load Missing Invalid SIP doesn't load SIP doesn't load OK Missing SIP loads SIP loads OK OK SIP loads SIP loads OK Invalid SIP loads incompletely SIP doesn't load Invalid Missing SIP doesn't load SIP doesn't load Invalid OK SIP doesn't load SIP doesn't load Invalid Invalid SIP doesn't load SIP doesn't load So in the case when users.conf doesn't load because there's a typo that disrupts the syntax, we may only partially load users, instead of failing with an error, which may cause some calls not to get processed. Worse yet, the old system would do this with no indication that anything was even wrong. (closes issue #10690) Reported by: dtyoo Patches: 20080716__bug10690.diff.txt uploaded by Corydon76 (license 14) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@142992 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r--main/asterisk.c7
-rw-r--r--main/cdr.c3
-rw-r--r--main/config.c17
-rw-r--r--main/dnsmgr.c4
-rw-r--r--main/dsp.c3
-rw-r--r--main/enum.c3
-rw-r--r--main/features.c2
-rw-r--r--main/http.c3
-rw-r--r--main/loader.c3
-rw-r--r--main/manager.c3
-rw-r--r--main/rtp.c4
-rw-r--r--main/udptl.c4
12 files changed, 41 insertions, 15 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index d8dc99b86..0aa9f9a3d 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2596,7 +2596,7 @@ static void ast_readconfig(void)
if (ast_opt_override_config) {
cfg = ast_config_load2(ast_config_AST_CONFIG_FILE, "" /* core, can't reload */, config_flags);
- if (!cfg)
+ if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
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_load2(config, "" /* core, can't reload */, config_flags);
@@ -2619,7 +2619,7 @@ static void ast_readconfig(void)
ast_set_default_eid(&g_eid);
/* no asterisk.conf? no problem, use buildtime config! */
- if (!cfg) {
+ if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
return;
}
@@ -2869,6 +2869,9 @@ static void run_startup_commands(void)
if (!(cfg = ast_config_load2("cli.conf", "" /* core, can't reload */, cfg_flags)))
return;
+ if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
+ return;
+ }
fd = open("/dev/null", O_RDWR);
if (fd < 0) {
diff --git a/main/cdr.c b/main/cdr.c
index b97736203..cf9d1bc61 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -1388,6 +1388,9 @@ static int do_reload(int reload)
if ((config = ast_config_load2("cdr.conf", "cdr", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
return 0;
+ if (config == CONFIG_STATUS_FILEMISSING || config == CONFIG_STATUS_FILEUNCHANGED || config == CONFIG_STATUS_FILEINVALID) {
+ return 0;
+ }
ast_mutex_lock(&cdr_batch_lock);
diff --git a/main/config.c b/main/config.c
index 40b116a47..870aaed57 100644
--- a/main/config.c
+++ b/main/config.c
@@ -1015,13 +1015,17 @@ static int process_text_line(struct ast_config *cfg, struct ast_category **cat,
cur++;
c = cur;
- while (*c && (*c > 32)) c++;
+ while (*c && (*c > 32)) {
+ c++;
+ }
+
if (*c) {
*c = '\0';
/* Find real argument */
c = ast_skip_blanks(c + 1);
- if (!(*c))
+ if (!(*c)) {
c = NULL;
+ }
} else
c = NULL;
if (!strcasecmp(cur, "include")) {
@@ -1390,7 +1394,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
char *buffer = ast_strip(process_buf);
if (!ast_strlen_zero(buffer)) {
if (process_text_line(cfg, &cat, buffer, lineno, fn, flags, comment_buffer, lline_buffer, suggested_include_file, &last_cat, &last_var, who_asked)) {
- cfg = NULL;
+ cfg = CONFIG_STATUS_FILEINVALID;
break;
}
}
@@ -1428,15 +1432,16 @@ 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 == NULL || cfg == CONFIG_STATUS_FILEUNCHANGED)
+ if (cfg == NULL || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
break;
+ }
}
globfree(&globbuf);
}
}
#endif
- if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg->include_level == 1 && ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
+ if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID && cfg->include_level == 1 && ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
if (comment_buffer)
ast_free(comment_buffer);
if (lline_buffer)
@@ -2055,7 +2060,7 @@ struct ast_config *ast_config_load2(const char *filename, const char *who_asked,
return NULL;
result = ast_config_internal_load(filename, cfg, flags, "", who_asked);
- if (!result || result == CONFIG_STATUS_FILEUNCHANGED)
+ if (!result || result == CONFIG_STATUS_FILEUNCHANGED || result == CONFIG_STATUS_FILEINVALID)
ast_config_destroy(cfg);
return result;
diff --git a/main/dnsmgr.c b/main/dnsmgr.c
index 2df778b45..7ff7a4f5d 100644
--- a/main/dnsmgr.c
+++ b/main/dnsmgr.c
@@ -372,8 +372,10 @@ static int do_reload(int loading)
int was_enabled;
int res = -1;
- if ((config = ast_config_load2("dnsmgr.conf", "dnsmgr", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ config = ast_config_load2("dnsmgr.conf", "dnsmgr", config_flags);
+ if (config == CONFIG_STATUS_FILEMISSING || config == CONFIG_STATUS_FILEUNCHANGED || config == CONFIG_STATUS_FILEINVALID) {
return 0;
+ }
/* ensure that no refresh cycles run while the reload is in progress */
ast_mutex_lock(&refresh_lock);
diff --git a/main/dsp.c b/main/dsp.c
index f3adcf0be..e5db83cd5 100644
--- a/main/dsp.c
+++ b/main/dsp.c
@@ -1614,6 +1614,9 @@ static int _dsp_init(int reload)
struct ast_config *cfg;
cfg = ast_config_load2(CONFIG_FILE_NAME, "dsp", config_flags);
+ if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
+ return 0;
+ }
if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED) {
const char *value;
diff --git a/main/enum.c b/main/enum.c
index 6f821c26d..d10864c0b 100644
--- a/main/enum.c
+++ b/main/enum.c
@@ -959,6 +959,9 @@ static int private_enum_init(int reload)
if ((cfg = ast_config_load2("enum.conf", "enum", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
return 0;
+ if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
+ return 0;
+ }
/* Destroy existing list */
ast_mutex_lock(&enumlock);
diff --git a/main/features.c b/main/features.c
index c8ce6ccde..275c006bd 100644
--- a/main/features.c
+++ b/main/features.c
@@ -3143,7 +3143,7 @@ static int load_config(void)
atxfercallbackretries = DEFAULT_ATXFER_CALLBACK_RETRIES;
cfg = ast_config_load2("features.conf", "features", config_flags);
- if (!cfg) {
+ if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
ast_log(LOG_WARNING,"Could not load features.conf\n");
return 0;
}
diff --git a/main/http.c b/main/http.c
index 7601158bb..b1bb878f7 100644
--- a/main/http.c
+++ b/main/http.c
@@ -851,7 +851,8 @@ static int __ast_http_load(int reload)
struct http_uri_redirect *redirect;
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
- if ((cfg = ast_config_load2("http.conf", "http", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
+ cfg = ast_config_load2("http.conf", "http", config_flags);
+ if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
return 0;
}
diff --git a/main/loader.c b/main/loader.c
index 735459f04..e8a5662ef 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -787,7 +787,8 @@ int load_modules(unsigned int preload_only)
embedded_module_list.first = NULL;
}
- if (!(cfg = ast_config_load2(AST_MODULE_CONFIG, "" /* core, can't reload */, config_flags))) {
+ cfg = ast_config_load2(AST_MODULE_CONFIG, "" /* core, can't reload */, config_flags);
+ if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG);
goto done;
}
diff --git a/main/manager.c b/main/manager.c
index 4aa1be631..7d57eb673 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -1132,7 +1132,8 @@ static int action_getconfig(struct mansession *s, const struct message *m)
astman_send_error(s, m, "Filename not specified");
return 0;
}
- if (!(cfg = ast_config_load2(fn, "manager", config_flags))) {
+ cfg = ast_config_load2(fn, "manager", config_flags);
+ if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
astman_send_error(s, m, "Config file not found");
return 0;
}
diff --git a/main/rtp.c b/main/rtp.c
index b4d7734d1..2f4bca429 100644
--- a/main/rtp.c
+++ b/main/rtp.c
@@ -4694,8 +4694,10 @@ static int __ast_rtp_reload(int reload)
const char *s;
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
- if ((cfg = ast_config_load2("rtp.conf", "rtp", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ cfg = ast_config_load2("rtp.conf", "rtp", config_flags);
+ if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
return 0;
+ }
rtpstart = 5000;
rtpend = 31000;
diff --git a/main/udptl.c b/main/udptl.c
index 6b14ec56f..ad1c96d63 100644
--- a/main/udptl.c
+++ b/main/udptl.c
@@ -1223,8 +1223,10 @@ static void __ast_udptl_reload(int reload)
const char *s;
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
- if ((cfg = ast_config_load2("udptl.conf", "udptl", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ cfg = ast_config_load2("udptl.conf", "udptl", config_flags);
+ if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
return;
+ }
udptlstart = 4500;
udptlend = 4999;