From e6b86850912ea480bf656f05928cf5325b74c3db Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Fri, 31 Jul 1998 20:17:36 +0000 Subject: Debugging functions are now in their own module. Chris -)----- (This used to be commit 2c6dc2779647bbc0c27a102632882e617ef7643e) --- source3/lib/debug.c | 533 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 533 insertions(+) create mode 100644 source3/lib/debug.c (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c new file mode 100644 index 0000000000..527ba05cd4 --- /dev/null +++ b/source3/lib/debug.c @@ -0,0 +1,533 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + Samba utility functions + Copyright (C) Andrew Tridgell 1992-1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* -------------------------------------------------------------------------- ** + * This module implements Samba's debugging utility. + * + * The syntax of a debugging log file is represented as: + * + * :== { } + * + * :== '\n' + * + * :== '[' TIME ',' LEVEL ']' [ [FILENAME ':'] [FUNCTION '()'] ] + * + * :== { } + * + * :== TEXT '\n' + * + * TEXT is a string of characters excluding the newline character. + * LEVEL is the DEBUG level of the message (an integer in the range 0..10). + * TIME is a timestamp. + * FILENAME is the name of the file from which the debug message was generated. + * FUNCTION is the function from which the debug message was generated. + * + * Basically, what that all means is: + * + * - A debugging log file is made up of debug messages. + * + * - Each debug message is made up of a header and text. The header is + * separated from the text by a newline. + * + * - The header begins with the timestamp and debug level of the message + * enclosed in brackets. The filename and function from which the + * message was generated may follow. The filename is terminated by a + * colon, and the function name is terminated by parenthesis. + * + * - The message text is made up of zero or more lines, each terminated by + * a newline. + */ + +/* -------------------------------------------------------------------------- ** + * External variables. + * + * dbf - Global debug file handle. + * debugf - Debug file name. + * append_log - If True, then the output file will be opened in append + * mode. + * DEBUGLEVEL - System-wide debug message limit. Messages with message- + * levels higher than DEBUGLEVEL will not be processed. + */ + +FILE *dbf = NULL; +pstring debugf = ""; +BOOL append_log = False; +int DEBUGLEVEL = 1; + + +/* -------------------------------------------------------------------------- ** + * Internal variables. + * + * stdout_logging - Default False, if set to True then dbf will be set to + * stdout and debug output will go to dbf only, and not + * to syslog. Set in setup_logging() and read in Debug1(). + * + * debug_count - Number of debug messages that have been output. + * Used to check log size. + * + * syslog_level - Internal copy of the message debug level. Written by + * dbghdr() and read by Debug1(). + * + * format_bufr - Used to format debug messages. The dbgtext() function + * prints debug messages to a string, and then passes the + * string to format_debug_text(), which uses format_bufr + * to build the formatted output. + * + * format_pos - Marks the first free byte of the format_bufr. + */ + +static BOOL stdout_logging = False; +static int debug_count = 0; +static int syslog_level = 0; +static pstring format_bufr = { '\0' }; +static int format_pos = 0; + + +/* -------------------------------------------------------------------------- ** + * Functions... + */ + +#if defined(SIGUSR2) +/* ************************************************************************** ** + * catch a sigusr2 - decrease the debug log level. + * ************************************************************************** ** + */ +int sig_usr2( void ) + { + BlockSignals( True, SIGUSR2 ); + + DEBUGLEVEL--; + if( DEBUGLEVEL < 0 ) + DEBUGLEVEL = 0; + + DEBUG( 0, ( "Got SIGUSR2; set debug level to %d.\n", DEBUGLEVEL ) ); + + BlockSignals( False, SIGUSR2 ); + +#ifndef DONT_REINSTALL_SIG + signal( SIGUSR2, SIGNAL_CAST sig_usr2 ); +#endif + return( 0 ); + } /* sig_usr2 */ +#endif /* SIGUSR1 */ + +#if defined(SIGUSR1) +/* ************************************************************************** ** + * catch a sigusr1 - increase the debug log level. + * ************************************************************************** ** + */ +int sig_usr1( void ) + { + BlockSignals( True, SIGUSR1 ); + + DEBUGLEVEL++; + + if( DEBUGLEVEL > 10 ) + DEBUGLEVEL = 10; + + 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 + return( 0 ); + } /* sig_usr1 */ +#endif /* SIGUSR1 */ + + +/* ************************************************************************** ** + * get ready for syslog stuff + * ************************************************************************** ** + */ +void setup_logging( char *pname, BOOL interactive ) + { + if( interactive ) + { + stdout_logging = True; + dbf = stdout; + } +#ifdef SYSLOG + else + { + char *p = strrchr( pname,'/' ); + + if( p ) + pname = p + 1; +#ifdef LOG_DAEMON + openlog( pname, LOG_PID, SYSLOG_FACILITY ); +#else /* for old systems that have no facility codes. */ + openlog( pname, LOG_PID ); +#endif + } +#endif + } /* setup_logging */ + +/* ************************************************************************** ** + * reopen the log files + * ************************************************************************** ** + */ +void reopen_logs( void ) + { + pstring fname; + + if( DEBUGLEVEL > 0 ) + { + pstrcpy( fname, debugf ); + if( lp_loaded() && (*lp_logfile()) ) + pstrcpy( fname, lp_logfile() ); + + if( !strcsequal( fname, debugf ) || !dbf || !file_exist( debugf, NULL ) ) + { + int oldumask = umask( 022 ); + + pstrcpy( debugf, fname ); + if( dbf ) + fclose( dbf ); + if( append_log ) + dbf = fopen( debugf, "a" ); + else + dbf = fopen( debugf, "w" ); + /* + * Fix from klausr@ITAP.Physik.Uni-Stuttgart.De + * to fix problem where smbd's that generate less + * than 100 messages keep growing the log. + */ + force_check_log_size(); + if( dbf ) + setbuf( dbf, NULL ); + umask( oldumask ); + } + } + else + { + if( dbf ) + { + fclose( dbf ); + dbf = NULL; + } + } + } /* reopen_logs */ + +/* ************************************************************************** ** + * Force a check of the log size. + * ************************************************************************** ** + */ +void force_check_log_size( void ) + { + debug_count = 100; + } /* force_check_log_size */ + +/* ************************************************************************** ** + * Check to see if the log has grown to be too big. + * ************************************************************************** ** + */ +static void check_log_size( void ) + { + int maxlog; + struct stat st; + + if( debug_count++ < 100 || getuid() != 0) + return; + + maxlog = lp_max_log_size() * 1024; + if( !dbf || maxlog <= 0 ) + return; + + if( fstat( fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) + { + fclose( dbf ); + dbf = NULL; + reopen_logs(); + if( dbf && file_size( debugf ) > maxlog ) + { + pstring name; + + fclose( dbf ); + dbf = NULL; + slprintf( name, sizeof(name)-1, "%s.old", debugf ); + rename( debugf, name ); + reopen_logs(); + } + } + debug_count = 0; + } /* check_log_size */ + +/* ************************************************************************** ** + * Write an debug message on the debugfile. + * This is called by dbghdr() and format_debug_text(). + * ************************************************************************** ** + */ +#ifdef __STDC__ + int Debug1( char *format_str, ... ) +{ +#else + int Debug1(va_alist) +va_dcl +{ + char *format_str; +#endif + va_list ap; + int old_errno = errno; + + if( stdout_logging ) + { +#ifdef __STDC__ + va_start( ap, format_str ); +#else + va_start( ap ); + format_str = va_arg( ap, char * ); +#endif + vfprintf( dbf, format_str, ap ); + va_end( ap ); + errno = old_errno; + return( 0 ); + } + +#ifdef SYSLOG + if( !lp_syslog_only() ) +#endif + { + if( !dbf ) + { + int oldumask = umask( 022 ); + + if( append_log ) + dbf = fopen( debugf, "a" ); + else + dbf = fopen( debugf, "w" ); + umask( oldumask ); + if( dbf ) + { + setbuf( dbf, NULL ); + } + else + { + errno = old_errno; + return(0); + } + } + } + +#ifdef SYSLOG + if( syslog_level < lp_syslog() ) + { + /* map debug levels to syslog() priorities + * note that not all DEBUG(0, ...) calls are + * necessarily errors + */ + static int priority_map[] = { + LOG_ERR, /* 0 */ + LOG_WARNING, /* 1 */ + LOG_NOTICE, /* 2 */ + LOG_INFO, /* 3 */ + }; + int priority; + pstring msgbuf; + + if( syslog_level >= ( sizeof(priority_map) / sizeof(priority_map[0]) ) + || syslog_level < 0) + priority = LOG_DEBUG; + else + priority = priority_map[syslog_level]; + +#ifdef __STDC__ + va_start( ap, format_str ); +#else + va_start( ap ); + format_str = va_arg( ap, char * ); +#endif + vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); + va_end( ap ); + + msgbuf[255] = '\0'; + syslog( priority, "%s", msgbuf ); + } +#endif + +#ifdef SYSLOG + if( !lp_syslog_only() ) +#endif + { +#ifdef __STDC__ + va_start( ap, format_str ); +#else + va_start( ap ); + format_str = va_arg( ap, char * ); +#endif + vfprintf( dbf, format_str, ap ); + va_end( ap ); + fflush( dbf ); + } + + check_log_size(); + + errno = old_errno; + + return( 0 ); + } /* Debug1 */ + +/* ************************************************************************** ** + * Format the debug message text. + * + * Input: msg - Text to be added to the "current" debug message text. + * + * Output: none. + * + * Notes: The purpose of this is two-fold. First, each call to syslog() + * (used by Debug1(), see above) generates a new line of syslog + * output. This is fixed by storing the partial lines until the + * newline character is encountered. Second, printing the debug + * message lines when a newline is encountered allows us to add + * spaces, thus indenting the body of the message and making it + * more readable. + * + * ************************************************************************** ** + */ +static void format_debug_text( char *msg ) + { + int max = sizeof( format_bufr ) - 1; + int i; + + for( i = 0; msg[i]; i++ ) + { + /* Indent two spaces at each new line. */ + if( 0 == format_pos ) + { + format_bufr[0] = format_bufr[1] = ' '; + format_pos = 2; + } + + /* If there's room, copy the character to the format buffer. */ + if( format_pos < max ) + format_bufr[format_pos++] = msg[i]; + + /* If a newline is encountered, print & restart. */ + if( '\n' == msg[i] ) + { + format_bufr[format_pos] = '\0'; + Debug1( format_bufr ); + format_pos = 0; + } + } + + /* Just to be safe... */ + format_bufr[format_pos] = '\0'; + } /* format_debug_text */ + +/* ************************************************************************** ** + * Print a Debug Header. + * + * Input: level - Debug level of the message (not the system-wide debug + * level. + * file - Pointer to a string containing the name of the file + * from which this function was called, or an empty string + * if the __FILE__ macro is not implemented. + * func - Pointer to a string containing the name of the function + * from which this function was called, or an empty string + * if the __FUNCTION__ macro is not implemented. + * line - line number of the call to dbghdr, assuming __LINE__ + * works. + * + * Output: Always True. This makes it easy to fudge a call to dbghdr() + * in a macro, since the function can be called as part of a test. + * Eg: ( (level <= DEBUGLEVEL) && (dbghdr(level,"",line)) ) + * + * Notes: This function takes care of setting syslog_level. + * + * ************************************************************************** ** + */ +BOOL dbghdr( int level, char *file, char *func, int line ) + { + if( format_pos ) + { + /* This is a fudge. If there is stuff sitting in the format_bufr, then + * the *right* thing to do is to call + * format_debug_text( "\n" ); + * to write the remainder, and then proceed with the new header. + * Unfortunately, there are several places in the code at which + * the DEBUG() macro is used to build partial lines. That in mind, + * we'll work under the assumption that an incomplete line indicates + * that a new header is *not* desired. + */ + return( True ); + } + + /* 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 ); + return( True ); + } /* dbghdr */ + +/* ************************************************************************** ** + * Add text to the body of the "current" debug message via the format buffer. + * + * Input: format_str - Format string, as used in printf(), et. al. + * ... - Variable argument list. + * + * ..or.. va_alist - Old style variable parameter list starting point. + * + * Output: Always True. See dbghdr() for more info, though this is not + * likely to be used in the same way. + * + * ************************************************************************** ** + */ +#ifdef __STDC__ + BOOL dbgtext( char *format_str, ... ) + { + va_list ap; + pstring msgbuf; + + va_start( ap, format_str ); + vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); + va_end( ap ); + + format_debug_text( msgbuf ); + + return( True ); + } /* dbgtext */ + +#else + BOOL dbgtext( va_alist ) + va_dcl + { + char *format_str; + va_list ap; + pstring msgbuf; + + va_start( ap ); + format_str = va_arg( ap, char * ); + vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); + va_end( ap ); + + format_debug_text( msgbuf ); + + return( True ); + } /* dbgtext */ + +#endif + +/* ************************************************************************** */ -- cgit From feb16291aa1877818cc00a8ac54d9d68f5ab4559 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Mon, 3 Aug 1998 03:22:42 +0000 Subject: I have fixed some of the autoconfigure problems. I'm studying the diffs for the rest. I've found that only debug.h seems to be out of sync (i.e., util.c itself appears to be okay). Chris -)----- (This used to be commit b41cdbffb7233f73ac15526f7b5499658256cd82) --- source3/lib/debug.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 527ba05cd4..e85643f259 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -167,7 +167,7 @@ void setup_logging( char *pname, BOOL interactive ) stdout_logging = True; dbf = stdout; } -#ifdef SYSLOG +#ifdef WITH_SYSLOG else { char *p = strrchr( pname,'/' ); @@ -278,7 +278,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 +292,7 @@ va_dcl if( stdout_logging ) { -#ifdef __STDC__ +#ifdef HAVE_STDARG_H va_start( ap, format_str ); #else va_start( ap ); @@ -304,7 +304,7 @@ va_dcl return( 0 ); } -#ifdef SYSLOG +#ifdef WITH_SYSLOG if( !lp_syslog_only() ) #endif { @@ -329,7 +329,7 @@ va_dcl } } -#ifdef SYSLOG +#ifdef WITH_SYSLOG if( syslog_level < lp_syslog() ) { /* map debug levels to syslog() priorities @@ -351,7 +351,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 +365,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 ); @@ -476,6 +476,10 @@ BOOL dbghdr( int level, char *file, char *func, int line ) /* Set syslog_level. */ syslog_level = level; + /* Don't print a header if we're logging to stdout. */ + if( stdout_logging ) + return( True ); + /* Print it all out at once. */ Debug1( "[%s, %d] %s%s%s(%d)\n", timestring(), level, file, (*file)?":":"", func, line ); @@ -495,7 +499,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; -- cgit From 8c372cf5e0ae9969b10a8b789a445787b1fd1d3b Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Mon, 3 Aug 1998 03:50:07 +0000 Subject: This is the remaining set of changes needed to replace the changes lost when Andrew and I were both working with util.c. I really don't know how I lost the autoconfigure changes (honest, I *did* run frequent updates). Chris -)----- (This used to be commit bedefc2066ac86199b29ccd7f65ad5f1d8a899c4) --- source3/lib/debug.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index e85643f259..476023a7ba 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -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 */ @@ -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; -- cgit From 7448091da6ee11709b8e5117ff6810515567f88a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 3 Aug 1998 19:07:55 +0000 Subject: First implementation of ChangeNotify - this version only checks for changes in the directory modify timestamps. A better version will look at the requested client flags, and create a hash that represents the current state of the directory, and check against this instead. debug.c: Added lp_timestamp_logs() function. loadparm.c: Added "change notify timeout" in seconds (default 60) - this is the scan rate for a directory. Added ""timestamp logs" boolean - default True. Turns off log timestamps (so I can read them :-). nttrans.c: ChangeNotify implementation. server.c: ChangeNotify implementation. shmem_sysv.c: Added exits on shmem errors (without them smbd can core dump if some calls fail). smb.h: Added ChangeNotify flags for future use. util.c: Tidied up typedef. Jeremy. (This used to be commit a0748c3f53974483680ebe2ea4f556ece8d7fa43) --- source3/lib/debug.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 476023a7ba..02bf6710f5 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -477,8 +477,9 @@ BOOL dbghdr( int level, char *file, char *func, int line ) return( True ); /* Print it all out at once. */ - Debug1( "[%s, %d] %s%s%s(%d)\n", - timestring(), level, file, (*file)?":":"", func, line ); + if(lp_timestamp_logs()) + Debug1( "[%s, %d] %s%s%s(%d)\n", + timestring(), level, file, (*file)?":":"", func, line ); return( True ); } /* dbghdr */ -- cgit From ab1bfe5b0d9795d3e7d993ac5247f1be63950353 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Aug 1998 14:09:05 +0000 Subject: fixed a nasty bug in debug.c Debug1() was being called like this: Debug1( format_bufr ); but if format_bufr contains any %s or other % arguments (such as when processing a smb.conf file containing % macros) then smbd dies a horrible death. The quick fix is to use: Debug1( "%s", format_bufr); (This used to be commit 5ae04012819ae3e63102d6875088ef00c27492b4) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 02bf6710f5..8f7887006f 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -422,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; } } -- cgit From 6a9170b1ae8685e8b84325911123fd73c062d685 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Tue, 11 Aug 1998 15:47:26 +0000 Subject: I've added a test for lp_loaded() so that timestamps *will* be output before the config file has been loaded. Otherwise the default is no timestamp. Chris -)----- (This used to be commit fd7eaed59efbe2ce6998d5902e70d79f533b3372) --- source3/lib/debug.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 8f7887006f..e234084d98 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -476,10 +476,15 @@ BOOL dbghdr( int level, char *file, char *func, int line ) if( stdout_logging ) return( True ); - /* Print it all out at once. */ - if(lp_timestamp_logs()) - Debug1( "[%s, %d] %s%s%s(%d)\n", - timestring(), level, file, (*file)?":":"", func, line ); + /* 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 */ -- cgit From e1b12729f6ddad97285acb4992ed46a76cca7f74 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Tue, 11 Aug 1998 18:07:18 +0000 Subject: Cleaned up some lint warnings (functions with return values that were ignored). (This used to be commit 8fedcfc48da2741722b867bbb056a078901e7431) --- source3/lib/debug.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index e234084d98..4270150d15 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -200,7 +200,7 @@ void reopen_logs( void ) pstrcpy( debugf, fname ); if( dbf ) - fclose( dbf ); + (void)fclose( dbf ); if( append_log ) dbf = fopen( debugf, "a" ); else @@ -212,14 +212,14 @@ void reopen_logs( void ) force_check_log_size(); if( dbf ) setbuf( dbf, NULL ); - umask( oldumask ); + (void)umask( oldumask ); } } else { if( dbf ) { - fclose( dbf ); + (void)fclose( dbf ); dbf = NULL; } } @@ -252,17 +252,17 @@ static void check_log_size( void ) if( fstat( fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { - fclose( dbf ); + (void)fclose( dbf ); dbf = NULL; reopen_logs(); if( dbf && file_size( debugf ) > maxlog ) { pstring name; - fclose( dbf ); + (void)fclose( dbf ); dbf = NULL; slprintf( name, sizeof(name)-1, "%s.old", debugf ); - rename( debugf, name ); + (void)rename( debugf, name ); reopen_logs(); } } @@ -294,7 +294,7 @@ va_dcl va_start( ap ); format_str = va_arg( ap, char * ); #endif - vfprintf( dbf, format_str, ap ); + (void)vfprintf( dbf, format_str, ap ); va_end( ap ); errno = old_errno; return( 0 ); @@ -312,7 +312,7 @@ va_dcl dbf = fopen( debugf, "a" ); else dbf = fopen( debugf, "w" ); - umask( oldumask ); + (void)umask( oldumask ); if( dbf ) { setbuf( dbf, NULL ); @@ -371,9 +371,9 @@ va_dcl va_start( ap ); format_str = va_arg( ap, char * ); #endif - vfprintf( dbf, format_str, ap ); + (void)vfprintf( dbf, format_str, ap ); va_end( ap ); - fflush( dbf ); + (void)fflush( dbf ); } check_log_size(); @@ -422,7 +422,7 @@ static void format_debug_text( char *msg ) if( '\n' == msg[i] ) { format_bufr[format_pos] = '\0'; - Debug1( "%s", format_bufr ); + (void)Debug1( "%s", format_bufr ); format_pos = 0; } } @@ -482,7 +482,8 @@ BOOL dbghdr( int level, char *file, char *func, int line ) 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 ); + (void)Debug1( "[%s, %d] %s:%s(%d)\n", + timestring(), level, file, func, line ); } return( True ); -- cgit From 08feb74221427423b44f3ea5cae182f7e392f0f5 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 12 Aug 1998 14:51:17 +0000 Subject: I've added a dbgflush() function to debug.c. Calling this will cause the debug format buffer to be written out (and reset). fflush() is also called to force the issue. I replaced the call to fflush() in client.c with a call to dbgflush(), which seems to have fixed the problem that Andrew was working on (i.e., that the prompt was not displayed when using smbclient). Chris -)----- (This used to be commit a97460869fe1448be5132fdab586d30872d21a69) --- source3/lib/debug.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 4270150d15..24f508c0b4 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -383,6 +383,22 @@ va_dcl return( 0 ); } /* Debug1 */ + +/* ************************************************************************** ** + * Print the buffer content via Debug1(), then reset the buffer. + * + * Input: none + * Output: none + * + * ************************************************************************** ** + */ +static void bufr_print( void ) + { + format_bufr[format_pos] = '\0'; + (void)Debug1( "%s", format_bufr ); + format_pos = 0; + } /* bufr_print */ + /* ************************************************************************** ** * Format the debug message text. * @@ -420,17 +436,27 @@ static void format_debug_text( char *msg ) /* If a newline is encountered, print & restart. */ if( '\n' == msg[i] ) - { - format_bufr[format_pos] = '\0'; - (void)Debug1( "%s", format_bufr ); - format_pos = 0; - } + bufr_print(); } /* Just to be safe... */ format_bufr[format_pos] = '\0'; } /* format_debug_text */ +/* ************************************************************************** ** + * Flush debug output, including the format buffer content. + * + * Input: none + * Output: none + * + * ************************************************************************** ** + */ +void dbgflush( void ) + { + bufr_print(); + (void)fflush( dbf ); + } /* dbgflush */ + /* ************************************************************************** ** * Print a Debug Header. * -- cgit From e13aeea928dd89373cfaf3916c96f853c1227884 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 15 Aug 1998 01:19:26 +0000 Subject: configure: Changes for extra headers. configure.in: Source for header changes. client/clitar.c: Fixed isXXX macros & debugs for gcc pedantic compile. include/config.h.in: Added MEMSET, BZERO, MEMORY, RPCSVC_YPCLNT, STRINGS headers. include/includes.h: Headers for the above. include/smb.h: Made SIGNAL_CAST POSIX by default void (*)(int). lib/access.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/charset.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/debug.c: Fixed signal functs. lib/kanji.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/smbrun.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/util.c: Fixed isXXX macros & debugs for gcc pedantic compile. libsmb/namequery.c: Fixed isXXX macros & debugs for gcc pedantic compile. locking/shmem.c: Fixed isXXX macros & debugs for gcc pedantic compile. locking/shmem_sysv.c: Fixed error messages in sysV stuff. nmbd/asyncdns.c: Fixed signal functs. nmbd/nmbd.c: Fixed isXXX macros & debugs for gcc pedantic compile. passdb/passdb.c: Fixed isXXX macros & debugs for gcc pedantic compile. passdb/smbpassfile.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/chgpasswd.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/ipc.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/nttrans.c: Fixed fsp code path. smbd/password.c: fixed HAVE_YP_GET_DEFAULT_DOMAIN problem. smbd/printing.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/reply.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/server.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/trans2.c: Fixed core dump bug. smbd/uid.c: Fixed isXXX macros & debugs for gcc pedantic compile. Jeremy. (This used to be commit 1b9cbcd02e575dc0a95fa589f720df30a4acc46b) --- source3/lib/debug.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 24f508c0b4..1303d0433b 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -112,7 +112,7 @@ static int format_pos = 0; * catch a sigusr2 - decrease the debug log level. * ************************************************************************** ** */ -int sig_usr2( void ) +void sig_usr2( int sig ) { BlockSignals( True, SIGUSR2 ); @@ -125,7 +125,6 @@ int sig_usr2( void ) BlockSignals( False, SIGUSR2 ); CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); - return( 0 ); } /* sig_usr2 */ #endif /* SIGUSR2 */ @@ -134,7 +133,7 @@ int sig_usr2( void ) * catch a sigusr1 - increase the debug log level. * ************************************************************************** ** */ -int sig_usr1( void ) +void sig_usr1( int sig ) { BlockSignals( True, SIGUSR1 ); @@ -148,7 +147,6 @@ int sig_usr1( void ) BlockSignals( False, SIGUSR1 ); CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); - return( 0 ); } /* sig_usr1 */ #endif /* SIGUSR1 */ -- cgit From c8b2ee3e4e85c6afc43ea72643e5609f23f49ae7 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Fri, 21 Aug 1998 19:57:59 +0000 Subject: Just tweaking. If the output line is longer than the format buffer could manage, I was simply ignoring the additional output (that is, *not* copying it to the format buffer--thus avoiding a buffer overrun). Instead, I now output the current content followed by " +>\n", and then reset the format buffer. I have never seen a debug line that exceeds the size of a pstring, but I might as well handle the situation...just in case. Chris -)----- (This used to be commit 8a11d04b7796b256953bf92b2f2ccab763215bc4) --- source3/lib/debug.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 1303d0433b..6469a3ca6c 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -21,6 +21,16 @@ #include "includes.h" +/* -------------------------------------------------------------------------- ** + * Defines... + * + * FORMAT_BUFR_MAX - Index of the last byte of the format buffer; + * format_bufr[FORMAT_BUFR_MAX] should always be reserved + * for a terminating nul byte. + */ + +#define FORMAT_BUFR_MAX ( sizeof( format_bufr ) - 1 ) + /* -------------------------------------------------------------------------- ** * This module implements Samba's debugging utility. * @@ -416,7 +426,6 @@ static void bufr_print( void ) */ static void format_debug_text( char *msg ) { - int max = sizeof( format_bufr ) - 1; int i; for( i = 0; msg[i]; i++ ) @@ -429,12 +438,21 @@ static void format_debug_text( char *msg ) } /* If there's room, copy the character to the format buffer. */ - if( format_pos < max ) + if( format_pos < FORMAT_BUFR_MAX ) format_bufr[format_pos++] = msg[i]; /* If a newline is encountered, print & restart. */ if( '\n' == msg[i] ) bufr_print(); + + /* If the buffer is full dump it out, reset it, and put out a line + * continuation indicator. + */ + if( format_pos >= FORMAT_BUFR_MAX ) + { + bufr_print(); + (void)Debug1( " +>\n" ); + } } /* Just to be safe... */ -- cgit From 36ca3e3411cd3193c84a71c935881ceab3b61055 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Aug 1998 05:57:21 +0000 Subject: don't put two spaces at the start of lines if logging to stdout or not timestamping. (This used to be commit 70ed0ec202c50655e3ba99535b06ad918409051e) --- source3/lib/debug.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 6469a3ca6c..c20229fcde 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -427,11 +427,13 @@ static void bufr_print( void ) static void format_debug_text( char *msg ) { int i; + BOOL timestamp = (!stdout_logging && (lp_timestamp_logs() || + !(lp_loaded()))); for( i = 0; msg[i]; i++ ) { /* Indent two spaces at each new line. */ - if( 0 == format_pos ) + if(timestamp && 0 == format_pos) { format_bufr[0] = format_bufr[1] = ' '; format_pos = 2; -- cgit From 18556274139cc5a00593471bd745354d98a35303 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 1 Sep 1998 20:11:54 +0000 Subject: More abstraction of file system data types, to move to a 64 bit file interface for the NT SMB's. Created a new define, SMB_STRUCT_STAT that currently is defined to be struct stat - this wil change to a user defined type containing 64 bit info when the correct wrappers are written for 64 bit stat(), fstat() and lstat() calls. Also changed all sys_xxxx() calls that were previously just wrappers to the same call prefixed by a dos_to_unix() call into dos_xxxx() calls. This makes it explicit when a pathname translation is being done, and when it is not. Now, all sys_xxx() calls are meant to be wrappers to mask OS differences, and not silently converting filenames on the fly. Jeremy. (This used to be commit 28aa182dbffaa4ffd86047e608400de4b26e80eb) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index c20229fcde..f5a0eadb96 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -249,7 +249,7 @@ void force_check_log_size( void ) static void check_log_size( void ) { int maxlog; - struct stat st; + SMB_STRUCT_STAT st; if( debug_count++ < 100 || getuid() != 0 ) return; -- cgit From 7bb86c1b132bce31a006ea9768a54db7a45fe1a5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 3 Sep 1998 18:40:31 +0000 Subject: Ok - this is the 64 bit widening check in. It changes the configure to check for stat64 and friends, and then changes much of Samba to use the data type SMB_OFF_T for file size information. stat/fstat/lstat/lseek/ftruncate have now become sys_stat etc. to hide the 64 bit calls if needed. Note that this still does not expose 64 bit functionality to the client, as the changes to the reply_xxx smb's are not yet done. This code change should make these changes possible. Still to do before full 64 bit-ness to the client: fcntl lock code. statfs code widening of dev_t and ino_t (now possible due to SMB_DEV_T and SMB_OFF_T types being in place). Let me know if wierd things happen after this check-in and I'll fix them :-). Jeremy. (This used to be commit 14500936c321d15995c963766aac67bf1f4e3824) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index f5a0eadb96..5f6ad5273a 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -258,7 +258,7 @@ static void check_log_size( void ) if( !dbf || maxlog <= 0 ) return; - if( fstat( fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) + if( sys_fstat( fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { (void)fclose( dbf ); dbf = NULL; -- cgit From b8b67f4fab4a6fd686c5796c2701882197a7bd9d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 17 Sep 1998 23:06:57 +0000 Subject: configure configure.in: Added checks for statvfs64. Last bit of 64 bit widening (I hope :-). include/config.h.in: Added #undef STAT_STATVFS64. include/includes.h: Added SMB_STRUCT_STATVFS type, Changed SMB_BIG_INTEGER to SMB_BIG_UINT and SMB_BIG_INT types. include/smb.h: Added flag defines from CIFS spec. lib/debug.c: Fixed one more mode_t issue. lib/system.c: Added sys_statvfs wrapper. lib/util.c: Changed trim_string to use size_t. param/loadparm.c: Moved "blocking locks" into locking section. Alphabetised locking options. Question - shuld we do this for all options ? passdb/ldap.c: Changed SMB_BIG_INTEGER to SMB_BIG_UINT. passdb/nispass.c: Changed SMB_BIG_INTEGER to SMB_BIG_UINT. passdb/smbpass.c: Changed SMB_BIG_INTEGER to SMB_BIG_UINT. smbd/dfree.c: Changed to use 64 bit types if available. Moved to use unsigned types. smbd/dosmode.c: Fixed one more mode_t issue. smbd/negprot.c: Changed literals to be FLAG_ #defines. smbd/nttrans.c: Removed dead code. smbd/open.c: Changed disk_free call. smbd/process.c: Changed literals to be FLAG_ #defines. smbd/reply.c: Changed disk_free call. smbd/trans2.c: Fixed but in SMB_QUERY_FS_VOLUME_INFO call. Was using UNICODE - should use ascii. tests/summary.c: Added STAT_STATVFS64 check. Jeremy. (This used to be commit c512b1b91fb7f2a7a93b9033a33e06d966daadb4) --- source3/lib/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 5f6ad5273a..0418098fb2 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -204,7 +204,7 @@ void reopen_logs( void ) if( !strcsequal( fname, debugf ) || !dbf || !file_exist( debugf, NULL ) ) { - int oldumask = umask( 022 ); + mode_t oldumask = umask( 022 ); pstrcpy( debugf, fname ); if( dbf ) @@ -314,7 +314,7 @@ va_dcl { if( !dbf ) { - int oldumask = umask( 022 ); + mode_t oldumask = umask( 022 ); if( append_log ) dbf = fopen( debugf, "a" ); -- cgit From cf3a9741dc7427efb97eff09a3c197a906ce6767 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 28 Sep 1998 21:43:48 +0000 Subject: Changes to test in configure if capabilities are enabled on a system. Changes to get Samba to compile cleanly with the IRIX compiler with the options : -fullwarn -woff 1209,1174 (the -woff options are to turn off warnings about unused function parameters and controlling loop expressions being constants). Split prototype generation as we hit a limit in IRIX nawk. Removed "." code in smbd/filename.c (yet again :-). Jeremy. (This used to be commit e0567433bd72aec17bf5a54cc292701095d25f09) --- source3/lib/debug.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 0418098fb2..6b7b9341a3 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -108,7 +108,9 @@ int DEBUGLEVEL = 1; static BOOL stdout_logging = False; static int debug_count = 0; +#ifdef WITH_SYSLOG static int syslog_level = 0; +#endif static pstring format_bufr = { '\0' }; static int format_pos = 0; @@ -513,8 +515,10 @@ BOOL dbghdr( int level, char *file, char *func, int line ) return( True ); } +#ifdef WITH_SYSLOG /* Set syslog_level. */ syslog_level = level; +#endif /* Don't print a header if we're logging to stdout. */ if( stdout_logging ) -- cgit From 74d539f5573a3ed3ff1b96c54752a389da4c3e14 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 17 Nov 1998 16:19:04 +0000 Subject: - group database API. oops and oh dear, the threat has been carried out: the pre-alpha "domain group" etc parameters have disappeared. - interactive debug detection - re-added mem_man (andrew's memory management, detects memory corruption) - american spellings of "initialise" replaced with english spelling of "initialise". - started on "lookup_name()" and "lookup_sid()" functions. proper ones. - moved lots of functions around. created some modules of commonly used code. e.g the password file locking code, which is used in groupfile.c and aliasfile.c and smbpass.c - moved RID_TYPE_MASK up another bit. this is really unfortunate, but there is no other "fast" way to identify users from groups from aliases. i do not believe that this code saves us anything (the multipliers) and puts us at a disadvantage (reduces the useable rid space). the designers of NT aren't silly: if they can get away with a user- interface-speed LsaLookupNames / LsaLookupSids, then so can we. i spoke with isaac at the cifs conference, the only time for example that they do a security context check is on file create. certainly not on individual file reads / writes, which would drastically hit their performance and ours, too. - renamed myworkgroup to global_sam_name, amongst other things, when used in the rpc code. there is also a global_member_name, as we are always responsible for a SAM database, the scope of which is limited by the role of the machine (e.g if a member of a workgroup, your SAM is for _local_ logins only, and its name is the name of your server. you even still have a SID. see LsaQueryInfoPolicy, levels 3 and 5). - updated functionality of groupname.c to be able to cope with names like DOMAIN\group and SERVER\alias. used this code to be able to do aliases as well as groups. this code may actually be better off being used in username mapping, too. - created a connect to serverlist function in clientgen.c and used it in password.c - initialisation in server.c depends on the role of the server. well, it does now. - rpctorture. smbtorture. EXERCISE EXTREME CAUTION. (This used to be commit 0d21e1e6090b933f396c764af535ca3388a562db) --- source3/lib/debug.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 6b7b9341a3..619a917747 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -75,6 +75,7 @@ * debugf - Debug file name. * append_log - If True, then the output file will be opened in append * mode. + * timestamp_log - * DEBUGLEVEL - System-wide debug message limit. Messages with message- * levels higher than DEBUGLEVEL will not be processed. */ @@ -82,6 +83,7 @@ FILE *dbf = NULL; pstring debugf = ""; BOOL append_log = False; +BOOL timestamp_log = True; int DEBUGLEVEL = 1; @@ -119,7 +121,17 @@ static int format_pos = 0; * Functions... */ -#if defined(SIGUSR2) +/* ************************************************************************** ** + * tells us if interactive logging was requested + * ************************************************************************** ** + */ + +BOOL dbg_interactive(void) +{ + return stdout_logging; +} + +#if defined(SIGUSR2) && !defined(MEM_MAN) /* ************************************************************************** ** * catch a sigusr2 - decrease the debug log level. * ************************************************************************** ** @@ -140,7 +152,7 @@ void sig_usr2( int sig ) } /* sig_usr2 */ #endif /* SIGUSR2 */ -#if defined(SIGUSR1) +#if defined(SIGUSR1) && !defined(MEM_MAN) /* ************************************************************************** ** * catch a sigusr1 - increase the debug log level. * ************************************************************************** ** @@ -429,7 +441,7 @@ static void bufr_print( void ) static void format_debug_text( char *msg ) { int i; - BOOL timestamp = (!stdout_logging && (lp_timestamp_logs() || + BOOL timestamp = (timestamp_log && !stdout_logging && (lp_timestamp_logs() || !(lp_loaded()))); for( i = 0; msg[i]; i++ ) @@ -527,7 +539,7 @@ BOOL dbghdr( int level, char *file, char *func, int line ) /* 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()) ) + if( timestamp_log && (lp_timestamp_logs() || !(lp_loaded()) )) { /* Print it all out at once to prevent split syslog output. */ (void)Debug1( "[%s, %d] %s:%s(%d)\n", -- cgit From 768761820e8d7481c586c4e0ab4ac7cb36d18c4b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 17 Nov 1998 20:50:07 +0000 Subject: Added the same open()/fopen()/creat()/mmap() -> sys_XXX calls. Tidied up some of the mess (no other word for it). Still doesn't compile cleanly. There are calls with incorrect parameters that don't seem to be doing the right thing. This code still needs surgery :-(. Jeremy. (This used to be commit 18ff93a9abbf68ee8c59c0af3e57c63e4a015dac) --- source3/lib/debug.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 619a917747..3a90da2f3d 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -224,9 +224,9 @@ void reopen_logs( void ) if( dbf ) (void)fclose( dbf ); if( append_log ) - dbf = fopen( debugf, "a" ); + dbf = sys_fopen( debugf, "a" ); else - dbf = fopen( debugf, "w" ); + dbf = sys_fopen( debugf, "w" ); /* Fix from klausr@ITAP.Physik.Uni-Stuttgart.De * to fix problem where smbd's that generate less * than 100 messages keep growing the log. @@ -331,9 +331,9 @@ va_dcl mode_t oldumask = umask( 022 ); if( append_log ) - dbf = fopen( debugf, "a" ); + dbf = sys_fopen( debugf, "a" ); else - dbf = fopen( debugf, "w" ); + dbf = sys_fopen( debugf, "w" ); (void)umask( oldumask ); if( dbf ) { -- cgit From dc003d8d408b87eecba9044d2d8732a3604827bf Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 16 Dec 1998 18:50:54 +0000 Subject: A while back, Andrew and I talked about making the debug parsing code a better "fit" with other Samba code. This is a small first step toward doing what (I think) we agreed to do. I've moved the key function from ubiqx/debugparse.c into lib/debug.c. I have also moved the enum from ubiqx/debugparse.h into the debug section in smb.h. The next thing to do is to get debug2html added into the Makefile.in so that it is always produced when compiling the suite. Chris -)----- (This used to be commit 782474f41e0c2bc0b1f098758a3e5cb44e87d8b1) --- source3/lib/debug.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 3a90da2f3d..ab11d81a21 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -125,7 +125,6 @@ static int format_pos = 0; * tells us if interactive logging was requested * ************************************************************************** ** */ - BOOL dbg_interactive(void) { return stdout_logging; @@ -597,4 +596,163 @@ BOOL dbghdr( int level, char *file, char *func, int line ) #endif +dbg_Token dbg_char2token( dbg_Token *state, int c ) + /* ************************************************************************ ** + * Parse input one character at a time. + * + * Input: state - A pointer to a token variable. This is used to + * maintain the parser state between calls. For + * each input stream, you should set up a separate + * state variable and initialize it to dbg_null. + * Pass a pointer to it into this function with each + * character in the input stream. See dbg_test() + * for an example. + * c - The "current" character in the input stream. + * + * Output: A token. + * The token value will change when delimiters are found, + * which indicate a transition between syntactical objects. + * Possible return values are: + * + * dbg_null - The input character was an end-of-line. + * This resets the parser to its initial state + * in preparation for parsing the next line. + * dbg_eof - Same as dbg_null, except that the character + * was an end-of-file. + * dbg_ignore - Returned for whitespace and delimiters. + * These lexical tokens are only of interest + * to the parser. + * dbg_header - Indicates the start of a header line. The + * input character was '[' and was the first on + * the line. + * dbg_timestamp - Indicates that the input character was part + * of a header timestamp. + * dbg_level - Indicates that the input character was part + * of the debug-level value in the header. + * dbg_sourcefile - Indicates that the input character was part + * of the sourcefile name in the header. + * dbg_function - Indicates that the input character was part + * of the function name in the header. + * dbg_lineno - Indicates that the input character was part + * of the DEBUG call line number in the header. + * dbg_message - Indicates that the input character was part + * of the DEBUG message text. + * + * ************************************************************************ ** + */ + { + /* The terminating characters that we see will greatly depend upon + * how they are read. For example, if gets() is used instead of + * fgets(), then we will not see newline characters. A lot also + * depends on the calling function, which may handle terminators + * itself. + * + * '\n', '\0', and EOF are all considered line terminators. The + * dbg_eof token is sent back if an EOF is encountered. + * + * Warning: only allow the '\0' character to be sent if you are + * using gets() to read whole lines (thus replacing '\n' + * with '\0'). Sending '\0' at the wrong time will mess + * up the parsing. + */ + switch( c ) + { + case EOF: + *state = dbg_null; /* Set state to null (initial state) so */ + return( dbg_eof ); /* that we can restart with new input. */ + case '\n': + case '\0': + *state = dbg_null; /* A newline or eoln resets to the null state. */ + return( dbg_null ); + } + + /* When within the body of the message, only a line terminator + * can cause a change of state. We've already checked for line + * terminators, so if the current state is dbg_msgtxt, simply + * return that as our current token. + */ + if( dbg_message == *state ) + return( dbg_message ); + + /* If we are at the start of a new line, and the input character + * is an opening bracket, then the line is a header line, otherwise + * it's a message body line. + */ + if( dbg_null == *state ) + { + if( '[' == c ) + { + *state = dbg_timestamp; + return( dbg_header ); + } + *state = dbg_message; + return( dbg_message ); + } + + /* We've taken care of terminators, text blocks and new lines. + * The remaining possibilities are all within the header line + * itself. + */ + + /* Within the header line, whitespace can be ignored *except* + * within the timestamp. + */ + if( isspace( c ) ) + { + /* Fudge. The timestamp may contain space characters. */ + if( (' ' == c) && (dbg_timestamp == *state) ) + return( dbg_timestamp ); + /* Otherwise, ignore whitespace. */ + return( dbg_ignore ); + } + + /* Okay, at this point we know we're somewhere in the header. + * Valid header *states* are: dbg_timestamp, dbg_level, + * dbg_sourcefile, dbg_function, and dbg_lineno. + */ + switch( c ) + { + case ',': + if( dbg_timestamp == *state ) + { + *state = dbg_level; + return( dbg_ignore ); + } + break; + case ']': + if( dbg_level == *state ) + { + *state = dbg_sourcefile; + return( dbg_ignore ); + } + break; + case ':': + if( dbg_sourcefile == *state ) + { + *state = dbg_function; + return( dbg_ignore ); + } + break; + case '(': + if( dbg_function == *state ) + { + *state = dbg_lineno; + return( dbg_ignore ); + } + break; + case ')': + if( dbg_lineno == *state ) + { + *state = dbg_null; + return( dbg_ignore ); + } + break; + } + + /* If the previous block did not result in a state change, then + * return the current state as the current token. + */ + return( *state ); + } /* dbg_char2token */ + /* ************************************************************************** */ -- cgit From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/lib/debug.c | 256 ++++++++++++---------------------------------------- 1 file changed, 60 insertions(+), 196 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index ab11d81a21..a0dfe61f7d 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -75,7 +75,6 @@ * debugf - Debug file name. * append_log - If True, then the output file will be opened in append * mode. - * timestamp_log - * DEBUGLEVEL - System-wide debug message limit. Messages with message- * levels higher than DEBUGLEVEL will not be processed. */ @@ -83,7 +82,6 @@ FILE *dbf = NULL; pstring debugf = ""; BOOL append_log = False; -BOOL timestamp_log = True; int DEBUGLEVEL = 1; @@ -114,51 +112,40 @@ static int debug_count = 0; static int syslog_level = 0; #endif static pstring format_bufr = { '\0' }; -static int format_pos = 0; +static size_t format_pos = 0; /* -------------------------------------------------------------------------- ** * Functions... */ -/* ************************************************************************** ** - * tells us if interactive logging was requested - * ************************************************************************** ** - */ -BOOL dbg_interactive(void) -{ - return stdout_logging; -} - -#if defined(SIGUSR2) && !defined(MEM_MAN) +#if defined(SIGUSR2) /* ************************************************************************** ** * catch a sigusr2 - decrease the debug log level. * ************************************************************************** ** */ void sig_usr2( int sig ) { - BlockSignals( True, SIGUSR2 ); - DEBUGLEVEL--; if( DEBUGLEVEL < 0 ) DEBUGLEVEL = 0; DEBUG( 0, ( "Got SIGUSR2; set debug level to %d.\n", DEBUGLEVEL ) ); - BlockSignals( False, SIGUSR2 ); +#if !defined(HAVE_SIGACTION) CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); +#endif } /* sig_usr2 */ #endif /* SIGUSR2 */ -#if defined(SIGUSR1) && !defined(MEM_MAN) +#if defined(SIGUSR1) /* ************************************************************************** ** * catch a sigusr1 - increase the debug log level. * ************************************************************************** ** */ void sig_usr1( int sig ) { - BlockSignals( True, SIGUSR1 ); DEBUGLEVEL++; @@ -167,8 +154,9 @@ void sig_usr1( int sig ) DEBUG( 0, ( "Got SIGUSR1; set debug level to %d.\n", DEBUGLEVEL ) ); - BlockSignals( False, SIGUSR1 ); +#if !defined(HAVE_SIGACTION) CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); +#endif } /* sig_usr1 */ #endif /* SIGUSR1 */ @@ -260,11 +248,11 @@ void force_check_log_size( void ) * ************************************************************************** ** */ static void check_log_size( void ) - { +{ int maxlog; SMB_STRUCT_STAT st; - if( debug_count++ < 100 || getuid() != 0 ) + if( debug_count++ < 100 || geteuid() != 0 ) return; maxlog = lp_max_log_size() * 1024; @@ -276,7 +264,7 @@ static void check_log_size( void ) (void)fclose( dbf ); dbf = NULL; reopen_logs(); - if( dbf && file_size( debugf ) > maxlog ) + if( dbf && get_file_size( debugf ) > maxlog ) { pstring name; @@ -287,8 +275,23 @@ static void check_log_size( void ) 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 */ +} /* check_log_size */ /* ************************************************************************** ** * Write an debug message on the debugfile. @@ -382,6 +385,8 @@ va_dcl } #endif + check_log_size(); + #ifdef WITH_SYSLOG if( !lp_syslog_only() ) #endif @@ -397,8 +402,6 @@ va_dcl (void)fflush( dbf ); } - check_log_size(); - errno = old_errno; return( 0 ); @@ -439,8 +442,8 @@ static void bufr_print( void ) */ static void format_debug_text( char *msg ) { - int i; - BOOL timestamp = (timestamp_log && !stdout_logging && (lp_timestamp_logs() || + size_t i; + BOOL timestamp = (!stdout_logging && (lp_timestamp_logs() || !(lp_loaded()))); for( i = 0; msg[i]; i++ ) @@ -510,10 +513,13 @@ void dbgflush( void ) * * ************************************************************************** ** */ + BOOL dbghdr( int level, char *file, char *func, int line ) - { - if( format_pos ) - { +{ + /* Ensure we don't lose any real errno value. */ + int old_errno = errno; + + if( format_pos ) { /* This is a fudge. If there is stuff sitting in the format_bufr, then * the *right* thing to do is to call * format_debug_text( "\n" ); @@ -524,7 +530,7 @@ BOOL dbghdr( int level, char *file, char *func, int line ) * that a new header is *not* desired. */ return( True ); - } + } #ifdef WITH_SYSLOG /* Set syslog_level. */ @@ -538,15 +544,32 @@ BOOL dbghdr( int level, char *file, char *func, int line ) /* Print the header if timestamps are turned on. If parameters are * not yet loaded, then default to timestamps on. */ - if( timestamp_log && (lp_timestamp_logs() || !(lp_loaded()) )) - { + if( lp_timestamp_logs() || !(lp_loaded()) ) { + char header_str[200]; + + header_str[0] = '\0'; + + if( lp_debug_pid()) + slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)getpid()); + + if( lp_debug_uid()) { + size_t hs_len = strlen(header_str); + slprintf(header_str + hs_len, + sizeof(header_str) - 1 - hs_len, + ", effective(%u, %u), real(%u, %u)", + (unsigned int)geteuid(), (unsigned int)getegid(), + (unsigned int)getuid(), (unsigned int)getgid()); + } + /* Print it all out at once to prevent split syslog output. */ - (void)Debug1( "[%s, %d] %s:%s(%d)\n", - timestring(), level, file, func, line ); - } + (void)Debug1( "[%s, %d%s] %s:%s(%d)\n", + timestring(lp_debug_hires_timestamp()), level, + header_str, file, func, line ); + } + errno = old_errno; return( True ); - } /* dbghdr */ +} /* ************************************************************************** ** * Add text to the body of the "current" debug message via the format buffer. @@ -596,163 +619,4 @@ BOOL dbghdr( int level, char *file, char *func, int line ) #endif -dbg_Token dbg_char2token( dbg_Token *state, int c ) - /* ************************************************************************ ** - * Parse input one character at a time. - * - * Input: state - A pointer to a token variable. This is used to - * maintain the parser state between calls. For - * each input stream, you should set up a separate - * state variable and initialize it to dbg_null. - * Pass a pointer to it into this function with each - * character in the input stream. See dbg_test() - * for an example. - * c - The "current" character in the input stream. - * - * Output: A token. - * The token value will change when delimiters are found, - * which indicate a transition between syntactical objects. - * Possible return values are: - * - * dbg_null - The input character was an end-of-line. - * This resets the parser to its initial state - * in preparation for parsing the next line. - * dbg_eof - Same as dbg_null, except that the character - * was an end-of-file. - * dbg_ignore - Returned for whitespace and delimiters. - * These lexical tokens are only of interest - * to the parser. - * dbg_header - Indicates the start of a header line. The - * input character was '[' and was the first on - * the line. - * dbg_timestamp - Indicates that the input character was part - * of a header timestamp. - * dbg_level - Indicates that the input character was part - * of the debug-level value in the header. - * dbg_sourcefile - Indicates that the input character was part - * of the sourcefile name in the header. - * dbg_function - Indicates that the input character was part - * of the function name in the header. - * dbg_lineno - Indicates that the input character was part - * of the DEBUG call line number in the header. - * dbg_message - Indicates that the input character was part - * of the DEBUG message text. - * - * ************************************************************************ ** - */ - { - /* The terminating characters that we see will greatly depend upon - * how they are read. For example, if gets() is used instead of - * fgets(), then we will not see newline characters. A lot also - * depends on the calling function, which may handle terminators - * itself. - * - * '\n', '\0', and EOF are all considered line terminators. The - * dbg_eof token is sent back if an EOF is encountered. - * - * Warning: only allow the '\0' character to be sent if you are - * using gets() to read whole lines (thus replacing '\n' - * with '\0'). Sending '\0' at the wrong time will mess - * up the parsing. - */ - switch( c ) - { - case EOF: - *state = dbg_null; /* Set state to null (initial state) so */ - return( dbg_eof ); /* that we can restart with new input. */ - case '\n': - case '\0': - *state = dbg_null; /* A newline or eoln resets to the null state. */ - return( dbg_null ); - } - - /* When within the body of the message, only a line terminator - * can cause a change of state. We've already checked for line - * terminators, so if the current state is dbg_msgtxt, simply - * return that as our current token. - */ - if( dbg_message == *state ) - return( dbg_message ); - - /* If we are at the start of a new line, and the input character - * is an opening bracket, then the line is a header line, otherwise - * it's a message body line. - */ - if( dbg_null == *state ) - { - if( '[' == c ) - { - *state = dbg_timestamp; - return( dbg_header ); - } - *state = dbg_message; - return( dbg_message ); - } - - /* We've taken care of terminators, text blocks and new lines. - * The remaining possibilities are all within the header line - * itself. - */ - - /* Within the header line, whitespace can be ignored *except* - * within the timestamp. - */ - if( isspace( c ) ) - { - /* Fudge. The timestamp may contain space characters. */ - if( (' ' == c) && (dbg_timestamp == *state) ) - return( dbg_timestamp ); - /* Otherwise, ignore whitespace. */ - return( dbg_ignore ); - } - - /* Okay, at this point we know we're somewhere in the header. - * Valid header *states* are: dbg_timestamp, dbg_level, - * dbg_sourcefile, dbg_function, and dbg_lineno. - */ - switch( c ) - { - case ',': - if( dbg_timestamp == *state ) - { - *state = dbg_level; - return( dbg_ignore ); - } - break; - case ']': - if( dbg_level == *state ) - { - *state = dbg_sourcefile; - return( dbg_ignore ); - } - break; - case ':': - if( dbg_sourcefile == *state ) - { - *state = dbg_function; - return( dbg_ignore ); - } - break; - case '(': - if( dbg_function == *state ) - { - *state = dbg_lineno; - return( dbg_ignore ); - } - break; - case ')': - if( dbg_lineno == *state ) - { - *state = dbg_null; - return( dbg_ignore ); - } - break; - } - - /* If the previous block did not result in a state change, then - * return the current state as the current token. - */ - return( *state ); - } /* dbg_char2token */ - /* ************************************************************************** */ -- cgit From 3cf31a194f5721b67b1255e3f168d4bc87d433fc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 15 Feb 2000 19:36:47 +0000 Subject: Added replacement functions sys_popen and sys_pclose. These are based on the glibc source code and are safer than the traditional popen as they don't use a shell to exec the requested command. Now we have these functions they can be tightened up (environment etc.) as required to make a safe popen. It should now be safe to add the environement variable loading code to loadparm.c Jeremy. (This used to be commit b52e92b09d4ca3b66e534f520468dee27065d048) --- source3/lib/debug.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index a0dfe61f7d..c88f4e1a41 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -318,7 +318,8 @@ va_dcl va_start( ap ); format_str = va_arg( ap, char * ); #endif - (void)vfprintf( dbf, format_str, ap ); + if(dbf) + (void)vfprintf( dbf, format_str, ap ); va_end( ap ); errno = old_errno; return( 0 ); @@ -397,9 +398,11 @@ va_dcl va_start( ap ); format_str = va_arg( ap, char * ); #endif - (void)vfprintf( dbf, format_str, ap ); + if(dbf) + (void)vfprintf( dbf, format_str, ap ); va_end( ap ); - (void)fflush( dbf ); + if(dbf) + (void)fflush( dbf ); } errno = old_errno; @@ -488,7 +491,8 @@ static void format_debug_text( char *msg ) void dbgflush( void ) { bufr_print(); - (void)fflush( dbf ); + if(dbf) + (void)fflush( dbf ); } /* dbgflush */ /* ************************************************************************** ** -- cgit From ce5e230952c18b2308d0e41fff39f0bfdf2cc32b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 15 Apr 2000 00:31:56 +0000 Subject: Log file check patch from Mattias Gronlund . 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. (This used to be commit c3794fd29fdc4e5a0dbd725cdc24fe210934caf2) --- source3/lib/debug.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index c88f4e1a41..ed27b93cfd 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -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 ); -- cgit From 693ffb8466ada58ecc59fde754ba79fc6f51528d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 2 May 2000 02:23:41 +0000 Subject: Added sys_fork() and sys_getpid() functions to stop the overhead of doing a system call every time we want to just get our pid. Jeremy. (This used to be commit 148628b616b5c29ba6340d65fc3ddbcabba6e67a) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index ed27b93cfd..675c2d8cfc 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -580,7 +580,7 @@ BOOL dbghdr( int level, char *file, char *func, int line ) header_str[0] = '\0'; if( lp_debug_pid()) - slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)getpid()); + slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)sys_getpid()); if( lp_debug_uid()) { size_t hs_len = strlen(header_str); -- cgit From b2d01bd2dbfed8b35cc324fad42eac562fcad3b4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 12 Jun 2000 15:53:31 +0000 Subject: totally rewrote the async signal, notification and oplock notification handling in Samba. This was needed due to several limitations and races in the previous code - as a side effect the new code is much cleaner :) in summary: - changed sys_select() to avoid a signal/select race condition. It is a rare race but once we have signals doing notification and oplocks it is important. - changed our main processing loop to take advantage of the new sys_select semantics - split the notify code into implementaion dependent and general parts. Added the following structure that defines an implementation: struct cnotify_fns { void * (*register_notify)(connection_struct *conn, char *path, uint32 flags); BOOL (*check_notify)(connection_struct *conn, uint16 vuid, char *path, uint32 flags, void *data, time_t t); void (*remove_notify)(void *data); }; then I wrote two implementations, one using hash/poll (like our old code) and the other using the new Linux kernel change notify. It should be easy to add other change notify implementations by creating a sructure of the above type. - fixed a bug in change notify where we were returning the wrong error code. - rewrote the core change notify code to be much simpler - moved to real-time signals for leases and change notify Amazingly, it all seems to work. I was very surprised! (This used to be commit 44766c39e0027c762bee8b33b12c621c109a3267) --- source3/lib/debug.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 675c2d8cfc..a388956d42 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -132,6 +132,8 @@ void sig_usr2( int sig ) DEBUG( 0, ( "Got SIGUSR2; set debug level to %d.\n", DEBUGLEVEL ) ); + sys_select_signal(); + #if !defined(HAVE_SIGACTION) CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); #endif @@ -154,6 +156,8 @@ void sig_usr1( int sig ) DEBUG( 0, ( "Got SIGUSR1; set debug level to %d.\n", DEBUGLEVEL ) ); + sys_select_signal(); + #if !defined(HAVE_SIGACTION) CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); #endif -- cgit From 4ff15c319eb70396f2534fb8c165b7f71c58b311 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 28 Aug 2000 03:17:22 +0000 Subject: made reopen_logs() always re-open logs, not try and be smart about not re-opening in some circumstances. This fixes a problem where a HUP does not re-open logs and leaves the log open on a unlinked file. (This used to be commit f99f028c77482e591741df2a3da7f036f7409a68) --- source3/lib/debug.c | 71 +++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 37 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index a388956d42..bfb638a38a 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -195,48 +195,45 @@ void setup_logging( char *pname, BOOL interactive ) /* ************************************************************************** ** * reopen the log files + * note that we now do this unconditionally * ************************************************************************** ** */ void reopen_logs( void ) - { - pstring fname; - - if( DEBUGLEVEL > 0 ) - { - pstrcpy( fname, debugf ); - if( lp_loaded() && (*lp_logfile()) ) - pstrcpy( fname, lp_logfile() ); +{ + pstring fname; + mode_t oldumask; + + if (DEBUGLEVEL <= 0) { + if (dbf) { + (void)fclose(dbf); + dbf = NULL; + } + return; + } - if( !strcsequal( fname, debugf ) || !dbf || !file_exist( debugf, NULL ) ) - { - mode_t oldumask = umask( 022 ); + oldumask = umask( 022 ); + + pstrcpy(fname, debugf ); + if (lp_loaded() && (*lp_logfile())) + pstrcpy(fname, lp_logfile()); + + pstrcpy( debugf, fname ); + if (dbf) + (void)fclose(dbf); + if (append_log) + dbf = sys_fopen( debugf, "a" ); + else + dbf = sys_fopen( debugf, "w" ); + /* Fix from klausr@ITAP.Physik.Uni-Stuttgart.De + * to fix problem where smbd's that generate less + * than 100 messages keep growing the log. + */ + force_check_log_size(); + if (dbf) + setbuf( dbf, NULL ); + (void)umask(oldumask); +} - pstrcpy( debugf, fname ); - if( dbf ) - (void)fclose( dbf ); - if( append_log ) - dbf = sys_fopen( debugf, "a" ); - else - dbf = sys_fopen( debugf, "w" ); - /* Fix from klausr@ITAP.Physik.Uni-Stuttgart.De - * to fix problem where smbd's that generate less - * than 100 messages keep growing the log. - */ - force_check_log_size(); - if( dbf ) - setbuf( dbf, NULL ); - (void)umask( oldumask ); - } - } - else - { - if( dbf ) - { - (void)fclose( dbf ); - dbf = NULL; - } - } - } /* reopen_logs */ /* ************************************************************************** ** * Force a check of the log size. -- cgit From 3689e4ffc10fceb4c39814ef58fe31697e7dd976 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 Sep 2000 07:02:43 +0000 Subject: the first cut of the internal messaging system. The motivation for this system is to replace the UDP message for oplocks, but this commit only does the "set debug level" message. (This used to be commit 2a34ee95f3929cff131db6c5a2b4820194c05b2d) --- source3/lib/debug.c | 61 +++++++++++++++-------------------------------------- 1 file changed, 17 insertions(+), 44 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index bfb638a38a..5279dda2e3 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -119,51 +119,24 @@ static size_t format_pos = 0; * Functions... */ -#if defined(SIGUSR2) -/* ************************************************************************** ** - * catch a sigusr2 - decrease the debug log level. - * ************************************************************************** ** - */ -void sig_usr2( int sig ) - { - DEBUGLEVEL--; - if( DEBUGLEVEL < 0 ) - DEBUGLEVEL = 0; - - DEBUG( 0, ( "Got SIGUSR2; set debug level to %d.\n", DEBUGLEVEL ) ); - - sys_select_signal(); - -#if !defined(HAVE_SIGACTION) - CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); -#endif - - } /* sig_usr2 */ -#endif /* SIGUSR2 */ - -#if defined(SIGUSR1) -/* ************************************************************************** ** - * catch a sigusr1 - increase the debug log level. - * ************************************************************************** ** - */ -void sig_usr1( int sig ) - { - - DEBUGLEVEL++; - - if( DEBUGLEVEL > 10 ) - DEBUGLEVEL = 10; - - DEBUG( 0, ( "Got SIGUSR1; set debug level to %d.\n", DEBUGLEVEL ) ); - - sys_select_signal(); - -#if !defined(HAVE_SIGACTION) - CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); -#endif +/**************************************************************************** +receive a "set debug level" message +****************************************************************************/ +void debug_message(pid_t src, void *buf, int len) +{ + int level; + memcpy(&level, buf, sizeof(int)); + DEBUGLEVEL = level; + DEBUG(1,("Debug level set to %d from pid %d\n", level, (int)src)); +} - } /* sig_usr1 */ -#endif /* SIGUSR1 */ +/**************************************************************************** +send a "set debug level" message +****************************************************************************/ +void debug_message_send(pid_t pid, int level) +{ + message_send_pid(pid, MSG_DEBUG, &level, sizeof(int)); +} /* ************************************************************************** ** -- cgit From 06eeb3c45803bcf26ee586103a974fd852de21b9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Sep 2000 00:47:11 +0000 Subject: much nicer message interface. We now register dispatch functions, allowing new bits of code or vfs modules to register functions without impacting on the messaging code itself. Also note that multiple registrations for the same message type are possible allowing the same message to be delivered to multiple parts of the code (possibly useful for reload messages). (This used to be commit c3350c77f52cade48d2945574e09cb630af85b92) --- source3/lib/debug.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 5279dda2e3..e67aea7fd3 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -122,7 +122,7 @@ static size_t format_pos = 0; /**************************************************************************** receive a "set debug level" message ****************************************************************************/ -void debug_message(pid_t src, void *buf, int len) +void debug_message(enum message_type msg_type, pid_t src, void *buf, size_t len) { int level; memcpy(&level, buf, sizeof(int)); @@ -143,28 +143,27 @@ void debug_message_send(pid_t pid, int level) * get ready for syslog stuff * ************************************************************************** ** */ -void setup_logging( char *pname, BOOL interactive ) - { - if( interactive ) - { - stdout_logging = True; - dbf = stdout; - } -#ifdef WITH_SYSLOG - else - { - char *p = strrchr( pname,'/' ); +void setup_logging(char *pname, BOOL interactive) +{ + message_register(MSG_DEBUG, debug_message); - if( p ) - pname = p + 1; + if (interactive) { + stdout_logging = True; + dbf = stdout; + } +#ifdef WITH_SYSLOG + else { + char *p = strrchr( pname,'/' ); + if (p) + pname = p + 1; #ifdef LOG_DAEMON - openlog( pname, LOG_PID, SYSLOG_FACILITY ); + openlog( pname, LOG_PID, SYSLOG_FACILITY ); #else /* for old systems that have no facility codes. */ - openlog( pname, LOG_PID ); + openlog( pname, LOG_PID ); #endif - } + } #endif - } /* setup_logging */ +} /* setup_logging */ /* ************************************************************************** ** * reopen the log files -- cgit From f0ce4f7ae3b58f45b70598e3a44539e3e12291ce Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Sep 2000 06:13:25 +0000 Subject: - changed the msg_type to be an int instead of an enum so that it is easier to add new message types to messages.h without breaking old binaries - added a MSG_FORCE_ELECTION message to force nmbd to hold an election (This used to be commit f1c49ca7ce56bc39259041a71479e84ebf53eeca) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index e67aea7fd3..1a53f4c2a8 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -122,7 +122,7 @@ static size_t format_pos = 0; /**************************************************************************** receive a "set debug level" message ****************************************************************************/ -void debug_message(enum message_type msg_type, pid_t src, void *buf, size_t len) +void debug_message(int msg_type, pid_t src, void *buf, size_t len) { int level; memcpy(&level, buf, sizeof(int)); -- cgit From c97023b14c942f7261808159a0d192926239b704 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 10 Nov 2000 22:07:57 +0000 Subject: Merge in Herb's changes from 2.2. Jeremy. (This used to be commit 24d76c5fbda29d89c96d7c22193ec2eb93ad3887) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 1a53f4c2a8..cdcd44955b 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -127,7 +127,7 @@ void debug_message(int msg_type, pid_t src, void *buf, size_t len) int level; memcpy(&level, buf, sizeof(int)); DEBUGLEVEL = level; - DEBUG(1,("Debug level set to %d from pid %d\n", level, (int)src)); + DEBUG(1,("INFO: Debug level set to %d from pid %d\n", level, (int)src)); } /**************************************************************************** -- cgit From cdac09614ef426092ed1b1de480fe90c3c4cdd83 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 16 Nov 2000 21:38:24 +0000 Subject: Fix for a problem with the new messaging system. If a sender is using the messaging system as a notification mechanism, and the speed of notification greatly exceeds the speed of message recovery, then you get a massively (>75Mb) growing tdb. If the message is a simple notification, then the message is static, and you only need one of them in transit to a target process at any one time. This patch adds a BOOL "allow_duplicates" to the message_send_XX primitives. If set to False, then before sending a message the sender checks the existing message queue for a target pid for a duplicate of this message, and doesn't add to it if one already exists. Also added code into msgtest.c to test this. Jeremy. (This used to be commit 3aa7995660395ecb85c8e35b638fa9fbbb952558) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index cdcd44955b..9d520b6c2f 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -135,7 +135,7 @@ send a "set debug level" message ****************************************************************************/ void debug_message_send(pid_t pid, int level) { - message_send_pid(pid, MSG_DEBUG, &level, sizeof(int)); + message_send_pid(pid, MSG_DEBUG, &level, sizeof(int), False); } -- cgit From 94fc44a93c46cece9b9fa947bff62087dbcd89fa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 12 Feb 2001 16:18:02 +0000 Subject: Merge of JohnR's changes to appliance-head, JF's changes to 2.2, updated the POSIX_ACL code to be in sync. Jeremy. (This used to be commit c0517d6f4e3079feca1309fd1ea7b21e83f0de02) --- source3/lib/debug.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 6 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 9d520b6c2f..e7772bbd38 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -82,7 +82,8 @@ FILE *dbf = NULL; pstring debugf = ""; BOOL append_log = False; -int DEBUGLEVEL = 1; +int DEBUGLEVEL_CLASS[DBGC_LAST]; +int DEBUGLEVEL = DEBUGLEVEL_CLASS; /* -------------------------------------------------------------------------- ** @@ -114,22 +115,137 @@ static int syslog_level = 0; static pstring format_bufr = { '\0' }; static size_t format_pos = 0; +/* +* Define all the debug class selection names here. Names *MUST NOT* contain +* white space. There must be one name for each DBGC_, and they +* must be in the table in the order of DBGC_.. +*/ +char *classname_table[] = { + "all", /* DBGC_ALL; index references traditional DEBUGLEVEL */ + "tdb", /* DBGC_TDB */ + "printdrivers", /* DBGC_PRINTDRIVERS */ + "lanman", /* DBGC_LANMAN */ +}; + /* -------------------------------------------------------------------------- ** * Functions... */ +/**************************************************************************** +utility access to debug class names's +****************************************************************************/ +char* debug_classname_from_index(int idx) +{ + return classname_table[idx]; +} + +/**************************************************************************** +utility to translate names to debug class index's +****************************************************************************/ +int debug_lookup_classname(char* classname) +{ + int i; + + if (!classname) return -1; + + for (i=0; i Date: Tue, 13 Feb 2001 16:28:48 +0000 Subject: It compiles for me now :-). rpc_server/srv_lsa.c - added fix to allow w2k clients to join a Samba domain - odd or even domain name length. Needs more testing. Jeremy. (This used to be commit 408672d38261e34cc3714200617b35464d88f931) --- source3/lib/debug.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index e7772bbd38..119292b781 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -135,9 +135,9 @@ char *classname_table[] = { /**************************************************************************** utility access to debug class names's ****************************************************************************/ -char* debug_classname_from_index(int idx) +char* debug_classname_from_index(int ndx) { - return classname_table[idx]; + return classname_table[ndx]; } /**************************************************************************** @@ -162,7 +162,7 @@ parse the debug levels from smbcontrol. Example debug level parameter: ****************************************************************************/ BOOL debug_parse_params(char **params, int *debuglevel_class) { - int i, idx; + int i, ndx; char *class_name; char *class_level; @@ -183,8 +183,8 @@ BOOL debug_parse_params(char **params, int *debuglevel_class) for (; i < DBGC_LAST && params[i]; i++) { if ((class_name=strtok(params[i],":")) && (class_level=strtok(NULL, "\0")) && - ((idx = debug_lookup_classname(class_name)) != -1)) { - debuglevel_class[idx] = atoi(class_level); + ((ndx = debug_lookup_classname(class_name)) != -1)) { + debuglevel_class[ndx] = atoi(class_level); } else { DEBUG(0,("debug_parse_params: unrecognized debug class name or format [%s]\n", params[i])); return False; @@ -208,7 +208,7 @@ BOOL debug_parse_levels(char *params_str) ZERO_ARRAY(params); ZERO_ARRAY(debuglevel_class); - if ( (params[0]=strtok(params_str," ,")) ) { + if ((params[0]=strtok(params_str," ,"))) { for (i=1; i Date: Tue, 20 Feb 2001 10:14:17 +0000 Subject: up the debug level of the debug level change msg (This used to be commit 9b25342f4ac4a250b3a10a3bb048ca6baa2ca41e) --- source3/lib/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 119292b781..2ba35c00db 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -234,13 +234,13 @@ void debug_message(int msg_type, pid_t src, void *buf, size_t len) /* Set the new DEBUGLEVEL_CLASS array from the pased array */ memcpy(DEBUGLEVEL_CLASS, buf, sizeof(DEBUGLEVEL_CLASS)); - DEBUG(1,("INFO: Debug class %s level = %d (pid %d from pid %d)\n", + DEBUG(3,("INFO: Debug class %s level = %d (pid %d from pid %d)\n", classname_table[DBGC_ALL], DEBUGLEVEL_CLASS[DBGC_ALL], getpid(), (int)src)); for (i=1; i Date: Sun, 11 Mar 2001 00:32:10 +0000 Subject: Merge of new 2.2 code into HEAD (Gerald I hate you :-) :-). Allows new SAMR RPC code to merge with new passdb code. Currently rpcclient doesn't compile. I'm working on it... Jeremy. (This used to be commit 0be41d5158ea4e645e93e8cd30617c038416e549) --- source3/lib/debug.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 2ba35c00db..27fa80ca3f 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -234,13 +234,13 @@ void debug_message(int msg_type, pid_t src, void *buf, size_t len) /* Set the new DEBUGLEVEL_CLASS array from the pased array */ memcpy(DEBUGLEVEL_CLASS, buf, sizeof(DEBUGLEVEL_CLASS)); - DEBUG(3,("INFO: Debug class %s level = %d (pid %d from pid %d)\n", + DEBUG(1,("INFO: Debug class %s level = %d (pid %d from pid %d)\n", classname_table[DBGC_ALL], DEBUGLEVEL_CLASS[DBGC_ALL], getpid(), (int)src)); for (i=1; i Date: Tue, 27 Mar 2001 01:19:54 +0000 Subject: Patch from David Gibson to reduce "silent abort" problems with smbd failing to create a log file. If we can't create a log file keep using the old file. Jeremy. (This used to be commit c4e6aa1322fa7bc59708163c42eef6ccbd6c2305) --- source3/lib/debug.c | 134 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 51 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 27fa80ca3f..9c97385db3 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -82,6 +82,7 @@ FILE *dbf = NULL; pstring debugf = ""; BOOL append_log = False; + int DEBUGLEVEL_CLASS[DBGC_LAST]; int DEBUGLEVEL = DEBUGLEVEL_CLASS; @@ -105,6 +106,12 @@ int DEBUGLEVEL = DEBUGLEVEL_CLASS; * to build the formatted output. * * format_pos - Marks the first free byte of the format_bufr. + * + * + * log_overflow - When this variable is True, never attempt to check the + * size of the log. This is a hack, so that we can write + * a message using DEBUG, from open_logs() when we + * are unable to open a new log file for some reason. */ static BOOL stdout_logging = False; @@ -114,6 +121,7 @@ static int syslog_level = 0; #endif static pstring format_bufr = { '\0' }; static size_t format_pos = 0; +static BOOL log_overflow = False; /* * Define all the debug class selection names here. Names *MUST NOT* contain @@ -289,19 +297,25 @@ void setup_logging(char *pname, BOOL interactive) /* ************************************************************************** ** * reopen the log files * note that we now do this unconditionally + * We attempt to open the new debug fp before closing the old. This means + * if we run out of fd's we just keep using the old fd rather than aborting. + * Fix from dgibson@linuxcare.com. * ************************************************************************** ** */ -void reopen_logs( void ) + +BOOL reopen_logs( void ) { pstring fname; mode_t oldumask; + FILE *new_dbf = NULL; + BOOL ret = True; if (DEBUGLEVEL_CLASS[ DBGC_ALL ] <= 0) { if (dbf) { (void)fclose(dbf); dbf = NULL; } - return; + return True; } oldumask = umask( 022 ); @@ -311,22 +325,33 @@ void reopen_logs( void ) pstrcpy(fname, lp_logfile()); pstrcpy( debugf, fname ); - if (dbf) - (void)fclose(dbf); if (append_log) - dbf = sys_fopen( debugf, "a" ); + new_dbf = sys_fopen( debugf, "a" ); else - dbf = sys_fopen( debugf, "w" ); + new_dbf = sys_fopen( debugf, "w" ); + + if (!new_dbf) { + log_overflow = True; + DEBUG(0, ("Unable to open new log file %s: %s\n", debugf, strerror(errno))); + log_overflow = False; + fflush(dbf); + ret = False; + } else { + setbuf(new_dbf, NULL); + if (dbf) + (void) fclose(dbf); + dbf = new_dbf; + } + /* Fix from klausr@ITAP.Physik.Uni-Stuttgart.De * to fix problem where smbd's that generate less * than 100 messages keep growing the log. */ force_check_log_size(); - if (dbf) - setbuf( dbf, NULL ); (void)umask(oldumask); -} + return ret; +} /* ************************************************************************** ** * Force a check of the log size. @@ -363,54 +388,61 @@ BOOL need_to_check_log_size( void ) void check_log_size( void ) { - int maxlog; - SMB_STRUCT_STAT st; + 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. - */ + /* + * 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( geteuid() != 0 ) + return; - if( !need_to_check_log_size() ) - return; + if(log_overflow || !need_to_check_log_size() ) + return; - maxlog = lp_max_log_size() * 1024; + 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; + if( sys_fstat( fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { + (void)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; + 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 */ /* ************************************************************************** ** -- cgit From 5345d9eb57d7d8e1c8b3a4ae17e20ef87c24345d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Apr 2001 22:02:23 +0000 Subject: More %d (uid_t) stuff... Jeremy. (This used to be commit 73b425121a8c99af3ed7adbdcff3f6f0cec92ac7) --- source3/lib/debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 9c97385db3..dc846f1b6f 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -180,7 +180,7 @@ BOOL debug_parse_params(char **params, int *debuglevel_class) /* Allow DBGC_ALL to be specifies w/o requiring its class name e.g."10" * v.s. "all:10", this is the traditional way to set DEBUGLEVEL */ - if (isdigit(params[0][0])) { + if (isdigit((int)params[0][0])) { debuglevel_class[DBGC_ALL] = atoi(params[0]); i = 1; /* start processing at the next params */ } @@ -242,9 +242,9 @@ void debug_message(int msg_type, pid_t src, void *buf, size_t len) /* Set the new DEBUGLEVEL_CLASS array from the pased array */ memcpy(DEBUGLEVEL_CLASS, buf, sizeof(DEBUGLEVEL_CLASS)); - DEBUG(1,("INFO: Debug class %s level = %d (pid %d from pid %d)\n", + DEBUG(1,("INFO: Debug class %s level = %d (pid %u from pid %u)\n", classname_table[DBGC_ALL], - DEBUGLEVEL_CLASS[DBGC_ALL], getpid(), (int)src)); + DEBUGLEVEL_CLASS[DBGC_ALL], (unsigned int)getpid(), (unsigned int)src)); for (i=1; i Date: Sat, 28 Apr 2001 13:49:34 +0000 Subject: - added test for vasprintf - cleaned up GNUC printf attribute macros - added enum handling in mkproto - removed non-vararg code - made slprintf and vslprintf just macros for snprintf and vsnprintf - don't need slprintf code any more (This used to be commit c7aeb2254dfc3cd0aa0b6c0bdd426f9323be0ddf) --- source3/lib/debug.c | 42 ------------------------------------------ 1 file changed, 42 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index dc846f1b6f..f7ad324e39 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -450,26 +450,14 @@ void check_log_size( void ) * This is called by dbghdr() and format_debug_text(). * ************************************************************************** ** */ -#ifdef HAVE_STDARG_H int Debug1( char *format_str, ... ) { -#else - int Debug1(va_alist) -va_dcl -{ - char *format_str; -#endif va_list ap; int old_errno = errno; if( stdout_logging ) { -#ifdef HAVE_STDARG_H va_start( ap, format_str ); -#else - va_start( ap ); - format_str = va_arg( ap, char * ); -#endif if(dbf) (void)vfprintf( dbf, format_str, ap ); va_end( ap ); @@ -524,12 +512,7 @@ va_dcl else priority = priority_map[syslog_level]; -#ifdef HAVE_STDARG_H va_start( ap, format_str ); -#else - va_start( ap ); - format_str = va_arg( ap, char * ); -#endif vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); va_end( ap ); @@ -544,12 +527,7 @@ va_dcl if( !lp_syslog_only() ) #endif { -#ifdef HAVE_STDARG_H va_start( ap, format_str ); -#else - va_start( ap ); - format_str = va_arg( ap, char * ); -#endif if(dbf) (void)vfprintf( dbf, format_str, ap ); va_end( ap ); @@ -740,7 +718,6 @@ BOOL dbghdr( int level, char *file, char *func, int line ) * * ************************************************************************** ** */ -#ifdef HAVE_STDARG_H BOOL dbgtext( char *format_str, ... ) { va_list ap; @@ -755,24 +732,5 @@ BOOL dbghdr( int level, char *file, char *func, int line ) return( True ); } /* dbgtext */ -#else - BOOL dbgtext( va_alist ) - va_dcl - { - char *format_str; - va_list ap; - pstring msgbuf; - - va_start( ap ); - format_str = va_arg( ap, char * ); - vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); - va_end( ap ); - - format_debug_text( msgbuf ); - - return( True ); - } /* dbgtext */ - -#endif /* ************************************************************************** */ -- cgit From b50d07252945b8026d0194809dde95c201489804 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 7 May 2001 23:46:48 +0000 Subject: Hey what happened to my debug messages? Early exit from reopen_logs() if using stdout_logging. (This used to be commit 831b0983bd799fd73de18921f09991a1647ec482) --- source3/lib/debug.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index f7ad324e39..934110a4d7 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -133,6 +133,9 @@ char *classname_table[] = { "tdb", /* DBGC_TDB */ "printdrivers", /* DBGC_PRINTDRIVERS */ "lanman", /* DBGC_LANMAN */ + "smb", /* DBGC_SMB */ + "rpc", /* DBGC_RPC */ + "rpc_hdr", /* DBGC_RPC_HDR */ }; @@ -227,6 +230,11 @@ BOOL debug_parse_levels(char *params_str) if (debug_parse_params(params, debuglevel_class)) { debug_message(0, getpid(), (void*)debuglevel_class, sizeof(debuglevel_class)); + +#if 0 + memcpy(DEBUGLEVEL_CLASS, debuglevel_class, + sizeof(debuglevel_class)); +#endif return True; } else return False; @@ -310,6 +318,9 @@ BOOL reopen_logs( void ) FILE *new_dbf = NULL; BOOL ret = True; + if (stdout_logging) + return True; + if (DEBUGLEVEL_CLASS[ DBGC_ALL ] <= 0) { if (dbf) { (void)fclose(dbf); -- cgit From 6dce5c47c62d6ad3d74489bde3824fbfb02d8616 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 1 Jun 2001 12:04:44 +0000 Subject: If a debug class was explicitly set to zero the debug system would not recognise it as there was no distinction made between zeroing a debug class and just not setting it to anything. I've added a debuglevel_isset array in parallel with the debuglevel_class array to fix this. Added a couple of new debug classes which I might start filling out to get smb, rpc header and rpc marshall/unmarshalling debugs tidied up. Fixed a bunch of cut&paste bugs in include/debug.h Modified smbcontrol and the messaging system debug handler to like the debuglevel_isset stuff. (This used to be commit 391e7caf76cbc22021629ef0ec5e0c32806edfd7) --- source3/lib/debug.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 934110a4d7..bd8babf827 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -84,6 +84,7 @@ pstring debugf = ""; BOOL append_log = False; int DEBUGLEVEL_CLASS[DBGC_LAST]; +BOOL DEBUGLEVEL_CLASS_ISSET[DBGC_LAST]; int DEBUGLEVEL = DEBUGLEVEL_CLASS; @@ -129,13 +130,14 @@ static BOOL log_overflow = False; * must be in the table in the order of DBGC_.. */ char *classname_table[] = { - "all", /* DBGC_ALL; index references traditional DEBUGLEVEL */ - "tdb", /* DBGC_TDB */ + "all", /* DBGC_ALL; index refs traditional DEBUGLEVEL */ + "tdb", /* DBGC_TDB */ "printdrivers", /* DBGC_PRINTDRIVERS */ - "lanman", /* DBGC_LANMAN */ - "smb", /* DBGC_SMB */ - "rpc", /* DBGC_RPC */ - "rpc_hdr", /* DBGC_RPC_HDR */ + "lanman", /* DBGC_LANMAN */ + "smb", /* DBGC_SMB */ + "rpc", /* DBGC_RPC */ + "rpc_hdr", /* DBGC_RPC_HDR */ + "bdc", /* DBGC_BDC */ }; @@ -171,7 +173,8 @@ int debug_lookup_classname(char* classname) parse the debug levels from smbcontrol. Example debug level parameter: printdrivers:7 ****************************************************************************/ -BOOL debug_parse_params(char **params, int *debuglevel_class) +BOOL debug_parse_params(char **params, int *debuglevel_class, + BOOL *debuglevel_class_isset) { int i, ndx; char *class_name; @@ -185,10 +188,11 @@ BOOL debug_parse_params(char **params, int *debuglevel_class) */ if (isdigit((int)params[0][0])) { debuglevel_class[DBGC_ALL] = atoi(params[0]); + debuglevel_class_isset[DBGC_ALL] = True; i = 1; /* start processing at the next params */ } else - i = 0; /* DBGC_ALL not specified OR calss name was included */ + i = 0; /* DBGC_ALL not specified OR class name was included */ /* Fill in new debug class levels */ for (; i < DBGC_LAST && params[i]; i++) { @@ -196,6 +200,7 @@ BOOL debug_parse_params(char **params, int *debuglevel_class) (class_level=strtok(NULL, "\0")) && ((ndx = debug_lookup_classname(class_name)) != -1)) { debuglevel_class[ndx] = atoi(class_level); + debuglevel_class_isset[ndx] = True; } else { DEBUG(0,("debug_parse_params: unrecognized debug class name or format [%s]\n", params[i])); return False; @@ -215,9 +220,11 @@ BOOL debug_parse_levels(char *params_str) int i; char *params[DBGC_LAST]; int debuglevel_class[DBGC_LAST]; + BOOL debuglevel_class_isset[DBGC_LAST]; ZERO_ARRAY(params); ZERO_ARRAY(debuglevel_class); + ZERO_ARRAY(debuglevel_class_isset); if ((params[0]=strtok(params_str," ,"))) { for (i=1; idebuglevel_class, sizeof(dm->debuglevel_class)); + memcpy(DEBUGLEVEL_CLASS_ISSET, dm->debuglevel_class_isset, sizeof(dm->debuglevel_class_isset)); + DEBUG(1,("INFO: Debug class %s level = %d (pid %u from pid %u)\n", classname_table[DBGC_ALL], DEBUGLEVEL_CLASS[DBGC_ALL], (unsigned int)getpid(), (unsigned int)src)); -- cgit From 17d5d660b5853e64ea0225ce107ed619b2aeb064 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 22 Jun 2001 19:46:38 +0000 Subject: Fix for race condition found by Herb where we can end up with a NULL dbf. Jeremy. (This used to be commit 5cbb2106735ad0533198a83d62541cabd7beed20) --- source3/lib/debug.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index bd8babf827..06092c6a35 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -343,14 +343,6 @@ BOOL reopen_logs( void ) if (stdout_logging) return True; - if (DEBUGLEVEL_CLASS[ DBGC_ALL ] <= 0) { - if (dbf) { - (void)fclose(dbf); - dbf = NULL; - } - return True; - } - oldumask = umask( 022 ); pstrcpy(fname, debugf ); -- cgit From 527e824293ee934ca5da0ef5424efe5ab7757248 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:36:09 +0000 Subject: strchr and strrchr are macros when compiling with optimisation in gcc, so we can't redefine them. damn. (This used to be commit c41fc06376d1a2b83690612304e85010b5e5f3cf) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 06092c6a35..27d5e55dc0 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -312,7 +312,7 @@ void setup_logging(char *pname, BOOL interactive) } #ifdef WITH_SYSLOG else { - char *p = strrchr( pname,'/' ); + char *p = strrchr_m( pname,'/' ); if (p) pname = p + 1; #ifdef LOG_DAEMON -- cgit From 22512215508c709bd7c68fe40511d3cd68f06c45 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 6 Jul 2001 03:18:54 +0000 Subject: got rid of insanely verbose debug messages on startup (This used to be commit c3a21fc0f21b3f493031cb0c9a6a990528b276d9) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 27d5e55dc0..82872478cf 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -249,7 +249,7 @@ BOOL debug_parse_levels(char *params_str) int q; for (q = 0; q < DBGC_LAST; q++) - DEBUG(0, ("%s: %d/%d\n", + DEBUG(5, ("%s: %d/%d\n", classname_table[q], DEBUGLEVEL_CLASS[q], DEBUGLEVEL_CLASS_ISSET[q])); -- cgit From e845532d7c3bda1ffc22a50b4cbea2a5088ea366 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 25 Jul 2001 04:10:23 +0000 Subject: got rid of INFO: msgs at debug level 1 (This used to be commit e6773b08a4a1a54dca4a2e2ec5d4e9c43383b072) --- source3/lib/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 82872478cf..4dbeda2f73 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -272,13 +272,13 @@ void debug_message(int msg_type, pid_t src, void *buf, size_t len) memcpy(DEBUGLEVEL_CLASS, dm->debuglevel_class, sizeof(dm->debuglevel_class)); memcpy(DEBUGLEVEL_CLASS_ISSET, dm->debuglevel_class_isset, sizeof(dm->debuglevel_class_isset)); - DEBUG(1,("INFO: Debug class %s level = %d (pid %u from pid %u)\n", + DEBUG(3,("INFO: Debug class %s level = %d (pid %u from pid %u)\n", classname_table[DBGC_ALL], DEBUGLEVEL_CLASS[DBGC_ALL], (unsigned int)getpid(), (unsigned int)src)); for (i=1; i Date: Mon, 10 Sep 2001 11:08:57 +0000 Subject: replaced stdio in many parts of samba with a XFILE. XFILE is a cut-down replacemnt of stdio that doesn't suffer from the 8-bit filedescriptor limit that we hit with nasty consequences on some systems I would eventually prefer us to have a configure test to see if we need to replace stdio, but for now this code needs to be tested widely so I'm enabling it by default. (This used to be commit 1af8bf34f1caa3e7ec312d8109c07d32a945a448) --- source3/lib/debug.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 4dbeda2f73..9eb490c27e 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -79,7 +79,7 @@ * levels higher than DEBUGLEVEL will not be processed. */ -FILE *dbf = NULL; +XFILE *dbf = NULL; pstring debugf = ""; BOOL append_log = False; @@ -308,7 +308,7 @@ void setup_logging(char *pname, BOOL interactive) if (interactive) { stdout_logging = True; - dbf = stdout; + dbf = x_stdout; } #ifdef WITH_SYSLOG else { @@ -337,7 +337,7 @@ BOOL reopen_logs( void ) { pstring fname; mode_t oldumask; - FILE *new_dbf = NULL; + XFILE *new_dbf = NULL; BOOL ret = True; if (stdout_logging) @@ -351,20 +351,20 @@ BOOL reopen_logs( void ) pstrcpy( debugf, fname ); if (append_log) - new_dbf = sys_fopen( debugf, "a" ); + new_dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644); else - new_dbf = sys_fopen( debugf, "w" ); + new_dbf = x_fopen( debugf, O_WRONLY|O_CREAT|O_TRUNC, 0644 ); if (!new_dbf) { log_overflow = True; DEBUG(0, ("Unable to open new log file %s: %s\n", debugf, strerror(errno))); log_overflow = False; - fflush(dbf); + x_fflush(dbf); ret = False; } else { - setbuf(new_dbf, NULL); + x_setbuf(new_dbf, NULL); if (dbf) - (void) fclose(dbf); + (void) x_fclose(dbf); dbf = new_dbf; } @@ -429,7 +429,7 @@ void check_log_size( void ) maxlog = lp_max_log_size() * 1024; - if( sys_fstat( fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { + if( sys_fstat( x_fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { (void)reopen_logs(); if( dbf && get_file_size( debugf ) > maxlog ) { pstring name; @@ -456,7 +456,7 @@ void check_log_size( void ) startup or when the log level is increased from zero. -dwg 6 June 2000 */ - dbf = sys_fopen( "/dev/console", "w" ); + dbf = x_fopen( "/dev/console", O_WRONLY, 0); if(dbf) { DEBUG(0,("check_log_size: open of debug file %s failed - using console.\n", debugf )); @@ -484,7 +484,7 @@ void check_log_size( void ) { va_start( ap, format_str ); if(dbf) - (void)vfprintf( dbf, format_str, ap ); + (void)x_vfprintf( dbf, format_str, ap ); va_end( ap ); errno = old_errno; return( 0 ); @@ -499,13 +499,13 @@ void check_log_size( void ) mode_t oldumask = umask( 022 ); if( append_log ) - dbf = sys_fopen( debugf, "a" ); + dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 ); else - dbf = sys_fopen( debugf, "w" ); + dbf = x_fopen( debugf, O_WRONLY|O_CREAT|O_TRUNC, 0644 ); (void)umask( oldumask ); if( dbf ) { - setbuf( dbf, NULL ); + x_setbuf( dbf, NULL ); } else { @@ -554,10 +554,10 @@ void check_log_size( void ) { va_start( ap, format_str ); if(dbf) - (void)vfprintf( dbf, format_str, ap ); + (void)x_vfprintf( dbf, format_str, ap ); va_end( ap ); if(dbf) - (void)fflush( dbf ); + (void)x_fflush( dbf ); } errno = old_errno; @@ -647,7 +647,7 @@ void dbgflush( void ) { bufr_print(); if(dbf) - (void)fflush( dbf ); + (void)x_fflush( dbf ); } /* dbgflush */ /* ************************************************************************** ** -- cgit From cb4b13a82ba26c70674fe903d89db1d38103dff7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 2 Oct 2001 06:57:18 +0000 Subject: Fixed the bug with member servers in a Samba PDC hosted domain not allowing other access. Problem was max time was being set to 0xffffffff, instead of 0x7fffffff. Jeremy. (This used to be commit 94403d841710391ec26539e4b4157439d5778ff7) --- source3/lib/debug.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 9eb490c27e..6524d58ecb 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -346,8 +346,14 @@ BOOL reopen_logs( void ) oldumask = umask( 022 ); pstrcpy(fname, debugf ); - if (lp_loaded() && (*lp_logfile())) - pstrcpy(fname, lp_logfile()); + + if (lp_loaded()) { + char *logfname; + + logfname = lp_logfile(); + if (*logfname) + pstrcpy(fname, logfname); + } pstrcpy( debugf, fname ); if (append_log) -- cgit From b947ad3a491b6ad2c8aebd8604dee056ac874435 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 27 Oct 2001 07:17:21 +0000 Subject: smbd/notify_hash.c: Merged Herb's fix. lib/debug.c: Fix for potential null pointer access. Jeremy. (This used to be commit 5a4d22dd66ab782f6161aa5a4162c0e7f1d811fb) --- source3/lib/debug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 6524d58ecb..92b80c8736 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -365,7 +365,8 @@ BOOL reopen_logs( void ) log_overflow = True; DEBUG(0, ("Unable to open new log file %s: %s\n", debugf, strerror(errno))); log_overflow = False; - x_fflush(dbf); + if (dbf) + x_fflush(dbf); ret = False; } else { x_setbuf(new_dbf, NULL); -- cgit From f9879578c6ebfba73b1d9a51f9833cb41fff23f2 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 29 Oct 2001 08:26:45 +0000 Subject: More spelling and grammer from Vance. Thanks! Andrew Bartlett (This used to be commit f019bed7663b4a20c1b5ab6b59fcadda17b89acd) --- source3/lib/debug.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 92b80c8736..a77328e343 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -26,7 +26,7 @@ * * FORMAT_BUFR_MAX - Index of the last byte of the format buffer; * format_bufr[FORMAT_BUFR_MAX] should always be reserved - * for a terminating nul byte. + * for a terminating null byte. */ #define FORMAT_BUFR_MAX ( sizeof( format_bufr ) - 1 ) @@ -125,10 +125,10 @@ static size_t format_pos = 0; static BOOL log_overflow = False; /* -* Define all the debug class selection names here. Names *MUST NOT* contain -* white space. There must be one name for each DBGC_, and they -* must be in the table in the order of DBGC_.. -*/ + * Define all the debug class selection names here. Names *MUST NOT* contain + * white space. There must be one name for each DBGC_, and they + * must be in the table in the order of DBGC_.. + */ char *classname_table[] = { "all", /* DBGC_ALL; index refs traditional DEBUGLEVEL */ "tdb", /* DBGC_TDB */ @@ -183,7 +183,7 @@ BOOL debug_parse_params(char **params, int *debuglevel_class, /* Set the new debug level array to the current DEBUGLEVEL array */ memcpy(debuglevel_class, DEBUGLEVEL_CLASS, sizeof(DEBUGLEVEL_CLASS)); - /* Allow DBGC_ALL to be specifies w/o requiring its class name e.g."10" + /* Allow DBGC_ALL to be specified w/o requiring its class name e.g."10" * v.s. "all:10", this is the traditional way to set DEBUGLEVEL */ if (isdigit((int)params[0][0])) { @@ -192,7 +192,7 @@ BOOL debug_parse_params(char **params, int *debuglevel_class, i = 1; /* start processing at the next params */ } else - i = 0; /* DBGC_ALL not specified OR class name was included */ + i = 0; /* DBGC_ALL not specified OR class name was included */ /* Fill in new debug class levels */ for (; i < DBGC_LAST && params[i]; i++) { @@ -317,7 +317,8 @@ void setup_logging(char *pname, BOOL interactive) pname = p + 1; #ifdef LOG_DAEMON openlog( pname, LOG_PID, SYSLOG_FACILITY ); -#else /* for old systems that have no facility codes. */ +#else + /* for old systems that have no facility codes. */ openlog( pname, LOG_PID ); #endif } @@ -457,12 +458,12 @@ void check_log_size( void ) 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 - */ + * 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 = x_fopen( "/dev/console", O_WRONLY, 0); if(dbf) { DEBUG(0,("check_log_size: open of debug file %s failed - using console.\n", @@ -661,7 +662,7 @@ void dbgflush( void ) * Print a Debug Header. * * Input: level - Debug level of the message (not the system-wide debug - * level. + * level. ) * file - Pointer to a string containing the name of the file * from which this function was called, or an empty string * if the __FILE__ macro is not implemented. -- cgit From f1256e847e6820c29f8bc74db4609d8aa282a1a1 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Mon, 7 Jan 2002 21:32:22 +0000 Subject: merge changes from 2.2 branch to prevent smb.conf from changing debug level of commands when specified on command line. (This used to be commit 39d6b31e14144a3ff4b992d4286b706147e58566) --- source3/lib/debug.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index a77328e343..f3b0f2be12 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -86,6 +86,7 @@ BOOL append_log = False; int DEBUGLEVEL_CLASS[DBGC_LAST]; BOOL DEBUGLEVEL_CLASS_ISSET[DBGC_LAST]; int DEBUGLEVEL = DEBUGLEVEL_CLASS; +BOOL AllowDebugChange = True; /* -------------------------------------------------------------------------- ** @@ -222,6 +223,8 @@ BOOL debug_parse_levels(char *params_str) int debuglevel_class[DBGC_LAST]; BOOL debuglevel_class_isset[DBGC_LAST]; + if (AllowDebugChange == False) + return True; ZERO_ARRAY(params); ZERO_ARRAY(debuglevel_class); ZERO_ARRAY(debuglevel_class_isset); -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/lib/debug.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index f3b0f2be12..87a8d42999 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. Samba utility functions Copyright (C) Andrew Tridgell 1992-1998 -- cgit From 57bd576445e42a55887c41d270f2230f5136b873 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 14 Mar 2002 01:53:04 +0000 Subject: getpid() -> sys_getpid() (This used to be commit a3cea5e9ae3b53ecbc45e61a39cbce0ca1b916aa) --- source3/lib/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 87a8d42999..7960c32b58 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -239,7 +239,7 @@ BOOL debug_parse_levels(char *params_str) if (debug_parse_params(params, debuglevel_class, debuglevel_class_isset)) { - debug_message(0, getpid(), (void*)debuglevel_class, sizeof(debuglevel_class)); + debug_message(0, sys_getpid(), (void*)debuglevel_class, sizeof(debuglevel_class)); memcpy(DEBUGLEVEL_CLASS, debuglevel_class, sizeof(debuglevel_class)); @@ -276,7 +276,7 @@ void debug_message(int msg_type, pid_t src, void *buf, size_t len) DEBUG(3,("INFO: Debug class %s level = %d (pid %u from pid %u)\n", classname_table[DBGC_ALL], - DEBUGLEVEL_CLASS[DBGC_ALL], (unsigned int)getpid(), (unsigned int)src)); + DEBUGLEVEL_CLASS[DBGC_ALL], (unsigned int)sys_getpid(), (unsigned int)src)); for (i=1; i Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/lib/debug.c | 363 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 290 insertions(+), 73 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 7960c32b58..f41c3b6497 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -2,6 +2,8 @@ Unix SMB/CIFS implementation. Samba utility functions Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Elrond 2002 + Copyright (C) Simo Sorce 2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -81,11 +83,23 @@ XFILE *dbf = NULL; pstring debugf = ""; BOOL append_log = False; +BOOL debug_warn_unknown_class = True; +BOOL debug_auto_add_unknown_class = True; +BOOL AllowDebugChange = True; -int DEBUGLEVEL_CLASS[DBGC_LAST]; -BOOL DEBUGLEVEL_CLASS_ISSET[DBGC_LAST]; -int DEBUGLEVEL = DEBUGLEVEL_CLASS; -BOOL AllowDebugChange = True; +/* + * This is to allow assignment to DEBUGLEVEL before the debug + * system has been initialised. + */ +static int debug_all_class_hack = 1; +static BOOL debug_all_class_isset_hack = True; + +static int debug_num_classes = 0; +int *DEBUGLEVEL_CLASS = &debug_all_class_hack; +BOOL *DEBUGLEVEL_CLASS_ISSET = &debug_all_class_isset_hack; + +/* DEBUGLEVEL is #defined to *debug_level */ +int DEBUGLEVEL = &debug_all_class_hack; /* -------------------------------------------------------------------------- ** @@ -129,46 +143,230 @@ static BOOL log_overflow = False; * white space. There must be one name for each DBGC_, and they * must be in the table in the order of DBGC_.. */ -char *classname_table[] = { +static const char *default_classname_table[] = { "all", /* DBGC_ALL; index refs traditional DEBUGLEVEL */ "tdb", /* DBGC_TDB */ "printdrivers", /* DBGC_PRINTDRIVERS */ "lanman", /* DBGC_LANMAN */ "smb", /* DBGC_SMB */ - "rpc", /* DBGC_RPC */ - "rpc_hdr", /* DBGC_RPC_HDR */ - "bdc", /* DBGC_BDC */ + "rpc_parse", /* DBGC_RPC_PARSE */ + "rpc_srv", /* DBGC_RPC_SRV */ + "rpc_cli", /* DBGC_RPC_CLI */ + "passdb", /* DBGC_PASSDB */ + "auth", /* DBGC_AUTH */ + "winbind", /* DBGC_WINBIND */ + NULL }; +static char **classname_table = NULL; + /* -------------------------------------------------------------------------- ** * Functions... */ + +/**************************************************************************** +utility lists registered debug class names's +****************************************************************************/ + +#define MAX_CLASS_NAME_SIZE 1024 + +static char *debug_list_class_names_and_levels(void) +{ + int i, dim; + char **list; + char *buf = NULL; + char *b; + BOOL err = False; + + if (DEBUGLEVEL_CLASS == &debug_all_class_hack) + return NULL; + + list = calloc(debug_num_classes + 1, sizeof(char *)); + if (!list) + return NULL; + + /* prepare strings */ + for (i = 0, dim = 0; i < debug_num_classes; i++) { + int l = asprintf(&list[i], + "%s:%d ", + classname_table[i], + DEBUGLEVEL_CLASS_ISSET[i]?DEBUGLEVEL_CLASS[i]:DEBUGLEVEL); + if (l < 0 || l > MAX_CLASS_NAME_SIZE) { + err = True; + goto done; + } + dim += l; + } + + /* create single string list */ + b = buf = malloc(dim); + if (!buf) { + err = True; + goto done; + } + for (i = 0; i < debug_num_classes; i++) { + int l = strlen(list[i]); + strncpy(b, list[i], l); + b = b + l; + } + b[-1] = '\0'; + +done: + /* free strings list */ + for (i = 0; i < debug_num_classes; i++) + if (list[i]) free(list[i]); + free(list); + + if (err) { + if (buf) + free(buf); + return NULL; + } else { + return buf; + } +} + /**************************************************************************** utility access to debug class names's ****************************************************************************/ -char* debug_classname_from_index(int ndx) +const char *debug_classname_from_index(int ndx) { - return classname_table[ndx]; + if (ndx < 0 || ndx >= debug_num_classes) + return NULL; + else + return classname_table[ndx]; } /**************************************************************************** -utility to translate names to debug class index's +utility to translate names to debug class index's (internal version) ****************************************************************************/ -int debug_lookup_classname(char* classname) +static int debug_lookup_classname_int(const char* classname) { int i; if (!classname) return -1; - for (i=0; i= 0) + return ndx; + ndx = debug_num_classes; + + new_ptr = DEBUGLEVEL_CLASS; + if (DEBUGLEVEL_CLASS == &debug_all_class_hack) + { + /* Initial loading... */ + new_ptr = NULL; + } + new_ptr = Realloc(new_ptr, + sizeof(int) * (debug_num_classes + 1)); + if (!new_ptr) + return -1; + DEBUGLEVEL_CLASS = new_ptr; + DEBUGLEVEL_CLASS[ndx] = 0; + + /* debug_level is the pointer used for the DEBUGLEVEL-thingy */ + if (ndx==0) + { + /* Transfer the initial level from debug_all_class_hack */ + DEBUGLEVEL_CLASS[ndx] = DEBUGLEVEL; + } + debug_level = DEBUGLEVEL_CLASS; + + new_ptr = DEBUGLEVEL_CLASS_ISSET; + if (new_ptr == &debug_all_class_isset_hack) + { + new_ptr = NULL; + } + new_ptr = Realloc(new_ptr, + sizeof(BOOL) * (debug_num_classes + 1)); + if (!new_ptr) + return -1; + DEBUGLEVEL_CLASS_ISSET = new_ptr; + DEBUGLEVEL_CLASS_ISSET[ndx] = False; + + new_ptr = Realloc(classname_table, + sizeof(char *) * (debug_num_classes + 1)); + if (!new_ptr) + return -1; + classname_table = new_ptr; + + classname_table[ndx] = strdup(classname); + if (! classname_table[ndx]) + return -1; + + debug_num_classes++; + + return ndx; +} + +/**************************************************************************** +utility to translate names to debug class index's (public version) +****************************************************************************/ +int debug_lookup_classname(const char *classname) +{ + int ndx; + + if (!classname || !*classname) return -1; + + ndx = debug_lookup_classname_int(classname); + + if (ndx != -1) + return ndx; + + if (debug_warn_unknown_class) + { + DEBUG(0, ("debug_lookup_classname(%s): Unknown class\n", + classname)); + } + if (debug_auto_add_unknown_class) + { + return debug_add_class(classname); + } + return -1; +} + + +/**************************************************************************** +dump the current registered denug levels +****************************************************************************/ +static void debug_dump_status(int level) +{ + int q; + + DEBUG(level, ("INFO: Current debug levels:\n")); + for (q = 0; q < debug_num_classes; q++) + { + DEBUGADD(level, (" %s: %s/%d\n", + classname_table[q], + (DEBUGLEVEL_CLASS_ISSET[q] + ? "True" : "False"), + DEBUGLEVEL_CLASS[q])); + } +} + /**************************************************************************** parse the debug levels from smbcontrol. Example debug level parameter: printdrivers:7 @@ -179,9 +377,9 @@ BOOL debug_parse_params(char **params, int *debuglevel_class, int i, ndx; char *class_name; char *class_level; - - /* Set the new debug level array to the current DEBUGLEVEL array */ - memcpy(debuglevel_class, DEBUGLEVEL_CLASS, sizeof(DEBUGLEVEL_CLASS)); + + if (!params) + return False; /* Allow DBGC_ALL to be specified w/o requiring its class name e.g."10" * v.s. "all:10", this is the traditional way to set DEBUGLEVEL @@ -195,7 +393,7 @@ BOOL debug_parse_params(char **params, int *debuglevel_class, i = 0; /* DBGC_ALL not specified OR class name was included */ /* Fill in new debug class levels */ - for (; i < DBGC_LAST && params[i]; i++) { + for (; i < debug_num_classes && params[i]; i++) { if ((class_name=strtok(params[i],":")) && (class_level=strtok(NULL, "\0")) && ((ndx = debug_lookup_classname(class_name)) != -1)) { @@ -215,83 +413,102 @@ parse the debug levels from smb.conf. Example debug level string: 3 tdb:5 printdrivers:7 Note: the 1st param has no "name:" preceeding it. ****************************************************************************/ -BOOL debug_parse_levels(char *params_str) +BOOL debug_parse_levels(const char *params_str) { - int i; - char *params[DBGC_LAST]; - int debuglevel_class[DBGC_LAST]; - BOOL debuglevel_class_isset[DBGC_LAST]; + char **params; + + /* Just in case */ + debug_init(); if (AllowDebugChange == False) return True; - ZERO_ARRAY(params); - ZERO_ARRAY(debuglevel_class); - ZERO_ARRAY(debuglevel_class_isset); - - if ((params[0]=strtok(params_str," ,"))) { - for (i=1; idebuglevel_class, sizeof(dm->debuglevel_class)); - memcpy(DEBUGLEVEL_CLASS_ISSET, dm->debuglevel_class_isset, sizeof(dm->debuglevel_class_isset)); + /* Check, it's a proper string! */ + if (params_str[len-1] != '\0') + { + DEBUG(1, ("Invalid debug message from pid %u to pid %u\n", + (unsigned int)src, (unsigned int)getpid())); + return; + } - DEBUG(3,("INFO: Debug class %s level = %d (pid %u from pid %u)\n", - classname_table[DBGC_ALL], - DEBUGLEVEL_CLASS[DBGC_ALL], (unsigned int)sys_getpid(), (unsigned int)src)); + DEBUG(3, ("INFO: Remote set of debug to `%s' (pid %u from pid %u)\n", + params_str, (unsigned int)getpid(), (unsigned int)src)); - for (i=1; i Date: Sat, 17 Aug 2002 17:00:51 +0000 Subject: sync 3.0 branch with head (This used to be commit 3928578b52cfc949be5e0ef444fce1558d75f290) --- source3/lib/debug.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index f41c3b6497..842d2dac1d 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -423,7 +423,7 @@ BOOL debug_parse_levels(const char *params_str) if (AllowDebugChange == False) return True; - params = str_list_make(params_str); + params = str_list_make(params_str, NULL); if (debug_parse_params(params, DEBUGLEVEL_CLASS, DEBUGLEVEL_CLASS_ISSET)) @@ -602,6 +602,12 @@ BOOL reopen_logs( void ) force_check_log_size(); (void)umask(oldumask); + /* Take over stderr to catch ouput into logs */ + if (dbf && sys_dup2(dbf->fd, 2) == -1) { + close_low_fds(True); /* Close stderr too, if dup2 can't point it + at the logfile */ + } + return ret; } -- cgit From a834a73e341059be154426390304a42e4a011f72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:19:00 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 65e7b5273bb58802bf0c389b77f7fcae0a1f6139) --- source3/lib/debug.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 842d2dac1d..f4f3ee2f9f 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -153,8 +153,10 @@ static const char *default_classname_table[] = { "rpc_srv", /* DBGC_RPC_SRV */ "rpc_cli", /* DBGC_RPC_CLI */ "passdb", /* DBGC_PASSDB */ + "sam", /* DBGC_SAM */ "auth", /* DBGC_AUTH */ "winbind", /* DBGC_WINBIND */ + "vfs", /* DBGC_VFS */ NULL }; @@ -350,7 +352,7 @@ int debug_lookup_classname(const char *classname) /**************************************************************************** -dump the current registered denug levels +dump the current registered debug levels ****************************************************************************/ static void debug_dump_status(int level) { @@ -371,8 +373,7 @@ static void debug_dump_status(int level) parse the debug levels from smbcontrol. Example debug level parameter: printdrivers:7 ****************************************************************************/ -BOOL debug_parse_params(char **params, int *debuglevel_class, - BOOL *debuglevel_class_isset) +static BOOL debug_parse_params(char **params) { int i, ndx; char *class_name; @@ -385,8 +386,8 @@ BOOL debug_parse_params(char **params, int *debuglevel_class, * v.s. "all:10", this is the traditional way to set DEBUGLEVEL */ if (isdigit((int)params[0][0])) { - debuglevel_class[DBGC_ALL] = atoi(params[0]); - debuglevel_class_isset[DBGC_ALL] = True; + DEBUGLEVEL_CLASS[DBGC_ALL] = atoi(params[0]); + DEBUGLEVEL_CLASS_ISSET[DBGC_ALL] = True; i = 1; /* start processing at the next params */ } else @@ -397,8 +398,8 @@ BOOL debug_parse_params(char **params, int *debuglevel_class, if ((class_name=strtok(params[i],":")) && (class_level=strtok(NULL, "\0")) && ((ndx = debug_lookup_classname(class_name)) != -1)) { - debuglevel_class[ndx] = atoi(class_level); - debuglevel_class_isset[ndx] = True; + DEBUGLEVEL_CLASS[ndx] = atoi(class_level); + DEBUGLEVEL_CLASS_ISSET[ndx] = True; } else { DEBUG(0,("debug_parse_params: unrecognized debug class name or format [%s]\n", params[i])); return False; @@ -425,8 +426,7 @@ BOOL debug_parse_levels(const char *params_str) params = str_list_make(params_str, NULL); - if (debug_parse_params(params, DEBUGLEVEL_CLASS, - DEBUGLEVEL_CLASS_ISSET)) + if (debug_parse_params(params)) { debug_dump_status(5); str_list_free(¶ms); -- cgit From 35ac9d287f000c27dc864789b341bebe7acb4c74 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 26 Oct 2002 02:20:59 +0000 Subject: Try to catch up on the code I've put into HEAD that should be in 3.0: - vorlan's hosts allow with DNS names patch - use x_fileno() in debug.c, not the struct directly. - check for server timeout on password change (was reporting success) - better error/status loggin in both the pam_winbind client and winbindd_pam server code. - (pdb_ldap) don't set the ldap version twice - we do it on every bind anyway. (This used to be commit 9fa1863d8e7788eda83911ca2610754486b33069) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index f4f3ee2f9f..483db71b85 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -603,7 +603,7 @@ BOOL reopen_logs( void ) (void)umask(oldumask); /* Take over stderr to catch ouput into logs */ - if (dbf && sys_dup2(dbf->fd, 2) == -1) { + if (dbf && sys_dup2(x_fileno(dbf), 2) == -1) { close_low_fds(True); /* Close stderr too, if dup2 can't point it at the logfile */ } -- cgit From f09109c7bc32966bb464df0712583b30602d6ad0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 9 Nov 2002 17:08:58 +0000 Subject: Last sync with HEAD (This used to be commit 1175b62337f5c29954cd5e8dfdc2327c9c80748c) --- source3/lib/debug.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 483db71b85..f2a362bb86 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -74,15 +74,12 @@ * * dbf - Global debug file handle. * debugf - Debug file name. - * append_log - If True, then the output file will be opened in append - * mode. * DEBUGLEVEL - System-wide debug message limit. Messages with message- * levels higher than DEBUGLEVEL will not be processed. */ XFILE *dbf = NULL; pstring debugf = ""; -BOOL append_log = False; BOOL debug_warn_unknown_class = True; BOOL debug_auto_add_unknown_class = True; BOOL AllowDebugChange = True; @@ -576,10 +573,7 @@ BOOL reopen_logs( void ) } pstrcpy( debugf, fname ); - if (append_log) - new_dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644); - else - new_dbf = x_fopen( debugf, O_WRONLY|O_CREAT|O_TRUNC, 0644 ); + new_dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644); if (!new_dbf) { log_overflow = True; @@ -731,10 +725,7 @@ void check_log_size( void ) { mode_t oldumask = umask( 022 ); - if( append_log ) - dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 ); - else - dbf = x_fopen( debugf, O_WRONLY|O_CREAT|O_TRUNC, 0644 ); + dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 ); (void)umask( oldumask ); if( dbf ) { -- cgit From 4b117b89179e49499c16d884dde9149ed1d69309 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 15 Nov 2002 14:06:35 +0000 Subject: Merge from HEAD: - heimdal updates to configure - make DEBUG() const - add testsuite for: - preexec - preexec close - valid users - fix testsuite for 'invalid users' Andrew Bartlett (This used to be commit aa41fb8703db4a4ecd3b353874c99a994e8ed630) --- source3/lib/debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index f2a362bb86..ea5bad3b6d 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -702,7 +702,7 @@ void check_log_size( void ) * This is called by dbghdr() and format_debug_text(). * ************************************************************************** ** */ - int Debug1( char *format_str, ... ) + int Debug1( const char *format_str, ... ) { va_list ap; int old_errno = errno; @@ -897,7 +897,7 @@ void dbgflush( void ) * ************************************************************************** ** */ -BOOL dbghdr( int level, char *file, char *func, int line ) +BOOL dbghdr( int level, const char *file, const char *func, int line ) { /* Ensure we don't lose any real errno value. */ int old_errno = errno; @@ -967,7 +967,7 @@ BOOL dbghdr( int level, char *file, char *func, int line ) * * ************************************************************************** ** */ - BOOL dbgtext( char *format_str, ... ) + BOOL dbgtext( const char *format_str, ... ) { va_list ap; pstring msgbuf; -- cgit From f5d5df9644abc08ae1b16a0826eb8cf5c3de54d1 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Jan 2003 17:39:30 +0000 Subject: patch to include support for daemontools from Michael Handler (This used to be commit a8db1b611d83bfd8dcf60f1e6d8fcbf57c798528) --- source3/lib/debug.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index ea5bad3b6d..966a53fca3 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -525,6 +525,7 @@ void setup_logging(const char *pname, BOOL interactive) if (interactive) { stdout_logging = True; dbf = x_stdout; + x_setbuf( x_stdout, NULL ); } #ifdef WITH_SYSLOG else { -- cgit From 2a9c68cdc8fe528803ef1bd48fa467082ebc235f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 4 Jan 2003 08:49:20 +0000 Subject: Merge from HEAD - baseless parinoia about never having a closed dbf (the debug file pointer). Andrew Bartlett (This used to be commit c8a809a2a83974330bc1015d07d69f40a4a09610) --- source3/lib/debug.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 966a53fca3..2efdd3c2a3 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -556,6 +556,7 @@ BOOL reopen_logs( void ) pstring fname; mode_t oldumask; XFILE *new_dbf = NULL; + XFILE *old_dbf = NULL; BOOL ret = True; if (stdout_logging) @@ -585,9 +586,10 @@ BOOL reopen_logs( void ) ret = False; } else { x_setbuf(new_dbf, NULL); - if (dbf) - (void) x_fclose(dbf); + old_dbf = dbf; dbf = new_dbf; + if (old_dbf) + (void) x_fclose(old_dbf); } /* Fix from klausr@ITAP.Physik.Uni-Stuttgart.De -- cgit From 655000e43ec9dccba3c53baef34ebe41028981b5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 29 Jan 2003 17:55:41 +0000 Subject: Removed duplicate fn to avoid compiler warning. (from HEAD - tpot). Jeremy. (This used to be commit 60be9a2f1e6d18562218a55e1a1f753e34fb1e5b) --- source3/lib/debug.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 2efdd3c2a3..23442a0193 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -468,6 +468,7 @@ void debug_message_send(pid_t pid, const char *params_str) } +#if 0 /**************************************************************************** Return current debug level. ****************************************************************************/ @@ -485,6 +486,7 @@ static void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len) DEBUG(0, ("debuglevel_message: error retrieving class levels!\n")); } } +#endif /**************************************************************************** Init debugging (one time stuff) -- cgit From 97027aa5ff4ba6bb05f66458e9b8db98c194c619 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 30 Jan 2003 04:37:18 +0000 Subject: Merge of REQ_DEBUGLEVEL messaging and debug_count fixes from HEAD. (This used to be commit abb112ba2ad362036c7b3f340d5f64d6fcc0cd3c) --- source3/lib/debug.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 23442a0193..dc675037a0 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -467,26 +467,19 @@ void debug_message_send(pid_t pid, const char *params_str) False); } - -#if 0 /**************************************************************************** Return current debug level. ****************************************************************************/ static void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len) { - char *debug_level_classes; + char *message = debug_list_class_names_and_levels(); + DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n",(unsigned int)src)); + message_send_pid(src, MSG_DEBUGLEVEL, message, strlen(message) + 1, True); - if ((debug_level_classes = debug_list_class_names_and_levels())) { - /*{ debug_level_classes = "test:1000";*/ - message_send_pid(src, MSG_DEBUGLEVEL, debug_level_classes, strlen(debug_level_classes) + 1, True); - SAFE_FREE(debug_level_classes); - } else { - DEBUG(0, ("debuglevel_message: error retrieving class levels!\n")); - } + SAFE_FREE(message); } -#endif /**************************************************************************** Init debugging (one time stuff) @@ -627,7 +620,7 @@ BOOL need_to_check_log_size( void ) { int maxlog; - if( debug_count++ < 100 ) + if( debug_count < 100 ) return( False ); maxlog = lp_max_log_size() * 1024; @@ -712,6 +705,8 @@ void check_log_size( void ) va_list ap; int old_errno = errno; + debug_count++; + if( stdout_logging ) { va_start( ap, format_str ); -- cgit From c823b191ab476fc2583d6d6aaa1e2edb09cbb88e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 12 May 2003 18:12:31 +0000 Subject: And finally IDMAP in 3_0 We really need idmap_ldap to have a good solution with ldapsam, porting it from the prvious code is beeing made, the code is really simple to do so I am confident it is not a problem to commit this code in. Not committing it would have been worst. I really would have been able to finish also the group code, maybe we can put it into a followin release after 3.0.0 even if it may be an upgrade problem. The code has been tested and seem to work right, more testing is needed for corner cases. Currently winbind pdc (working only for users and not for groups) is disabled as I was not able to make a complete group code replacement that works somewhat in a week (I have a complete patch, but there are bugs) Simo. (This used to be commit 0e58085978f984436815114a2ec347cf7899a89d) --- source3/lib/debug.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index dc675037a0..fdbd54fafb 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -154,6 +154,7 @@ static const char *default_classname_table[] = { "auth", /* DBGC_AUTH */ "winbind", /* DBGC_WINBIND */ "vfs", /* DBGC_VFS */ + "idmap", /* DBGC_IDMAP */ NULL }; -- cgit From 9343c89cb4a1b9f47c38d00b12f3e9058d15b18d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 15 Jan 2004 08:49:30 +0000 Subject: * Fix XFS quotas: XFS_USER_QUOTA -> USRQUOTA XFS_GROUP_QUOTA -> GRPQUOTA * Fix disk_free calculation with group quotas. * Add debug class 'quota' and a lot of DEBUG()'s to the quota code. metze (This used to be commit e9e5e2036f13ff847aa3ef52e8be657bef7d5774) --- source3/lib/debug.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index fdbd54fafb..0050761e9a 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -155,6 +155,7 @@ static const char *default_classname_table[] = { "winbind", /* DBGC_WINBIND */ "vfs", /* DBGC_VFS */ "idmap", /* DBGC_IDMAP */ + "quota", /* DBGC_QUOTA */ NULL }; -- cgit From bfa1b2a8bdd785af576c8706e8f27e9448ef94b5 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 26 Mar 2004 15:40:06 +0000 Subject: source code fix for bug 1095 -- honor the '-l' option (This used to be commit ab48af6993b427f525c36aa0ffd57c612c100561) --- source3/lib/debug.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 0050761e9a..1a926053bb 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -84,6 +84,13 @@ BOOL debug_warn_unknown_class = True; BOOL debug_auto_add_unknown_class = True; BOOL AllowDebugChange = True; +/* + used to check if the user specified a + logfile on the command line +*/ +BOOL override_logfile; + + /* * This is to allow assignment to DEBUGLEVEL before the debug * system has been initialised. -- cgit From 9139b89259afaf3772bbbb92ea925d015d5850ad Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Thu, 29 Apr 2004 23:05:58 +0000 Subject: r416: add a newline to the debuglevel message returned string and have smbcontrol print the PID with it (This used to be commit d3edf71885bfb5d342e62d46542db8ca814f3303) --- source3/lib/debug.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 1a926053bb..fe4cd52a8b 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -208,8 +208,8 @@ static char *debug_list_class_names_and_levels(void) dim += l; } - /* create single string list */ - b = buf = malloc(dim); + /* create single string list - add space for newline */ + b = buf = malloc(dim+1); if (!buf) { err = True; goto done; @@ -219,7 +219,8 @@ static char *debug_list_class_names_and_levels(void) strncpy(b, list[i], l); b = b + l; } - b[-1] = '\0'; + b[-1] = '\n'; /* replace last space with newline */ + b[0] = '\0'; /* null terminate string */ done: /* free strings list */ -- cgit From fc52c330aed4bbfd406d96cccc273c8e551255c2 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Fri, 30 Apr 2004 14:28:38 +0000 Subject: r428: add acls debug class (This used to be commit b7703799f8899affda205eacb0bf79cf8e2b9362) --- source3/lib/debug.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index fe4cd52a8b..b0d8ff3523 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -163,6 +163,7 @@ static const char *default_classname_table[] = { "vfs", /* DBGC_VFS */ "idmap", /* DBGC_IDMAP */ "quota", /* DBGC_QUOTA */ + "acls", /* DBGC_QUOTA */ NULL }; -- cgit From a30e1a4277500b388de3c8a20f72bb508569f4ce Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 18 May 2004 17:24:59 +0000 Subject: r772: fix cut and paste error in comment (This used to be commit a3bb4909c34c50673e0859be35200a8628ecdb8c) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index b0d8ff3523..f9c8b0c46a 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -163,7 +163,7 @@ static const char *default_classname_table[] = { "vfs", /* DBGC_VFS */ "idmap", /* DBGC_IDMAP */ "quota", /* DBGC_QUOTA */ - "acls", /* DBGC_QUOTA */ + "acls", /* DBGC_ACLS */ NULL }; -- cgit From 060cb43ee4d76768dffddd3a890b893aa221ce94 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 9 Jul 2004 20:49:43 +0000 Subject: r1425: Fix memleak in interactive mode. Reformat.. Jeremy. (This used to be commit 5d720e52d749489726c2c671c6cac2d706f750c8) --- source3/lib/debug.c | 604 +++++++++++++++++++++++++--------------------------- 1 file changed, 292 insertions(+), 312 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index f9c8b0c46a..e5e203e076 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -239,8 +239,9 @@ done: } /**************************************************************************** -utility access to debug class names's + Utility access to debug class names's. ****************************************************************************/ + const char *debug_classname_from_index(int ndx) { if (ndx < 0 || ndx >= debug_num_classes) @@ -250,8 +251,9 @@ const char *debug_classname_from_index(int ndx) } /**************************************************************************** -utility to translate names to debug class index's (internal version) + Utility to translate names to debug class index's (internal version). ****************************************************************************/ + static int debug_lookup_classname_int(const char* classname) { int i; @@ -266,8 +268,9 @@ static int debug_lookup_classname_int(const char* classname) } /**************************************************************************** -Add a new debug class to the system + Add a new debug class to the system. ****************************************************************************/ + int debug_add_class(const char *classname) { int ndx; @@ -285,33 +288,28 @@ int debug_add_class(const char *classname) ndx = debug_num_classes; new_ptr = DEBUGLEVEL_CLASS; - if (DEBUGLEVEL_CLASS == &debug_all_class_hack) - { + if (DEBUGLEVEL_CLASS == &debug_all_class_hack) { /* Initial loading... */ new_ptr = NULL; } - new_ptr = Realloc(new_ptr, - sizeof(int) * (debug_num_classes + 1)); + new_ptr = Realloc(new_ptr, sizeof(int) * (debug_num_classes + 1)); if (!new_ptr) return -1; DEBUGLEVEL_CLASS = new_ptr; DEBUGLEVEL_CLASS[ndx] = 0; /* debug_level is the pointer used for the DEBUGLEVEL-thingy */ - if (ndx==0) - { + if (ndx==0) { /* Transfer the initial level from debug_all_class_hack */ DEBUGLEVEL_CLASS[ndx] = DEBUGLEVEL; } debug_level = DEBUGLEVEL_CLASS; new_ptr = DEBUGLEVEL_CLASS_ISSET; - if (new_ptr == &debug_all_class_isset_hack) - { + if (new_ptr == &debug_all_class_isset_hack) { new_ptr = NULL; } - new_ptr = Realloc(new_ptr, - sizeof(BOOL) * (debug_num_classes + 1)); + new_ptr = Realloc(new_ptr, sizeof(BOOL) * (debug_num_classes + 1)); if (!new_ptr) return -1; DEBUGLEVEL_CLASS_ISSET = new_ptr; @@ -333,42 +331,41 @@ int debug_add_class(const char *classname) } /**************************************************************************** -utility to translate names to debug class index's (public version) + Utility to translate names to debug class index's (public version). ****************************************************************************/ + int debug_lookup_classname(const char *classname) { int ndx; - if (!classname || !*classname) return -1; + if (!classname || !*classname) + return -1; ndx = debug_lookup_classname_int(classname); if (ndx != -1) return ndx; - if (debug_warn_unknown_class) - { + if (debug_warn_unknown_class) { DEBUG(0, ("debug_lookup_classname(%s): Unknown class\n", classname)); } - if (debug_auto_add_unknown_class) - { + if (debug_auto_add_unknown_class) { return debug_add_class(classname); } return -1; } - /**************************************************************************** -dump the current registered debug levels + Dump the current registered debug levels. ****************************************************************************/ + static void debug_dump_status(int level) { int q; DEBUG(level, ("INFO: Current debug levels:\n")); - for (q = 0; q < debug_num_classes; q++) - { + for (q = 0; q < debug_num_classes; q++) { DEBUGADD(level, (" %s: %s/%d\n", classname_table[q], (DEBUGLEVEL_CLASS_ISSET[q] @@ -378,9 +375,10 @@ static void debug_dump_status(int level) } /**************************************************************************** -parse the debug levels from smbcontrol. Example debug level parameter: - printdrivers:7 + parse the debug levels from smbcontrol. Example debug level parameter: + printdrivers:7 ****************************************************************************/ + static BOOL debug_parse_params(char **params) { int i, ndx; @@ -397,9 +395,9 @@ static BOOL debug_parse_params(char **params) DEBUGLEVEL_CLASS[DBGC_ALL] = atoi(params[0]); DEBUGLEVEL_CLASS_ISSET[DBGC_ALL] = True; i = 1; /* start processing at the next params */ - } - else + } else { i = 0; /* DBGC_ALL not specified OR class name was included */ + } /* Fill in new debug class levels */ for (; i < debug_num_classes && params[i]; i++) { @@ -418,10 +416,11 @@ static BOOL debug_parse_params(char **params) } /**************************************************************************** -parse the debug levels from smb.conf. Example debug level string: + Parse the debug levels from smb.conf. Example debug level string: 3 tdb:5 printdrivers:7 -Note: the 1st param has no "name:" preceeding it. + Note: the 1st param has no "name:" preceeding it. ****************************************************************************/ + BOOL debug_parse_levels(const char *params_str) { char **params; @@ -434,8 +433,7 @@ BOOL debug_parse_levels(const char *params_str) params = str_list_make(params_str, NULL); - if (debug_parse_params(params)) - { + if (debug_parse_params(params)) { debug_dump_status(5); str_list_free(¶ms); return True; @@ -446,15 +444,15 @@ BOOL debug_parse_levels(const char *params_str) } /**************************************************************************** -receive a "set debug level" message + Receive a "set debug level" message. ****************************************************************************/ + static void debug_message(int msg_type, pid_t src, void *buf, size_t len) { const char *params_str = buf; /* Check, it's a proper string! */ - if (params_str[len-1] != '\0') - { + if (params_str[len-1] != '\0') { DEBUG(1, ("Invalid debug message from pid %u to pid %u\n", (unsigned int)src, (unsigned int)getpid())); return; @@ -466,10 +464,10 @@ static void debug_message(int msg_type, pid_t src, void *buf, size_t len) debug_parse_levels(params_str); } - /**************************************************************************** -send a "set debug level" message + Send a "set debug level" message. ****************************************************************************/ + void debug_message_send(pid_t pid, const char *params_str) { if (!params_str) @@ -495,6 +493,7 @@ static void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len) /**************************************************************************** Init debugging (one time stuff) ****************************************************************************/ + void debug_init(void) { static BOOL initialised = False; @@ -508,17 +507,15 @@ void debug_init(void) message_register(MSG_DEBUG, debug_message); message_register(MSG_REQ_DEBUGLEVEL, debuglevel_message); - for(p = default_classname_table; *p; p++) - { + for(p = default_classname_table; *p; p++) { debug_add_class(*p); } } +/*************************************************************************** + Get ready for syslog stuff +**************************************************************************/ -/* ************************************************************************** ** - * get ready for syslog stuff - * ************************************************************************** ** - */ void setup_logging(const char *pname, BOOL interactive) { debug_init(); @@ -526,6 +523,11 @@ void setup_logging(const char *pname, BOOL interactive) /* reset to allow multiple setup calls, going from interactive to non-interactive */ stdout_logging = False; + if (dbf) { + x_fflush(dbf); + (void) x_fclose(dbf); + } + dbf = NULL; if (interactive) { @@ -546,16 +548,15 @@ void setup_logging(const char *pname, BOOL interactive) #endif } #endif -} /* setup_logging */ - -/* ************************************************************************** ** - * reopen the log files - * note that we now do this unconditionally - * We attempt to open the new debug fp before closing the old. This means - * if we run out of fd's we just keep using the old fd rather than aborting. - * Fix from dgibson@linuxcare.com. - * ************************************************************************** ** - */ +} + +/************************************************************************** + reopen the log files + note that we now do this unconditionally + We attempt to open the new debug fp before closing the old. This means + if we run out of fd's we just keep using the old fd rather than aborting. + Fix from dgibson@linuxcare.com. +**************************************************************************/ BOOL reopen_logs( void ) { @@ -614,13 +615,13 @@ BOOL reopen_logs( void ) return ret; } -/* ************************************************************************** ** - * Force a check of the log size. - * ************************************************************************** ** - */ +/************************************************************************** + Force a check of the log size. + ***************************************************************************/ + void force_check_log_size( void ) { - debug_count = 100; + debug_count = 100; } /*************************************************************************** @@ -642,10 +643,9 @@ BOOL need_to_check_log_size( void ) return( True ); } -/* ************************************************************************** ** - * Check to see if the log has grown to be too big. - * ************************************************************************** ** - */ +/************************************************************************** + Check to see if the log has grown to be too big. + **************************************************************************/ void check_log_size( void ) { @@ -704,293 +704,273 @@ void check_log_size( void ) } } debug_count = 0; -} /* check_log_size */ +} + +/************************************************************************* + Write an debug message on the debugfile. + This is called by dbghdr() and format_debug_text(). +************************************************************************/ -/* ************************************************************************** ** - * Write an debug message on the debugfile. - * This is called by dbghdr() and format_debug_text(). - * ************************************************************************** ** - */ int Debug1( const char *format_str, ... ) { - va_list ap; - int old_errno = errno; - - debug_count++; - - if( stdout_logging ) - { - va_start( ap, format_str ); - if(dbf) - (void)x_vfprintf( dbf, format_str, ap ); - va_end( ap ); - errno = old_errno; - return( 0 ); - } + va_list ap; + int old_errno = errno; + + debug_count++; + + if( stdout_logging ) { + va_start( ap, format_str ); + if(dbf) + (void)x_vfprintf( dbf, format_str, ap ); + va_end( ap ); + errno = old_errno; + return( 0 ); + } #ifdef WITH_SYSLOG - if( !lp_syslog_only() ) + if( !lp_syslog_only() ) #endif - { - if( !dbf ) - { - mode_t oldumask = umask( 022 ); - - dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 ); - (void)umask( oldumask ); - if( dbf ) - { - x_setbuf( dbf, NULL ); - } - else - { - errno = old_errno; - return(0); - } - } - } + { + if( !dbf ) { + mode_t oldumask = umask( 022 ); + + dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 ); + (void)umask( oldumask ); + if( dbf ) { + x_setbuf( dbf, NULL ); + } else { + errno = old_errno; + return(0); + } + } + } #ifdef WITH_SYSLOG - if( syslog_level < lp_syslog() ) - { - /* map debug levels to syslog() priorities - * note that not all DEBUG(0, ...) calls are - * necessarily errors - */ - static int priority_map[] = { - LOG_ERR, /* 0 */ - LOG_WARNING, /* 1 */ - LOG_NOTICE, /* 2 */ - LOG_INFO, /* 3 */ - }; - int priority; - pstring msgbuf; - - if( syslog_level >= ( sizeof(priority_map) / sizeof(priority_map[0]) ) - || syslog_level < 0) - priority = LOG_DEBUG; - else - priority = priority_map[syslog_level]; - - va_start( ap, format_str ); - vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); - va_end( ap ); - - msgbuf[255] = '\0'; - syslog( priority, "%s", msgbuf ); - } + if( syslog_level < lp_syslog() ) { + /* map debug levels to syslog() priorities + * note that not all DEBUG(0, ...) calls are + * necessarily errors */ + static int priority_map[] = { + LOG_ERR, /* 0 */ + LOG_WARNING, /* 1 */ + LOG_NOTICE, /* 2 */ + LOG_INFO, /* 3 */ + }; + int priority; + pstring msgbuf; + + if( syslog_level >= ( sizeof(priority_map) / sizeof(priority_map[0]) ) || syslog_level < 0) + priority = LOG_DEBUG; + else + priority = priority_map[syslog_level]; + + va_start( ap, format_str ); + vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); + va_end( ap ); + + msgbuf[255] = '\0'; + syslog( priority, "%s", msgbuf ); + } #endif - check_log_size(); + check_log_size(); #ifdef WITH_SYSLOG - if( !lp_syslog_only() ) + if( !lp_syslog_only() ) #endif - { - va_start( ap, format_str ); - if(dbf) - (void)x_vfprintf( dbf, format_str, ap ); - va_end( ap ); - if(dbf) - (void)x_fflush( dbf ); - } + { + va_start( ap, format_str ); + if(dbf) + (void)x_vfprintf( dbf, format_str, ap ); + va_end( ap ); + if(dbf) + (void)x_fflush( dbf ); + } - errno = old_errno; + errno = old_errno; - return( 0 ); - } /* Debug1 */ + return( 0 ); +} -/* ************************************************************************** ** - * Print the buffer content via Debug1(), then reset the buffer. - * - * Input: none - * Output: none - * - * ************************************************************************** ** - */ +/************************************************************************** + Print the buffer content via Debug1(), then reset the buffer. + Input: none + Output: none +****************************************************************************/ + static void bufr_print( void ) - { - format_bufr[format_pos] = '\0'; - (void)Debug1( "%s", format_bufr ); - format_pos = 0; - } /* bufr_print */ - -/* ************************************************************************** ** - * Format the debug message text. - * - * Input: msg - Text to be added to the "current" debug message text. - * - * Output: none. - * - * Notes: The purpose of this is two-fold. First, each call to syslog() - * (used by Debug1(), see above) generates a new line of syslog - * output. This is fixed by storing the partial lines until the - * newline character is encountered. Second, printing the debug - * message lines when a newline is encountered allows us to add - * spaces, thus indenting the body of the message and making it - * more readable. - * - * ************************************************************************** ** - */ -static void format_debug_text( char *msg ) - { - size_t i; - BOOL timestamp = (!stdout_logging && (lp_timestamp_logs() || - !(lp_loaded()))); - - for( i = 0; msg[i]; i++ ) - { - /* Indent two spaces at each new line. */ - if(timestamp && 0 == format_pos) - { - format_bufr[0] = format_bufr[1] = ' '; - format_pos = 2; - } - - /* If there's room, copy the character to the format buffer. */ - if( format_pos < FORMAT_BUFR_MAX ) - format_bufr[format_pos++] = msg[i]; - - /* If a newline is encountered, print & restart. */ - if( '\n' == msg[i] ) - bufr_print(); - - /* If the buffer is full dump it out, reset it, and put out a line - * continuation indicator. - */ - if( format_pos >= FORMAT_BUFR_MAX ) - { - bufr_print(); - (void)Debug1( " +>\n" ); - } - } - - /* Just to be safe... */ - format_bufr[format_pos] = '\0'; - } /* format_debug_text */ - -/* ************************************************************************** ** - * Flush debug output, including the format buffer content. - * - * Input: none - * Output: none - * - * ************************************************************************** ** - */ +{ + format_bufr[format_pos] = '\0'; + (void)Debug1( "%s", format_bufr ); + format_pos = 0; +} + +/*************************************************************************** + Format the debug message text. + + Input: msg - Text to be added to the "current" debug message text. + + Output: none. + + Notes: The purpose of this is two-fold. First, each call to syslog() + (used by Debug1(), see above) generates a new line of syslog + output. This is fixed by storing the partial lines until the + newline character is encountered. Second, printing the debug + message lines when a newline is encountered allows us to add + spaces, thus indenting the body of the message and making it + more readable. +**************************************************************************/ + +static void format_debug_text( const char *msg ) +{ + size_t i; + BOOL timestamp = (!stdout_logging && (lp_timestamp_logs() || !(lp_loaded()))); + + for( i = 0; msg[i]; i++ ) { + /* Indent two spaces at each new line. */ + if(timestamp && 0 == format_pos) { + format_bufr[0] = format_bufr[1] = ' '; + format_pos = 2; + } + + /* If there's room, copy the character to the format buffer. */ + if( format_pos < FORMAT_BUFR_MAX ) + format_bufr[format_pos++] = msg[i]; + + /* If a newline is encountered, print & restart. */ + if( '\n' == msg[i] ) + bufr_print(); + + /* If the buffer is full dump it out, reset it, and put out a line + * continuation indicator. + */ + if( format_pos >= FORMAT_BUFR_MAX ) { + bufr_print(); + (void)Debug1( " +>\n" ); + } + } + + /* Just to be safe... */ + format_bufr[format_pos] = '\0'; +} + +/*************************************************************************** + Flush debug output, including the format buffer content. + + Input: none + Output: none +***************************************************************************/ + void dbgflush( void ) - { - bufr_print(); - if(dbf) - (void)x_fflush( dbf ); - } /* dbgflush */ - -/* ************************************************************************** ** - * Print a Debug Header. - * - * Input: level - Debug level of the message (not the system-wide debug - * level. ) - * file - Pointer to a string containing the name of the file - * from which this function was called, or an empty string - * if the __FILE__ macro is not implemented. - * func - Pointer to a string containing the name of the function - * from which this function was called, or an empty string - * if the __FUNCTION__ macro is not implemented. - * line - line number of the call to dbghdr, assuming __LINE__ - * works. - * - * Output: Always True. This makes it easy to fudge a call to dbghdr() - * in a macro, since the function can be called as part of a test. - * Eg: ( (level <= DEBUGLEVEL) && (dbghdr(level,"",line)) ) - * - * Notes: This function takes care of setting syslog_level. - * - * ************************************************************************** ** - */ +{ + bufr_print(); + if(dbf) + (void)x_fflush( dbf ); +} + +/*************************************************************************** + Print a Debug Header. + + Input: level - Debug level of the message (not the system-wide debug + level. ) + file - Pointer to a string containing the name of the file + from which this function was called, or an empty string + if the __FILE__ macro is not implemented. + func - Pointer to a string containing the name of the function + from which this function was called, or an empty string + if the __FUNCTION__ macro is not implemented. + line - line number of the call to dbghdr, assuming __LINE__ + works. + + Output: Always True. This makes it easy to fudge a call to dbghdr() + in a macro, since the function can be called as part of a test. + Eg: ( (level <= DEBUGLEVEL) && (dbghdr(level,"",line)) ) + + Notes: This function takes care of setting syslog_level. + +****************************************************************************/ BOOL dbghdr( int level, const char *file, const char *func, int line ) { - /* Ensure we don't lose any real errno value. */ - int old_errno = errno; - - if( format_pos ) { - /* This is a fudge. If there is stuff sitting in the format_bufr, then - * the *right* thing to do is to call - * format_debug_text( "\n" ); - * to write the remainder, and then proceed with the new header. - * Unfortunately, there are several places in the code at which - * the DEBUG() macro is used to build partial lines. That in mind, - * we'll work under the assumption that an incomplete line indicates - * that a new header is *not* desired. - */ - return( True ); - } + /* Ensure we don't lose any real errno value. */ + int old_errno = errno; + + if( format_pos ) { + /* This is a fudge. If there is stuff sitting in the format_bufr, then + * the *right* thing to do is to call + * format_debug_text( "\n" ); + * to write the remainder, and then proceed with the new header. + * Unfortunately, there are several places in the code at which + * the DEBUG() macro is used to build partial lines. That in mind, + * we'll work under the assumption that an incomplete line indicates + * that a new header is *not* desired. + */ + return( True ); + } #ifdef WITH_SYSLOG - /* Set syslog_level. */ - syslog_level = level; + /* Set syslog_level. */ + syslog_level = level; #endif - /* Don't print a header if we're logging to stdout. */ - if( stdout_logging ) - return( True ); + /* 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()) ) { - char header_str[200]; + /* 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()) ) { + char header_str[200]; - header_str[0] = '\0'; + header_str[0] = '\0'; - if( lp_debug_pid()) - slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)sys_getpid()); + if( lp_debug_pid()) + slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)sys_getpid()); - if( lp_debug_uid()) { - size_t hs_len = strlen(header_str); - slprintf(header_str + hs_len, - sizeof(header_str) - 1 - hs_len, - ", effective(%u, %u), real(%u, %u)", - (unsigned int)geteuid(), (unsigned int)getegid(), - (unsigned int)getuid(), (unsigned int)getgid()); - } + if( lp_debug_uid()) { + size_t hs_len = strlen(header_str); + slprintf(header_str + hs_len, + sizeof(header_str) - 1 - hs_len, + ", effective(%u, %u), real(%u, %u)", + (unsigned int)geteuid(), (unsigned int)getegid(), + (unsigned int)getuid(), (unsigned int)getgid()); + } - /* Print it all out at once to prevent split syslog output. */ - (void)Debug1( "[%s, %d%s] %s:%s(%d)\n", - timestring(lp_debug_hires_timestamp()), level, - header_str, file, func, line ); - } + /* Print it all out at once to prevent split syslog output. */ + (void)Debug1( "[%s, %d%s] %s:%s(%d)\n", + timestring(lp_debug_hires_timestamp()), level, + header_str, file, func, line ); + } - errno = old_errno; - return( True ); + errno = old_errno; + return( True ); } -/* ************************************************************************** ** - * Add text to the body of the "current" debug message via the format buffer. - * - * Input: format_str - Format string, as used in printf(), et. al. - * ... - Variable argument list. - * - * ..or.. va_alist - Old style variable parameter list starting point. - * - * Output: Always True. See dbghdr() for more info, though this is not - * likely to be used in the same way. - * - * ************************************************************************** ** - */ - BOOL dbgtext( const char *format_str, ... ) - { - va_list ap; - pstring msgbuf; +/*************************************************************************** + Add text to the body of the "current" debug message via the format buffer. - va_start( ap, format_str ); - vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); - va_end( ap ); + Input: format_str - Format string, as used in printf(), et. al. + ... - Variable argument list. - format_debug_text( msgbuf ); + ..or.. va_alist - Old style variable parameter list starting point. - return( True ); - } /* dbgtext */ + Output: Always True. See dbghdr() for more info, though this is not + likely to be used in the same way. +***************************************************************************/ -/* ************************************************************************** */ + BOOL dbgtext( const char *format_str, ... ) +{ + va_list ap; + pstring msgbuf; + + va_start( ap, format_str ); + vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); + va_end( ap ); + + format_debug_text( msgbuf ); + + return( True ); +} -- cgit From cc72b666ed93556a2413055f161e67437024a320 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 16 Aug 2004 15:30:17 +0000 Subject: r1834: prevent infinite recusion in reopen_logs() when expanding the smb.conf variable %I (This used to be commit 08037bd4427a99150c1cc65770681ec3f92f4ad5) --- source3/lib/debug.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index e5e203e076..01aedb4774 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -572,6 +572,7 @@ BOOL reopen_logs( void ) oldumask = umask( 022 ); pstrcpy(fname, debugf ); + debugf[0] = '\0'; if (lp_loaded()) { char *logfname; @@ -726,7 +727,12 @@ void check_log_size( void ) errno = old_errno; return( 0 ); } - + + /* prevent recursion by checking if reopen_logs() has temporaily + set the debugf string to "" */ + if( debugf[0] == '\0') + return( 0 ); + #ifdef WITH_SYSLOG if( !lp_syslog_only() ) #endif -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/lib/debug.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 01aedb4774..b69a35ecd5 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -192,7 +192,7 @@ static char *debug_list_class_names_and_levels(void) if (DEBUGLEVEL_CLASS == &debug_all_class_hack) return NULL; - list = calloc(debug_num_classes + 1, sizeof(char *)); + list = SMB_CALLOC_ARRAY(char *, debug_num_classes + 1); if (!list) return NULL; @@ -210,7 +210,7 @@ static char *debug_list_class_names_and_levels(void) } /* create single string list - add space for newline */ - b = buf = malloc(dim+1); + b = buf = SMB_MALLOC(dim+1); if (!buf) { err = True; goto done; @@ -292,7 +292,7 @@ int debug_add_class(const char *classname) /* Initial loading... */ new_ptr = NULL; } - new_ptr = Realloc(new_ptr, sizeof(int) * (debug_num_classes + 1)); + new_ptr = SMB_REALLOC_ARRAY(new_ptr, int, debug_num_classes + 1); if (!new_ptr) return -1; DEBUGLEVEL_CLASS = new_ptr; @@ -309,19 +309,18 @@ int debug_add_class(const char *classname) if (new_ptr == &debug_all_class_isset_hack) { new_ptr = NULL; } - new_ptr = Realloc(new_ptr, sizeof(BOOL) * (debug_num_classes + 1)); + new_ptr = SMB_REALLOC_ARRAY(new_ptr, BOOL, debug_num_classes + 1); if (!new_ptr) return -1; DEBUGLEVEL_CLASS_ISSET = new_ptr; DEBUGLEVEL_CLASS_ISSET[ndx] = False; - new_ptr = Realloc(classname_table, - sizeof(char *) * (debug_num_classes + 1)); + new_ptr = SMB_REALLOC_ARRAY(classname_table, char *, debug_num_classes + 1); if (!new_ptr) return -1; classname_table = new_ptr; - classname_table[ndx] = strdup(classname); + classname_table[ndx] = SMB_STRDUP(classname); if (! classname_table[ndx]) return -1; -- cgit From ed1f7121a39d863066ef47e985b77fe3dbedbc9b Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 27 Apr 2005 18:32:37 +0000 Subject: r6502: add LOCKING debug class - pull PRINTINGDB class definition from trunk so our numbers don't get out of sync (This used to be commit 58e307664e02ebf0415f19ed625d2f166d9cb1cc) --- source3/lib/debug.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index b69a35ecd5..43d1f64eb1 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -164,6 +164,8 @@ static const char *default_classname_table[] = { "idmap", /* DBGC_IDMAP */ "quota", /* DBGC_QUOTA */ "acls", /* DBGC_ACLS */ + "printerdb", /* DBGC_PRINTERDB */ + "locking", /* DBGC_LOCKING */ NULL }; -- cgit From bf547ff1ad4120f898e89fd75ec94f577a0fc84d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 28 Jun 2005 19:25:48 +0000 Subject: r7981: MS-DFS tidyup patches from James Peach . Looking forward to the day he can commit these himself :-). Jeremy. (This used to be commit 12ff2978295a84fe6177af129c495a0021befacc) --- source3/lib/debug.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 43d1f64eb1..d6785f83ad 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -166,6 +166,7 @@ static const char *default_classname_table[] = { "acls", /* DBGC_ACLS */ "printerdb", /* DBGC_PRINTERDB */ "locking", /* DBGC_LOCKING */ + "msdfs", /* DBGC_MSDFS */ NULL }; -- cgit From 9dcfaf01a1d9f5ee9441f187b410a92f8c987e7e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 13 Jul 2005 14:46:57 +0000 Subject: r8428: some more old printerdb stuff. Guenther (This used to be commit 25fa0e82c1ee1a568ffe201fbabb95cc809162b6) --- source3/lib/debug.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index d6785f83ad..f877d540fb 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -164,7 +164,6 @@ static const char *default_classname_table[] = { "idmap", /* DBGC_IDMAP */ "quota", /* DBGC_QUOTA */ "acls", /* DBGC_ACLS */ - "printerdb", /* DBGC_PRINTERDB */ "locking", /* DBGC_LOCKING */ "msdfs", /* DBGC_MSDFS */ NULL -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/lib/debug.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index f877d540fb..f3676070dc 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -448,19 +448,22 @@ BOOL debug_parse_levels(const char *params_str) Receive a "set debug level" message. ****************************************************************************/ -static void debug_message(int msg_type, pid_t src, void *buf, size_t len) +static void debug_message(int msg_type, struct process_id src, + void *buf, size_t len) { const char *params_str = buf; /* Check, it's a proper string! */ if (params_str[len-1] != '\0') { DEBUG(1, ("Invalid debug message from pid %u to pid %u\n", - (unsigned int)src, (unsigned int)getpid())); + (unsigned int)procid_to_pid(&src), + (unsigned int)getpid())); return; } DEBUG(3, ("INFO: Remote set of debug to `%s' (pid %u from pid %u)\n", - params_str, (unsigned int)getpid(), (unsigned int)src)); + params_str, (unsigned int)getpid(), + (unsigned int)procid_to_pid(&src))); debug_parse_levels(params_str); } @@ -473,7 +476,8 @@ void debug_message_send(pid_t pid, const char *params_str) { if (!params_str) return; - message_send_pid(pid, MSG_DEBUG, params_str, strlen(params_str) + 1, + message_send_pid(pid_to_procid(pid), MSG_DEBUG, + params_str, strlen(params_str) + 1, False); } @@ -481,11 +485,13 @@ void debug_message_send(pid_t pid, const char *params_str) Return current debug level. ****************************************************************************/ -static void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len) +static void debuglevel_message(int msg_type, struct process_id src, + void *buf, size_t len) { char *message = debug_list_class_names_and_levels(); - DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n",(unsigned int)src)); + DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n", + (unsigned int)procid_to_pid(&src))); message_send_pid(src, MSG_DEBUGLEVEL, message, strlen(message) + 1, True); SAFE_FREE(message); -- cgit From 85d3b74844453bcfa0bb46f1c28aab2ae40d0d39 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Mar 2006 20:37:24 +0000 Subject: r14397: Fix deadcode in coverity error #1. Jeremy. (This used to be commit 4a4953c4d27cd1e925c9afe24fa49b015ce033ec) --- source3/lib/debug.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index f3676070dc..29d879adbc 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -191,12 +191,14 @@ static char *debug_list_class_names_and_levels(void) char *b; BOOL err = False; - if (DEBUGLEVEL_CLASS == &debug_all_class_hack) + if (DEBUGLEVEL_CLASS == &debug_all_class_hack) { return NULL; + } list = SMB_CALLOC_ARRAY(char *, debug_num_classes + 1); - if (!list) + if (!list) { return NULL; + } /* prepare strings */ for (i = 0, dim = 0; i < debug_num_classes; i++) { @@ -227,13 +229,12 @@ static char *debug_list_class_names_and_levels(void) done: /* free strings list */ - for (i = 0; i < debug_num_classes; i++) - if (list[i]) free(list[i]); - free(list); + for (i = 0; i < debug_num_classes; i++) { + SAFE_FREE(list[i]); + } + SAFE_FREE(list); if (err) { - if (buf) - free(buf); return NULL; } else { return buf; -- cgit From 40d0707827ee154bcb03013abe6f72f1026a70c9 Mon Sep 17 00:00:00 2001 From: James Peach Date: Wed, 22 Mar 2006 23:49:09 +0000 Subject: r14668: Set the FILE_STATUS_OFFLINE bit by observing the events a DMAPI-based HSM is interested in. Tested on both IRIX and SLES9. (This used to be commit 514a767c57f8194547e5b708ad2573ab9a0719c6) --- source3/lib/debug.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 29d879adbc..97a147f17d 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -166,6 +166,7 @@ static const char *default_classname_table[] = { "acls", /* DBGC_ACLS */ "locking", /* DBGC_LOCKING */ "msdfs", /* DBGC_MSDFS */ + "dmapi", /* DBGC_DMAPI */ NULL }; -- cgit From bbf666e447132a5f6b206ddf9ca918298b756392 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 8 Apr 2006 17:25:31 +0000 Subject: r15003: patch based on code from Arkady Glabek to ensure that global memory is freed when unloading pam_winbind.so (needs more testing on non-linux platforms) (This used to be commit 1e0b79e591d70352a96e0a0487d8f394dc7b36ba) --- source3/lib/debug.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 97a147f17d..b8c42686cd 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -177,6 +177,27 @@ static char **classname_table = NULL; * Functions... */ +/*************************************************************************** + Free memory pointed to by global pointers. +****************************************************************************/ + +void gfree_debugsyms(void) +{ + int i; + + if ( classname_table ) { + for ( i = 0; i < debug_num_classes; i++ ) { + SAFE_FREE( classname_table[i] ); + } + SAFE_FREE( classname_table ); + } + + if ( DEBUGLEVEL_CLASS != &debug_all_class_hack ) + SAFE_FREE( DEBUGLEVEL_CLASS ); + + if ( DEBUGLEVEL_CLASS_ISSET != &debug_all_class_isset_hack ) + SAFE_FREE( DEBUGLEVEL_CLASS_ISSET ); +} /**************************************************************************** utility lists registered debug class names's @@ -510,7 +531,7 @@ void debug_init(void) if (initialised) return; - + initialised = True; message_register(MSG_DEBUG, debug_message); -- cgit From a39643f170d53f7de0ccbd5df79114a29c7ac27f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 20 Jun 2006 01:12:44 +0000 Subject: r16388: Klocwork #320. Null deref. Jeremy. (This used to be commit ceea8e21006bd6bae9e203a672f82e4d066bba28) --- source3/lib/debug.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index b8c42686cd..2b6c42b8eb 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -513,6 +513,11 @@ static void debuglevel_message(int msg_type, struct process_id src, { char *message = debug_list_class_names_and_levels(); + if (!message) { + DEBUG(0,("debuglevel_message - debug_list_class_names_and_levels returned NULL\n")); + return; + } + DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n", (unsigned int)procid_to_pid(&src))); message_send_pid(src, MSG_DEBUGLEVEL, message, strlen(message) + 1, True); -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 2b6c42b8eb..bf75bdf3d3 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -981,7 +981,7 @@ BOOL dbghdr( int level, const char *file, const char *func, int line ) /* Print it all out at once to prevent split syslog output. */ (void)Debug1( "[%s, %d%s] %s:%s(%d)\n", - timestring(lp_debug_hires_timestamp()), level, + current_timestring(lp_debug_hires_timestamp()), level, header_str, file, func, line ); } -- cgit From 1cf1e648feed823244731eef5f56bd34e15cb045 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 31 Jul 2006 04:30:55 +0000 Subject: r17334: Some C++ warnings (This used to be commit 8ae7ed1f3cecbb5285313d17b5f9511e2e622f0b) --- source3/lib/debug.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index bf75bdf3d3..00f6b0e72f 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -236,7 +236,7 @@ static char *debug_list_class_names_and_levels(void) } /* create single string list - add space for newline */ - b = buf = SMB_MALLOC(dim+1); + b = buf = (char *)SMB_MALLOC(dim+1); if (!buf) { err = True; goto done; @@ -320,7 +320,7 @@ int debug_add_class(const char *classname) new_ptr = SMB_REALLOC_ARRAY(new_ptr, int, debug_num_classes + 1); if (!new_ptr) return -1; - DEBUGLEVEL_CLASS = new_ptr; + DEBUGLEVEL_CLASS = (int *)new_ptr; DEBUGLEVEL_CLASS[ndx] = 0; /* debug_level is the pointer used for the DEBUGLEVEL-thingy */ @@ -337,13 +337,13 @@ int debug_add_class(const char *classname) new_ptr = SMB_REALLOC_ARRAY(new_ptr, BOOL, debug_num_classes + 1); if (!new_ptr) return -1; - DEBUGLEVEL_CLASS_ISSET = new_ptr; + DEBUGLEVEL_CLASS_ISSET = (int *)new_ptr; DEBUGLEVEL_CLASS_ISSET[ndx] = False; new_ptr = SMB_REALLOC_ARRAY(classname_table, char *, debug_num_classes + 1); if (!new_ptr) return -1; - classname_table = new_ptr; + classname_table = (char **)new_ptr; classname_table[ndx] = SMB_STRDUP(classname); if (! classname_table[ndx]) @@ -474,7 +474,7 @@ BOOL debug_parse_levels(const char *params_str) static void debug_message(int msg_type, struct process_id src, void *buf, size_t len) { - const char *params_str = buf; + const char *params_str = (const char *)buf; /* Check, it's a proper string! */ if (params_str[len-1] != '\0') { -- cgit From caf8c6a76be051559ffcfe97084edca43e0a3cee Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 30 Jan 2007 22:22:06 +0000 Subject: r21064: The core of this patch is void message_register(int msg_type, void (*fn)(int msg_type, struct process_id pid, - void *buf, size_t len)) + void *buf, size_t len, + void *private_data), + void *private_data) { struct dispatch_fns *dfn; So this adds a (so far unused) private pointer that is passed from message_register to the message handler. A prerequisite to implement a tiny samba4-API compatible wrapper around our messaging system. That itself is necessary for the Samba4 notify system. Yes, I know, I could import the whole Samba4 messaging system, but I want to do it step by step and I think getting notify in is more important in this step. Volker (This used to be commit c8ae60ed65dcce9660ee39c75488f2838cf9a28b) --- source3/lib/debug.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 00f6b0e72f..5f14166110 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -472,7 +472,7 @@ BOOL debug_parse_levels(const char *params_str) ****************************************************************************/ static void debug_message(int msg_type, struct process_id src, - void *buf, size_t len) + void *buf, size_t len, void *private_data) { const char *params_str = (const char *)buf; @@ -509,7 +509,7 @@ void debug_message_send(pid_t pid, const char *params_str) ****************************************************************************/ static void debuglevel_message(int msg_type, struct process_id src, - void *buf, size_t len) + void *buf, size_t len, void *private_data) { char *message = debug_list_class_names_and_levels(); @@ -539,8 +539,8 @@ void debug_init(void) initialised = True; - message_register(MSG_DEBUG, debug_message); - message_register(MSG_REQ_DEBUGLEVEL, debuglevel_message); + message_register(MSG_DEBUG, debug_message, NULL); + message_register(MSG_REQ_DEBUGLEVEL, debuglevel_message, NULL); for(p = default_classname_table; *p; p++) { debug_add_class(*p); -- cgit From 93128b863bb10aeca6202f4d5ba7935e31cf5c5f Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 13 Mar 2007 17:39:06 +0000 Subject: r21825: add debug prefix timestamp to allow "short timestamps" to be added to debug messages (This used to be commit 4af2795e65f6bab156b300d720c7ea75c944bb87) --- source3/lib/debug.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 5f14166110..62fda5741c 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -962,7 +962,7 @@ BOOL dbghdr( int level, const char *file, const char *func, int line ) /* 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()) ) { + if( lp_timestamp_logs() || lp_debug_prefix_timestamp() || !(lp_loaded()) ) { char header_str[200]; header_str[0] = '\0'; @@ -980,9 +980,15 @@ BOOL dbghdr( int level, const char *file, const char *func, int line ) } /* Print it all out at once to prevent split syslog output. */ - (void)Debug1( "[%s, %d%s] %s:%s(%d)\n", + if( lp_debug_prefix_timestamp() ) { + (void)Debug1( "[%s, %d%s] ", + current_timestring(lp_debug_hires_timestamp()), level, + header_str); + } else { + (void)Debug1( "[%s, %d%s] %s:%s(%d)\n", current_timestring(lp_debug_hires_timestamp()), level, header_str, file, func, line ); + } } errno = old_errno; -- cgit From 8d0cfddb26a354606844a10254055fb8cd54e792 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 18 Mar 2007 10:13:35 +0000 Subject: r21868: Remove check_log_size from the central smbd processing loop. This can be done with a become_root/unbecome_root in debug.c. (This used to be commit 4632a0caaf251d9cc7b9d84cbd20362d37f0e4e0) --- source3/lib/debug.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 62fda5741c..a2e8574bbd 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -688,20 +688,15 @@ 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( x_fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { + + become_root_uid_only(); + (void)reopen_logs(); if( dbf && get_file_size( debugf ) > maxlog ) { pstring name; @@ -714,6 +709,8 @@ void check_log_size( void ) (void)rename(name, debugf); } } + + unbecome_root_uid_only(); } /* -- cgit From bc45c82904e268327bfbf72cd3f35699ae6e7397 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 5 Apr 2007 23:56:10 +0000 Subject: r22096: become_root_uid_only() is unneeded - it's only used in messages.c. Refactor to use become_root() instead and make it local to messages.c Jeremy. (This used to be commit f3ffb3f98472b69b476b702dfe5c0575b32da018) --- source3/lib/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index a2e8574bbd..138c52cdce 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -695,7 +695,7 @@ void check_log_size( void ) if( sys_fstat( x_fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { - become_root_uid_only(); + become_root(); (void)reopen_logs(); if( dbf && get_file_size( debugf ) > maxlog ) { @@ -710,7 +710,7 @@ void check_log_size( void ) } } - unbecome_root_uid_only(); + unbecome_root(); } /* -- cgit From a633b42592080982b38f5e3cde8d32bf2fd80e7e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 14 Apr 2007 06:40:47 +0000 Subject: r22213: We can't use become_root() here, as it does DEBUG() itself. become_root_uid_only did not :-) Revert 21868, we need to find a better way. Volker (This used to be commit 629f966714c7a8d96b06027d514b86cde81b69b9) --- source3/lib/debug.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 138c52cdce..62fda5741c 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -688,15 +688,20 @@ 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( x_fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { - - become_root(); - (void)reopen_logs(); if( dbf && get_file_size( debugf ) > maxlog ) { pstring name; @@ -709,8 +714,6 @@ void check_log_size( void ) (void)rename(name, debugf); } } - - unbecome_root(); } /* -- cgit From e6383f47629368d9dd4e803f17566a24e9d7359e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 7 May 2007 09:35:35 +0000 Subject: r22736: Start to merge the low-hanging fruit from the now 7000-line cluster patch. This changes "struct process_id" to "struct server_id", keeping both is just too much hassle. No functional change (I hope ;-)) Volker (This used to be commit 0ad4b1226c9d91b72136310d3bbb640d2c5d67b8) --- source3/lib/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 62fda5741c..d231f55585 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -471,7 +471,7 @@ BOOL debug_parse_levels(const char *params_str) Receive a "set debug level" message. ****************************************************************************/ -static void debug_message(int msg_type, struct process_id src, +static void debug_message(int msg_type, struct server_id src, void *buf, size_t len, void *private_data) { const char *params_str = (const char *)buf; @@ -508,7 +508,7 @@ void debug_message_send(pid_t pid, const char *params_str) Return current debug level. ****************************************************************************/ -static void debuglevel_message(int msg_type, struct process_id src, +static void debuglevel_message(int msg_type, struct server_id src, void *buf, size_t len, void *private_data) { char *message = debug_list_class_names_and_levels(); -- cgit From 84758bd1f8633d3efe30e293887596db6bfd5e5b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 15 May 2007 15:14:32 +0000 Subject: r22908: All callers of message_init now also call messaging_init. Unify those. (This used to be commit 330946ad2307ca34f0a8d068a0193fcb8a0d6036) --- source3/lib/debug.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index d231f55585..5ef07f806b 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -491,19 +491,6 @@ static void debug_message(int msg_type, struct server_id src, debug_parse_levels(params_str); } -/**************************************************************************** - Send a "set debug level" message. -****************************************************************************/ - -void debug_message_send(pid_t pid, const char *params_str) -{ - if (!params_str) - return; - message_send_pid(pid_to_procid(pid), MSG_DEBUG, - params_str, strlen(params_str) + 1, - False); -} - /**************************************************************************** Return current debug level. ****************************************************************************/ @@ -539,14 +526,17 @@ void debug_init(void) initialised = True; - message_register(MSG_DEBUG, debug_message, NULL); - message_register(MSG_REQ_DEBUGLEVEL, debuglevel_message, NULL); - for(p = default_classname_table; *p; p++) { debug_add_class(*p); } } +void debug_register_msgs(void) +{ + message_register(MSG_DEBUG, debug_message, NULL); + message_register(MSG_REQ_DEBUGLEVEL, debuglevel_message, NULL); +} + /*************************************************************************** Get ready for syslog stuff **************************************************************************/ -- cgit From 6669aa051e6e2e3cb79cb4e4b97c2dcd4e31d02b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 15 May 2007 15:41:37 +0000 Subject: r22910: Make message_send_pid static to messages.c (This used to be commit 27224922cf964cc70aad7cf529ab6c03fb277a89) --- source3/lib/debug.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 5ef07f806b..049ef5cfa4 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -471,13 +471,16 @@ BOOL debug_parse_levels(const char *params_str) Receive a "set debug level" message. ****************************************************************************/ -static void debug_message(int msg_type, struct server_id src, - void *buf, size_t len, void *private_data) +static void debug_message(struct messaging_context *msg_ctx, + void *private_data, + uint32_t msg_type, + struct server_id src, + DATA_BLOB *data) { - const char *params_str = (const char *)buf; + const char *params_str = (const char *)data->data; /* Check, it's a proper string! */ - if (params_str[len-1] != '\0') { + if (params_str[(data->length)-1] != '\0') { DEBUG(1, ("Invalid debug message from pid %u to pid %u\n", (unsigned int)procid_to_pid(&src), (unsigned int)getpid())); @@ -495,8 +498,11 @@ static void debug_message(int msg_type, struct server_id src, Return current debug level. ****************************************************************************/ -static void debuglevel_message(int msg_type, struct server_id src, - void *buf, size_t len, void *private_data) +static void debuglevel_message(struct messaging_context *msg_ctx, + void *private_data, + uint32_t msg_type, + struct server_id src, + DATA_BLOB *data) { char *message = debug_list_class_names_and_levels(); @@ -505,9 +511,10 @@ static void debuglevel_message(int msg_type, struct server_id src, return; } - DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n", - (unsigned int)procid_to_pid(&src))); - message_send_pid(src, MSG_DEBUGLEVEL, message, strlen(message) + 1, True); + DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %s\n", + procid_str_static(&src))); + messaging_send_buf(msg_ctx, src, MSG_DEBUGLEVEL, + (uint8 *)message, strlen(message) + 1); SAFE_FREE(message); } @@ -531,10 +538,11 @@ void debug_init(void) } } -void debug_register_msgs(void) +void debug_register_msgs(struct messaging_context *msg_ctx) { - message_register(MSG_DEBUG, debug_message, NULL); - message_register(MSG_REQ_DEBUGLEVEL, debuglevel_message, NULL); + messaging_register(msg_ctx, NULL, MSG_DEBUG, debug_message); + messaging_register(msg_ctx, NULL, MSG_REQ_DEBUGLEVEL, + debuglevel_message); } /*************************************************************************** -- cgit From 2b69775756a6395f14b1d0e2ef64cc7d84deeca9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 29 May 2007 19:36:13 +0000 Subject: r23226: Make the "debug prefix timestamp" output a bit more readable by making the debug level alway at least 2 digits (This used to be commit 94d2fd919c268efa3df2661d2ccb32e492c52f53) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 049ef5cfa4..4bbbf88d0d 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -979,7 +979,7 @@ BOOL dbghdr( int level, const char *file, const char *func, int line ) /* Print it all out at once to prevent split syslog output. */ if( lp_debug_prefix_timestamp() ) { - (void)Debug1( "[%s, %d%s] ", + (void)Debug1( "[%s, %2d%s] ", current_timestring(lp_debug_hires_timestamp()), level, header_str); } else { -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 4bbbf88d0d..1ee5967a56 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/lib/debug.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 1ee5967a56..bd67196271 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From d3dd14b70e1b0d25c75513bb8c3f5ecca8515ed4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 28 Sep 2007 23:03:08 +0000 Subject: r25416: Add registry debug class. Guenther (This used to be commit b28dd747cb5a3d0eee865076eb4733dc123a6968) --- source3/lib/debug.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index bd67196271..6aa34b59e8 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -166,6 +166,7 @@ static const char *default_classname_table[] = { "locking", /* DBGC_LOCKING */ "msdfs", /* DBGC_MSDFS */ "dmapi", /* DBGC_DMAPI */ + "registry", /* DBGC_REGISTRY */ NULL }; -- cgit From 9cffea618a13d37a82980ade71bb1ec927c153a0 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 29 Sep 2007 07:18:23 +0000 Subject: r25424: Align log level (by two) in debugging output. Michael (This used to be commit 9265b3cde25208884a8d3a9c42461d1c6e6fc353) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 6aa34b59e8..fc7b1d67f6 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -983,7 +983,7 @@ BOOL dbghdr( int level, const char *file, const char *func, int line ) current_timestring(lp_debug_hires_timestamp()), level, header_str); } else { - (void)Debug1( "[%s, %d%s] %s:%s(%d)\n", + (void)Debug1( "[%s, %2d%s] %s:%s(%d)\n", current_timestring(lp_debug_hires_timestamp()), level, header_str, file, func, line ); } -- cgit From b6a6fbd49309630e00983f9c2e654b805336ffae Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 30 Sep 2007 08:07:06 +0000 Subject: r25434: Add the option to print the debug class (DBGC_CLASS) in the debug header. Control this by a new boolean smb.conf option "debug class" which is by default set to "no" to keep the default debug header unchanged. Michael Note: You need to make clean for this patch. (This used to be commit 066a46ba91ca734d9e20cb9d6db36fec209a27d7) --- source3/lib/debug.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index fc7b1d67f6..69da08be77 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -913,6 +913,7 @@ void dbgflush( void ) Input: level - Debug level of the message (not the system-wide debug level. ) + cls - Debuglevel class of the calling module. file - Pointer to a string containing the name of the file from which this function was called, or an empty string if the __FILE__ macro is not implemented. @@ -930,7 +931,7 @@ void dbgflush( void ) ****************************************************************************/ -BOOL dbghdr( int level, const char *file, const char *func, int line ) +BOOL dbghdr(int level, int cls, const char *file, const char *func, int line) { /* Ensure we don't lose any real errno value. */ int old_errno = errno; @@ -976,6 +977,14 @@ BOOL dbghdr( int level, const char *file, const char *func, int line ) (unsigned int)geteuid(), (unsigned int)getegid(), (unsigned int)getuid(), (unsigned int)getgid()); } + + if (lp_debug_class() && (cls != DBGC_ALL)) { + size_t hs_len = strlen(header_str); + slprintf(header_str + hs_len, + sizeof(header_str) -1 - hs_len, + ", class=%s", + default_classname_table[cls]); + } /* Print it all out at once to prevent split syslog output. */ if( lp_debug_prefix_timestamp() ) { -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/lib/debug.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 69da08be77..72285277ec 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -79,15 +79,15 @@ XFILE *dbf = NULL; pstring debugf = ""; -BOOL debug_warn_unknown_class = True; -BOOL debug_auto_add_unknown_class = True; -BOOL AllowDebugChange = True; +bool debug_warn_unknown_class = True; +bool debug_auto_add_unknown_class = True; +bool AllowDebugChange = True; /* used to check if the user specified a logfile on the command line */ -BOOL override_logfile; +bool override_logfile; /* @@ -95,11 +95,11 @@ BOOL override_logfile; * system has been initialised. */ static int debug_all_class_hack = 1; -static BOOL debug_all_class_isset_hack = True; +static bool debug_all_class_isset_hack = True; static int debug_num_classes = 0; int *DEBUGLEVEL_CLASS = &debug_all_class_hack; -BOOL *DEBUGLEVEL_CLASS_ISSET = &debug_all_class_isset_hack; +bool *DEBUGLEVEL_CLASS_ISSET = &debug_all_class_isset_hack; /* DEBUGLEVEL is #defined to *debug_level */ int DEBUGLEVEL = &debug_all_class_hack; @@ -132,14 +132,14 @@ int DEBUGLEVEL = &debug_all_class_hack; * are unable to open a new log file for some reason. */ -static BOOL stdout_logging = False; +static bool stdout_logging = False; static int debug_count = 0; #ifdef WITH_SYSLOG static int syslog_level = 0; #endif static pstring format_bufr = { '\0' }; static size_t format_pos = 0; -static BOOL log_overflow = False; +static bool log_overflow = False; /* * Define all the debug class selection names here. Names *MUST NOT* contain @@ -211,7 +211,7 @@ static char *debug_list_class_names_and_levels(void) char **list; char *buf = NULL; char *b; - BOOL err = False; + bool err = False; if (DEBUGLEVEL_CLASS == &debug_all_class_hack) { return NULL; @@ -334,10 +334,10 @@ int debug_add_class(const char *classname) if (new_ptr == &debug_all_class_isset_hack) { new_ptr = NULL; } - new_ptr = SMB_REALLOC_ARRAY(new_ptr, BOOL, debug_num_classes + 1); + new_ptr = SMB_REALLOC_ARRAY(new_ptr, bool, debug_num_classes + 1); if (!new_ptr) return -1; - DEBUGLEVEL_CLASS_ISSET = (int *)new_ptr; + DEBUGLEVEL_CLASS_ISSET = (bool *)new_ptr; DEBUGLEVEL_CLASS_ISSET[ndx] = False; new_ptr = SMB_REALLOC_ARRAY(classname_table, char *, debug_num_classes + 1); @@ -403,7 +403,7 @@ static void debug_dump_status(int level) printdrivers:7 ****************************************************************************/ -static BOOL debug_parse_params(char **params) +static bool debug_parse_params(char **params) { int i, ndx; char *class_name; @@ -445,7 +445,7 @@ static BOOL debug_parse_params(char **params) Note: the 1st param has no "name:" preceeding it. ****************************************************************************/ -BOOL debug_parse_levels(const char *params_str) +bool debug_parse_levels(const char *params_str) { char **params; @@ -525,7 +525,7 @@ Init debugging (one time stuff) void debug_init(void) { - static BOOL initialised = False; + static bool initialised = False; const char **p; if (initialised) @@ -549,7 +549,7 @@ void debug_register_msgs(struct messaging_context *msg_ctx) Get ready for syslog stuff **************************************************************************/ -void setup_logging(const char *pname, BOOL interactive) +void setup_logging(const char *pname, bool interactive) { debug_init(); @@ -591,13 +591,13 @@ void setup_logging(const char *pname, BOOL interactive) Fix from dgibson@linuxcare.com. **************************************************************************/ -BOOL reopen_logs( void ) +bool reopen_logs( void ) { pstring fname; mode_t oldumask; XFILE *new_dbf = NULL; XFILE *old_dbf = NULL; - BOOL ret = True; + bool ret = True; if (stdout_logging) return True; @@ -662,7 +662,7 @@ void force_check_log_size( void ) Check to see if there is any need to check if the logfile has grown too big. **************************************************************************/ -BOOL need_to_check_log_size( void ) +bool need_to_check_log_size( void ) { int maxlog; @@ -864,7 +864,7 @@ static void bufr_print( void ) static void format_debug_text( const char *msg ) { size_t i; - BOOL timestamp = (!stdout_logging && (lp_timestamp_logs() || !(lp_loaded()))); + bool timestamp = (!stdout_logging && (lp_timestamp_logs() || !(lp_loaded()))); for( i = 0; msg[i]; i++ ) { /* Indent two spaces at each new line. */ @@ -931,7 +931,7 @@ void dbgflush( void ) ****************************************************************************/ -BOOL dbghdr(int level, int cls, const char *file, const char *func, int line) +bool dbghdr(int level, int cls, const char *file, const char *func, int line) { /* Ensure we don't lose any real errno value. */ int old_errno = errno; @@ -1015,7 +1015,7 @@ BOOL dbghdr(int level, int cls, const char *file, const char *func, int line) ***************************************************************************/ - BOOL dbgtext( const char *format_str, ... ) + bool dbgtext( const char *format_str, ... ) { va_list ap; pstring msgbuf; -- cgit From 68be9a820059ee96dd26c527efd7c14e679d3f2c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 15 Nov 2007 14:19:52 -0800 Subject: More pstring removal. This one was tricky. I had to add one horror (pstring_clean_name()) which will have to remain until I've removed all pstrings from the client code. Jeremy. (This used to be commit 1ea3ac80146b83c2522b69e7747c823366a2b47d) --- source3/lib/debug.c | 105 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 36 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 72285277ec..49ec40ae84 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -29,7 +29,8 @@ * for a terminating null byte. */ -#define FORMAT_BUFR_MAX ( sizeof( format_bufr ) - 1 ) +#define FORMAT_BUFR_SIZE 1024 +#define FORMAT_BUFR_MAX (FORMAT_BUFR_SIZE - 1) /* -------------------------------------------------------------------------- ** * This module implements Samba's debugging utility. @@ -78,16 +79,16 @@ */ XFILE *dbf = NULL; -pstring debugf = ""; +static char *debugf = NULL; bool debug_warn_unknown_class = True; bool debug_auto_add_unknown_class = True; bool AllowDebugChange = True; -/* - used to check if the user specified a - logfile on the command line +/* + used to check if the user specified a + logfile on the command line */ -bool override_logfile; +bool override_logfile; /* @@ -137,7 +138,7 @@ static int debug_count = 0; #ifdef WITH_SYSLOG static int syslog_level = 0; #endif -static pstring format_bufr = { '\0' }; +static char *format_bufr = NULL; static size_t format_pos = 0; static bool log_overflow = False; @@ -536,6 +537,10 @@ void debug_init(void) for(p = default_classname_table; *p; p++) { debug_add_class(*p); } + format_bufr = SMB_MALLOC(FORMAT_BUFR_SIZE); + if (!format_bufr) { + smb_panic("debug_init: unable to create buffer"); + } } void debug_register_msgs(struct messaging_context *msg_ctx) @@ -583,6 +588,16 @@ void setup_logging(const char *pname, bool interactive) #endif } +/*************************************************************************** + Set the logfile name. +**************************************************************************/ + +void debug_set_logfile(const char *name) +{ + SAFE_FREE(debugf); + debugf = SMB_STRDUP(name); +} + /************************************************************************** reopen the log files note that we now do this unconditionally @@ -593,7 +608,7 @@ void setup_logging(const char *pname, bool interactive) bool reopen_logs( void ) { - pstring fname; + char *fname = NULL; mode_t oldumask; XFILE *new_dbf = NULL; XFILE *old_dbf = NULL; @@ -603,19 +618,27 @@ bool reopen_logs( void ) return True; oldumask = umask( 022 ); - - pstrcpy(fname, debugf ); - debugf[0] = '\0'; + + fname = debugf; + if (!fname) { + return false; + } + debugf = NULL; if (lp_loaded()) { char *logfname; logfname = lp_logfile(); - if (*logfname) - pstrcpy(fname, logfname); + if (*logfname) { + SAFE_FREE(fname); + fname = SMB_STRDUP(logfname); + if (!fname) { + return false; + } + } } - pstrcpy( debugf, fname ); + debugf = fname; new_dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644); if (!new_dbf) { @@ -702,15 +725,18 @@ void check_log_size( void ) if( sys_fstat( x_fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { (void)reopen_logs(); if( dbf && get_file_size( debugf ) > maxlog ) { - pstring name; + char *name = NULL; + + if (asprintf(&name, "%s.old", debugf ) < 0) { + return; + } + (void)rename(debugf, 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); } + SAFE_FREE(name); } } @@ -747,7 +773,7 @@ void check_log_size( void ) int Debug1( const char *format_str, ... ) { - va_list ap; + va_list ap; int old_errno = errno; debug_count++; @@ -762,8 +788,8 @@ void check_log_size( void ) } /* prevent recursion by checking if reopen_logs() has temporaily - set the debugf string to "" */ - if( debugf[0] == '\0') + set the debugf string to NULL */ + if( debugf == NULL) return( 0 ); #ifdef WITH_SYSLOG @@ -789,29 +815,31 @@ void check_log_size( void ) /* map debug levels to syslog() priorities * note that not all DEBUG(0, ...) calls are * necessarily errors */ - static int priority_map[] = { + static int priority_map[] = { LOG_ERR, /* 0 */ LOG_WARNING, /* 1 */ LOG_NOTICE, /* 2 */ LOG_INFO, /* 3 */ }; int priority; - pstring msgbuf; + char *msgbuf = NULL; if( syslog_level >= ( sizeof(priority_map) / sizeof(priority_map[0]) ) || syslog_level < 0) priority = LOG_DEBUG; else priority = priority_map[syslog_level]; - va_start( ap, format_str ); - vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); - va_end( ap ); + va_start(ap, format_str); + vasprintf(&msgbuf, format_str, ap); + va_end(ap); - msgbuf[255] = '\0'; - syslog( priority, "%s", msgbuf ); + if (msgbuf) { + syslog(priority, "%s", msgbuf); + } + SAFE_FREE(msgbuf); } #endif - + check_log_size(); #ifdef WITH_SYSLOG @@ -1018,13 +1046,18 @@ bool dbghdr(int level, int cls, const char *file, const char *func, int line) bool dbgtext( const char *format_str, ... ) { va_list ap; - pstring msgbuf; - - va_start( ap, format_str ); - vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); - va_end( ap ); + char *msgbuf = NULL; + bool ret = true; - format_debug_text( msgbuf ); + va_start(ap, format_str); + vasprintf(&msgbuf, format_str, ap); + va_end(ap); - return( True ); + if (msgbuf) { + format_debug_text(msgbuf); + } else { + ret = false; + } + SAFE_FREE(msgbuf); + return ret; } -- cgit From 5d85dd682a82a0d2c54ebfca3ad9c234f2599b84 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 26 Nov 2007 11:55:55 +0100 Subject: Fix a C++ warning (This used to be commit 9bf5ead4b2be57fa84e5b3137bfa0305a916f10f) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 49ec40ae84..4afc953c3e 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -537,7 +537,7 @@ void debug_init(void) for(p = default_classname_table; *p; p++) { debug_add_class(*p); } - format_bufr = SMB_MALLOC(FORMAT_BUFR_SIZE); + format_bufr = (char *)SMB_MALLOC(FORMAT_BUFR_SIZE); if (!format_bufr) { smb_panic("debug_init: unable to create buffer"); } -- cgit From 1410c9e37dc638f04053ebe1b7d5688575ff235b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 14 Dec 2007 08:21:59 +0100 Subject: debug: fix crash bug when DEBUG() is used before setup_logging() this was introduced by the pstring removal (1ea3ac80146b83c2522b69e7747c823366a2b47d) metze (This used to be commit a412e6c7c676a054acd9db371221a50078cfe1d9) --- source3/lib/debug.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 4afc953c3e..185c2373f4 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -894,6 +894,10 @@ static void format_debug_text( const char *msg ) size_t i; bool timestamp = (!stdout_logging && (lp_timestamp_logs() || !(lp_loaded()))); + if (!format_bufr) { + debug_init(); + } + for( i = 0; msg[i]; i++ ) { /* Indent two spaces at each new line. */ if(timestamp && 0 == format_pos) { -- cgit From db98b921449d8f3d766e5ae2696125d718054a15 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 15 Dec 2007 21:05:11 +0100 Subject: Add debug_ctx according to an idea by Tridge Sorry, Jeremy, I think for debug messages this is just the right way to do it. (This used to be commit 6312016e2727c2b5b1a4964a98cfb9585d77cc8c) --- source3/lib/debug.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 185c2373f4..87ec9ed8f5 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -90,6 +90,7 @@ bool AllowDebugChange = True; */ bool override_logfile; +static TALLOC_CTX *tmp_debug_ctx; /* * This is to allow assignment to DEBUGLEVEL before the debug @@ -856,6 +857,8 @@ void check_log_size( void ) errno = old_errno; + TALLOC_FREE(tmp_debug_ctx); + return( 0 ); } @@ -1065,3 +1068,14 @@ bool dbghdr(int level, int cls, const char *file, const char *func, int line) SAFE_FREE(msgbuf); return ret; } + +/* + * Get us a temporary talloc context usable just for DEBUG arguments + */ +TALLOC_CTX *debug_ctx(void) +{ + if (tmp_debug_ctx == NULL) { + tmp_debug_ctx = talloc_named_const(NULL, 0, "debug_ctx"); + } + return tmp_debug_ctx; +} -- cgit From 07867ec373b98d6c0d3048983091ba4c49231196 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 26 Dec 2007 23:44:24 +0100 Subject: Fix some memleaks (This used to be commit 78b0b66cbac349625257260d2e45d918e0c93617) --- source3/lib/debug.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 87ec9ed8f5..9ea2dc151a 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -785,13 +785,13 @@ void check_log_size( void ) (void)x_vfprintf( dbf, format_str, ap ); va_end( ap ); errno = old_errno; - return( 0 ); + goto done; } /* prevent recursion by checking if reopen_logs() has temporaily set the debugf string to NULL */ if( debugf == NULL) - return( 0 ); + goto done; #ifdef WITH_SYSLOG if( !lp_syslog_only() ) @@ -806,7 +806,7 @@ void check_log_size( void ) x_setbuf( dbf, NULL ); } else { errno = old_errno; - return(0); + goto done; } } } @@ -855,10 +855,11 @@ void check_log_size( void ) (void)x_fflush( dbf ); } - errno = old_errno; - + done: TALLOC_FREE(tmp_debug_ctx); + errno = old_errno; + return( 0 ); } -- cgit From 68ec31427735e3d127544e52d4107d1e97eeeada Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 12:41:18 +0100 Subject: In gfree_debugsyms() free the format_bufr as well. Guenther (This used to be commit 48f09ca376f9fc7923309f3466e5d72f7c21a56f) --- source3/lib/debug.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 9ea2dc151a..6c1bfea04f 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -199,6 +199,8 @@ void gfree_debugsyms(void) if ( DEBUGLEVEL_CLASS_ISSET != &debug_all_class_isset_hack ) SAFE_FREE( DEBUGLEVEL_CLASS_ISSET ); + + SAFE_FREE(format_bufr); } /**************************************************************************** -- cgit From 587cf54c61c9f1f7bcae431a82035fd942716c32 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 23 Jan 2008 11:04:10 +0100 Subject: strtok -> strtok_r (This used to be commit fd34ce437057bb34cdc37f4b066e424000d36789) --- source3/lib/debug.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 6c1bfea04f..51bb0d7541 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -429,8 +429,9 @@ static bool debug_parse_params(char **params) /* Fill in new debug class levels */ for (; i < debug_num_classes && params[i]; i++) { - if ((class_name=strtok(params[i],":")) && - (class_level=strtok(NULL, "\0")) && + char *saveptr; + if ((class_name = strtok_r(params[i],":", &saveptr)) && + (class_level = strtok_r(NULL, "\0", &saveptr)) && ((ndx = debug_lookup_classname(class_name)) != -1)) { DEBUGLEVEL_CLASS[ndx] = atoi(class_level); DEBUGLEVEL_CLASS_ISSET[ndx] = True; -- cgit From 2762b9a97582b9b28fd5985ba8e3d0299126820e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 4 Feb 2008 20:57:35 +0100 Subject: Always pass a TALLOC_CTX to str_list_make and str_list_copy (This used to be commit e2c9fc4cf5f0ff725330fa44f53782db65fca37e) --- source3/lib/debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 51bb0d7541..9ff267b607 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -460,14 +460,14 @@ bool debug_parse_levels(const char *params_str) if (AllowDebugChange == False) return True; - params = str_list_make(params_str, NULL); + params = str_list_make(talloc_tos(), params_str, NULL); if (debug_parse_params(params)) { debug_dump_status(5); - str_list_free(¶ms); + TALLOC_FREE(params); return True; } else { - str_list_free(¶ms); + TALLOC_FREE(params); return False; } } -- cgit From 317639287886181edf08ccecad1b324e4cc55d0b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 25 Feb 2008 15:24:49 +0100 Subject: Fix some warnings warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result (This used to be commit ad37b7b0aee265a3e4d8b7552610f4b9a105434d) --- source3/lib/debug.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 9ff267b607..c4a0d1b47b 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -827,6 +827,7 @@ void check_log_size( void ) }; int priority; char *msgbuf = NULL; + int ret; if( syslog_level >= ( sizeof(priority_map) / sizeof(priority_map[0]) ) || syslog_level < 0) priority = LOG_DEBUG; @@ -834,10 +835,10 @@ void check_log_size( void ) priority = priority_map[syslog_level]; va_start(ap, format_str); - vasprintf(&msgbuf, format_str, ap); + ret = vasprintf(&msgbuf, format_str, ap); va_end(ap); - if (msgbuf) { + if (ret == -1) { syslog(priority, "%s", msgbuf); } SAFE_FREE(msgbuf); @@ -1059,12 +1060,13 @@ bool dbghdr(int level, int cls, const char *file, const char *func, int line) va_list ap; char *msgbuf = NULL; bool ret = true; + int res; va_start(ap, format_str); - vasprintf(&msgbuf, format_str, ap); + res = vasprintf(&msgbuf, format_str, ap); va_end(ap); - if (msgbuf) { + if (res != -1) { format_debug_text(msgbuf); } else { ret = false; -- cgit From 9644b6cb50ec01c04a0d6ab17a8e39054fd8b0f8 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 28 Mar 2008 15:49:13 +0100 Subject: Add a talloc context parameter to current_timestring() to fix memleaks. current_timestring used to return a string talloced to talloc_tos(). When called by DEBUG from a TALLOC_FREE, this produced messages "no talloc stackframe around, leaking memory". For example when used from net conf. This also adds a temporary talloc context to alloc_sub_basic(). For this purpose, the exit strategy is slightly altered: a common exit point is used for success and failure. Michael (This used to be commit 16b5800d4e3a8b88bac67b2550d14e0aaaa302a9) --- source3/lib/debug.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index c4a0d1b47b..a76a8dbf53 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -1029,12 +1029,14 @@ bool dbghdr(int level, int cls, const char *file, const char *func, int line) /* Print it all out at once to prevent split syslog output. */ if( lp_debug_prefix_timestamp() ) { (void)Debug1( "[%s, %2d%s] ", - current_timestring(lp_debug_hires_timestamp()), level, - header_str); + current_timestring(debug_ctx(), + lp_debug_hires_timestamp()), + level, header_str); } else { (void)Debug1( "[%s, %2d%s] %s:%s(%d)\n", - current_timestring(lp_debug_hires_timestamp()), level, - header_str, file, func, line ); + current_timestring(debug_ctx(), + lp_debug_hires_timestamp()), + level, header_str, file, func, line ); } } -- cgit From 065760ede0b4d785adf8a5dcdd9237a494b4876a Mon Sep 17 00:00:00 2001 From: Darshan Purandare Date: Tue, 1 Jul 2008 11:37:13 -0700 Subject: MSG_DEBUG now forwarded to all the winbindd children by parent. smbcontrol winbindd debug level would only set the debug level of the parent winbindd process and not the child processes. This patch adds the functionality of broadcasting the debug message to all winbindd children. Now the debug level message is propagated to all the winbindd processes that includes parent and children. (This used to be commit cfbcfc3ffe74f28ec874a6bf1ab93f55f405b6e6) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index a76a8dbf53..2ded6bdc33 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -476,7 +476,7 @@ bool debug_parse_levels(const char *params_str) Receive a "set debug level" message. ****************************************************************************/ -static void debug_message(struct messaging_context *msg_ctx, +void debug_message(struct messaging_context *msg_ctx, void *private_data, uint32_t msg_type, struct server_id src, -- cgit From 03991ab0734ecbb87a75238d1356fbe0e5b1d38d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Aug 2008 13:35:15 -0700 Subject: Fix bug 5686 - libsmbclient segfaults with more than one SMBCCTX. Here is a patch to allow many subsystems to be re-initialized. The only functional change I made was to remove the null context tracking, as the memory allocated here is designed to be left for the complete lifetime of the program. Freeing this early (when all smb contexts are destroyed) could crash other users of talloc. Jeremy. (This used to be commit 8c630efd25cf17aff59448ca05c1b44a41964b16) --- source3/lib/debug.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'source3/lib/debug.c') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 2ded6bdc33..d835ea7c17 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -94,7 +94,7 @@ static TALLOC_CTX *tmp_debug_ctx; /* * This is to allow assignment to DEBUGLEVEL before the debug - * system has been initialised. + * system has been initialized. */ static int debug_all_class_hack = 1; static bool debug_all_class_isset_hack = True; @@ -183,6 +183,8 @@ static char **classname_table = NULL; Free memory pointed to by global pointers. ****************************************************************************/ +static bool initialized; + void gfree_debugsyms(void) { int i; @@ -194,13 +196,23 @@ void gfree_debugsyms(void) SAFE_FREE( classname_table ); } - if ( DEBUGLEVEL_CLASS != &debug_all_class_hack ) + if ( DEBUGLEVEL_CLASS != &debug_all_class_hack ) { SAFE_FREE( DEBUGLEVEL_CLASS ); + DEBUGLEVEL_CLASS = &debug_all_class_hack; + } - if ( DEBUGLEVEL_CLASS_ISSET != &debug_all_class_isset_hack ) + if ( DEBUGLEVEL_CLASS_ISSET != &debug_all_class_isset_hack ) { SAFE_FREE( DEBUGLEVEL_CLASS_ISSET ); + DEBUGLEVEL_CLASS_ISSET = &debug_all_class_isset_hack; + } SAFE_FREE(format_bufr); + + debug_num_classes = 0; + + debug_level = DEBUGLEVEL_CLASS; + + initialized = false; } /**************************************************************************** @@ -530,13 +542,12 @@ Init debugging (one time stuff) void debug_init(void) { - static bool initialised = False; const char **p; - if (initialised) + if (initialized) return; - initialised = True; + initialized = true; for(p = default_classname_table; *p; p++) { debug_add_class(*p); -- cgit