/* ************************************************************************** ** * 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) { 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); } /* Don't print a header if we're logging to stdout. */ if (stdout_logging) return (True); /* Print the header if timestamps are turned on. If parameters are * not yet loaded, then default to timestamps on. */ if (lp_timestamp_logs () || !(lp_loaded ())) { /* Print it all out at once to prevent split syslog output. */ (void) Debug1 ("[%s, %d] %s:%s(%d)\n", timestring (), level, file, func, line); } return (True); } /* dbghdr */
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 ); } #ifdef WITH_SYSLOG /* Set syslog_level. */ syslog_level = level; #endif /* 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]; header_str[0] = '\0'; 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()); } /* 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 ); }
/* ************************************************************************** ** * 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 */