xref: /illumos-gate/usr/src/uts/common/sys/strlog.h (revision b4203d75)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #ifndef _SYS_STRLOG_H
32*7c478bd9Sstevel@tonic-gate #define	_SYS_STRLOG_H
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/types32.h>
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
38*7c478bd9Sstevel@tonic-gate extern "C" {
39*7c478bd9Sstevel@tonic-gate #endif
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate /*
42*7c478bd9Sstevel@tonic-gate  * Streams Log Driver Interface Definitions
43*7c478bd9Sstevel@tonic-gate  */
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  * structure of control portion of log message
47*7c478bd9Sstevel@tonic-gate  */
48*7c478bd9Sstevel@tonic-gate typedef struct log_ctl {
49*7c478bd9Sstevel@tonic-gate 	short	mid;
50*7c478bd9Sstevel@tonic-gate 	short	sid;
51*7c478bd9Sstevel@tonic-gate 	char 	level;		/* level of message for tracing */
52*7c478bd9Sstevel@tonic-gate 	short	flags;		/* message disposition */
53*7c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_I32LPx)
54*7c478bd9Sstevel@tonic-gate 	clock32_t ltime;	/* time in machine ticks since boot */
55*7c478bd9Sstevel@tonic-gate 	time32_t ttime;		/* time in seconds since 1970 */
56*7c478bd9Sstevel@tonic-gate #else
57*7c478bd9Sstevel@tonic-gate 	clock_t	ltime;
58*7c478bd9Sstevel@tonic-gate 	time_t	ttime;
59*7c478bd9Sstevel@tonic-gate #endif
60*7c478bd9Sstevel@tonic-gate 	int	seq_no;		/* sequence number */
61*7c478bd9Sstevel@tonic-gate 	int	pri;		/* priority = (facility|level) */
62*7c478bd9Sstevel@tonic-gate } log_ctl_t;
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate /*
65*7c478bd9Sstevel@tonic-gate  * Public flags for log messages
66*7c478bd9Sstevel@tonic-gate  */
67*7c478bd9Sstevel@tonic-gate #define	SL_FATAL	0x01	/* indicates fatal error */
68*7c478bd9Sstevel@tonic-gate #define	SL_NOTIFY	0x02	/* logger must notify administrator */
69*7c478bd9Sstevel@tonic-gate #define	SL_ERROR	0x04	/* include on the error log */
70*7c478bd9Sstevel@tonic-gate #define	SL_TRACE	0x08	/* include on the trace log */
71*7c478bd9Sstevel@tonic-gate #define	SL_CONSOLE	0x10	/* include on the console log */
72*7c478bd9Sstevel@tonic-gate #define	SL_WARN		0x20	/* warning message */
73*7c478bd9Sstevel@tonic-gate #define	SL_NOTE		0x40	/* notice message */
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate /*
76*7c478bd9Sstevel@tonic-gate  * Private flags for log messages -- used by internal implementation only
77*7c478bd9Sstevel@tonic-gate  */
78*7c478bd9Sstevel@tonic-gate #define	SL_CONSONLY	0x1000	/* send message only to /dev/console */
79*7c478bd9Sstevel@tonic-gate #define	SL_LOGONLY	0x2000	/* send message only to /var/adm/messages */
80*7c478bd9Sstevel@tonic-gate #define	SL_USER		0x4000	/* send message to user's terminal */
81*7c478bd9Sstevel@tonic-gate #define	SL_PANICMSG	0x8000	/* message was created while panicking */
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate /*
84*7c478bd9Sstevel@tonic-gate  * Structure defining ids and levels desired by the tracer (I_TRCLOG).
85*7c478bd9Sstevel@tonic-gate  */
86*7c478bd9Sstevel@tonic-gate typedef struct trace_ids {
87*7c478bd9Sstevel@tonic-gate 	short	ti_mid;
88*7c478bd9Sstevel@tonic-gate 	short	ti_sid;
89*7c478bd9Sstevel@tonic-gate 	int8_t	ti_level;
90*7c478bd9Sstevel@tonic-gate } trace_ids_t;
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate /*
93*7c478bd9Sstevel@tonic-gate  * Log Driver I_STR ioctl commands
94*7c478bd9Sstevel@tonic-gate  */
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate #define	LOGCTL		(('L')<<8)
97*7c478bd9Sstevel@tonic-gate #define	I_TRCLOG	(LOGCTL|1)	/* process is tracer */
98*7c478bd9Sstevel@tonic-gate #define	I_ERRLOG	(LOGCTL|2)	/* process is error logger */
99*7c478bd9Sstevel@tonic-gate #define	I_CONSLOG	(LOGCTL|3)	/* process is console logger */
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate #define	STRLOG_MAKE_MSGID(fmt, msgid)					\
102*7c478bd9Sstevel@tonic-gate {									\
103*7c478bd9Sstevel@tonic-gate 	uchar_t *__cp = (uchar_t *)fmt;					\
104*7c478bd9Sstevel@tonic-gate 	uchar_t __c;							\
105*7c478bd9Sstevel@tonic-gate 	uint32_t __id = 0;						\
106*7c478bd9Sstevel@tonic-gate 	while ((__c = *__cp++) != '\0')					\
107*7c478bd9Sstevel@tonic-gate 		if (__c >= ' ')						\
108*7c478bd9Sstevel@tonic-gate 			__id = (__id >> 5) + (__id << 27) + __c;	\
109*7c478bd9Sstevel@tonic-gate 	msgid = (__id % 899981) + 100000;				\
110*7c478bd9Sstevel@tonic-gate }
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate #ifndef _ASM
115*7c478bd9Sstevel@tonic-gate #include <sys/va_list.h>
116*7c478bd9Sstevel@tonic-gate #endif
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate /*PRINTFLIKE5*/
119*7c478bd9Sstevel@tonic-gate extern int strlog(short, short, char, unsigned short, char *, ...)
120*7c478bd9Sstevel@tonic-gate 	__KPRINTFLIKE(5);
121*7c478bd9Sstevel@tonic-gate extern int vstrlog(short, short, char, unsigned short, char *, __va_list)
122*7c478bd9Sstevel@tonic-gate 	__KVPRINTFLIKE(5);
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate /*
125*7c478bd9Sstevel@tonic-gate  * STRLOG(mid,sid,level,flags,fmt,args) should be used for those trace
126*7c478bd9Sstevel@tonic-gate  * calls that are only to be made during debugging.
127*7c478bd9Sstevel@tonic-gate  */
128*7c478bd9Sstevel@tonic-gate #if defined(DEBUG) || defined(__lint)
129*7c478bd9Sstevel@tonic-gate #define	STRLOG	strlog
130*7c478bd9Sstevel@tonic-gate #else
131*7c478bd9Sstevel@tonic-gate #define	STRLOG	0 && strlog
132*7c478bd9Sstevel@tonic-gate #endif	/* DEBUG || __lint */
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate #endif
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_STRLOG_H */
141