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