summaryrefslogtreecommitdiff
path: root/source/lib/util.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1997-10-10 02:35:55 +0000
committerAndrew Tridgell <tridge@samba.org>1997-10-10 02:35:55 +0000
commita70d0fc26ff0eed6ab4adea1b17f2d184d133d05 (patch)
tree622bdae09433539da8c9562cf051b92a75e49fec /source/lib/util.c
parent4bf12a48435b3ec504439251638586c76742010c (diff)
downloadsamba-a70d0fc26ff0eed6ab4adea1b17f2d184d133d05.tar.gz
fixed the log wrapping bug.
This is a very nasty bug that I think explains quite a few intermittent problems people have been having with Samba. It may be worth checking on other cases where errno can be overwritten by seemingly innocuous things (in this case a DEBUG() line)
Diffstat (limited to 'source/lib/util.c')
-rw-r--r--source/lib/util.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/source/lib/util.c b/source/lib/util.c
index 7f785332e6a..459745b8b14 100644
--- a/source/lib/util.c
+++ b/source/lib/util.c
@@ -156,7 +156,7 @@ static void check_log_size(void)
int maxlog;
struct stat st;
- if (debug_count++ < 100) return;
+ if (debug_count++ < 100 || getuid() != 0) return;
maxlog = lp_max_log_size() * 1024;
if (!dbf || maxlog <= 0) return;
@@ -175,7 +175,6 @@ static void check_log_size(void)
debug_count=0;
}
-
/*******************************************************************
write an debug message on the debugfile. This is called by the DEBUG
macro
@@ -190,7 +189,8 @@ va_dcl
char *format_str;
#endif
va_list ap;
-
+ int old_errno = errno;
+
if (stdout_logging) {
#ifdef __STDC__
va_start(ap, format_str);
@@ -200,6 +200,7 @@ va_dcl
#endif
vfprintf(dbf,format_str,ap);
va_end(ap);
+ errno = old_errno;
return(0);
}
@@ -207,16 +208,17 @@ va_dcl
if (!lp_syslog_only())
#endif
{
- if (!dbf)
- {
- int oldumask = umask(022);
- dbf = fopen(debugf,"w");
- umask(oldumask);
- if (dbf)
- setbuf(dbf,NULL);
- else
- return(0);
- }
+ if (!dbf) {
+ int oldumask = umask(022);
+ dbf = fopen(debugf,"w");
+ umask(oldumask);
+ if (dbf) {
+ setbuf(dbf,NULL);
+ } else {
+ errno = old_errno;
+ return(0);
+ }
+ }
}
#ifdef SYSLOG
@@ -273,6 +275,8 @@ va_dcl
check_log_size();
+ errno = old_errno;
+
return(0);
}