00268 {
00269
char old[
AST_CONFIG_MAX_PATH] =
"";
00270
char new[
AST_CONFIG_MAX_PATH];
00271
struct logchannel *f;
00272 FILE *myf;
00273
00274
int x;
00275
ast_mutex_lock(&loglock);
00276
if (eventlog)
00277 fclose(eventlog);
00278
else
00279 rotate = 0;
00280 eventlog = NULL;
00281
00282
00283
00284 mkdir((
char *)ast_config_AST_LOG_DIR, 0755);
00285 snprintf(old,
sizeof(old),
"%s/%s", (
char *)ast_config_AST_LOG_DIR, EVENTLOG);
00286
00287
if(rotate) {
00288
for(x=0;;x++) {
00289 snprintf(
new,
sizeof(
new),
"%s/%s.%d", (
char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
00290 myf = fopen((
char *)
new,
"r");
00291
if(myf)
00292 fclose(myf);
00293
else
00294
break;
00295 }
00296
00297
00298
if (rename(old,
new))
00299 fprintf(stderr,
"Unable to rename file '%s' to '%s'\n", old,
new);
00300 }
00301
00302 eventlog = fopen(old,
"a");
00303
00304 f = logchannels;
00305
while(f) {
00306
if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
00307 fclose(f->fileptr);
00308 f->fileptr = NULL;
00309
if(rotate) {
00310 strncpy(old, f->filename,
sizeof(old) - 1);
00311
00312
for(x=0;;x++) {
00313 snprintf(
new,
sizeof(
new),
"%s.%d", f->filename, x);
00314 myf = fopen((
char *)
new,
"r");
00315
if (myf) {
00316 fclose(myf);
00317 }
else {
00318
break;
00319 }
00320 }
00321
00322
00323
if (rename(old,
new))
00324 fprintf(stderr,
"Unable to rename file '%s' to '%s'\n", old,
new);
00325 }
00326 }
00327 f = f->next;
00328 }
00329
00330
ast_mutex_unlock(&loglock);
00331
00332 queue_log_init();
00333
00334
if (eventlog) {
00335 init_logger_chain();
00336
ast_log(LOG_EVENT,
"Restarted Asterisk Event Logger\n");
00337
if (
option_verbose)
00338
ast_verbose(
"Asterisk Event Logger restarted\n");
00339
return 0;
00340 }
else
00341
ast_log(LOG_ERROR,
"Unable to create event log: %s\n", strerror(errno));
00342 init_logger_chain();
00343 pending_logger_reload = 0;
00344
return -1;
00345 }