From 1ece349db580ff8ca5a90339d20381dcb24f1c4c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 10 Oct 1997 02:32:01 +0000 Subject: 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) (This used to be commit 1448f528b60402170257c1cdf6831cc40b4c86c9) --- source3/lib/util.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/source3/lib/util.c b/source3/lib/util.c index 701f324554..4e6bfb7054 100644 --- a/source3/lib/util.c +++ b/source3/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; @@ -190,7 +190,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 +201,7 @@ va_dcl #endif vfprintf(dbf,format_str,ap); va_end(ap); + errno = old_errno; return(0); } @@ -207,16 +209,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 +276,8 @@ va_dcl check_log_size(); + errno = old_errno; + return(0); } -- cgit