void check_log_size( void ) { int maxlog; SMB_STRUCT_STAT st; /* * 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; if(log_overflow || !need_to_check_log_size() ) return; maxlog = lp_max_log_size() * 1024; if( sys_fstat( fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { (void)reopen_logs(); if( dbf && get_file_size( debugf ) > maxlog ) { pstring name; slprintf( name, sizeof(name)-1, "%s.old", debugf ); (void)rename( debugf, name ); if (!reopen_logs()) { /* We failed to reopen a log - continue using the old name. */ (void)rename(name, debugf); } } } /* * Here's where we need to panic if dbf == NULL.. */ if(dbf == NULL) { /* This code should only be reached in very strange circumstances. If we merely fail to open the new log we should stick with the old one. ergo this should only be reached when opening the logs for the first time: at startup or when the log level is increased from zero. -dwg 6 June 2000 */ dbf = sys_fopen( "/dev/console", "w" ); if(dbf) { DEBUG(0,("check_log_size: open of debug file %s failed - using console.\n", debugf )); } else { /* * We cannot continue without a debug file handle. */ abort(); } } debug_count = 0; } /* check_log_size */
void check_log_size( void ) { int maxlog; SMB_STRUCT_STAT st; /* * 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; 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 ); dbf = NULL; reopen_logs(); if( dbf && get_file_size( debugf ) > maxlog ) { pstring name; (void)fclose( dbf ); dbf = NULL; slprintf( name, sizeof(name)-1, "%s.old", debugf ); (void)rename( debugf, name ); reopen_logs(); } } /* * Here's where we need to panic if dbf == NULL.. */ if(dbf == NULL) { dbf = sys_fopen( "/dev/console", "w" ); if(dbf) { DEBUG(0,("check_log_size: open of debug file %s failed - using console.\n", debugf )); } else { /* * We cannot continue without a debug file handle. */ abort(); } } debug_count = 0; } /* check_log_size */
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 ); }