[asterisk-commits] russell: trunk r202262 - /trunk/cdr/cdr_manager.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Jun 21 11:11:59 CDT 2009
Author: russell
Date: Sun Jun 21 11:11:48 2009
New Revision: 202262
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=202262
Log:
Fix possibility of crashiness during reload in custom fields handling.
Modified:
trunk/cdr/cdr_manager.c
Modified: trunk/cdr/cdr_manager.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/cdr/cdr_manager.c?view=diff&rev=202262&r1=202261&r2=202262
==============================================================================
--- trunk/cdr/cdr_manager.c (original)
+++ trunk/cdr/cdr_manager.c Sun Jun 21 11:11:48 2009
@@ -47,11 +47,8 @@
static int enablecdr = 0;
-/*!
- * XXX
- * \bug The handling of this variable is not thread-safe. Crashes are possible on reload.
- */
static struct ast_str *customfields;
+AST_RWLOCK_DEFINE_STATIC(customfields_lock);
static int manager_log(struct ast_cdr *cdr);
@@ -72,11 +69,6 @@
ast_log(LOG_ERROR, "Config file '%s' could not be parsed\n", CONF_FILE);
return -1;
}
-
- if (reload && customfields) {
- ast_free(customfields);
- }
- customfields = NULL;
if (!cfg) {
/* Standard configuration */
@@ -85,6 +77,15 @@
ast_cdr_unregister(name);
enablecdr = 0;
return -1;
+ }
+
+ if (reload) {
+ ast_rwlock_wrlock(&customfields_lock);
+ }
+
+ if (reload && customfields) {
+ ast_free(customfields);
+ customfields = NULL;
}
while ( (cat = ast_category_browse(cfg, cat)) ) {
@@ -115,6 +116,10 @@
}
}
+ if (reload) {
+ ast_rwlock_unlock(&customfields_lock);
+ }
+
ast_config_destroy(cfg);
if (enablecdr && !newenablecdr)
@@ -148,9 +153,9 @@
ast_localtime(&cdr->end, &timeresult, NULL);
ast_strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
- buf[0] = 0;
- /* Custom fields handling */
- if (customfields != NULL && ast_str_strlen(customfields)) {
+ buf[0] = '\0';
+ ast_rwlock_rdlock(&customfields_lock);
+ if (customfields && ast_str_strlen(customfields)) {
struct ast_channel *dummy = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Substitution/%p", cdr);
if (!dummy) {
ast_log(LOG_ERROR, "Unable to allocate channel for variable substitution.\n");
@@ -160,6 +165,7 @@
pbx_substitute_variables_helper(dummy, ast_str_buffer(customfields), buf, sizeof(buf) - 1);
ast_channel_release(dummy);
}
+ ast_rwlock_unlock(&customfields_lock);
manager_event(EVENT_FLAG_CDR, "Cdr",
"AccountCode: %s\r\n"
More information about the asterisk-commits
mailing list