Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: syslog.h,v 1.44 2024/08/21 16:30:27 gutteridge Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1988, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	@(#)syslog.h	8.1 (Berkeley) 6/2/93
     32  */
     33 
     34 #ifndef _SYS_SYSLOG_H_
     35 #define _SYS_SYSLOG_H_
     36 
     37 #include <sys/cdefs.h>
     38 #include <sys/featuretest.h>
     39 #include <sys/ansi.h>
     40 #include <sys/stdarg.h>
     41 
     42 #define	_PATH_LOG	"/var/run/log"
     43 
     44 /*
     45  * priorities/facilities are encoded into a single 32-bit quantity, where the
     46  * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
     47  * (0-big number).  Both the priorities and the facilities map roughly
     48  * one-to-one to strings in the syslogd(8) source code.  This mapping is
     49  * included in this file.
     50  *
     51  * priorities (these are ordered)
     52  */
     53 #define	LOG_EMERG	0	/* system is unusable */
     54 #define	LOG_ALERT	1	/* action must be taken immediately */
     55 #define	LOG_CRIT	2	/* critical conditions */
     56 #define	LOG_ERR		3	/* error conditions */
     57 #define	LOG_WARNING	4	/* warning conditions */
     58 #define	LOG_NOTICE	5	/* normal but significant condition */
     59 #define	LOG_INFO	6	/* informational */
     60 #define	LOG_DEBUG	7	/* debug-level messages */
     61 
     62 #define	LOG_PRIMASK	0x07	/* mask to extract priority part (internal) */
     63 				/* extract priority */
     64 #define	LOG_PRI(p)	((p) & LOG_PRIMASK)
     65 
     66 #ifdef SYSLOG_NAMES
     67 #define	INTERNAL_NOPRI	0x10	/* the "no priority" priority */
     68 				/* mark "facility" */
     69 #define	INTERNAL_MARK	(LOG_NFACILITIES<<3)
     70 typedef struct _code {
     71 	const char	*c_name;
     72 	int	c_val;
     73 } CODE;
     74 
     75 CODE prioritynames[] = {
     76 	{ "alert",	LOG_ALERT },
     77 	{ "crit",	LOG_CRIT },
     78 	{ "debug",	LOG_DEBUG },
     79 	{ "emerg",	LOG_EMERG },
     80 	{ "err",	LOG_ERR },
     81 	{ "error",	LOG_ERR },		/* DEPRECATED */
     82 	{ "info",	LOG_INFO },
     83 	{ "none",	INTERNAL_NOPRI },	/* INTERNAL */
     84 	{ "notice",	LOG_NOTICE },
     85 	{ "panic",	LOG_EMERG },		/* DEPRECATED */
     86 	{ "warn",	LOG_WARNING },		/* DEPRECATED */
     87 	{ "warning",	LOG_WARNING },
     88 	{ NULL,		-1 }
     89 };
     90 #endif /* SYSLOG_NAMES */
     91 
     92 /* facility codes */
     93 #define	LOG_KERN	(0<<3)	/* kernel messages */
     94 #define	LOG_USER	(1<<3)	/* random user-level messages */
     95 #define	LOG_MAIL	(2<<3)	/* mail system */
     96 #define	LOG_DAEMON	(3<<3)	/* system daemons */
     97 #define	LOG_AUTH	(4<<3)	/* security/authorization messages */
     98 #define	LOG_SYSLOG	(5<<3)	/* messages generated internally by syslogd */
     99 #define	LOG_LPR		(6<<3)	/* line printer subsystem */
    100 #define	LOG_NEWS	(7<<3)	/* network news subsystem */
    101 #define	LOG_UUCP	(8<<3)	/* UUCP subsystem */
    102 #define	LOG_CRON	(9<<3)	/* clock daemon */
    103 #define	LOG_AUTHPRIV	(10<<3)	/* security/authorization messages (private) */
    104 #define	LOG_FTP		(11<<3)	/* ftp daemon */
    105 
    106 	/* other codes through 15 reserved for system use */
    107 #define	LOG_LOCAL0	(16<<3)	/* reserved for local use */
    108 #define	LOG_LOCAL1	(17<<3)	/* reserved for local use */
    109 #define	LOG_LOCAL2	(18<<3)	/* reserved for local use */
    110 #define	LOG_LOCAL3	(19<<3)	/* reserved for local use */
    111 #define	LOG_LOCAL4	(20<<3)	/* reserved for local use */
    112 #define	LOG_LOCAL5	(21<<3)	/* reserved for local use */
    113 #define	LOG_LOCAL6	(22<<3)	/* reserved for local use */
    114 #define	LOG_LOCAL7	(23<<3)	/* reserved for local use */
    115 
    116 #define	LOG_NFACILITIES	24	/* current number of facilities */
    117 #define	LOG_FACMASK	0x03f8	/* mask to extract facility part */
    118 				/* facility of pri */
    119 #define	LOG_FAC(p)	(((p) & LOG_FACMASK) >> 3)
    120 
    121 #ifdef SYSLOG_NAMES
    122 CODE facilitynames[] = {
    123 	{ "auth",	LOG_AUTH },
    124 	{ "authpriv",	LOG_AUTHPRIV },
    125 	{ "cron",	LOG_CRON },
    126 	{ "daemon",	LOG_DAEMON },
    127 	{ "ftp",	LOG_FTP },
    128 	{ "kern",	LOG_KERN },
    129 	{ "lpr",	LOG_LPR },
    130 	{ "mail",	LOG_MAIL },
    131 	{ "mark",	INTERNAL_MARK },	/* INTERNAL */
    132 	{ "news",	LOG_NEWS },
    133 	{ "security",	LOG_AUTH },		/* DEPRECATED */
    134 	{ "syslog",	LOG_SYSLOG },
    135 	{ "user",	LOG_USER },
    136 	{ "uucp",	LOG_UUCP },
    137 	{ "local0",	LOG_LOCAL0 },
    138 	{ "local1",	LOG_LOCAL1 },
    139 	{ "local2",	LOG_LOCAL2 },
    140 	{ "local3",	LOG_LOCAL3 },
    141 	{ "local4",	LOG_LOCAL4 },
    142 	{ "local5",	LOG_LOCAL5 },
    143 	{ "local6",	LOG_LOCAL6 },
    144 	{ "local7",	LOG_LOCAL7 },
    145 	{ NULL,		-1 }
    146 };
    147 #endif /* SYSLOG_NAMES */
    148 
    149 #ifdef _KERNEL
    150 #define	LOG_PRINTF	-1	/* pseudo-priority to indicate use of printf */
    151 #endif
    152 
    153 /*
    154  * arguments to setlogmask.
    155  */
    156 #define	LOG_MASK(pri)	(1 << (pri))		/* mask for one priority */
    157 #define	LOG_UPTO(pri)	((1 << ((pri)+1)) - 1)	/* all priorities through pri */
    158 
    159 /*
    160  * Option flags for openlog.
    161  *
    162  * LOG_ODELAY no longer does anything.
    163  * LOG_NDELAY is the inverse of what it used to be.
    164  */
    165 #define	LOG_PID		0x01	/* log the pid with each message */
    166 #define	LOG_CONS	0x02	/* log on the console if errors in sending */
    167 #define	LOG_ODELAY	0x04	/* delay open until first syslog() (default) */
    168 #define	LOG_NDELAY	0x08	/* don't delay open */
    169 #define	LOG_NOWAIT	0x10	/* don't wait for console forks: DEPRECATED */
    170 #define	LOG_PERROR	0x20	/* log to stderr as well */
    171 #define LOG_PTRIM	0x40	/* trim tag and pid from messages to stderr */
    172 #define LOG_NLOG	0x80	/* don't write to the system log */
    173 
    174 #ifndef _KERNEL
    175 
    176 /* Used by reentrant functions */
    177 
    178 struct syslog_data {
    179 	int	log_version;
    180 	int	log_file;
    181 	int	log_connected;
    182 	int	log_opened;
    183 	int	log_stat;
    184 	const char	*log_tag;
    185 	char	log_hostname[256];	/* MAXHOSTNAMELEN */
    186 	int	log_fac;
    187 	int	log_mask;
    188 };
    189 
    190 #define SYSLOG_DATA_INIT { \
    191     .log_version = 1, \
    192     .log_file = -1, \
    193     .log_connected = 0, \
    194     .log_opened = 0, \
    195     .log_stat = 0, \
    196     .log_tag  = 0, \
    197     .log_hostname = { '\0' }, \
    198     .log_fac = LOG_USER, \
    199     .log_mask = 0xff, \
    200 }
    201 
    202 __BEGIN_DECLS
    203 void	closelog(void);
    204 void	openlog(const char *, int, int);
    205 int	setlogmask(int);
    206 void	syslog(int, const char *, ...) __sysloglike(2, 3);
    207 #if defined(_NETBSD_SOURCE)
    208 void	vsyslog(int, const char *, __va_list) __sysloglike(2, 0);
    209 #ifndef __LIBC12_SOURCE__
    210 void	closelog_r(struct syslog_data *) __RENAME(__closelog_r60);
    211 void	openlog_r(const char *, int, int, struct syslog_data *)
    212     __RENAME(__openlog_r60);
    213 int	setlogmask_r(int, struct syslog_data *) __RENAME(__setlogmask_r60);
    214 void	syslog_r(int, struct syslog_data *, const char *, ...)
    215     __RENAME(__syslog_r60) __sysloglike(3, 4);
    216 void	vsyslog_r(int, struct syslog_data *, const char *, __va_list)
    217     __RENAME(__vsyslog_r60) __sysloglike(3, 0);
    218 void	syslogp_r(int, struct syslog_data *, const char *, const char *,
    219     const char *, ...) __RENAME(__syslogp_r60) __sysloglike(5, 6);
    220 void	vsyslogp_r(int, struct syslog_data *, const char *, const char *,
    221     const char *, __va_list) __RENAME(__vsyslogp_r60) __sysloglike(5, 0);
    222 void	syslog_ss(int, struct syslog_data *, const char *, ...)
    223     __RENAME(__syslog_ss60) __sysloglike(3, 4);
    224 void    vsyslog_ss(int, struct syslog_data *, const char *, va_list)
    225     __RENAME(__vsyslog_ss60) __sysloglike(3, 0);
    226 void	syslogp_ss(int, struct syslog_data *, const char *, const char *,
    227     const char *, ...) __RENAME(__syslogp_ss60) __sysloglike(5, 0);
    228 void	vsyslogp_ss(int, struct syslog_data *, const char *, const char *,
    229     const char *, va_list) __RENAME(__vsyslogp_ss60) __sysloglike(5, 0);
    230 #endif
    231 void	syslogp(int, const char *, const char *, const char *, ...)
    232     __sysloglike(4, 5);
    233 void	vsyslogp(int, const char *, const char *, const char *, __va_list)
    234     __sysloglike(4, 0);
    235 #endif
    236 __END_DECLS
    237 
    238 #else /* !_KERNEL */
    239 
    240 void	logpri(int);
    241 void	log(int, const char *, ...) __printflike(2, 3);
    242 void	vlog(int, const char *, __va_list) __printflike(2, 0);
    243 void	addlog(const char *, ...) __printflike(1, 2);
    244 void	logwakeup(void);
    245 
    246 #endif /* !_KERNEL */
    247 
    248 #endif /* !_SYS_SYSLOG_H_ */
    249