]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/gen/syslog.3
Merge bmake-20200517
[FreeBSD/FreeBSD.git] / lib / libc / gen / syslog.3
1 .\" Copyright (c) 1985, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)syslog.3    8.1 (Berkeley) 6/4/93
29 .\" $FreeBSD$
30 .\"
31 .Dd November 25, 2018
32 .Dt SYSLOG 3
33 .Os
34 .Sh NAME
35 .Nm syslog ,
36 .Nm vsyslog ,
37 .Nm openlog ,
38 .Nm closelog ,
39 .Nm setlogmask
40 .Nd control system log
41 .Sh LIBRARY
42 .Lb libc
43 .Sh SYNOPSIS
44 .In syslog.h
45 .Ft void
46 .Fn syslog "int priority" "const char *message" "..."
47 .Ft void
48 .Fn openlog "const char *ident" "int logopt" "int facility"
49 .Ft void
50 .Fn closelog void
51 .Ft int
52 .Fn setlogmask "int maskpri"
53 .In syslog.h
54 .In stdarg.h
55 .Ft void
56 .Fn vsyslog "int priority" "const char *message" "va_list args"
57 .Sh DESCRIPTION
58 The
59 .Fn syslog
60 function
61 writes
62 .Fa message
63 to the system message logger.
64 The message is then written to the system console, log files,
65 logged-in users, or forwarded to other machines as appropriate.
66 (See
67 .Xr syslogd 8 . )
68 .Pp
69 The message is identical to a
70 .Xr printf 3
71 format string, except that
72 .Ql %m
73 is replaced by the current error
74 message.
75 (As denoted by the global variable
76 .Va errno ;
77 see
78 .Xr strerror 3 . )
79 A trailing newline is added if none is present.
80 .Pp
81 The
82 .Fn vsyslog
83 function
84 is an alternate form in which the arguments have already been captured
85 using the variable-length argument facilities of
86 .Xr stdarg 3 .
87 .Pp
88 The message is tagged with
89 .Fa priority .
90 Priorities are encoded as a
91 .Fa facility
92 and a
93 .Em level .
94 The facility describes the part of the system
95 generating the message.
96 The level is selected from the following
97 .Em ordered
98 (high to low) list:
99 .Bl -tag -width LOG_AUTHPRIV
100 .It Dv LOG_EMERG
101 A panic condition.
102 This is normally broadcast to all users.
103 .It Dv LOG_ALERT
104 A condition that should be corrected immediately, such as a corrupted
105 system database.
106 .It Dv LOG_CRIT
107 Critical conditions, e.g., hard device errors.
108 .It Dv LOG_ERR
109 Errors.
110 .It Dv LOG_WARNING
111 Warning messages.
112 .It Dv LOG_NOTICE
113 Conditions that are not error conditions,
114 but should possibly be handled specially.
115 .It Dv LOG_INFO
116 Informational messages.
117 .It Dv LOG_DEBUG
118 Messages that contain information
119 normally of use only when debugging a program.
120 .El
121 .Pp
122 The
123 .Fn openlog
124 function
125 provides for more specialized processing of the messages sent
126 by
127 .Fn syslog
128 and
129 .Fn vsyslog .
130 The
131 .Fa ident
132 argument
133 is a string that will be prepended to every message.
134 The
135 .Fa logopt
136 argument
137 is a bit field specifying logging options, which is formed by
138 .Tn OR Ns 'ing
139 one or more of the following values:
140 .Bl -tag -width LOG_AUTHPRIV
141 .It Dv LOG_CONS
142 If
143 .Fn syslog
144 cannot pass the message to
145 .Xr syslogd 8
146 it will attempt to write the message to the console
147 .Pq Dq Pa /dev/console .
148 .It Dv LOG_NDELAY
149 Open the connection to
150 .Xr syslogd 8
151 immediately.
152 Normally the open is delayed until the first message is logged.
153 Useful for programs that need to manage the order in which file
154 descriptors are allocated.
155 .It Dv LOG_PERROR
156 Write the message to standard error output as well to the system log.
157 .It Dv LOG_PID
158 Log the process id with each message: useful for identifying
159 instantiations of daemons.
160 On
161 .Fx ,
162 this option is enabled by default.
163 .El
164 .Pp
165 The
166 .Fa facility
167 argument encodes a default facility to be assigned to all messages
168 that do not have an explicit facility encoded:
169 .Bl -tag -width LOG_AUTHPRIV
170 .It Dv LOG_AUTH
171 The authorization system:
172 .Xr login 1 ,
173 .Xr su 1 ,
174 .Xr getty 8 ,
175 etc.
176 .It Dv LOG_AUTHPRIV
177 The same as
178 .Dv LOG_AUTH ,
179 but logged to a file readable only by
180 selected individuals.
181 .It Dv LOG_CONSOLE
182 Messages written to
183 .Pa /dev/console
184 by the kernel console output driver.
185 .It Dv LOG_CRON
186 The cron daemon:
187 .Xr cron 8 .
188 .It Dv LOG_DAEMON
189 System daemons, such as
190 .Xr routed 8 ,
191 that are not provided for explicitly by other facilities.
192 .It Dv LOG_FTP
193 The file transfer protocol daemons:
194 .Xr ftpd 8 ,
195 .Xr tftpd 8 .
196 .It Dv LOG_KERN
197 Messages generated by the kernel.
198 These cannot be generated by any user processes.
199 .It Dv LOG_LPR
200 The line printer spooling system:
201 .Xr lpr 1 ,
202 .Xr lpc 8 ,
203 .Xr lpd 8 ,
204 etc.
205 .It Dv LOG_MAIL
206 The mail system.
207 .It Dv LOG_NEWS
208 The network news system.
209 .It Dv LOG_NTP
210 The network time protocol system.
211 .It Dv LOG_SECURITY
212 Security subsystems, such as
213 .Xr ipfw 4 .
214 .It Dv LOG_SYSLOG
215 Messages generated internally by
216 .Xr syslogd 8 .
217 .It Dv LOG_USER
218 Messages generated by random user processes.
219 This is the default facility identifier if none is specified.
220 .It Dv LOG_UUCP
221 The uucp system.
222 .It Dv LOG_LOCAL0
223 Reserved for local use.
224 Similarly for
225 .Dv LOG_LOCAL1
226 through
227 .Dv LOG_LOCAL7 .
228 .El
229 .Pp
230 The
231 .Fn closelog
232 function
233 can be used to close the log file.
234 .Pp
235 The
236 .Fn setlogmask
237 function
238 sets the log priority mask to
239 .Fa maskpri
240 and returns the previous mask.
241 Calls to
242 .Fn syslog
243 with a priority not set in
244 .Fa maskpri
245 are rejected.
246 The mask for an individual priority
247 .Fa pri
248 is calculated by the macro
249 .Fn LOG_MASK pri ;
250 the mask for all priorities up to and including
251 .Fa toppri
252 is given by the macro
253 .Fn LOG_UPTO toppri ; .
254 The default allows all priorities to be logged.
255 .Sh RETURN VALUES
256 The routines
257 .Fn closelog ,
258 .Fn openlog ,
259 .Fn syslog
260 and
261 .Fn vsyslog
262 return no value.
263 .Pp
264 The routine
265 .Fn setlogmask
266 always returns the previous log mask level.
267 .Sh EXAMPLES
268 .Bd -literal -offset indent -compact
269 syslog(LOG_ALERT, "who: internal error 23");
270
271 openlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
272
273 setlogmask(LOG_UPTO(LOG_ERR));
274
275 syslog(LOG_INFO, "Connection from host %d", CallingHost);
276
277 syslog(LOG_ERR|LOG_LOCAL2, "foobar error: %m");
278 .Ed
279 .Sh SEE ALSO
280 .Xr logger 1 ,
281 .Xr syslogd 8
282 .Sh HISTORY
283 These
284 functions appeared in
285 .Bx 4.2 .
286 .Sh BUGS
287 Never pass a string with user-supplied data as a format without using
288 .Ql %s .
289 An attacker can put format specifiers in the string to mangle your stack,
290 leading to a possible security hole.
291 This holds true even if the string was built using a function like
292 .Fn snprintf ,
293 as the resulting string may still contain user-supplied conversion specifiers
294 for later interpolation by
295 .Fn syslog .
296 .Pp
297 Always use the proper secure idiom:
298 .Pp
299 .Dl syslog(priority, \*q%s\*q, string);