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