[asterisk-commits] seanbright: branch group/newcdr r202485 - /team/group/newcdr/cel/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jun 22 11:59:57 CDT 2009
Author: seanbright
Date: Mon Jun 22 11:59:54 2009
New Revision: 202485
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=202485
Log:
Fix lock usage in cel_sqlite3_custom to avoid potential crashes during reload.
Pointed out by Russell while working on the CEL branch.
Modified:
team/group/newcdr/cel/cel_sqlite3_custom.c
Modified: team/group/newcdr/cel/cel_sqlite3_custom.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/cel/cel_sqlite3_custom.c?view=diff&rev=202485&r1=202484&r2=202485
==============================================================================
--- team/group/newcdr/cel/cel_sqlite3_custom.c (original)
+++ team/group/newcdr/cel/cel_sqlite3_custom.c Mon Jun 22 11:59:54 2009
@@ -75,7 +75,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)
{
@@ -172,11 +172,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;
}
@@ -191,7 +188,6 @@
/* Columns */
if (load_column_config(ast_variable_retrieve(cfg, "master", "columns"))) {
- ast_mutex_unlock(&lock);
ast_config_destroy(cfg);
free_config();
return -1;
@@ -199,7 +195,6 @@
/* Values */
if (load_values_config(ast_variable_retrieve(cfg, "master", "values"))) {
- ast_mutex_unlock(&lock);
ast_config_destroy(cfg);
free_config();
return -1;
@@ -207,17 +202,14 @@
ast_verb(3, "Logging CEL 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);
@@ -232,10 +224,6 @@
while ((value = AST_LIST_REMOVE_HEAD(&sql_values, list))) {
ast_free(value);
}
-
- ast_mutex_unlock(&lock);
-
- return 0;
}
static void sqlite3_log(const struct ast_event *event, void *userdata)
@@ -248,6 +236,8 @@
/* Should not have loaded, but be failsafe. */
return;
}
+
+ ast_mutex_lock(&lock);
{ /* Make it obvious that only sql should be used outside of this block */
char *escaped;
@@ -260,6 +250,7 @@
if (!dummy) {
ast_log(LOG_ERROR, "Unable to fabricate channel from CEL event.\n");
ast_free(value_string);
+ ast_mutex_unlock(&lock);
return;
}
AST_LIST_TRAVERSE(&sql_values, value, list) {
@@ -274,8 +265,6 @@
ast_free(value_string);
}
- ast_mutex_lock(&lock);
-
/* XXX This seems awful arbitrary... */
for (count = 0; count < 5; count++) {
int res = sqlite3_exec(db, sql, NULL, NULL, &error);
@@ -301,11 +290,11 @@
static int unload_module(void)
{
- free_config();
-
if (event_sub) {
event_sub = ast_event_unsubscribe(event_sub);
}
+
+ free_config();
return 0;
}
@@ -317,14 +306,7 @@
int res;
char *sql;
- if (!load_config(0)) {
- event_sub = ast_event_subscribe(AST_EVENT_CEL, sqlite3_log, "CEL sqlite3 custom backend", NULL, AST_EVENT_IE_END);
- if (!event_sub) {
- ast_log(LOG_ERROR, "Unable to register custom SQLite3 CEL handling\n");
- free_config();
- return AST_MODULE_LOAD_DECLINE;
- }
- } else {
+ if (load_config(0)) {
return AST_MODULE_LOAD_DECLINE;
}
@@ -354,12 +336,25 @@
}
}
+ event_sub = ast_event_subscribe(AST_EVENT_CEL, sqlite3_log, "CEL sqlite3 custom backend", NULL, AST_EVENT_IE_END);
+ if (!event_sub) {
+ ast_log(LOG_ERROR, "Unable to register custom SQLite3 CEL 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_lock(&lock);
+
+ return res;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "SQLite3 Custom CEL Module",
More information about the asterisk-commits
mailing list