From 2cd40c2bd704fb4fb261aca925ec92741cdae141 Mon Sep 17 00:00:00 2001 From: Rodrigo Ramírez Norambuena Date: Mon, 1 Jun 2015 13:08:22 -0400 Subject: cdr/cdr_csv.c: Set file name for csv master to the module when (re)loaded. Compute the location for the csv master file when the module is loaded or reload. Before it was calculated every time a log entry was written. Change-Id: I3ed9f6a8f965308099db70b71128f43d4d3f5585 --- cdr/cdr_csv.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'cdr') diff --git a/cdr/cdr_csv.c b/cdr/cdr_csv.c index 6fb2b7160..31f95c00f 100644 --- a/cdr/cdr_csv.c +++ b/cdr/cdr_csv.c @@ -60,6 +60,7 @@ static int loguserfield = 0; 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 */ @@ -120,6 +121,12 @@ static int load_config(int reload) return 0; } + /* compute the location of the csv master file */ + ast_mutex_lock(&f_lock); + snprintf(file_csv_master, sizeof(file_csv_master), + "%s/%s/%s", ast_config_AST_LOG_DIR, CSV_LOG_DIR, CSV_MASTER); + ast_mutex_unlock(&f_lock); + for (; v; v = v->next) { if (!strcasecmp(v->name, "usegmtime")) { usegmtime = ast_true(v->value); @@ -293,16 +300,14 @@ static int csv_log(struct ast_cdr *cdr) { /* 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)) -- cgit v1.2.3