diff options
author | qwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-03-25 22:52:24 +0000 |
---|---|---|
committer | qwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-03-25 22:52:24 +0000 |
commit | e17a82292e4e73be1cd98e2919a59cb71e197ef9 (patch) | |
tree | 2946e9ebb0c3a48933656d77073e708e7f500e45 | |
parent | 009e06f774e0b74b8fce8a0e5d19f440d8444d5c (diff) |
Merged revisions 110780 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r110780 | qwell | 2008-03-25 17:51:55 -0500 (Tue, 25 Mar 2008) | 14 lines
Merged revisions 110779 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r110779 | qwell | 2008-03-25 17:51:17 -0500 (Tue, 25 Mar 2008) | 6 lines
Make file access in cdr_custom similar to cdr_csv.
Fixes issue #12268.
Patch borrowed from r82344
........
................
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@110781 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | cdr/cdr_custom.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/cdr/cdr_custom.c b/cdr/cdr_custom.c index fbfb8d527..6ecef8af4 100644 --- a/cdr/cdr_custom.c +++ b/cdr/cdr_custom.c @@ -43,17 +43,17 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/config.h" #include "asterisk/pbx.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]=""; @@ -104,6 +104,8 @@ static int load_config(int reload) 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; @@ -120,23 +122,24 @@ static int custom_log(struct ast_cdr *cdr) /* 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; } @@ -149,8 +152,6 @@ static int load_module(void) 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; |