Try to unscrew logger

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1828 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.0
Mark Spencer 22 years ago
parent fac7eaffa9
commit 09573266da

@ -185,9 +185,9 @@ static void init_logger_chain(void)
int reload_logger(int rotate) int reload_logger(int rotate)
{ {
char old[AST_CONFIG_MAX_PATH]; char old[AST_CONFIG_MAX_PATH];
char tmp[AST_CONFIG_MAX_PATH];
char new[AST_CONFIG_MAX_PATH]; char new[AST_CONFIG_MAX_PATH];
struct logfile *f; struct logfile *f;
FILE *myf;
int x; int x;
@ -196,49 +196,50 @@ int reload_logger(int rotate)
fclose(eventlog); fclose(eventlog);
else else
rotate = 0; rotate = 0;
eventlog = NULL;
mkdir((char *)ast_config_AST_LOG_DIR, 0755); mkdir((char *)ast_config_AST_LOG_DIR, 0755);
snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG); snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
if(rotate) {
for(x=0;;x++) { for(x=0;;x++) {
snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x); snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
eventlog = fopen((char *)new, "r"); myf = fopen((char *)new, "r");
if(eventlog) if(myf)
fclose(eventlog); fclose(myf);
else else
break; break;
} }
if(rotate) {
/* do it */ /* do it */
if(! link(old,new)) if (rename(old,new))
unlink(old); fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
strcpy(tmp,old);
} }
eventlog = fopen(old, "a");
f = logfiles; f = logfiles;
while(f) { while(f) {
if (f->f && (f->f != stdout) && (f->f != stderr)) { if (f->f && (f->f != stdout) && (f->f != stderr)) {
fclose(f->f); fclose(f->f);
f->f = NULL;
if(rotate) {
snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR,f->fn); snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR,f->fn);
for(x=0;;x++) { for(x=0;;x++) {
snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR,f->fn,x); snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR,f->fn,x);
eventlog = fopen((char *)new, "r"); myf = fopen((char *)new, "r");
if(eventlog) if(f)
fclose(eventlog); fclose(myf);
else else
break; break;
} }
if(rotate) {
/* do it */ /* do it */
if(! link(old,new)) if (rename(old,new))
unlink(old); fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
f->f = fopen((char *)old, "a");
} }
@ -249,7 +250,6 @@ int reload_logger(int rotate)
} }
eventlog = fopen((char *)tmp, "a");
ast_mutex_unlock(&loglock); ast_mutex_unlock(&loglock);
if (eventlog) { if (eventlog) {

Loading…
Cancel
Save