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