[svn-commits] seanbright: branch 1.6.2 r202473 - in /branches/1.6.2: ./ cdr/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Mon Jun 22 11:31:09 CDT 2009
Author: seanbright
Date: Mon Jun 22 11:31:05 2009
New Revision: 202473
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=202473
Log:
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.
........
Modified:
branches/1.6.2/ (props changed)
branches/1.6.2/cdr/cdr_sqlite3_custom.c
Propchange: branches/1.6.2/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.
Modified: branches/1.6.2/cdr/cdr_sqlite3_custom.c
URL: http://svn.asterisk.org/svn-view/asterisk/branches/1.6.2/cdr/cdr_sqlite3_custom.c?view=diff&rev=202473&r1=202472&r2=202473
==============================================================================
--- branches/1.6.2/cdr/cdr_sqlite3_custom.c (original)
+++ branches/1.6.2/cdr/cdr_sqlite3_custom.c Mon Jun 22 11:31:05 2009
@@ -70,7 +70,7 @@
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)
{
@@ -166,11 +166,8 @@
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;
}
@@ -185,7 +182,6 @@
/* Columns */
if (load_column_config(ast_variable_retrieve(cfg, "master", "columns"))) {
- ast_mutex_unlock(&lock);
ast_config_destroy(cfg);
free_config();
return -1;
@@ -193,7 +189,6 @@
/* Values */
if (load_values_config(ast_variable_retrieve(cfg, "master", "values"))) {
- ast_mutex_unlock(&lock);
ast_config_destroy(cfg);
free_config();
return -1;
@@ -201,17 +196,14 @@
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);
@@ -226,10 +218,6 @@
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)
@@ -244,6 +232,8 @@
/* Should not have loaded, but be failsafe. */
return 0;
}
+
+ ast_mutex_lock(&lock);
{ /* Make it obvious that only sql should be used outside of this block */
char *escaped;
@@ -262,8 +252,6 @@
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);
@@ -289,9 +277,9 @@
static int unload_module(void)
{
+ ast_cdr_unregister(name);
+
free_config();
-
- ast_cdr_unregister(name);
return 0;
}
@@ -303,14 +291,7 @@
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;
}
@@ -340,12 +321,25 @@
}
}
- 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",
More information about the svn-commits
mailing list