Log file check patch from Mattias Gronlund <Mattias.Gronlund@sa.erisoft.se>.
authorJeremy Allison <jra@samba.org>
Sat, 15 Apr 2000 00:21:27 +0000 (00:21 +0000)
committerJeremy Allison <jra@samba.org>
Sat, 15 Apr 2000 00:21:27 +0000 (00:21 +0000)
Modified to do checks in timeout processing not in main loop. This (IMHO)
is the correct place as (a) we are already root, and (b) it is guarenteed
to be called every 200 smb requests.
Jeremy.

source/include/proto.h
source/lib/debug.c
source/smbd/process.c

index 98422c264d77f16e81214e515558663a531d43c0..dce584a49c3bcf4bdb5637dfa1301755571190bd 100644 (file)
@@ -54,6 +54,8 @@ void sig_usr1( int sig );
 void setup_logging( char *pname, BOOL interactive );
 void reopen_logs( void );
 void force_check_log_size( void );
+BOOL need_to_check_log_size( void );
+void check_log_size( void );
 void dbgflush( void );
 BOOL dbghdr( int level, char *file, char *func, int line );
 
index c88f4e1a41f4a76313da37fd40b0fa816c121fb7..ed27b93cfd0ccd79e918464b7717a649eb76a5a6 100644 (file)
@@ -239,26 +239,52 @@ void reopen_logs( void )
  * ************************************************************************** **
  */
 void force_check_log_size( void )
-  {
+{
   debug_count = 100;
-  } /* force_check_log_size */
+}
+
+/***************************************************************************
+ Check to see if there is any need to check if the logfile has grown too big.
+**************************************************************************/
+
+BOOL need_to_check_log_size( void )
+{
+       int maxlog;
+
+       if( debug_count++ < 100 )
+               return( False );
+
+       maxlog = lp_max_log_size() * 1024;
+       if( !dbf || maxlog <= 0 ) {
+               debug_count = 0;
+               return(False);
+       }
+       return( True );
+}
 
 /* ************************************************************************** **
  * Check to see if the log has grown to be too big.
  * ************************************************************************** **
  */
-static void check_log_size( void )
+
+void check_log_size( void )
 {
   int         maxlog;
   SMB_STRUCT_STAT st;
 
-  if( debug_count++ < 100 || geteuid() != 0 )
+  /*
+   *  We need to be root to check/change log-file, skip this and let the main
+   *  loop check do a new check as root.
+   */
+
+  if( geteuid() != 0 )
     return;
 
-  maxlog = lp_max_log_size() * 1024;
-  if( !dbf || maxlog <= 0 )
+  if( !need_to_check_log_size() )
     return;
 
+  maxlog = lp_max_log_size() * 1024;
+
   if( sys_fstat( fileno( dbf ), &st ) == 0 && st.st_size > maxlog )
     {
     (void)fclose( dbf );
index 07b3ca7d35914528d1cd39d1a202ffd1eb1b3ae8..cf91de9f0f19da6b20f749fcab45204268b91b3e 100644 (file)
@@ -967,6 +967,12 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup ));
    */
   process_pending_change_notify_queue(t);
 
+  /*
+   * Now we are root, check if the log files need pruning.
+   */
+  if(need_to_check_log_size())
+      check_log_size();
+
   /*
    * Modify the select timeout depending upon
    * what we have remaining in our queues.