]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/syslog.h
xnu-201.5.tar.gz
[apple/xnu.git] / bsd / sys / syslog.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
23 /*
24 * Copyright (c) 1982, 1986, 1988, 1993
25 * The Regents of the University of California. All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * @(#)syslog.h 8.1 (Berkeley) 6/2/93
56 */
57
58 #ifndef _SYS_SYSLOG_H_
59 #define _SYS_SYSLOG_H_
60
61 #define _PATH_LOG "/var/run/syslog"
62
63 /*
64 * priorities/facilities are encoded into a single 32-bit quantity, where the
65 * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
66 * (0-big number). Both the priorities and the facilities map roughly
67 * one-to-one to strings in the syslogd(8) source code. This mapping is
68 * included in this file.
69 *
70 * priorities (these are ordered)
71 */
72 #define LOG_EMERG 0 /* system is unusable */
73 #define LOG_ALERT 1 /* action must be taken immediately */
74 #define LOG_CRIT 2 /* critical conditions */
75 #define LOG_ERR 3 /* error conditions */
76 #define LOG_WARNING 4 /* warning conditions */
77 #define LOG_NOTICE 5 /* normal but significant condition */
78 #define LOG_INFO 6 /* informational */
79 #define LOG_DEBUG 7 /* debug-level messages */
80
81 #define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */
82 /* extract priority */
83 #define LOG_PRI(p) ((p) & LOG_PRIMASK)
84 #define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
85
86 #ifdef SYSLOG_NAMES
87 #define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
88 /* mark "facility" */
89 #define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0)
90 typedef struct _code {
91 char *c_name;
92 int c_val;
93 } CODE;
94
95 CODE prioritynames[] = {
96 "alert", LOG_ALERT,
97 "crit", LOG_CRIT,
98 "debug", LOG_DEBUG,
99 "emerg", LOG_EMERG,
100 "err", LOG_ERR,
101 "error", LOG_ERR, /* DEPRECATED */
102 "info", LOG_INFO,
103 "none", INTERNAL_NOPRI, /* INTERNAL */
104 "notice", LOG_NOTICE,
105 "panic", LOG_EMERG, /* DEPRECATED */
106 "warn", LOG_WARNING, /* DEPRECATED */
107 "warning", LOG_WARNING,
108 NULL, -1,
109 };
110 #endif
111
112 /* facility codes */
113 #define LOG_KERN (0<<3) /* kernel messages */
114 #define LOG_USER (1<<3) /* random user-level messages */
115 #define LOG_MAIL (2<<3) /* mail system */
116 #define LOG_DAEMON (3<<3) /* system daemons */
117 #define LOG_AUTH (4<<3) /* security/authorization messages */
118 #define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */
119 #define LOG_LPR (6<<3) /* line printer subsystem */
120 #define LOG_NEWS (7<<3) /* network news subsystem */
121 #define LOG_UUCP (8<<3) /* UUCP subsystem */
122 #define LOG_CRON (9<<3) /* clock daemon */
123 #define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */
124 #define LOG_FTP (11<<3) /* ftp daemon */
125 #define LOG_NETINFO (12<<3) /* NetInfo */
126 #define LOG_REMOTEAUTH (13<<3) /* remote authentication/authorization */
127
128 /* other codes through 15 reserved for system use */
129 #define LOG_LOCAL0 (16<<3) /* reserved for local use */
130 #define LOG_LOCAL1 (17<<3) /* reserved for local use */
131 #define LOG_LOCAL2 (18<<3) /* reserved for local use */
132 #define LOG_LOCAL3 (19<<3) /* reserved for local use */
133 #define LOG_LOCAL4 (20<<3) /* reserved for local use */
134 #define LOG_LOCAL5 (21<<3) /* reserved for local use */
135 #define LOG_LOCAL6 (22<<3) /* reserved for local use */
136 #define LOG_LOCAL7 (23<<3) /* reserved for local use */
137
138 #define LOG_NFACILITIES 24 /* current number of facilities */
139 #define LOG_FACMASK 0x03f8 /* mask to extract facility part */
140 /* facility of pri */
141 #define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3)
142
143 #ifdef SYSLOG_NAMES
144 CODE facilitynames[] = {
145 "auth", LOG_AUTH,
146 "authpriv", LOG_AUTHPRIV,
147 "cron", LOG_CRON,
148 "daemon", LOG_DAEMON,
149 "ftp", LOG_FTP,
150 "kern", LOG_KERN,
151 "lpr", LOG_LPR,
152 "mail", LOG_MAIL,
153 "mark", INTERNAL_MARK, /* INTERNAL */
154 "netinfo", LOG_NETINFO,
155 "remoteauth", LOG_REMOTEAUTH,
156 "news", LOG_NEWS,
157 "security", LOG_AUTH, /* DEPRECATED */
158 "syslog", LOG_SYSLOG,
159 "user", LOG_USER,
160 "uucp", LOG_UUCP,
161 "local0", LOG_LOCAL0,
162 "local1", LOG_LOCAL1,
163 "local2", LOG_LOCAL2,
164 "local3", LOG_LOCAL3,
165 "local4", LOG_LOCAL4,
166 "local5", LOG_LOCAL5,
167 "local6", LOG_LOCAL6,
168 "local7", LOG_LOCAL7,
169 NULL, -1,
170 };
171 #endif
172
173 #ifdef KERNEL
174 #define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */
175 #endif
176
177 /*
178 * arguments to setlogmask.
179 */
180 #define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */
181 #define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */
182
183 /*
184 * Option flags for openlog.
185 *
186 * LOG_ODELAY no longer does anything.
187 * LOG_NDELAY is the inverse of what it used to be.
188 */
189 #define LOG_PID 0x01 /* log the pid with each message */
190 #define LOG_CONS 0x02 /* log on the console if errors in sending */
191 #define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */
192 #define LOG_NDELAY 0x08 /* don't delay open */
193 #define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */
194 #define LOG_PERROR 0x20 /* log to stderr as well */
195
196 #include <sys/cdefs.h>
197
198 #ifndef KERNEL
199
200 /*
201 * Don't use va_list in the vsyslog() prototype. Va_list is typedef'd in two
202 * places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one
203 * of them here we may collide with the utility's includes. It's unreasonable
204 * for utilities to have to include one of them to include syslog.h, so we get
205 * _BSD_VA_LIST_ from <machine/ansi.h> and use it.
206 */
207 #include <machine/ansi.h>
208
209 __BEGIN_DECLS
210 void closelog __P((void));
211 void openlog __P((const char *, int, int));
212 int setlogmask __P((int));
213 void syslog __P((int, const char *, ...));
214 void vsyslog __P((int, const char *, _BSD_VA_LIST_));
215 __END_DECLS
216
217 #else /* !KERNEL */
218
219 /*
220 * bit field descriptions for printf %r and %R formats
221 */
222
223 /*
224 * printf("%r %R", val, reg_descp);
225 * struct reg_desc *reg_descp;
226 *
227 * the %r and %R formats allow formatted output of bit fields.
228 * reg_descp points to an array of reg_desc structures, each element of the
229 * array describes a range of bits within val. the array should have a
230 * final element with all structure elements 0.
231 * %r outputs a string of the format "<bit field descriptions>"
232 * %R outputs a string of the format "0x%x<bit field descriptions>"
233 *
234 * The fields in a reg_desc are:
235 * unsigned rd_mask; An appropriate mask to isolate the bit field
236 * within a word, and'ed with val
237 *
238 * int rd_shift; A shift amount to be done to the isolated
239 * bit field. done before printing the isolate
240 * bit field with rd_format and before searching
241 * for symbolic value names in rd_values
242 *
243 * char *rd_name; If non-null, a bit field name to label any
244 * out from rd_format or searching rd_values.
245 * if neither rd_format or rd_values is non-null
246 * rd_name is printed only if the isolated
247 * bit field is non-null.
248 *
249 * char *rd_format; If non-null, the shifted bit field value
250 * is printed using this format.
251 *
252 * struct reg_values *rd_values; If non-null, a pointer to a table
253 * matching numeric values with symbolic names.
254 * rd_values are searched and the symbolic
255 * value is printed if a match is found, if no
256 * match is found "???" is printed.
257 *
258 * printf("%n %N", val, reg_valuesp);
259 * struct reg_values *reg_valuesp;
260 *
261 * the %n and %N formats allow formatted output of symbolic constants
262 * Reg_valuesp is a pointer to an array of struct reg_values which pairs
263 * numeric values (rv_value) with symbolic names (rv_name). The array is
264 * terminated with a reg_values entry that has a null pointer for the
265 * rv_name field. When %n or %N is used rd_values are searched and the
266 * symbolic value is printed if a match is found, if no match is found
267 * "???" is printed.
268 *
269 * printf("%C", val);
270 * int val;
271 *
272 * the %C format prints an int as a 4 character string.
273 * The most significant byte of the int is printed first, the least
274 * significant byte is printed last.
275 */
276
277 /*
278 * register values
279 * map between numeric values and symbolic values
280 */
281 struct reg_values {
282 unsigned rv_value;
283 char *rv_name;
284 };
285
286 /*
287 * register descriptors are used for formatted prints of register values
288 * rd_mask and rd_shift must be defined, other entries may be null
289 */
290 struct reg_desc {
291 unsigned rd_mask; /* mask to extract field */
292 int rd_shift; /* shift for extracted value, - >>, + << */
293 char *rd_name; /* field name */
294 char *rd_format; /* format to print field */
295 struct reg_values *rd_values; /* symbolic names of values */
296 };
297
298 void logpri __P((int));
299 void log __P((int, const char *, ...));
300 void addlog __P((const char *, ...));
301
302 #endif /* !KERNEL */
303 #endif /* !_SYS_SYSLOG_H_ */