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