I've added a test for lp_loaded() so that timestamps *will* be output
[samba.git] / source3 / lib / debug.c
index 527ba05cd48b104fe1fa8c41003e93740af68893..e234084d98f7810c588a181541e2ea8a5a3cbbfb 100644 (file)
@@ -123,14 +123,12 @@ int sig_usr2( void )
   DEBUG( 0, ( "Got SIGUSR2; set debug level to %d.\n", DEBUGLEVEL ) );
 
   BlockSignals( False, SIGUSR2 );
+  CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 );
 
-#ifndef DONT_REINSTALL_SIG
-  signal( SIGUSR2, SIGNAL_CAST sig_usr2 );
-#endif
   return( 0 );
   } /* sig_usr2 */
-#endif /* SIGUSR1 */
-   
+#endif /* SIGUSR2 */
+
 #if defined(SIGUSR1)
 /* ************************************************************************** **
  * catch a sigusr1 - increase the debug log level. 
@@ -148,9 +146,8 @@ int sig_usr1( void )
   DEBUG( 0, ( "Got SIGUSR1; set debug level to %d.\n", DEBUGLEVEL ) );
 
   BlockSignals( False, SIGUSR1 );
-#ifndef DONT_REINSTALL_SIG
-  signal( SIGUSR1, SIGNAL_CAST sig_usr1 );
-#endif
+  CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 );
+
   return( 0 );
   } /* sig_usr1 */
 #endif /* SIGUSR1 */
@@ -167,7 +164,7 @@ void setup_logging( char *pname, BOOL interactive )
     stdout_logging = True;
     dbf = stdout;
     }
-#ifdef SYSLOG
+#ifdef WITH_SYSLOG
   else
     {
     char *p = strrchr( pname,'/' );
@@ -208,8 +205,7 @@ void reopen_logs( void )
         dbf = fopen( debugf, "a" );
       else
         dbf = fopen( debugf, "w" );
-      /*
-       * Fix from klausr@ITAP.Physik.Uni-Stuttgart.De
+      /* Fix from klausr@ITAP.Physik.Uni-Stuttgart.De
        * to fix problem where smbd's that generate less
        * than 100 messages keep growing the log.
        */
@@ -247,7 +243,7 @@ static void check_log_size( void )
   int         maxlog;
   struct stat st;
 
-  if( debug_count++ < 100 || getuid() != 0)
+  if( debug_count++ < 100 || getuid() != 0 )
     return;
 
   maxlog = lp_max_log_size() * 1024;
@@ -278,7 +274,7 @@ static void check_log_size( void )
  * This is called by dbghdr() and format_debug_text().
  * ************************************************************************** **
  */
-#ifdef __STDC__
+#ifdef HAVE_STDARG_H
  int Debug1( char *format_str, ... )
 {
 #else
@@ -292,7 +288,7 @@ va_dcl
 
   if( stdout_logging )
     {
-#ifdef __STDC__
+#ifdef HAVE_STDARG_H
     va_start( ap, format_str );
 #else
     va_start( ap );
@@ -304,7 +300,7 @@ va_dcl
     return( 0 );
     }
   
-#ifdef SYSLOG
+#ifdef WITH_SYSLOG
   if( !lp_syslog_only() )
 #endif
     {
@@ -329,7 +325,7 @@ va_dcl
       }
     }
 
-#ifdef SYSLOG
+#ifdef WITH_SYSLOG
   if( syslog_level < lp_syslog() )
     {
     /* map debug levels to syslog() priorities
@@ -351,7 +347,7 @@ va_dcl
     else
       priority = priority_map[syslog_level];
       
-#ifdef __STDC__
+#ifdef HAVE_STDARG_H
     va_start( ap, format_str );
 #else
     va_start( ap );
@@ -365,11 +361,11 @@ va_dcl
     }
 #endif
   
-#ifdef SYSLOG
+#ifdef WITH_SYSLOG
   if( !lp_syslog_only() )
 #endif
     {
-#ifdef __STDC__
+#ifdef HAVE_STDARG_H
     va_start( ap, format_str );
 #else
     va_start( ap );
@@ -426,7 +422,7 @@ static void format_debug_text( char *msg )
     if( '\n' == msg[i] )
       {
       format_bufr[format_pos] = '\0';
-      Debug1( format_bufr );
+      Debug1( "%s", format_bufr );
       format_pos = 0;
       }
     }
@@ -476,9 +472,19 @@ BOOL dbghdr( int level, char *file, char *func, int line )
   /* Set syslog_level. */
   syslog_level = level;
 
-  /* Print it all out at once. */
-  Debug1( "[%s, %d] %s%s%s(%d)\n",
-          timestring(), level, file, (*file)?":":"", func, line );
+  /* Don't print a header if we're logging to stdout. */
+  if( stdout_logging )
+    return( True );
+
+  /* Print the header if timestamps are turned on.  If parameters are
+   * not yet loaded, then default to timestamps on.
+   */
+  if( lp_timestamp_logs() || !(lp_loaded()) )
+    {
+    /* Print it all out at once to prevent split syslog output. */
+    Debug1( "[%s, %d] %s:%s(%d)\n", timestring(), level, file, func, line );
+    }
+
   return( True );
   } /* dbghdr */
 
@@ -495,7 +501,7 @@ BOOL dbghdr( int level, char *file, char *func, int line )
  *
  * ************************************************************************** **
  */
-#ifdef __STDC__
+#ifdef HAVE_STDARG_H
  BOOL dbgtext( char *format_str, ... )
   {
   va_list ap;