[asterisk-commits] qwell: branch 1.4 r110779 - /branches/1.4/cdr/cdr_custom.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 25 17:51:18 CDT 2008


Author: qwell
Date: Tue Mar 25 17:51:17 2008
New Revision: 110779

URL: http://svn.digium.com/view/asterisk?view=rev&rev=110779
Log:
Make file access in cdr_custom similar to cdr_csv.

Fixes issue #12268.

Patch borrowed from r82344

Modified:
    branches/1.4/cdr/cdr_custom.c

Modified: branches/1.4/cdr/cdr_custom.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/cdr/cdr_custom.c?view=diff&rev=110779&r1=110778&r2=110779
==============================================================================
--- branches/1.4/cdr/cdr_custom.c (original)
+++ branches/1.4/cdr/cdr_custom.c Tue Mar 25 17:51:17 2008
@@ -50,16 +50,16 @@
 #include "asterisk/pbx.h"
 #include "asterisk/logger.h"
 #include "asterisk/utils.h"
+#include "asterisk/lock.h"
 
 #define CUSTOM_LOG_DIR "/cdr_custom"
 
 #define DATE_FORMAT "%Y-%m-%d %T"
 
 AST_MUTEX_DEFINE_STATIC(lock);
+AST_MUTEX_DEFINE_STATIC(mf_lock);
 
 static char *name = "cdr-custom";
-
-static FILE *mf = NULL;
 
 static char master[PATH_MAX];
 static char format[1024]="";
@@ -107,6 +107,8 @@
 
 static int custom_log(struct ast_cdr *cdr)
 {
+	FILE *mf = NULL;
+
 	/* Make sure we have a big enough buf */
 	char buf[2048];
 	struct ast_channel dummy;
@@ -124,23 +126,24 @@
 	/* because of the absolutely unconditional need for the
 	   highest reliability possible in writing billing records,
 	   we open write and close the log file each time */
+	ast_mutex_lock(&mf_lock);
 	mf = fopen(master, "a");
-	if (!mf) {
-		ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n", master, strerror(errno));
-	}
 	if (mf) {
 		fputs(buf, mf);
 		fflush(mf); /* be particularly anal here */
 		fclose(mf);
 		mf = NULL;
+		ast_mutex_unlock(&mf_lock);
+	} else {
+		ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n", master, strerror(errno));
+		ast_mutex_unlock(&mf_lock);
 	}
+
 	return 0;
 }
 
 static int unload_module(void)
 {
-	if (mf)
-		fclose(mf);
 	ast_cdr_unregister(name);
 	return 0;
 }
@@ -153,8 +156,6 @@
 		res = ast_cdr_register(name, ast_module_info->description, custom_log);
 		if (res)
 			ast_log(LOG_ERROR, "Unable to register custom CDR handling\n");
-		if (mf)
-			fclose(mf);
 		return res;
 	} else 
 		return AST_MODULE_LOAD_DECLINE;




More information about the asterisk-commits mailing list