summaryrefslogtreecommitdiff
path: root/logger.c
diff options
context:
space:
mode:
authorMark Spencer <markster@digium.com>2003-12-05 00:50:42 +0000
committerMark Spencer <markster@digium.com>2003-12-05 00:50:42 +0000
commit09573266da4d5b608792385f18d4c1d134a74a4b (patch)
treed455ce4edf1f404fb3c7befc604ce5e92aaca43a /logger.c
parentfac7eaffa947788a5a42f7dcc94c20ac635f1dab (diff)
Try to unscrew logger
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1828 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'logger.c')
-rwxr-xr-xlogger.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/logger.c b/logger.c
index d344611b1..a0f5dac12 100755
--- a/logger.c
+++ b/logger.c
@@ -185,9 +185,9 @@ static void init_logger_chain(void)
int reload_logger(int rotate)
{
char old[AST_CONFIG_MAX_PATH];
- char tmp[AST_CONFIG_MAX_PATH];
char new[AST_CONFIG_MAX_PATH];
struct logfile *f;
+ FILE *myf;
int x;
@@ -196,50 +196,51 @@ int reload_logger(int rotate)
fclose(eventlog);
else
rotate = 0;
+ eventlog = NULL;
mkdir((char *)ast_config_AST_LOG_DIR, 0755);
snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
- for(x=0;;x++) {
- snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
- eventlog = fopen((char *)new, "r");
- if(eventlog)
- fclose(eventlog);
- else
- break;
- }
-
if(rotate) {
- /* do it */
- if(! link(old,new))
- unlink(old);
- strcpy(tmp,old);
+ for(x=0;;x++) {
+ snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
+ myf = fopen((char *)new, "r");
+ if(myf)
+ fclose(myf);
+ else
+ break;
+ }
+
+ /* do it */
+ if (rename(old,new))
+ fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
}
+ eventlog = fopen(old, "a");
f = logfiles;
while(f) {
if (f->f && (f->f != stdout) && (f->f != stderr)) {
fclose(f->f);
- snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR,f->fn);
-
- for(x=0;;x++) {
- snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR,f->fn,x);
- eventlog = fopen((char *)new, "r");
- if(eventlog)
- fclose(eventlog);
- else
- break;
- }
-
+ f->f = NULL;
if(rotate) {
- /* do it */
- if(! link(old,new))
- unlink(old);
- f->f = fopen((char *)old, "a");
- }
+ snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR,f->fn);
+
+ for(x=0;;x++) {
+ snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR,f->fn,x);
+ myf = fopen((char *)new, "r");
+ if(f)
+ fclose(myf);
+ else
+ break;
+ }
+
+ /* do it */
+ if (rename(old,new))
+ fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
+ }
}
@@ -249,7 +250,6 @@ int reload_logger(int rotate)
}
- eventlog = fopen((char *)tmp, "a");
ast_mutex_unlock(&loglock);
if (eventlog) {