mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-26 06:26:41 +00:00
Try to unscrew logger
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1828 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
62
logger.c
62
logger.c
@@ -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,50 +196,51 @@ 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);
|
||||||
|
|
||||||
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) {
|
if(rotate) {
|
||||||
/* do it */
|
for(x=0;;x++) {
|
||||||
if(! link(old,new))
|
snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
|
||||||
unlink(old);
|
myf = fopen((char *)new, "r");
|
||||||
strcpy(tmp,old);
|
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;
|
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);
|
||||||
snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR,f->fn);
|
f->f = NULL;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(rotate) {
|
if(rotate) {
|
||||||
/* do it */
|
snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR,f->fn);
|
||||||
if(! link(old,new))
|
|
||||||
unlink(old);
|
for(x=0;;x++) {
|
||||||
f->f = fopen((char *)old, "a");
|
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);
|
ast_mutex_unlock(&loglock);
|
||||||
|
|
||||||
if (eventlog) {
|
if (eventlog) {
|
||||||
|
|||||||
Reference in New Issue
Block a user