[asterisk-commits] tilghman: trunk r107791 - in /trunk: include/asterisk/ main/ res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Mar 11 17:55:16 CDT 2008
Author: tilghman
Date: Tue Mar 11 17:55:16 2008
New Revision: 107791
URL: http://svn.digium.com/view/asterisk?view=rev&rev=107791
Log:
An offhand comment from Russell made me realize that the configuration file
caching would not work properly for users.conf and any other file read from
more than one place. I needed to add the filename which requested the config
file to get it to work properly.
Modified:
trunk/include/asterisk/config.h
trunk/main/config.c
trunk/res/res_config_curl.c
trunk/res/res_config_ldap.c
trunk/res/res_config_odbc.c
trunk/res/res_config_pgsql.c
trunk/res/res_config_sqlite.c
Modified: trunk/include/asterisk/config.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/config.h?view=diff&rev=107791&r1=107790&r2=107791
==============================================================================
--- trunk/include/asterisk/config.h (original)
+++ trunk/include/asterisk/config.h Tue Mar 11 17:55:16 2008
@@ -64,7 +64,7 @@
char stuff[0];
};
-typedef struct ast_config *config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file);
+typedef struct ast_config *config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file, const char *who_asked);
typedef struct ast_variable *realtime_var_get(const char *database, const char *table, va_list ap);
typedef struct ast_config *realtime_multi_get(const char *database, const char *table, va_list ap);
typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap);
@@ -86,6 +86,7 @@
/*! \brief Load a config file
* \param filename path of file to open. If no preceding '/' character, path is considered relative to AST_CONFIG_DIR
* Create a config structure from a given configuration file.
+ * \param who_asked The module which is making this request.
* \param flags Optional flags:
* CONFIG_FLAG_WITHCOMMENTS - load the file with comments intact;
* CONFIG_FLAG_FILEUNCHANGED - check the file mtime and return CONFIG_STATUS_FILEUNCHANGED if the mtime is the same; or
@@ -94,7 +95,9 @@
* \retval an ast_config data structure on success
* \retval NULL on error
*/
-struct ast_config *ast_config_load(const char *filename, struct ast_flags flags);
+struct ast_config *ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags);
+
+#define ast_config_load(filename, flags) ast_config_load2(filename, __FILE__, flags)
/*! \brief Destroys a config
* \param config pointer to config data structure
@@ -282,7 +285,7 @@
int config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator);
-struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file);
+struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked);
/*! \brief Support code to parse config file arguments
*
Modified: trunk/main/config.c
URL: http://svn.digium.com/view/asterisk/trunk/main/config.c?view=diff&rev=107791&r1=107790&r2=107791
==============================================================================
--- trunk/main/config.c (original)
+++ trunk/main/config.c Tue Mar 11 17:55:16 2008
@@ -92,6 +92,7 @@
AST_LIST_HEAD(includes, cache_file_include) includes;
unsigned int has_exec:1;
time_t mtime;
+ char *who_asked;
char filename[0];
};
@@ -854,7 +855,7 @@
ATTRIBUTE_EXEC = 1,
};
-static void config_cache_attribute(const char *configfile, enum config_cache_attribute_enum attrtype, const char *filename)
+static void config_cache_attribute(const char *configfile, enum config_cache_attribute_enum attrtype, const char *filename, const char *who_asked)
{
struct cache_file_mtime *cfmtime;
struct cache_file_include *cfinclude;
@@ -867,13 +868,15 @@
break;
}
if (!cfmtime) {
- cfmtime = ast_calloc(1, sizeof(*cfmtime) + strlen(configfile) + 1);
+ cfmtime = ast_calloc(1, sizeof(*cfmtime) + strlen(configfile) + 1 + strlen(who_asked) + 1);
if (!cfmtime) {
AST_LIST_UNLOCK(&cfmtime_head);
return;
}
AST_LIST_HEAD_INIT(&cfmtime->includes);
strcpy(cfmtime->filename, configfile);
+ cfmtime->who_asked = cfmtime->filename + strlen(configfile) + 1;
+ strcpy(cfmtime->who_asked, who_asked);
/* Note that the file mtime is initialized to 0, i.e. 1970 */
AST_LIST_INSERT_TAIL(&cfmtime_head, cfmtime, list);
}
@@ -918,7 +921,7 @@
struct ast_str *comment_buffer,
struct ast_str *lline_buffer,
const char *suggested_include_file,
- struct ast_category **last_cat, struct ast_variable **last_var)
+ struct ast_category **last_cat, struct ast_variable **last_var, const char *who_asked)
{
char *c;
char *cur = buf;
@@ -1054,21 +1057,21 @@
We create a tmp file, then we #include it, then we delete it. */
if (!do_include) {
if (!ast_test_flag(&flags, CONFIG_FLAG_NOCACHE))
- config_cache_attribute(configfile, ATTRIBUTE_EXEC, NULL);
+ config_cache_attribute(configfile, ATTRIBUTE_EXEC, NULL, who_asked);
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 {
if (!ast_test_flag(&flags, CONFIG_FLAG_NOCACHE))
- config_cache_attribute(configfile, ATTRIBUTE_INCLUDE, cur);
+ config_cache_attribute(configfile, ATTRIBUTE_INCLUDE, cur, who_asked);
exec_file[0] = '\0';
}
/* A #include */
/* record this inclusion */
inclu = ast_include_new(cfg, configfile, cur, !do_include, cur2, lineno, real_inclusion_name, sizeof(real_inclusion_name));
- do_include = ast_config_internal_load(cur, cfg, flags, real_inclusion_name) ? 1 : 0;
+ do_include = ast_config_internal_load(cur, cfg, flags, real_inclusion_name, who_asked) ? 1 : 0;
if (!ast_strlen_zero(exec_file))
unlink(exec_file);
if (!do_include) {
@@ -1121,7 +1124,7 @@
return 0;
}
-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, const char *suggested_include_file)
+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, const char *suggested_include_file, const char *who_asked)
{
char fn[256];
char buf[8192];
@@ -1196,15 +1199,17 @@
/* 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))
+ if (!strcmp(cfmtime->filename, fn) && !strcmp(cfmtime->who_asked, who_asked))
break;
}
if (!cfmtime) {
- cfmtime = ast_calloc(1, sizeof(*cfmtime) + strlen(fn) + 1);
+ cfmtime = ast_calloc(1, sizeof(*cfmtime) + strlen(fn) + 1 + strlen(who_asked) + 1);
if (!cfmtime)
continue;
AST_LIST_HEAD_INIT(&cfmtime->includes);
strcpy(cfmtime->filename, fn);
+ cfmtime->who_asked = cfmtime->filename + strlen(fn) + 1;
+ strcpy(cfmtime->who_asked, who_asked);
/* Note that the file mtime is initialized to 0, i.e. 1970 */
AST_LIST_INSERT_TAIL(&cfmtime_head, cfmtime, list);
}
@@ -1232,7 +1237,8 @@
#else
ast_copy_string(fn2, cfinclude->include);
#endif
- if (config_text_file_load(NULL, NULL, fn2, NULL, flags, "") == NULL) { /* that last field needs to be looked at in this case... TODO */
+ if (config_text_file_load(NULL, NULL, fn2, NULL, flags, "", who_asked) == NULL) {
+ /* that second-to-last field needs to be looked at in this case... TODO */
unchanged = 0;
/* One change is enough to short-circuit and reload the whole shebang */
break;
@@ -1346,7 +1352,7 @@
if (process_buf) {
char *buf = ast_strip(process_buf);
if (!ast_strlen_zero(buf)) {
- if (process_text_line(cfg, &cat, buf, lineno, fn, flags, comment_buffer, lline_buffer, suggested_include_file, &last_cat, &last_var)) {
+ if (process_text_line(cfg, &cat, buf, lineno, fn, flags, comment_buffer, lline_buffer, suggested_include_file, &last_cat, &last_var, who_asked)) {
cfg = NULL;
break;
}
@@ -1815,7 +1821,7 @@
configtmp = ast_config_new();
configtmp->max_include_level = 1;
- config = ast_config_internal_load(extconfig_conf, configtmp, flags, "");
+ config = ast_config_internal_load(extconfig_conf, configtmp, flags, "", "config.c");
if (!config) {
ast_config_destroy(configtmp);
return 0;
@@ -1956,7 +1962,7 @@
.load_func = config_text_file_load,
};
-struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg, struct ast_flags flags, const char *suggested_include_file)
+struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg, struct ast_flags flags, const char *suggested_include_file, const char *who_asked)
{
char db[256];
char table[256];
@@ -1986,7 +1992,7 @@
}
}
- result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file);
+ result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file, who_asked);
if (result && result != CONFIG_STATUS_FILEUNCHANGED)
result->include_level--;
@@ -1996,7 +2002,7 @@
return result;
}
-struct ast_config *ast_config_load(const char *filename, struct ast_flags flags)
+struct ast_config *ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
{
struct ast_config *cfg;
struct ast_config *result;
@@ -2005,7 +2011,7 @@
if (!cfg)
return NULL;
- result = ast_config_internal_load(filename, cfg, flags, "");
+ result = ast_config_internal_load(filename, cfg, flags, "", who_asked);
if (!result || result == CONFIG_STATUS_FILEUNCHANGED)
ast_config_destroy(cfg);
Modified: trunk/res/res_config_curl.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_config_curl.c?view=diff&rev=107791&r1=107790&r2=107791
==============================================================================
--- trunk/res/res_config_curl.c (original)
+++ trunk/res/res_config_curl.c Tue Mar 11 17:55:16 2008
@@ -407,7 +407,7 @@
}
-static struct ast_config *config_curl(const char *url, const char *unused, const char *file, struct ast_config *cfg, struct ast_flags flags, const char *sugg_incl)
+static struct ast_config *config_curl(const char *url, const char *unused, const char *file, struct ast_config *cfg, struct ast_flags flags, const char *sugg_incl, const char *who_asked)
{
struct ast_str *query;
char buf1[200];
@@ -463,7 +463,7 @@
}
if (!strcmp(var_name, "#include")) {
- if (!ast_config_internal_load(var_val, cfg, loader_flags, ""))
+ if (!ast_config_internal_load(var_val, cfg, loader_flags, "", who_asked))
return NULL;
}
Modified: trunk/res/res_config_ldap.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_config_ldap.c?view=diff&rev=107791&r1=107790&r2=107791
==============================================================================
--- trunk/res/res_config_ldap.c (original)
+++ trunk/res/res_config_ldap.c Tue Mar 11 17:55:16 2008
@@ -1006,7 +1006,7 @@
* called on a reload
*/
static struct ast_config *config_ldap(const char *basedn, const char *table_name,
- const char *file, struct ast_config *cfg, struct ast_flags config_flags, const char *sugg_incl)
+ const char *file, struct ast_config *cfg, struct ast_flags config_flags, const char *sugg_incl, const char *who_asked)
{
unsigned int vars_count = 0;
struct ast_variable **vars;
@@ -1088,7 +1088,7 @@
for (i = 0; i < vars_count; i++) {
if (!strcmp(categories[i].variable_name, "#include")) {
struct ast_flags config_flags = { 0 };
- if (!ast_config_internal_load(categories[i].variable_value, cfg, config_flags, ""))
+ if (!ast_config_internal_load(categories[i].variable_value, cfg, config_flags, "", who_asked))
break;
continue;
}
Modified: trunk/res/res_config_odbc.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_config_odbc.c?view=diff&rev=107791&r1=107790&r2=107791
==============================================================================
--- trunk/res/res_config_odbc.c (original)
+++ trunk/res/res_config_odbc.c Tue Mar 11 17:55:16 2008
@@ -625,7 +625,7 @@
return sth;
}
-static struct ast_config *config_odbc(const char *database, const char *table, const char *file, struct ast_config *cfg, struct ast_flags flags, const char *sugg_incl)
+static struct ast_config *config_odbc(const char *database, const char *table, const char *file, struct ast_config *cfg, struct ast_flags flags, const char *sugg_incl, const char *who_asked)
{
struct ast_variable *new_v;
struct ast_category *cur_cat;
@@ -682,7 +682,7 @@
while ((res = SQLFetch(stmt)) != SQL_NO_DATA) {
if (!strcmp (q.var_name, "#include")) {
- if (!ast_config_internal_load(q.var_val, cfg, loader_flags, "")) {
+ if (!ast_config_internal_load(q.var_val, cfg, loader_flags, "", who_asked)) {
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
ast_odbc_release_obj(obj);
return NULL;
Modified: trunk/res/res_config_pgsql.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_config_pgsql.c?view=diff&rev=107791&r1=107790&r2=107791
==============================================================================
--- trunk/res/res_config_pgsql.c (original)
+++ trunk/res/res_config_pgsql.c Tue Mar 11 17:55:16 2008
@@ -658,7 +658,7 @@
static struct ast_config *config_pgsql(const char *database, const char *table,
const char *file, struct ast_config *cfg,
- struct ast_flags flags, const char *suggested_incl)
+ struct ast_flags flags, const char *suggested_incl, const char *who_asked)
{
PGresult *result = NULL;
long num_rows;
@@ -723,7 +723,7 @@
char *field_var_val = PQgetvalue(result, rowIndex, 2);
char *field_cat_metric = PQgetvalue(result, rowIndex, 3);
if (!strcmp(field_var_name, "#include")) {
- if (!ast_config_internal_load(field_var_val, cfg, flags, "")) {
+ if (!ast_config_internal_load(field_var_val, cfg, flags, "", who_asked)) {
PQclear(result);
ast_mutex_unlock(&pgsql_lock);
return NULL;
Modified: trunk/res/res_config_sqlite.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_config_sqlite.c?view=diff&rev=107791&r1=107790&r2=107791
==============================================================================
--- trunk/res/res_config_sqlite.c (original)
+++ trunk/res/res_config_sqlite.c Tue Mar 11 17:55:16 2008
@@ -178,6 +178,7 @@
struct ast_category *cat;
char *cat_name;
struct ast_flags flags;
+ const char *who_asked;
};
/*!
@@ -277,7 +278,7 @@
* \see add_cfg_entry()
*/
static struct ast_config * config_handler(const char *database, const char *table, const char *file,
- struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl);
+ struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl, const char *who_asked);
/*!
* \brief Helper function to parse a va_list object into 2 dynamic arrays of
@@ -710,7 +711,7 @@
char *val;
val = argv[RES_CONFIG_SQLITE_CONFIG_VAR_VAL];
- cfg = ast_config_internal_load(val, args->cfg, args->flags, "");
+ cfg = ast_config_internal_load(val, args->cfg, args->flags, "", args->who_asked);
if (!cfg) {
ast_log(LOG_WARNING, "Unable to include %s\n", val);
@@ -753,7 +754,7 @@
}
static struct ast_config *config_handler(const char *database, const char *table, const char *file,
- struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl)
+ struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl, const char *who_asked)
{
struct cfg_entry_args args;
char *query, *errormsg;
@@ -779,6 +780,7 @@
args.cat = NULL;
args.cat_name = NULL;
args.flags = flags;
+ args.who_asked = who_asked;
ast_mutex_lock(&mutex);
More information about the asterisk-commits
mailing list