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
commit4ecfd2ea934f17367b48a195b57026035a72d578 (patch)
tree55c80b64826f9edb3ac056b9f1c393291c1c94c2
parentfe1337ba7b5eb683386f0794779b9f2e783e00a1 (diff)
downloadsamba-4ecfd2ea934f17367b48a195b57026035a72d578.tar.gz
samba-4ecfd2ea934f17367b48a195b57026035a72d578.tar.xz
samba-4ecfd2ea934f17367b48a195b57026035a72d578.zip
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)
-rw-r--r--source3/lib/util.c83
1 files changed, 50 insertions, 33 deletions
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
@@ -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);
}