2003-08-07 20:42:00 +04:00
|
|
|
.\" $NetBSD: syslog.3,v 1.19 2003/08/07 16:42:57 agc Exp $
|
1995-02-27 08:50:11 +03:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1985, 1991, 1993
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
2003-08-07 20:42:00 +04:00
|
|
|
.\" 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
1995-02-27 08:50:11 +03:00
|
|
|
.\" @(#)syslog.3 8.1 (Berkeley) 6/4/93
|
1993-03-21 12:45:37 +03:00
|
|
|
.\"
|
2001-03-14 09:12:35 +03:00
|
|
|
.Dd March 14, 2001
|
1993-03-21 12:45:37 +03:00
|
|
|
.Dt SYSLOG 3
|
1999-03-22 22:44:33 +03:00
|
|
|
.Os
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh NAME
|
|
|
|
.Nm syslog ,
|
|
|
|
.Nm vsyslog ,
|
|
|
|
.Nm openlog ,
|
|
|
|
.Nm closelog ,
|
|
|
|
.Nm setlogmask
|
|
|
|
.Nd control system log
|
1998-02-05 21:45:17 +03:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In syslog.h
|
1993-03-21 12:45:37 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn syslog "int priority" "const char *message" "..."
|
|
|
|
.Ft void
|
|
|
|
.Fn openlog "const char *ident" "int logopt" "int facility"
|
|
|
|
.Ft void
|
|
|
|
.Fn closelog void
|
|
|
|
.Ft int
|
|
|
|
.Fn setlogmask "int maskpri"
|
2003-04-16 17:34:34 +04:00
|
|
|
.In stdarg.h
|
2001-03-14 09:12:35 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn vsyslog "int priority" "const char *message" "va_list args"
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn syslog
|
|
|
|
function
|
|
|
|
writes
|
|
|
|
.Fa message
|
|
|
|
to the system message logger.
|
|
|
|
The message is then written to the system console, log files,
|
1998-04-29 00:11:33 +04:00
|
|
|
logged-in users, or forwarded to other machines as appropriate (See
|
|
|
|
.Xr syslogd 8 ) .
|
1993-03-21 12:45:37 +03:00
|
|
|
.Pp
|
|
|
|
The message is identical to a
|
|
|
|
.Xr printf 3
|
|
|
|
format string, except that
|
|
|
|
.Ql %m
|
|
|
|
is replaced by the current error
|
2002-10-01 20:48:34 +04:00
|
|
|
message.
|
|
|
|
(As denoted by the global variable
|
1993-03-21 12:45:37 +03:00
|
|
|
.Va errno ;
|
|
|
|
see
|
|
|
|
.Xr strerror 3 . )
|
|
|
|
A trailing newline is added if none is present.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn vsyslog
|
|
|
|
function
|
1997-03-08 16:36:38 +03:00
|
|
|
is an alternative form in which the arguments have already been captured
|
1993-03-21 12:45:37 +03:00
|
|
|
using the variable-length argument facilities of
|
|
|
|
.Xr varargs 3 .
|
|
|
|
.Pp
|
|
|
|
The message is tagged with
|
|
|
|
.Fa priority .
|
|
|
|
Priorities are encoded as a
|
|
|
|
.Fa facility
|
|
|
|
and a
|
|
|
|
.Em level .
|
|
|
|
The facility describes the part of the system
|
|
|
|
generating the message.
|
|
|
|
The level is selected from the following
|
|
|
|
.Em ordered
|
|
|
|
(high to low) list:
|
|
|
|
.Bl -tag -width LOG_AUTHPRIV
|
|
|
|
.It Dv LOG_EMERG
|
|
|
|
A panic condition.
|
|
|
|
This is normally broadcast to all users.
|
|
|
|
.It Dv LOG_ALERT
|
|
|
|
A condition that should be corrected immediately, such as a corrupted
|
|
|
|
system database.
|
|
|
|
.It Dv LOG_CRIT
|
|
|
|
Critical conditions, e.g., hard device errors.
|
|
|
|
.It Dv LOG_ERR
|
|
|
|
Errors.
|
|
|
|
.It Dv LOG_WARNING
|
|
|
|
Warning messages.
|
|
|
|
.It Dv LOG_NOTICE
|
|
|
|
Conditions that are not error conditions,
|
|
|
|
but should possibly be handled specially.
|
|
|
|
.It Dv LOG_INFO
|
|
|
|
Informational messages.
|
|
|
|
.It Dv LOG_DEBUG
|
|
|
|
Messages that contain information
|
|
|
|
normally of use only when debugging a program.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn openlog
|
|
|
|
function
|
|
|
|
provides for more specialized processing of the messages sent
|
|
|
|
by
|
|
|
|
.Fn syslog
|
|
|
|
and
|
|
|
|
.Fn vsyslog .
|
|
|
|
The parameter
|
|
|
|
.Fa ident
|
|
|
|
is a string that will be prepended to every message.
|
|
|
|
The
|
|
|
|
.Fa logopt
|
|
|
|
argument
|
|
|
|
is a bit field specifying logging options, which is formed by
|
|
|
|
.Tn OR Ns 'ing
|
|
|
|
one or more of the following values:
|
|
|
|
.Bl -tag -width LOG_AUTHPRIV
|
|
|
|
.It Dv LOG_CONS
|
|
|
|
If
|
|
|
|
.Fn syslog
|
|
|
|
cannot pass the message to
|
1998-04-29 00:11:33 +04:00
|
|
|
.Xr syslogd 8
|
1993-03-21 12:45:37 +03:00
|
|
|
it will attempt to write the message to the console
|
2001-09-16 06:57:03 +04:00
|
|
|
.Pq Dq Pa /dev/console .
|
1998-04-29 00:11:33 +04:00
|
|
|
.It Dv LOG_NDELAY
|
1993-03-21 12:45:37 +03:00
|
|
|
Open the connection to
|
1998-04-29 00:11:33 +04:00
|
|
|
.Xr syslogd 8
|
1993-03-21 12:45:37 +03:00
|
|
|
immediately.
|
|
|
|
Normally the open is delayed until the first message is logged.
|
|
|
|
Useful for programs that need to manage the order in which file
|
|
|
|
descriptors are allocated.
|
|
|
|
.It Dv LOG_PERROR
|
|
|
|
Write the message to standard error output as well to the system log.
|
|
|
|
.It Dv LOG_PID
|
|
|
|
Log the process id with each message: useful for identifying
|
2003-05-06 12:28:38 +04:00
|
|
|
instantiations of daemons.
|
|
|
|
(This PID is placed within brackets
|
2003-05-02 12:26:46 +04:00
|
|
|
between the ident and the message.)
|
1993-03-21 12:45:37 +03:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fa facility
|
|
|
|
parameter encodes a default facility to be assigned to all messages
|
|
|
|
that do not have an explicit facility encoded:
|
|
|
|
.Bl -tag -width LOG_AUTHPRIV
|
|
|
|
.It Dv LOG_AUTH
|
|
|
|
The authorization system:
|
|
|
|
.Xr login 1 ,
|
|
|
|
.Xr su 1 ,
|
|
|
|
.Xr getty 8 ,
|
|
|
|
etc.
|
|
|
|
.It Dv LOG_AUTHPRIV
|
|
|
|
The same as
|
|
|
|
.Dv LOG_AUTH ,
|
|
|
|
but logged to a file readable only by
|
|
|
|
selected individuals.
|
|
|
|
.It Dv LOG_CRON
|
1995-08-11 04:34:34 +04:00
|
|
|
The cron daemon:
|
|
|
|
.Xr cron 8 .
|
1995-08-12 09:02:46 +04:00
|
|
|
.It Dv LOG_DAEMON
|
1993-03-21 12:45:37 +03:00
|
|
|
System daemons, such as
|
|
|
|
.Xr routed 8 ,
|
1995-02-27 08:50:11 +03:00
|
|
|
that are not provided for explicitly by other facilities.
|
1995-08-11 04:34:34 +04:00
|
|
|
.It Dv LOG_FTP
|
|
|
|
The file transfer protocol daemon:
|
|
|
|
.Xr ftpd 8 .
|
1993-03-21 12:45:37 +03:00
|
|
|
.It Dv LOG_KERN
|
|
|
|
Messages generated by the kernel.
|
|
|
|
These cannot be generated by any user processes.
|
|
|
|
.It Dv LOG_LPR
|
|
|
|
The line printer spooling system:
|
|
|
|
.Xr lpr 1 ,
|
|
|
|
.Xr lpc 8 ,
|
|
|
|
.Xr lpd 8 ,
|
|
|
|
etc.
|
|
|
|
.It Dv LOG_MAIL
|
|
|
|
The mail system.
|
|
|
|
.It Dv LOG_NEWS
|
|
|
|
The network news system.
|
|
|
|
.It Dv LOG_SYSLOG
|
|
|
|
Messages generated internally by
|
|
|
|
.Xr syslogd 8 .
|
|
|
|
.It Dv LOG_USER
|
|
|
|
Messages generated by random user processes.
|
|
|
|
This is the default facility identifier if none is specified.
|
|
|
|
.It Dv LOG_UUCP
|
|
|
|
The uucp system.
|
|
|
|
.It Dv LOG_LOCAL0
|
|
|
|
Reserved for local use.
|
|
|
|
Similarly for
|
|
|
|
.Dv LOG_LOCAL1
|
|
|
|
through
|
|
|
|
.Dv LOG_LOCAL7 .
|
1998-04-29 00:11:33 +04:00
|
|
|
.El
|
1993-03-21 12:45:37 +03:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn closelog
|
|
|
|
function
|
|
|
|
can be used to close the log file.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn setlogmask
|
|
|
|
function
|
|
|
|
sets the log priority mask to
|
|
|
|
.Fa maskpri
|
|
|
|
and returns the previous mask.
|
|
|
|
Calls to
|
|
|
|
.Fn syslog
|
|
|
|
with a priority not set in
|
|
|
|
.Fa maskpri
|
|
|
|
are rejected.
|
|
|
|
The mask for an individual priority
|
|
|
|
.Fa pri
|
|
|
|
is calculated by the macro
|
|
|
|
.Fn LOG_MASK pri ;
|
|
|
|
the mask for all priorities up to and including
|
|
|
|
.Fa toppri
|
|
|
|
is given by the macro
|
2003-05-01 17:58:03 +04:00
|
|
|
.Fn LOG_UPTO toppri .
|
1993-03-21 12:45:37 +03:00
|
|
|
The default allows all priorities to be logged.
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
The routines
|
|
|
|
.Fn closelog ,
|
|
|
|
.Fn openlog ,
|
|
|
|
.Fn syslog
|
|
|
|
and
|
|
|
|
.Fn vsyslog
|
|
|
|
return no value.
|
|
|
|
.Pp
|
|
|
|
The routine
|
|
|
|
.Fn setlogmask
|
|
|
|
always returns the previous log mask level.
|
|
|
|
.Sh EXAMPLES
|
|
|
|
.Bd -literal -offset indent -compact
|
|
|
|
syslog(LOG_ALERT, "who: internal error 23");
|
|
|
|
|
1995-08-11 04:34:34 +04:00
|
|
|
openlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
setlogmask(LOG_UPTO(LOG_ERR));
|
1995-08-11 04:34:34 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
syslog(LOG_INFO, "Connection from host %d", CallingHost);
|
|
|
|
|
|
|
|
syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
|
|
|
|
.Ed
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr logger 1 ,
|
|
|
|
.Xr syslogd 8
|
|
|
|
.Sh HISTORY
|
|
|
|
These
|
1998-04-29 00:11:33 +04:00
|
|
|
functions appeared in
|
1993-03-21 12:45:37 +03:00
|
|
|
.Bx 4.2 .
|
2002-07-10 18:37:12 +04:00
|
|
|
.Sh CAVEATS
|
|
|
|
It is important never to pass a string with user-supplied data as a
|
|
|
|
format without using
|
|
|
|
.Ql %s .
|
|
|
|
An attacker can put format specifiers in the string to mangle your stack,
|
|
|
|
leading to a possible security hole.
|
|
|
|
This holds true even if you have built the string
|
|
|
|
.Dq by hand
|
|
|
|
using a function like
|
|
|
|
.Fn snprintf ,
|
|
|
|
as the resulting string may still contain user-supplied conversion specifiers
|
|
|
|
for later interpolation by
|
|
|
|
.Fn syslog .
|
|
|
|
.Pp
|
|
|
|
Always be sure to use the proper secure idiom:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
syslog(priority, "%s", string);
|
|
|
|
.Ed
|