[asterisk-commits] anthonyl: branch anthonyl/log-reload r48856 -
/team/anthonyl/log-reload/logger.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Thu Dec 21 21:52:53 MST 2006
Author: anthonyl
Date: Thu Dec 21 22:52:53 2006
New Revision: 48856
URL: http://svn.digium.com/view/asterisk?view=rev&rev=48856
Log:
after doing some research in glibc's code _IO_FILE defined in libio.h keeps track of things using (char *)'s writing to anywhere in the file using fprintf. so checking aginst INT_MAX works in my testing cases, im not totally sure if this is the perfect way to do this
Modified:
team/anthonyl/log-reload/logger.c
Modified: team/anthonyl/log-reload/logger.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/log-reload/logger.c?view=diff&rev=48856&r1=48855&r2=48856
==============================================================================
--- team/anthonyl/log-reload/logger.c (original)
+++ team/anthonyl/log-reload/logger.c Thu Dec 21 22:52:53 2006
@@ -80,7 +80,6 @@
AST_MUTEX_DEFINE_STATIC(msglist_lock);
AST_MUTEX_DEFINE_STATIC(loglock);
-static int filesize_reload_needed = 0;
static int global_logmask = -1;
static struct {
@@ -434,8 +433,6 @@
f = f->next;
}
- filesize_reload_needed = 0;
-
init_logger_chain();
if (logfiles.event_log) {
@@ -593,20 +590,12 @@
handle_logger_rotate, "Rotates and reopens the log files",
logger_rotate_help };
-static int handle_SIGXFSZ(int sig)
-{
- /* Indicate need to reload */
- filesize_reload_needed = 1;
- return 0;
-}
-
int init_logger(void)
{
char tmp[256];
int res = 0;
- /* auto rotate if sig SIGXFSZ comes a-knockin */
- (void) signal(SIGXFSZ,(void *) handle_SIGXFSZ);
+ (void) sigignore(SIGXFSZ);
/* register the relaod logger cli command */
ast_cli_register(&reload_logger_cli);
@@ -694,6 +683,7 @@
{
struct logchannel *chan;
char buf[BUFSIZ];
+ unsigned int f_pos;
time_t t;
struct tm tm;
char date[256];
@@ -714,7 +704,7 @@
}
return;
}
-
+
/* don't display LOG_DEBUG messages unless option_verbose _or_ option_debug
are non-zero; LOG_DEBUG messages can still be displayed if option_debug
is zero, if option_verbose is non-zero (this allows for 'level zero'
@@ -785,6 +775,13 @@
int res;
snprintf(buf, sizeof(buf), option_timestamp ? "[%s] %s[%ld]: " : "%s %s[%ld] %s: ", date,
levels[level], (long)GETTID(), file);
+ res = ftell(chan->fileptr);
+ if (res <= 0 || f_pos >= (INT_MAX - strlen(buf))) {
+ /* the log requres reloading here, this locking seems messy.*/
+ ast_mutex_unlock(&loglock);
+ reload_logger(1);
+ ast_mutex_lock(&loglock);
+ }
res = fprintf(chan->fileptr, buf);
if (res <= 0 && buf[0] != '\0') { /* Error, no characters printed */
fprintf(stderr,"**** Asterisk Logging Error: ***********\n");
@@ -805,15 +802,7 @@
}
}
chan = chan->next;
- }
-
ast_mutex_unlock(&loglock);
- /* end critical section */
- if (filesize_reload_needed) {
- reload_logger(1);
- ast_log(LOG_EVENT,"Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n");
- if (option_verbose)
- ast_verbose("Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n");
}
}
More information about the asterisk-commits
mailing list