xref: /onnv-gate/usr/src/cmd/sendmail/include/sm/debug.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright (c) 2000, 2001, 2003 Sendmail, Inc. and its suppliers.
3*0Sstevel@tonic-gate  *	All rights reserved.
4*0Sstevel@tonic-gate  *
5*0Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
6*0Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
7*0Sstevel@tonic-gate  * the sendmail distribution.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  *	$Id: debug.h,v 1.16 2003/01/10 00:26:06 ca Exp $
10*0Sstevel@tonic-gate  */
11*0Sstevel@tonic-gate 
12*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
13*0Sstevel@tonic-gate 
14*0Sstevel@tonic-gate /*
15*0Sstevel@tonic-gate **  libsm debugging and tracing
16*0Sstevel@tonic-gate **  See libsm/debug.html for documentation.
17*0Sstevel@tonic-gate */
18*0Sstevel@tonic-gate 
19*0Sstevel@tonic-gate #ifndef SM_DEBUG_H
20*0Sstevel@tonic-gate # define SM_DEBUG_H
21*0Sstevel@tonic-gate 
22*0Sstevel@tonic-gate # include <sm/gen.h>
23*0Sstevel@tonic-gate # include <sm/io.h>
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate /*
26*0Sstevel@tonic-gate **  abstractions for printing trace messages
27*0Sstevel@tonic-gate */
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate extern SM_FILE_T *
30*0Sstevel@tonic-gate sm_debug_file __P((void));
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate extern void
33*0Sstevel@tonic-gate sm_debug_setfile __P(( SM_FILE_T *));
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate extern void PRINTFLIKE(1, 2)
36*0Sstevel@tonic-gate sm_dprintf __P((char *_fmt, ...));
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate extern void
39*0Sstevel@tonic-gate sm_dflush __P((void));
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate extern void
42*0Sstevel@tonic-gate sm_debug_close __P((void));
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate /*
45*0Sstevel@tonic-gate **  abstractions for setting and testing debug activation levels
46*0Sstevel@tonic-gate */
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate extern void
49*0Sstevel@tonic-gate sm_debug_addsettings_x __P((const char *));
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate extern void
52*0Sstevel@tonic-gate sm_debug_addsetting_x __P((const char *, int));
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate # define SM_DEBUG_UNKNOWN	((SM_ATOMIC_UINT_T)(-1))
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate extern const char SmDebugMagic[];
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate typedef struct sm_debug SM_DEBUG_T;
59*0Sstevel@tonic-gate struct sm_debug
60*0Sstevel@tonic-gate {
61*0Sstevel@tonic-gate 	const char *sm_magic;	/* points to SmDebugMagic */
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate 	/*
64*0Sstevel@tonic-gate 	**  debug_level is the activation level of this debug
65*0Sstevel@tonic-gate 	**  object.  Level 0 means no debug activity.
66*0Sstevel@tonic-gate 	**  It is initialized to SM_DEBUG_UNKNOWN, which indicates
67*0Sstevel@tonic-gate 	**  that the true value is unknown.  If debug_level ==
68*0Sstevel@tonic-gate 	**  SM_DEBUG_UNKNOWN, then the access functions will look up
69*0Sstevel@tonic-gate 	**  its true value in the internal table of debug settings.
70*0Sstevel@tonic-gate 	*/
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate 	SM_ATOMIC_UINT_T debug_level;
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate 	/*
75*0Sstevel@tonic-gate 	**  debug_name is the name used to reference this SM_DEBUG
76*0Sstevel@tonic-gate 	**  structure via the sendmail -d option.
77*0Sstevel@tonic-gate 	*/
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate 	char *debug_name;
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate 	/*
82*0Sstevel@tonic-gate 	**  debug_desc is a literal character string of the form
83*0Sstevel@tonic-gate 	**  "@(#)$Debug: <name> - <short description> $"
84*0Sstevel@tonic-gate 	*/
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate 	char *debug_desc;
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate 	/*
89*0Sstevel@tonic-gate 	**  We keep a linked list of initialized SM_DEBUG structures
90*0Sstevel@tonic-gate 	**  so that when sm_debug_addsetting is called, we can reset
91*0Sstevel@tonic-gate 	**  them all back to the uninitialized state.
92*0Sstevel@tonic-gate 	*/
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate 	SM_DEBUG_T *debug_next;
95*0Sstevel@tonic-gate };
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate # ifndef SM_DEBUG_CHECK
98*0Sstevel@tonic-gate #  define SM_DEBUG_CHECK 1
99*0Sstevel@tonic-gate # endif /* ! SM_DEBUG_CHECK */
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate # if SM_DEBUG_CHECK
102*0Sstevel@tonic-gate /*
103*0Sstevel@tonic-gate **  This macro is cleverly designed so that if the debug object is below
104*0Sstevel@tonic-gate **  the specified level, then the only overhead is a single comparison
105*0Sstevel@tonic-gate **  (except for the first time this macro is invoked).
106*0Sstevel@tonic-gate */
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate #  define sm_debug_active(debug, level) \
109*0Sstevel@tonic-gate 	    ((debug)->debug_level >= (level) && \
110*0Sstevel@tonic-gate 	     ((debug)->debug_level != SM_DEBUG_UNKNOWN || \
111*0Sstevel@tonic-gate 	      sm_debug_loadactive(debug, level)))
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate #  define sm_debug_level(debug) \
114*0Sstevel@tonic-gate 	    ((debug)->debug_level == SM_DEBUG_UNKNOWN \
115*0Sstevel@tonic-gate 	     ? sm_debug_loadlevel(debug) : (debug)->debug_level)
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate #  define sm_debug_unknown(debug) ((debug)->debug_level == SM_DEBUG_UNKNOWN)
118*0Sstevel@tonic-gate # else /* SM_DEBUG_CHECK */
119*0Sstevel@tonic-gate #  define sm_debug_active(debug, level)	0
120*0Sstevel@tonic-gate #  define sm_debug_level(debug)		0
121*0Sstevel@tonic-gate #  define sm_debug_unknown(debug)	0
122*0Sstevel@tonic-gate # endif /* SM_DEBUG_CHECK */
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate extern bool
125*0Sstevel@tonic-gate sm_debug_loadactive __P((SM_DEBUG_T *, int));
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate extern int
128*0Sstevel@tonic-gate sm_debug_loadlevel __P((SM_DEBUG_T *));
129*0Sstevel@tonic-gate 
130*0Sstevel@tonic-gate # define SM_DEBUG_INITIALIZER(name, desc) { \
131*0Sstevel@tonic-gate 		SmDebugMagic, \
132*0Sstevel@tonic-gate 		SM_DEBUG_UNKNOWN, \
133*0Sstevel@tonic-gate 		name, \
134*0Sstevel@tonic-gate 		desc, \
135*0Sstevel@tonic-gate 		NULL}
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate #endif /* ! SM_DEBUG_H */
138