From 4ecfd2ea934f17367b48a195b57026035a72d578 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 29 May 1996 03:11:42 +0000 Subject: cleaned up the way the max log size stuff works and fixed a potential problem with varargs usage in Debug() (This used to be commit 8d5a3156ce42198b2f3ca8753e208b08572cafce) --- source3/lib/util.c | 83 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 33 deletions(-) (limited to 'source3') diff --git a/source3/lib/util.c b/source3/lib/util.c index bc0edb15c1..233e987271 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -150,6 +150,35 @@ void reopen_logs(void) } +/******************************************************************* +check if the log has grown too big +********************************************************************/ +static void check_log_size(void) +{ + static int debug_count=0; + int maxlog; + struct stat st; + + if (debug_count++ < 100) return; + + maxlog = lp_max_log_size() * 1024; + if (!dbf || maxlog <= 0) return; + + if (fstat(fileno(dbf),&st) == 0 && st.st_size > maxlog) { + fclose(dbf); dbf = NULL; + reopen_logs(); + if (dbf && file_size(debugf) > maxlog) { + pstring name; + fclose(dbf); dbf = NULL; + sprintf(name,"%s.old",debugf); + sys_rename(debugf,name); + reopen_logs(); + } + } + debug_count=0; +} + + /******************************************************************* write an debug message on the debugfile. This is called by the DEBUG macro @@ -165,44 +194,17 @@ va_dcl #endif va_list ap; + if (stdout_logging) { #ifdef __STDC__ - va_start(ap, format_str); + va_start(ap, format_str); #else - va_start(ap); - format_str = va_arg(ap,char *); + va_start(ap); + format_str = va_arg(ap,char *); #endif - - if (stdout_logging) { vfprintf(dbf,format_str,ap); va_end(ap); return(0); } - - { - static int debug_count=0; - - debug_count++; - if (debug_count == 100) { - int maxlog = lp_max_log_size() * 1024; - if (dbf && maxlog > 0) - { - struct stat st; - - if (fstat(fileno(dbf),&st) == 0 && st.st_size > maxlog) { - fclose(dbf); dbf = NULL; - reopen_logs(); - if (dbf && file_size(debugf) > maxlog) { - pstring name; - fclose(dbf); dbf = NULL; - sprintf(name,"%s.old",debugf); - sys_rename(debugf,name); - reopen_logs(); - } - } - } - debug_count=0; - } - } #ifdef SYSLOG if (!lp_syslog_only()) @@ -241,7 +243,14 @@ va_dcl else priority = priority_map[syslog_level]; +#ifdef __STDC__ + va_start(ap, format_str); +#else + va_start(ap); + format_str = va_arg(ap,char *); +#endif vsprintf(msgbuf, format_str, ap); + va_end(ap); msgbuf[255] = '\0'; syslog(priority, "%s", msgbuf); @@ -252,11 +261,19 @@ va_dcl if (!lp_syslog_only()) #endif { +#ifdef __STDC__ + va_start(ap, format_str); +#else + va_start(ap); + format_str = va_arg(ap,char *); +#endif vfprintf(dbf,format_str,ap); + va_end(ap); fflush(dbf); } - - va_end(ap); + + check_log_size(); + return(0); } -- cgit