/*
* Copyright (c) 2000, 2001, 2003, 2004 Proofpoint, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*/
/*
** libsm debugging and tracing
** For documentation, see debug.html.
*/
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#endif /* _FFR_DEBUG_PID_TIME */
#include <setjmp.h>
static void sm_debug_reset __P((void));
static const char *parse_named_setting_x __P((const char *));
/*
** Abstractions for printing trace messages.
*/
/*
** The output file to which trace output is directed.
** There is a controversy over whether this variable
** should be process global or thread local.
** To make the interface more abstract, we've hidden the
** variable behind access functions.
*/
/*
** SM_DEBUG_FILE -- Returns current debug file pointer.
**
** Parameters:
** none.
**
** Returns:
** current debug file pointer.
*/
{
return SmDebugOutput;
}
/*
** SM_DEBUG_SETFILE -- Sets debug file pointer.
**
** Parameters:
** fp -- new debug file pointer.
**
** Returns:
** none.
**
** Side Effects:
** Sets SmDebugOutput.
*/
void
{
SmDebugOutput = fp;
}
/*
** SM_DEBUG_CLOSE -- Close debug file pointer.
**
** Parameters:
** none.
**
** Returns:
** none.
**
** Side Effects:
** Closes SmDebugOutput.
*/
void
{
{
}
}
/*
** SM_DPRINTF -- printf() for debug output.
**
** Parameters:
** fmt -- format for printf()
**
** Returns:
** none.
*/
"@(#)$Debug: sm_trace_pid_time - print pid and time in debug $");
#endif /* _FFR_DEBUG_PID_TIME */
void
#if SM_VA_STD
#else /* SM_VA_STD */
char *fmt;
#endif /* SM_VA_STD */
{
if (SmDebugOutput == NULL)
return;
/* note: this is ugly if the output isn't a full line! */
{
}
#endif /* _FFR_DEBUG_PID_TIME */
}
/*
** SM_DFLUSH -- Flush debug output.
**
** Parameters:
** none.
**
** Returns:
** none.
*/
void
{
}
/*
** This is the internal database of debug settings.
** The semantics of looking up a setting in the settings database
** are that the *last* setting specified in a -d option on the sendmail
** command line that matches a given SM_DEBUG structure is the one that is
** used. That is necessary to conform to the existing semantics of
** the sendmail -d option. We store the settings as a linked list in
** reverse order, so when we do a lookup, we take the *first* entry
** that matches.
*/
struct sm_debug_setting
{
const char *ds_pattern;
unsigned int ds_level;
};
/*
** We keep a linked list of SM_DEBUG structures that have been initialized,
** for use by sm_debug_reset.
*/
/*
** SM_DEBUG_RESET -- Reset SM_DEBUG structures.
**
** Reset all SM_DEBUG structures back to the uninitialized state.
** This is used by sm_debug_addsetting to ensure that references to
** SM_DEBUG structures that occur before sendmail processes its -d flags
** do not cause those structures to be permanently forced to level 0.
**
** Parameters:
** none.
**
** Returns:
** none.
*/
static void
{
for (debug = SmDebugInitialized;
{
}
}
/*
** SM_DEBUG_ADDSETTING_X -- add an entry to the database of debug settings
**
** Parameters:
** pattern -- a shell-style glob pattern (see sm_match).
** WARNING: the storage for 'pattern' will be owned by
** the debug package, so it should either be a string
** literal or the result of a call to sm_strdup_x.
** level -- a non-negative integer.
**
** Returns:
** none.
**
** Exceptions:
** F:sm_heap -- out of memory
*/
void
const char *pattern;
int level;
{
SM_REQUIRE(level >= 0);
s = sm_malloc_x(sizeof(SM_DEBUG_SETTING_T));
s->ds_pattern = pattern;
s->ds_next = SmDebugSettings;
SmDebugSettings = s;
}
/*
** PARSE_NAMED_SETTING_X -- process a symbolic debug setting
**
** Parameters:
** s -- Points to a non-empty \0 or , terminated string,
** of which the initial character is not a digit.
**
** Returns:
** pointer to terminating \0 or , character.
**
** Exceptions:
** F:sm.heap -- out of memory.
**
** Side Effects:
** adds the setting to the database.
*/
static const char *
const char *s;
{
int level;
pat = s;
while (*s != '\0' && *s != ',' && *s != '.')
++s;
endpat = s;
if (*s == '.')
{
++s;
level = 0;
{
++s;
}
if (level < 0)
level = 0;
}
else
level = 1;
/* skip trailing junk */
while (*s != '\0' && *s != ',')
++s;
return s;
}
/*
** SM_DEBUG_ADDSETTINGS_X -- process a list of debug options
**
** Parameters:
** s -- a list of debug settings, eg the argument to the
** sendmail -d option.
**
** The syntax of the string s is as follows:
**
** <settings> ::= <setting> | <settings> "," <setting>
** <setting> ::= <categories> | <categories> "." <level>
** <categories> ::= [a-zA-Z_*?][a-zA-Z0-9_*?]*
**
** However, note that we skip over anything we don't
** understand, rather than report an error.
**
** Returns:
** none.
**
** Exceptions:
** F:sm.heap -- out of memory
**
** Side Effects:
** updates the database of debug settings.
*/
void
const char *s;
{
for (;;)
{
if (*s == '\0')
return;
if (*s == ',')
{
++s;
continue;
}
s = parse_named_setting_x(s);
}
}
/*
** SM_DEBUG_LOADLEVEL -- Get activation level of the specified debug object.
**
** Parameters:
** debug -- debug object.
**
** Returns:
** Activation level of the specified debug object.
**
** Side Effects:
** Ensures that the debug object is initialized.
*/
int
{
{
{
{
goto initialized;
}
}
debug->debug_level = 0;
}
return (int) debug->debug_level;
}
/*
** SM_DEBUG_LOADACTIVE -- Activation level reached?
**
** Parameters:
** debug -- debug object.
** level -- level to check.
**
** Returns:
** true iff the activation level of the specified debug
** object >= level.
**
** Side Effects:
** Ensures that the debug object is initialized.
*/
bool
int level;
{
}