xref: /minix3/lib/libc/gen/syslog.3 (revision f14fb602092e015ff630df58e17c2a9cd57d29b3)
1*f14fb602SLionel Sambuc.\"	$NetBSD: syslog.3,v 1.29 2011/07/25 19:42:50 njoly Exp $
22fe8fb19SBen Gras.\"	$OpenBSD: syslog.3,v 1.25 2005/07/22 03:16:58 jaredy Exp $
32fe8fb19SBen Gras.\"
42fe8fb19SBen Gras.\" Copyright (c) 1985, 1991, 1993
52fe8fb19SBen Gras.\"	The Regents of the University of California.  All rights reserved.
62fe8fb19SBen Gras.\"
72fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
82fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
92fe8fb19SBen Gras.\" are met:
102fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
112fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
122fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
132fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
142fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
152fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors
162fe8fb19SBen Gras.\"    may be used to endorse or promote products derived from this software
172fe8fb19SBen Gras.\"    without specific prior written permission.
182fe8fb19SBen Gras.\"
192fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
202fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
212fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
222fe8fb19SBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
232fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
242fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
252fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
262fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
272fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
282fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
292fe8fb19SBen Gras.\" SUCH DAMAGE.
302fe8fb19SBen Gras.\"
312fe8fb19SBen Gras.\"     @(#)syslog.3	8.1 (Berkeley) 6/4/93
322fe8fb19SBen Gras.\"
332fe8fb19SBen Gras.Dd May 3, 2010
342fe8fb19SBen Gras.Dt SYSLOG 3
352fe8fb19SBen Gras.Os
362fe8fb19SBen Gras.Sh NAME
372fe8fb19SBen Gras.Nm syslog ,
382fe8fb19SBen Gras.Nm syslog_r ,
392fe8fb19SBen Gras.Nm vsyslog ,
402fe8fb19SBen Gras.Nm vsyslog_r ,
412fe8fb19SBen Gras.Nm syslogp ,
422fe8fb19SBen Gras.Nm syslogp_r ,
432fe8fb19SBen Gras.Nm vsyslogp ,
442fe8fb19SBen Gras.Nm vsyslogp_r ,
452fe8fb19SBen Gras.Nm openlog ,
462fe8fb19SBen Gras.Nm openlog_r ,
472fe8fb19SBen Gras.Nm closelog ,
482fe8fb19SBen Gras.Nm closelog_r ,
492fe8fb19SBen Gras.Nm setlogmask ,
502fe8fb19SBen Gras.Nm setlogmask_r
512fe8fb19SBen Gras.Nd control system log
522fe8fb19SBen Gras.Sh LIBRARY
532fe8fb19SBen Gras.Lb libc
542fe8fb19SBen Gras.Sh SYNOPSIS
552fe8fb19SBen Gras.In syslog.h
562fe8fb19SBen Gras.Ft void
572fe8fb19SBen Gras.Fn syslog "int priority" "const char *message" "..."
582fe8fb19SBen Gras.Ft void
592fe8fb19SBen Gras.Fn syslog_r "int priority" "struct syslog_data *data" "const char *message" "..."
602fe8fb19SBen Gras.Ft void
612fe8fb19SBen Gras.Fn syslogp "int priority" "const char *msgid" "const char *sdfmt" "const char *message" "..."
622fe8fb19SBen Gras.Ft void
632fe8fb19SBen Gras.Fn syslogp_r "int priority" "struct syslog_data *data" "const char *msgid" "const char *sdfmt" "const char *message" "..."
642fe8fb19SBen Gras.\" .Ft void
652fe8fb19SBen Gras.\" .Fn syslog_ss "int priority" "struct syslog_data *data" "const char *message" "..."
662fe8fb19SBen Gras.Ft void
672fe8fb19SBen Gras.Fn openlog "const char *ident" "int logopt" "int facility"
682fe8fb19SBen Gras.Ft void
692fe8fb19SBen Gras.Fn openlog_r "const char *ident" "int logopt" "int facility" "struct syslog_data *data"
702fe8fb19SBen Gras.Ft void
712fe8fb19SBen Gras.Fn closelog void
722fe8fb19SBen Gras.Ft void
732fe8fb19SBen Gras.Fn closelog_r "struct syslog_data *data"
742fe8fb19SBen Gras.Ft int
752fe8fb19SBen Gras.Fn setlogmask "int maskpri"
762fe8fb19SBen Gras.Ft int
772fe8fb19SBen Gras.Fn setlogmask_r "int maskpri" "struct syslog_data *data"
782fe8fb19SBen Gras.In stdarg.h
792fe8fb19SBen Gras.Ft void
802fe8fb19SBen Gras.Fn vsyslog "int priority" "const char *message" "va_list args"
812fe8fb19SBen Gras.Ft void
822fe8fb19SBen Gras.Fn vsyslog_r "int priority" "struct syslog_data *data" "const char *message" "va_list args"
832fe8fb19SBen Gras.Ft void
842fe8fb19SBen Gras.Fn vsyslogp "int priority" "const char *msgid" "const char *sdfmt" "const char *message" "va_list args"
852fe8fb19SBen Gras.Ft void
862fe8fb19SBen Gras.Fn vsyslogp_r "int priority" "struct syslog_data *data" "const char *msgid" "const char *sdfmt" "const char *message" "va_list args"
872fe8fb19SBen Gras.\" .Ft void
882fe8fb19SBen Gras.\" .Fn vsyslog_ss "int priority" "struct syslog_data *data" "const char *message" "va_list args"
892fe8fb19SBen Gras.Sh DESCRIPTION
902fe8fb19SBen GrasThe
912fe8fb19SBen Gras.Fn syslog
922fe8fb19SBen Grasfunction
932fe8fb19SBen Graswrites
942fe8fb19SBen Gras.Fa message
952fe8fb19SBen Grasto the system message logger.
962fe8fb19SBen GrasThe message is then written to the system console, log files,
972fe8fb19SBen Graslogged-in users, or forwarded to other machines as appropriate (see
982fe8fb19SBen Gras.Xr syslogd 8 ) .
992fe8fb19SBen Gras.Pp
1002fe8fb19SBen GrasThe message is identical to a
1012fe8fb19SBen Gras.Xr printf 3
1022fe8fb19SBen Grasformat string, except that
1032fe8fb19SBen Gras.Ql %m
1042fe8fb19SBen Grasis replaced by the current error
1052fe8fb19SBen Grasmessage.
1062fe8fb19SBen Gras(As denoted by the global variable
1072fe8fb19SBen Gras.Va errno ;
1082fe8fb19SBen Grassee
1092fe8fb19SBen Gras.Xr strerror 3 . )
1102fe8fb19SBen GrasA trailing newline is added if none is present.
1112fe8fb19SBen Gras.\" shouldn't the newline statement be removed?
1122fe8fb19SBen Gras.\" when logging through a socket a newline is
1132fe8fb19SBen Gras.\" not added nor is it required. -- ms
1142fe8fb19SBen Gras.Pp
1152fe8fb19SBen GrasThe
1162fe8fb19SBen Gras.Fn syslog_r
1172fe8fb19SBen Grasfunction is a multithread-safe version of the
1182fe8fb19SBen Gras.Fn syslog
1192fe8fb19SBen Grasfunction.
1202fe8fb19SBen GrasIt takes a pointer to a
1212fe8fb19SBen Gras.Fa syslog_data
1222fe8fb19SBen Grasstructure which is used to store
1232fe8fb19SBen Grasinformation.
1242fe8fb19SBen GrasThis parameter must be initialized before
1252fe8fb19SBen Gras.Fn syslog_r
1262fe8fb19SBen Grasis called.
1272fe8fb19SBen GrasThe
1282fe8fb19SBen Gras.Dv SYSLOG_DATA_INIT
1292fe8fb19SBen Grasconstant is used for this purpose.
1302fe8fb19SBen GrasThe
1312fe8fb19SBen Gras.Fa syslog_data
1322fe8fb19SBen Grasstructure and the
1332fe8fb19SBen Gras.Dv SYSLOG_DATA_INIT
1342fe8fb19SBen Grasconstant are defined as:
1352fe8fb19SBen Gras.Bd -literal -offset indent
1362fe8fb19SBen Grasstruct syslog_data {
1372fe8fb19SBen Gras        int             log_file;
1382fe8fb19SBen Gras        int             connected;
1392fe8fb19SBen Gras        int             opened;
1402fe8fb19SBen Gras        int             log_stat;
1412fe8fb19SBen Gras        const char     *log_tag;
1422fe8fb19SBen Gras        int             log_fac;
1432fe8fb19SBen Gras        int             log_mask;
1442fe8fb19SBen Gras};
1452fe8fb19SBen Gras
1462fe8fb19SBen Gras#define SYSLOG_DATA_INIT { \e
1472fe8fb19SBen Gras    .log_file = -1, \e
1482fe8fb19SBen Gras    .log_fac = LOG_USER, \e
1492fe8fb19SBen Gras    .log_mask = 0xff, \e
1502fe8fb19SBen Gras}
1512fe8fb19SBen Gras.Ed
1522fe8fb19SBen Gras.Pp
1532fe8fb19SBen GrasThe structure is composed of the following elements:
1542fe8fb19SBen Gras.Bl -tag -width connected -offset indent
1552fe8fb19SBen Gras.It Va log_file
1562fe8fb19SBen Grascontains the file descriptor of the file where the message is logged
1572fe8fb19SBen Gras.It Va connected
1582fe8fb19SBen Grasindicates if connect has been done
1592fe8fb19SBen Gras.It Va opened
1602fe8fb19SBen Grasindicates if
1612fe8fb19SBen Gras.Fn openlog_r
1622fe8fb19SBen Grashas been called
1632fe8fb19SBen Gras.It Va log_stat
1642fe8fb19SBen Grasstatus bits, set by
1652fe8fb19SBen Gras.Fn openlog_r
1662fe8fb19SBen Gras.It Va log_tag
1672fe8fb19SBen Grasstring to tag the entry with
1682fe8fb19SBen Gras.It Va log_fac
1692fe8fb19SBen Grasfacility code
1702fe8fb19SBen Gras.It Va log_mask
1712fe8fb19SBen Grasmask of priorities to be logged
1722fe8fb19SBen Gras.El
1732fe8fb19SBen Gras.\" .Pp
1742fe8fb19SBen Gras.\" The
1752fe8fb19SBen Gras.\" .Fn syslog_ss
1762fe8fb19SBen Gras.\" is the async-signal-safe version of
1772fe8fb19SBen Gras.\" .Fn syslog_r
1782fe8fb19SBen Gras.\" and is also multithread-safe.
1792fe8fb19SBen Gras.\" It has the following limitations:
1802fe8fb19SBen Gras.\" .Bl -enum -offset indent
1812fe8fb19SBen Gras.\" .It
1822fe8fb19SBen Gras.\" The format string cannot contain multi-byte character sequences.
1832fe8fb19SBen Gras.\" .It
1842fe8fb19SBen Gras.\" Floating point formats are not supported and print
1852fe8fb19SBen Gras.\" .Dq UNK .
1862fe8fb19SBen Gras.\" .It
1872fe8fb19SBen Gras.\" The time of the event is not sent to
1882fe8fb19SBen Gras.\" .Xr syslogd 8 .
1892fe8fb19SBen Gras.\" .It
1902fe8fb19SBen Gras.\" The error string in the %m format is not printed symbolically but as
1912fe8fb19SBen Gras.\" .Dq Error %d .
1922fe8fb19SBen Gras.\" .El
1932fe8fb19SBen Gras.\" .Pp
1942fe8fb19SBen Gras.\" For more information about async-signal-safe functions and signal handlers, see
1952fe8fb19SBen Gras.\" .Xr signal 7 .
1962fe8fb19SBen Gras.Pp
1972fe8fb19SBen GrasThe
1982fe8fb19SBen Gras.Fn vsyslog
1992fe8fb19SBen Grasfunction
2002fe8fb19SBen Grasis an alternative form in which the arguments have already been captured
2012fe8fb19SBen Grasusing the variable-length argument facilities of
202*f14fb602SLionel Sambuc.Xr stdarg 3 .
2032fe8fb19SBen Gras.Pp
2042fe8fb19SBen GrasThe
2052fe8fb19SBen Gras.Fn syslogp
2062fe8fb19SBen Grasvariants take additional arguments which correspond to new fields in the
2072fe8fb19SBen Grassyslog-protocol message format.
2082fe8fb19SBen GrasAll three arguments are evaluated as
2092fe8fb19SBen Gras.Xr printf 3
2102fe8fb19SBen Grasformat strings and any of them can be
2112fe8fb19SBen Gras.Dv NULL .
2122fe8fb19SBen GrasThis enables applications to use message IDs, structured data, and UTF-8 encoded
2132fe8fb19SBen Grascontent in messages.
2142fe8fb19SBen Gras.Pp
2152fe8fb19SBen GrasThe message is tagged with
2162fe8fb19SBen Gras.Fa priority .
2172fe8fb19SBen GrasPriorities are encoded as a
2182fe8fb19SBen Gras.Fa facility
2192fe8fb19SBen Grasand a
2202fe8fb19SBen Gras.Em level .
2212fe8fb19SBen GrasThe facility describes the part of the system
2222fe8fb19SBen Grasgenerating the message.
2232fe8fb19SBen GrasThe level is selected from the following
2242fe8fb19SBen Gras.Em ordered
2252fe8fb19SBen Gras(high to low) list:
2262fe8fb19SBen Gras.Bl -tag -width LOG_AUTHPRIV
2272fe8fb19SBen Gras.It Dv LOG_EMERG
2282fe8fb19SBen GrasA panic condition.
2292fe8fb19SBen GrasThis is normally broadcast to all users.
2302fe8fb19SBen Gras.It Dv LOG_ALERT
2312fe8fb19SBen GrasA condition that should be corrected immediately, such as a corrupted
2322fe8fb19SBen Grassystem database.
2332fe8fb19SBen Gras.It Dv LOG_CRIT
2342fe8fb19SBen GrasCritical conditions, e.g., hard device errors.
2352fe8fb19SBen Gras.It Dv LOG_ERR
2362fe8fb19SBen GrasErrors.
2372fe8fb19SBen Gras.It Dv LOG_WARNING
2382fe8fb19SBen GrasWarning messages.
2392fe8fb19SBen Gras.It Dv LOG_NOTICE
2402fe8fb19SBen GrasConditions that are not error conditions,
2412fe8fb19SBen Grasbut should possibly be handled specially.
2422fe8fb19SBen Gras.It Dv LOG_INFO
2432fe8fb19SBen GrasInformational messages.
2442fe8fb19SBen Gras.It Dv LOG_DEBUG
2452fe8fb19SBen GrasMessages that contain information
2462fe8fb19SBen Grasnormally of use only when debugging a program.
2472fe8fb19SBen Gras.El
2482fe8fb19SBen Gras.Pp
2492fe8fb19SBen GrasThe
2502fe8fb19SBen Gras.Fn vsyslog_r
2512fe8fb19SBen Grasis used the same way as
2522fe8fb19SBen Gras.Fn vsyslog
2532fe8fb19SBen Grasexcept that it takes an additional pointer to a
2542fe8fb19SBen Gras.Fa syslog_data
2552fe8fb19SBen Grasstructure.
2562fe8fb19SBen GrasIt is a multithread-safe version of the
2572fe8fb19SBen Gras.Fn vsyslog
2582fe8fb19SBen Grasfunction described above.
2592fe8fb19SBen Gras.\" The
2602fe8fb19SBen Gras.\" .Fn vsyslog_ss
2612fe8fb19SBen Gras.\" is the async-signal-safe version of
2622fe8fb19SBen Gras.\" .Fn vsyslog_r ,
2632fe8fb19SBen Gras.\" is also multithread-safe, and has the same limitations as
2642fe8fb19SBen Gras.\" .Fn syslog_ss .
2652fe8fb19SBen Gras.Pp
2662fe8fb19SBen GrasThe
2672fe8fb19SBen Gras.Fn openlog
2682fe8fb19SBen Grasfunction
2692fe8fb19SBen Grasprovides for more specialized processing of the messages sent
2702fe8fb19SBen Grasby
2712fe8fb19SBen Gras.Fn syslog
2722fe8fb19SBen Grasand
2732fe8fb19SBen Gras.Fn vsyslog .
2742fe8fb19SBen GrasThe parameter
2752fe8fb19SBen Gras.Fa ident
2762fe8fb19SBen Grasis a string that will be prepended to every message.
2772fe8fb19SBen GrasThe
2782fe8fb19SBen Gras.Fa logopt
2792fe8fb19SBen Grasargument
2802fe8fb19SBen Grasis a bit field specifying logging options, which is formed by
2812fe8fb19SBen Gras.Tn OR Ns 'ing
2822fe8fb19SBen Grasone or more of the following values:
2832fe8fb19SBen Gras.Bl -tag -width LOG_AUTHPRIV
2842fe8fb19SBen Gras.It Dv LOG_CONS
2852fe8fb19SBen GrasIf
2862fe8fb19SBen Gras.Fn syslog
2872fe8fb19SBen Grascannot pass the message to
2882fe8fb19SBen Gras.Xr syslogd 8
2892fe8fb19SBen Grasit will attempt to write the message to the console
2902fe8fb19SBen Gras.Pq Dq Pa /dev/console .
2912fe8fb19SBen Gras.It Dv LOG_NDELAY
2922fe8fb19SBen GrasOpen the connection to
2932fe8fb19SBen Gras.Xr syslogd 8
2942fe8fb19SBen Grasimmediately.
2952fe8fb19SBen GrasNormally the open is delayed until the first message is logged.
2962fe8fb19SBen GrasUseful for programs that need to manage the order in which file
2972fe8fb19SBen Grasdescriptors are allocated.
2982fe8fb19SBen Gras.It Dv LOG_PERROR
2992fe8fb19SBen GrasWrite the message to standard error output as well to the system log.
3002fe8fb19SBen Gras.It Dv LOG_PID
3012fe8fb19SBen GrasLog the process id with each message: useful for identifying
3022fe8fb19SBen Grasinstantiations of daemons.
3032fe8fb19SBen Gras(This PID is placed within brackets
3042fe8fb19SBen Grasbetween the ident and the message.)
3052fe8fb19SBen Gras.El
3062fe8fb19SBen Gras.Pp
3072fe8fb19SBen GrasThe
3082fe8fb19SBen Gras.Fa facility
3092fe8fb19SBen Grasparameter encodes a default facility to be assigned to all messages
3102fe8fb19SBen Grasthat do not have an explicit facility encoded:
3112fe8fb19SBen Gras.Bl -tag -width LOG_AUTHPRIV
3122fe8fb19SBen Gras.It Dv LOG_AUTH
3132fe8fb19SBen GrasThe authorization system:
3142fe8fb19SBen Gras.Xr login 1 ,
3152fe8fb19SBen Gras.Xr su 1 ,
3162fe8fb19SBen Gras.Xr getty 8 ,
3172fe8fb19SBen Grasetc.
3182fe8fb19SBen Gras.It Dv LOG_AUTHPRIV
3192fe8fb19SBen GrasThe same as
3202fe8fb19SBen Gras.Dv LOG_AUTH ,
3212fe8fb19SBen Grasbut logged to a file readable only by
3222fe8fb19SBen Grasselected individuals.
3232fe8fb19SBen Gras.It Dv LOG_CRON
3242fe8fb19SBen GrasThe cron daemon:
3252fe8fb19SBen Gras.Xr cron 8 .
3262fe8fb19SBen Gras.It Dv LOG_DAEMON
3272fe8fb19SBen GrasSystem daemons, such as
3282fe8fb19SBen Gras.Xr routed 8 ,
3292fe8fb19SBen Grasthat are not provided for explicitly by other facilities.
3302fe8fb19SBen Gras.It Dv LOG_FTP
3312fe8fb19SBen GrasThe file transfer protocol daemon:
3322fe8fb19SBen Gras.Xr ftpd 8 .
3332fe8fb19SBen Gras.It Dv LOG_KERN
3342fe8fb19SBen GrasMessages generated by the kernel.
3352fe8fb19SBen GrasThese cannot be generated by any user processes.
3362fe8fb19SBen Gras.It Dv LOG_LPR
3372fe8fb19SBen GrasThe line printer spooling system:
3382fe8fb19SBen Gras.Xr lpr 1 ,
3392fe8fb19SBen Gras.Xr lpc 8 ,
3402fe8fb19SBen Gras.Xr lpd 8 ,
3412fe8fb19SBen Grasetc.
3422fe8fb19SBen Gras.It Dv LOG_MAIL
3432fe8fb19SBen GrasThe mail system.
3442fe8fb19SBen Gras.It Dv LOG_NEWS
3452fe8fb19SBen GrasThe network news system.
3462fe8fb19SBen Gras.It Dv LOG_SYSLOG
3472fe8fb19SBen GrasMessages generated internally by
3482fe8fb19SBen Gras.Xr syslogd 8 .
3492fe8fb19SBen Gras.It Dv LOG_USER
3502fe8fb19SBen GrasMessages generated by random user processes.
3512fe8fb19SBen GrasThis is the default facility identifier if none is specified.
3522fe8fb19SBen Gras.It Dv LOG_UUCP
3532fe8fb19SBen GrasThe uucp system.
3542fe8fb19SBen Gras.It Dv LOG_LOCAL0
3552fe8fb19SBen GrasReserved for local use.
3562fe8fb19SBen GrasSimilarly for
3572fe8fb19SBen Gras.Dv LOG_LOCAL1
3582fe8fb19SBen Grasthrough
3592fe8fb19SBen Gras.Dv LOG_LOCAL7 .
3602fe8fb19SBen Gras.El
3612fe8fb19SBen Gras.Pp
3622fe8fb19SBen GrasThe
3632fe8fb19SBen Gras.Fn openlog_r
3642fe8fb19SBen Grasfunction is the multithread-safe version of the
3652fe8fb19SBen Gras.Fn openlog
3662fe8fb19SBen Grasfunction.
3672fe8fb19SBen GrasIt takes an additional pointer to a
3682fe8fb19SBen Gras.Fa syslog_data
3692fe8fb19SBen Grasstructure.
3702fe8fb19SBen GrasThis function must be used in conjunction with the other
3712fe8fb19SBen Grasmultithread-safe functions.
3722fe8fb19SBen Gras.Pp
3732fe8fb19SBen GrasThe
3742fe8fb19SBen Gras.Fn closelog
3752fe8fb19SBen Grasfunction
3762fe8fb19SBen Grascan be used to close the log file.
3772fe8fb19SBen Gras.Pp
3782fe8fb19SBen GrasThe
3792fe8fb19SBen Gras.Fn closelog_r
3802fe8fb19SBen Grasdoes the same thing as
3812fe8fb19SBen Gras.Xr closelog 3
3822fe8fb19SBen Grasbut in a multithread-safe way and takes an additional
3832fe8fb19SBen Graspointer to a
3842fe8fb19SBen Gras.Fa syslog_data
3852fe8fb19SBen Grasstructure.
3862fe8fb19SBen Gras.Pp
3872fe8fb19SBen GrasThe
3882fe8fb19SBen Gras.Fn setlogmask
3892fe8fb19SBen Grasfunction
3902fe8fb19SBen Grassets the log priority mask to
3912fe8fb19SBen Gras.Fa maskpri
3922fe8fb19SBen Grasand returns the previous mask.
3932fe8fb19SBen GrasCalls to
3942fe8fb19SBen Gras.Fn syslog
3952fe8fb19SBen Graswith a priority not set in
3962fe8fb19SBen Gras.Fa maskpri
3972fe8fb19SBen Grasare rejected.
3982fe8fb19SBen GrasThe mask for an individual priority
3992fe8fb19SBen Gras.Fa pri
4002fe8fb19SBen Grasis calculated by the macro
4012fe8fb19SBen Gras.Fn LOG_MASK pri ;
4022fe8fb19SBen Grasthe mask for all priorities up to and including
4032fe8fb19SBen Gras.Fa toppri
4042fe8fb19SBen Grasis given by the macro
4052fe8fb19SBen Gras.Fn LOG_UPTO toppri .
4062fe8fb19SBen GrasThe default allows all priorities to be logged.
4072fe8fb19SBen Gras.Pp
4082fe8fb19SBen GrasThe
4092fe8fb19SBen Gras.Fn setlogmask_r
4102fe8fb19SBen Grasfunction is the multithread-safe version of
4112fe8fb19SBen Gras.Fn setlogmask .
4122fe8fb19SBen GrasIt takes an additional pointer to a
4132fe8fb19SBen Gras.Fa syslog_data
4142fe8fb19SBen Grasstructure.
4152fe8fb19SBen Gras.Sh RETURN VALUES
4162fe8fb19SBen GrasThe routines
4172fe8fb19SBen Gras.Fn closelog ,
4182fe8fb19SBen Gras.Fn closelog_r ,
4192fe8fb19SBen Gras.Fn openlog ,
4202fe8fb19SBen Gras.Fn openlog_r ,
4212fe8fb19SBen Gras.Fn syslog ,
4222fe8fb19SBen Gras.Fn syslog_r ,
4232fe8fb19SBen Gras.Fn vsyslog ,
4242fe8fb19SBen Gras.Fn vsyslog_r ,
4252fe8fb19SBen Gras.Fn syslogp ,
4262fe8fb19SBen Gras.Fn syslogp_r ,
4272fe8fb19SBen Gras.Fn vsyslogp ,
4282fe8fb19SBen Grasand
4292fe8fb19SBen Gras.Fn vsyslogp_r
4302fe8fb19SBen Grasreturn no value.
4312fe8fb19SBen Gras.Pp
4322fe8fb19SBen GrasThe routines
4332fe8fb19SBen Gras.Fn setlogmask
4342fe8fb19SBen Grasand
4352fe8fb19SBen Gras.Fn setlogmask_r
4362fe8fb19SBen Grasalways return the previous log mask level.
4372fe8fb19SBen Gras.Sh EXAMPLES
4382fe8fb19SBen Gras.Bd -literal -offset indent -compact
4392fe8fb19SBen Grassyslog(LOG_ALERT, "who: internal error 23");
4402fe8fb19SBen Gras
4412fe8fb19SBen Grasopenlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
4422fe8fb19SBen Gras
4432fe8fb19SBen Grassetlogmask(LOG_UPTO(LOG_ERR));
4442fe8fb19SBen Gras
4452fe8fb19SBen Grassyslog(LOG_INFO, "Connection from host %d", CallingHost);
4462fe8fb19SBen Gras
4472fe8fb19SBen Grassyslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
4482fe8fb19SBen Gras
4492fe8fb19SBen Grassyslogp(LOG_INFO|LOG_LOCAL2, NULL, NULL, "foobar error: %m");
4502fe8fb19SBen Gras
4512fe8fb19SBen Grassyslogp(LOG_INFO, "ID%d", "[meta language=\e"en-US\e"]",
4522fe8fb19SBen Gras        "event: %s", 42, EventDescription);
4532fe8fb19SBen Gras.Ed
4542fe8fb19SBen Gras.Pp
4552fe8fb19SBen GrasFor the multithread-safe functions:
4562fe8fb19SBen Gras.Bd -literal -offset indent
4572fe8fb19SBen Grasstruct syslog_data sdata = SYSLOG_DATA_INIT;
4582fe8fb19SBen Gras
4592fe8fb19SBen Grassyslog_r(LOG_INFO|LOG_LOCAL2, \*[Am]sdata, "foobar error: %m");
4602fe8fb19SBen Gras.Ed
4612fe8fb19SBen Gras.Sh SEE ALSO
4622fe8fb19SBen Gras.Xr logger 1 ,
4632fe8fb19SBen Gras.Xr syslogd 8
4642fe8fb19SBen Gras.Rs
4652fe8fb19SBen Gras.%R RFC
4662fe8fb19SBen Gras.%N 3164
4672fe8fb19SBen Gras.%D August 2001
4682fe8fb19SBen Gras.%T The BSD syslog Protocol
4692fe8fb19SBen Gras.Re
4702fe8fb19SBen Gras.Rs
4712fe8fb19SBen Gras.%R Internet-Draft
4722fe8fb19SBen Gras.%N draft-ietf-syslog-protocol-23
4732fe8fb19SBen Gras.%D September 2007
4742fe8fb19SBen Gras.%T The syslog Protocol
4752fe8fb19SBen Gras.Re
4762fe8fb19SBen Gras.Sh HISTORY
4772fe8fb19SBen GrasThese non-multithread-safe functions appeared in
4782fe8fb19SBen Gras.Bx 4.2 .
4792fe8fb19SBen GrasThe multithread-safe functions appeared in
4802fe8fb19SBen Gras.Ox 3.1
4812fe8fb19SBen Grasand then in
4822fe8fb19SBen Gras.Nx 4.0 .
4832fe8fb19SBen GrasThe async-signal-safe functions appeared in
4842fe8fb19SBen Gras.Nx 4.0 .
4852fe8fb19SBen GrasThe syslog-protocol functions appeared in
4862fe8fb19SBen Gras.Nx 5.0 .
4872fe8fb19SBen Gras.Sh CAVEATS
4882fe8fb19SBen GrasIt is important never to pass a string with user-supplied data as a
4892fe8fb19SBen Grasformat without using
4902fe8fb19SBen Gras.Ql %s .
4912fe8fb19SBen GrasAn attacker can put format specifiers in the string to mangle your stack,
4922fe8fb19SBen Grasleading to a possible security hole.
4932fe8fb19SBen GrasThis holds true even if you have built the string
4942fe8fb19SBen Gras.Dq by hand
4952fe8fb19SBen Grasusing a function like
4962fe8fb19SBen Gras.Fn snprintf ,
4972fe8fb19SBen Grasas the resulting string may still contain user-supplied conversion specifiers
4982fe8fb19SBen Grasfor later interpolation by
4992fe8fb19SBen Gras.Fn syslog .
5002fe8fb19SBen Gras.Pp
5012fe8fb19SBen GrasAlways be sure to use the proper secure idiom:
5022fe8fb19SBen Gras.Bd -literal -offset indent
5032fe8fb19SBen Grassyslog(priority, "%s", string);
5042fe8fb19SBen Gras.Ed
5052fe8fb19SBen Gras.Pp
5062fe8fb19SBen GrasWith
5072fe8fb19SBen Gras.Fn syslogp
5082fe8fb19SBen Grasthe caller is responsible to use the right formatting for the message fields.
5092fe8fb19SBen GrasA
5102fe8fb19SBen Gras.Fa msgid
5112fe8fb19SBen Grasmust only contain up to 32 ASCII characters.
5122fe8fb19SBen GrasA
5132fe8fb19SBen Gras.Fa sdfmt
5142fe8fb19SBen Grashas strict rules for paranthesis and character quoting.
5152fe8fb19SBen GrasIf the
5162fe8fb19SBen Gras.Fa msgfmt
5172fe8fb19SBen Grascontains UTF-8 characters, then it has to start with a Byte Order Mark.
518