[Asterisk-code-review] cdr/cdr csv.c: Set file name for csv master to the module wh... (asterisk[master])

Rodrigo Ramirez Norambuena asteriskteam at digium.com
Thu May 7 19:56:53 CDT 2015


Rodrigo Ramirez Norambuena has uploaded a new change for review.

  https://gerrit.asterisk.org/404

Change subject: cdr/cdr_csv.c: Set file name for csv master to the module when (re)loaded.
......................................................................

cdr/cdr_csv.c: Set file name for csv master to the module when (re)loaded.

Change the compute the location for file csv master when the module is
loaded or reload. Before is calculated every time wrote a log.

Change-Id: I3ed9f6a8f965308099db70b71128f43d4d3f5585
---
M cdr/cdr_csv.c
1 file changed, 7 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/04/404/1

diff --git a/cdr/cdr_csv.c b/cdr/cdr_csv.c
index 6fb2b71..189156b 100644
--- a/cdr/cdr_csv.c
+++ b/cdr/cdr_csv.c
@@ -60,6 +60,7 @@
 static int loaded = 0;
 static int newcdrcolumns = 0;
 static const char config[] = "cdr.conf";
+static char file_csv_master[PATH_MAX];
 
 /* #define CSV_LOGUNIQUEID 1 */
 /* #define CSV_LOGUSERFIELD 1 */
@@ -119,6 +120,10 @@
 		ast_config_destroy(cfg);
 		return 0;
 	}
+
+	/* compute the location of the csv master file */
+	snprintf(file_csv_master, sizeof(file_csv_master),
+		"%s/%s/%s", ast_config_AST_LOG_DIR, CSV_LOG_DIR, CSV_MASTER);
 
 	for (; v; v = v->next) {
 		if (!strcasecmp(v->name, "usegmtime")) {
@@ -293,16 +298,14 @@
 {
 	/* Make sure we have a big enough buf */
 	char buf[1024];
-	char csvmaster[PATH_MAX];
-	snprintf(csvmaster, sizeof(csvmaster),"%s/%s/%s", ast_config_AST_LOG_DIR, CSV_LOG_DIR, CSV_MASTER);
 	if (build_csv_record(buf, sizeof(buf), cdr)) {
 		ast_log(LOG_WARNING, "Unable to create CSV record in %d bytes.  CDR not recorded!\n", (int)sizeof(buf));
 		return 0;
 	}
 
 	ast_mutex_lock(&f_lock);
-	if (writefile(buf, csvmaster))
-		ast_log(LOG_WARNING, "Unable to write CSV record to master '%s' : %s\n", csvmaster, strerror(errno));
+	if (writefile(buf, file_csv_master))
+		ast_log(LOG_WARNING, "Unable to write CSV record to master '%s' : %s\n", file_csv_master, strerror(errno));
 
 	if (accountlogs && !ast_strlen_zero(cdr->accountcode)) {
 		if (writefile_account(buf, cdr->accountcode))

-- 
To view, visit https://gerrit.asterisk.org/404
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3ed9f6a8f965308099db70b71128f43d4d3f5585
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Rodrigo Ramirez Norambuena <decipher.hk at gmail.com>



More information about the asterisk-code-review mailing list