summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1996-05-29 03:11:42 +0000
committerAndrew Tridgell <tridge@samba.org>1996-05-29 03:11:42 +0000
commit8d5a3156ce42198b2f3ca8753e208b08572cafce (patch)
treebfa85572e2f1bb728493dfedeeee102e60bf68d6
parent234ba8569705009eed00ba044d6bb0459e506a7d (diff)
downloadsamba-8d5a3156ce42198b2f3ca8753e208b08572cafce.tar.gz
samba-8d5a3156ce42198b2f3ca8753e208b08572cafce.tar.xz
samba-8d5a3156ce42198b2f3ca8753e208b08572cafce.zip
cleaned up the way the max log size stuff works and fixed a potential
problem with varargs usage in Debug()
-rw-r--r--source/lib/util.c83
1 files changed, 50 insertions, 33 deletions
diff --git a/source/lib/util.c b/source/lib/util.c
index bc0edb15c17..233e9872711 100644
--- a/source/lib/util.c
+++ b/source/lib/util.c
@@ -151,6 +151,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);
}