diff options
Diffstat (limited to 'source/lib/debug.c')
-rw-r--r-- | source/lib/debug.c | 142 |
1 files changed, 61 insertions, 81 deletions
diff --git a/source/lib/debug.c b/source/lib/debug.c index 7960c32b583..3731b3656fa 100644 --- a/source/lib/debug.c +++ b/source/lib/debug.c @@ -1,5 +1,6 @@ /* - Unix SMB/CIFS implementation. + Unix SMB/Netbios implementation. + Version 1.9. Samba utility functions Copyright (C) Andrew Tridgell 1992-1998 @@ -25,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 null byte. + * for a terminating nul byte. */ #define FORMAT_BUFR_MAX ( sizeof( format_bufr ) - 1 ) @@ -78,15 +79,14 @@ * levels higher than DEBUGLEVEL will not be processed. */ -XFILE *dbf = NULL; +FILE *dbf = NULL; pstring debugf = ""; BOOL append_log = False; int DEBUGLEVEL_CLASS[DBGC_LAST]; -BOOL DEBUGLEVEL_CLASS_ISSET[DBGC_LAST]; int DEBUGLEVEL = DEBUGLEVEL_CLASS; BOOL AllowDebugChange = True; - +int parsed_debuglevel_class[DBGC_LAST]; /* -------------------------------------------------------------------------- ** * Internal variables. @@ -125,19 +125,15 @@ 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_<class name>, and they - * must be in the table in the order of DBGC_<class name>.. - */ +* Define all the debug class selection names here. Names *MUST NOT* contain +* white space. There must be one name for each DBGC_<class name>, and they +* must be in the table in the order of DBGC_<class name>.. +*/ char *classname_table[] = { - "all", /* DBGC_ALL; index refs traditional DEBUGLEVEL */ - "tdb", /* DBGC_TDB */ + "all", /* DBGC_ALL; index references 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 */ + "lanman", /* DBGC_LANMAN */ }; @@ -173,8 +169,7 @@ 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 *debuglevel_class_isset) +BOOL debug_parse_params(char **params, int *debuglevel_class) { int i, ndx; char *class_name; @@ -183,16 +178,15 @@ 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 specified w/o requiring its class name e.g."10" + /* 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((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 class name was included */ + i = 0; /* DBGC_ALL not specified OR calss name was included */ /* Fill in new debug class levels */ for (; i < DBGC_LAST && params[i]; i++) { @@ -200,7 +194,6 @@ 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; @@ -220,13 +213,9 @@ BOOL debug_parse_levels(char *params_str) int i; char *params[DBGC_LAST]; 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); if ((params[0]=strtok(params_str," ,"))) { for (i=1; i<DBGC_LAST;i++) { @@ -237,26 +226,19 @@ BOOL debug_parse_levels(char *params_str) else return False; - if (debug_parse_params(params, debuglevel_class, - debuglevel_class_isset)) { - debug_message(0, sys_getpid(), (void*)debuglevel_class, sizeof(debuglevel_class)); - - memcpy(DEBUGLEVEL_CLASS, debuglevel_class, - sizeof(debuglevel_class)); - - memcpy(DEBUGLEVEL_CLASS_ISSET, debuglevel_class_isset, - sizeof(debuglevel_class_isset)); - - { - int q; - - for (q = 0; q < DBGC_LAST; q++) - DEBUG(5, ("%s: %d/%d\n", - classname_table[q], - DEBUGLEVEL_CLASS[q], - DEBUGLEVEL_CLASS_ISSET[q])); - } + if (AllowDebugChange == False) { + int old_debuglevel_class[DBGC_LAST]; + /* save current debug level */ + memcpy(old_debuglevel_class, DEBUGLEVEL_CLASS, sizeof(DEBUGLEVEL_CLASS)); + if (debug_parse_params(params, debuglevel_class)) + debug_message(0, getpid(), (void*)debuglevel_class, sizeof(debuglevel_class)); + memcpy(parsed_debuglevel_class, DEBUGLEVEL_CLASS, sizeof(DEBUGLEVEL_CLASS)); + memcpy(DEBUGLEVEL_CLASS, old_debuglevel_class, sizeof(old_debuglevel_class)); + return True; + } + if (debug_parse_params(params, debuglevel_class)) { + debug_message(DEBUGLEVEL, getpid(), (void*)debuglevel_class, sizeof(debuglevel_class)); return True; } else return False; @@ -265,22 +247,20 @@ BOOL debug_parse_levels(char *params_str) /**************************************************************************** receive a "set debug level" message ****************************************************************************/ -void debug_message(int msg_type, pid_t src, void *buf, size_t len) +void debug_message(int msg_level, pid_t src, void *buf, size_t len) { - struct debuglevel_message *dm = (struct debuglevel_message *)buf; int i; - /* Set the new DEBUGLEVEL_CLASS array from the passed message */ - memcpy(DEBUGLEVEL_CLASS, dm->debuglevel_class, sizeof(dm->debuglevel_class)); - memcpy(DEBUGLEVEL_CLASS_ISSET, dm->debuglevel_class_isset, sizeof(dm->debuglevel_class_isset)); - - DEBUG(3,("INFO: Debug class %s level = %d (pid %u from pid %u)\n", + /* Set the new DEBUGLEVEL_CLASS array from the pased array */ + memcpy(DEBUGLEVEL_CLASS, buf, sizeof(DEBUGLEVEL_CLASS)); + + DEBUG(msg_level,("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)); + DEBUGLEVEL_CLASS[DBGC_ALL], (unsigned int)getpid(), (unsigned int)src)); for (i=1; i<DBGC_LAST; i++) { if (DEBUGLEVEL_CLASS[i]) - DEBUGADD(3,("INFO: Debug class %s level = %d\n", + DEBUGADD(1,("INFO: Debug class %s level = %d\n", classname_table[i], DEBUGLEVEL_CLASS[i])); } } @@ -310,17 +290,16 @@ void setup_logging(char *pname, BOOL interactive) if (interactive) { stdout_logging = True; - dbf = x_stdout; + dbf = stdout; } #ifdef WITH_SYSLOG else { - char *p = strrchr_m( pname,'/' ); + 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. */ +#else /* for old systems that have no facility codes. */ openlog( pname, LOG_PID ); #endif } @@ -340,7 +319,7 @@ BOOL reopen_logs( void ) { pstring fname; mode_t oldumask; - XFILE *new_dbf = NULL; + FILE *new_dbf = NULL; BOOL ret = True; if (stdout_logging) @@ -358,23 +337,24 @@ BOOL reopen_logs( void ) pstrcpy(fname, logfname); } - pstrcpy( debugf, fname ); + pstrcpy(debugf, fname); + if (append_log) - new_dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644); + new_dbf = sys_fopen( debugf, "a" ); else - new_dbf = x_fopen( debugf, O_WRONLY|O_CREAT|O_TRUNC, 0644 ); + 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; if (dbf) - x_fflush(dbf); + fflush(dbf); ret = False; } else { - x_setbuf(new_dbf, NULL); + setbuf(new_dbf, NULL); if (dbf) - (void) x_fclose(dbf); + (void) fclose(dbf); dbf = new_dbf; } @@ -439,7 +419,7 @@ void check_log_size( void ) maxlog = lp_max_log_size() * 1024; - if( sys_fstat( x_fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { + if( sys_fstat( fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { (void)reopen_logs(); if( dbf && get_file_size( debugf ) > maxlog ) { pstring name; @@ -460,13 +440,13 @@ 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 - */ - dbf = x_fopen( "/dev/console", O_WRONLY, 0); + 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 )); @@ -494,7 +474,7 @@ void check_log_size( void ) { va_start( ap, format_str ); if(dbf) - (void)x_vfprintf( dbf, format_str, ap ); + (void)vfprintf( dbf, format_str, ap ); va_end( ap ); errno = old_errno; return( 0 ); @@ -509,13 +489,13 @@ void check_log_size( void ) mode_t oldumask = umask( 022 ); if( append_log ) - dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 ); + dbf = sys_fopen( debugf, "a" ); else - dbf = x_fopen( debugf, O_WRONLY|O_CREAT|O_TRUNC, 0644 ); + dbf = sys_fopen( debugf, "w" ); (void)umask( oldumask ); if( dbf ) { - x_setbuf( dbf, NULL ); + setbuf( dbf, NULL ); } else { @@ -564,10 +544,10 @@ void check_log_size( void ) { va_start( ap, format_str ); if(dbf) - (void)x_vfprintf( dbf, format_str, ap ); + (void)vfprintf( dbf, format_str, ap ); va_end( ap ); if(dbf) - (void)x_fflush( dbf ); + (void)fflush( dbf ); } errno = old_errno; @@ -657,14 +637,14 @@ void dbgflush( void ) { bufr_print(); if(dbf) - (void)x_fflush( dbf ); + (void)fflush( dbf ); } /* dbgflush */ /* ************************************************************************** ** * 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. |