diff options
author | seanbright <seanbright@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-06-22 16:31:02 +0000 |
---|---|---|
committer | seanbright <seanbright@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-06-22 16:31:02 +0000 |
commit | 6132bd8ddced6cb1fd4c21c40624baf1afe33631 (patch) | |
tree | d525187307004a0a4d48b3c18e59a85d6bb37883 /cdr | |
parent | 629fc68556ec39180e65a8c018ee5503bbdafce8 (diff) |
Merged revisions 202417 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
........
r202417 | seanbright | 2009-06-22 12:09:50 -0400 (Mon, 22 Jun 2009) | 4 lines
Fix lock usage in cdr_sqlite3_custom to avoid potential crashes during reload.
Pointed out by Russell while working on the CEL branch.
........
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.1@202472 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cdr')
-rw-r--r-- | cdr/cdr_sqlite3_custom.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/cdr/cdr_sqlite3_custom.c b/cdr/cdr_sqlite3_custom.c index fc4741d41..64981191d 100644 --- a/cdr/cdr_sqlite3_custom.c +++ b/cdr/cdr_sqlite3_custom.c @@ -70,7 +70,7 @@ struct values { static AST_LIST_HEAD_STATIC(sql_values, values); -static int free_config(void); +static void free_config(void); static int load_column_config(const char *tmp) { @@ -170,11 +170,8 @@ static int load_config(int reload) if (reload) free_config(); - ast_mutex_lock(&lock); - if (!(mappingvar = ast_variable_browse(cfg, "master"))) { /* Nothing configured */ - ast_mutex_unlock(&lock); ast_config_destroy(cfg); return -1; } @@ -191,7 +188,6 @@ static int load_config(int reload) /* Columns */ tmp = ast_variable_retrieve(cfg, "master", "columns"); if (load_column_config(tmp)) { - ast_mutex_unlock(&lock); ast_config_destroy(cfg); free_config(); return -1; @@ -200,7 +196,6 @@ static int load_config(int reload) /* Values */ tmp = ast_variable_retrieve(cfg, "master", "values"); if (load_values_config(tmp)) { - ast_mutex_unlock(&lock); ast_config_destroy(cfg); free_config(); return -1; @@ -208,18 +203,15 @@ static int load_config(int reload) ast_verb(3, "cdr_sqlite3_custom: Logging CDR records to table '%s' in 'master.db'\n", table); - ast_mutex_unlock(&lock); ast_config_destroy(cfg); return 0; } -static int free_config(void) +static void free_config(void) { struct values *value; - ast_mutex_lock(&lock); - if (db) { sqlite3_close(db); db = NULL; @@ -232,10 +224,6 @@ static int free_config(void) while ((value = AST_LIST_REMOVE_HEAD(&sql_values, list))) ast_free(value); - - ast_mutex_unlock(&lock); - - return 0; } static int sqlite3_log(struct ast_cdr *cdr) @@ -251,6 +239,8 @@ static int sqlite3_log(struct ast_cdr *cdr) return 0; } + ast_mutex_lock(&lock); + { /* Make it obvious that only sql should be used outside of this block */ char *escaped; char subst_buf[2048]; @@ -272,8 +262,6 @@ static int sqlite3_log(struct ast_cdr *cdr) ast_free(value_string); } - ast_mutex_lock(&lock); - /* XXX This seems awful arbitrary... */ for (count = 0; count < 5; count++) { res = sqlite3_exec(db, sql, NULL, NULL, &error); @@ -297,10 +285,10 @@ static int sqlite3_log(struct ast_cdr *cdr) static int unload_module(void) { - free_config(); - ast_cdr_unregister(name); + free_config(); + return 0; } @@ -311,15 +299,9 @@ static int load_module(void) int res; char *sql; - if (!load_config(0)) { - res = ast_cdr_register(name, desc, sqlite3_log); - if (res) { - ast_log(LOG_ERROR, "Unable to register custom SQLite3 CDR handling\n"); - free_config(); - return AST_MODULE_LOAD_DECLINE; - } - } else + if (load_config(0)) { return AST_MODULE_LOAD_DECLINE; + } /* is the database there? */ snprintf(filename, sizeof(filename), "%s/master.db", ast_config_AST_LOG_DIR); @@ -347,12 +329,25 @@ static int load_module(void) } } - return 0; + res = ast_cdr_register(name, desc, sqlite3_log); + if (res) { + ast_log(LOG_ERROR, "Unable to register custom SQLite3 CDR handling\n"); + free_config(); + return AST_MODULE_LOAD_DECLINE; + } + + return AST_MODULE_LOAD_SUCCESS; } static int reload(void) { - return load_config(1); + int res = 0; + + ast_mutex_lock(&lock); + res = load_config(1); + ast_mutex_unlock(&lock); + + return res; } AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "SQLite3 Custom CDR Module", |