/*
*这个头文件是linux系统里的,存在于/usr/include/sys/目录下
*不是这个包(sysklogd-1.3)中的文件,在这个包的某些源文件中引用到
*这个头文件。
* Copyright (c) 1982, 1986, 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
* 4. Neither the name of the University nor the names of its contributors
* 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.
*
* @(#)syslog.h 8.1 (Berkeley) 6/2/93
*/
#ifndef _SYS_SYSLOG_H
#define _SYS_SYSLOG_H 1
#include <features.h>
#define __need___va_list
#include <stdarg.h>
#define _PATH_LOG "/dev/log"
/*
* priorities/facilities are encoded into a single 32-bit quantity, where the
* bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
* (0-big number). Both the priorities and the facilities map roughly
* one-to-one to strings in the syslogd(8) source code. This mapping is
* included in this file.
* priorities和facilities使用一个32位的整数进行编码。末尾的三位表示priority(0-7),
* 前面28位表示facility(0-最大数)。(这句话不会翻译????)
* 这个对应关系被包含在各个文件中。
* priorities (these are ordered)
*/
#define LOG_EMERG 0 /* system is unusable */
#define LOG_ALERT 1 /* action must be taken immediately */
#define LOG_CRIT 2 /* critical conditions */
#define LOG_ERR 3 /* error conditions */
#define LOG_WARNING 4 /* warning conditions */
#define LOG_NOTICE 5 /* normal but significant condition */
#define LOG_INFO 6 /* informational */
#define LOG_DEBUG 7 /* debug-level messages */
#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) 为获取priority值,所使用的掩码,作用就像子网掩码*/
/* extract priority */
#define LOG_PRI(p) ((p) & LOG_PRIMASK) /*根据给定的整数p,计算出priority的值*/
#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))/* 相当于(fac*8+pri)。计算出一个值,可以表示facility和priority。给出这个值,可以用宏“LOG_PRI(p)”和“LOG_FAC(p)”分别计算出这两个值。*/
#ifdef SYSLOG_NAMES
#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
/* mark "facility" */
#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0)
???上面一段没有看懂???
typedef struct _code {
char *c_name;
int c_val;
} CODE;
CODE prioritynames[] =
{
{ "alert", LOG_ALERT },
{ "crit", LOG_CRIT },
{ "debug", LOG_DEBUG },
{ "emerg", LOG_EMERG },
{ "err", LOG_ERR },
{ "error", LOG_ERR }, /* DEPRECATED 不赞成使用*/
{ "info", LOG_INFO },
{ "none", INTERNAL_NOPRI }, /* INTERNAL 如配置文件中"mail.none"表示对mail的信息不做记录*/
{ "notice", LOG_NOTICE },
{ "panic", LOG_EMERG }, /* DEPRECATED 不赞成使用*/
{ "warn", LOG_WARNING }, /* DEPRECATED 不赞成使用*/
{ "warning", LOG_WARNING },
{ NULL, -1 }
};
#endif
/* facility codes */
/*
*在32位的整数中,priority使用后3位表示,facility用前面28位表示。所以,要
*使用下面的方法把0-24都左移3个bit。然后,加上priority就形成了完整的编码。
*左移三位可以用另一种方法实现:将0-24分别乘以8.两者等效。
*左移三位就等于扩大8倍。
*/
#define LOG_KERN (0<<3) /* kernel messages */
#define LOG_USER (1<<3) /* random user-level messages */
#define LOG_MAIL (2<<3) /* mail system */
#define LOG_DAEMON (3<<3) /* system daemons */
#define LOG_AUTH (4<<3) /* security/authorization messages */
#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */
#define LOG_LPR (6<<3) /* line printer subsystem */
#define LOG_NEWS (7<<3) /* network news subsystem */
#define LOG_UUCP (8<<3) /* UUCP subsystem */
#define LOG_CRON (9<<3) /* clock daemon */
#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */
#define LOG_FTP (11<<3) /* ftp daemon */
/* other codes through 15 reserved for system use */
#define LOG_LOCAL0 (16<<3) /* reserved for local use */
#define LOG_LOCAL1 (17<<3) /* reserved for local use */
#define LOG_LOCAL2 (18<<3) /* reserved for local use */
#define LOG_LOCAL3 (19<<3) /* reserved for local use */
#define LOG_LOCAL4 (20<<3) /* reserved for local use */
#define LOG_LOCAL5 (21<<3) /* reserved for local use */
#define LOG_LOCAL6 (22<<3) /* reserved for local use */
#define LOG_LOCAL7 (23<<3) /* reserved for local use */
#define LOG_NFACILITIES 24 /* current number of facilities 当前的facility数量????????*/
#define LOG_FACMASK 0x03f8 /* mask to extract facility part 这个掩码是0000-0011-1111-1000*/
/* 说明facility并并没有用到28位,只用了7位,可以表示*/
/*255种facility,目前的facility远小于255。不知道为什么不*/
/*直接用0xfffffff8*/
/* facility of pri */
#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3)/*根据给定的整数p,计算出facility的值*/
#ifdef SYSLOG_NAMES
CODE facilitynames[] =
{
{ "auth", LOG_AUTH },
{ "authpriv", LOG_AUTHPRIV },
{ "cron", LOG_CRON },
{ "daemon", LOG_DAEMON },
{ "ftp", LOG_FTP },
{ "kern", LOG_KERN },
{ "lpr", LOG_LPR },
{ "mail", LOG_MAIL },
{ "mark", INTERNAL_MARK }, /* INTERNAL */
{ "news", LOG_NEWS },
{ "security", LOG_AUTH }, /* DEPRECATED */
{ "syslog", LOG_SYSLOG },
{ "user", LOG_USER },
{ "uucp", LOG_UUCP },
{ "local0", LOG_LOCAL0 },
{ "local1", LOG_LOCAL1 },
{ "local2", LOG_LOCAL2 },
{ "local3", LOG_LOCAL3 },
{ "local4", LOG_LOCAL4 },
{ "local5", LOG_LOCAL5 },
{ "local6", LOG_LOCAL6 },
{ "local7", LOG_LOCAL7 },
{ NULL, -1 }
};
#endif
/*
* arguments to setlogmask.
*/
#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */
#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */
/*
* Option flags for openlog.
* 函数openlog使用的选项标致。
* LOG_ODELAY no longer does anything.
* LOG_NDELAY is the inverse of what it used to be.
*/
#define LOG_PID 0x01 /* log the pid with each message在消息中记录pid */
#define LOG_CONS 0x02 /* log on the console if errors in sending如果消息无法送到syslogd,直接输出到系统console */
#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) 与LOG_NDELAY 正相反*/
#define LOG_NDELAY 0x08 /* don't delay open立即打开到syslogd的连接,默认连接是在第一次写入讯息时才打开的*/
#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */
#define LOG_PERROR 0x20 /* log to stderr as well将消息也同时送到stderr 上 */
__BEGIN_DECLS
/* Close desriptor used to write to system logger. */
extern void closelog (void) __THROW;
/* Open connection to system logger. */
extern void openlog (__const char *__ident, int __option, int __facility)
__THROW;
/* __THROW表明该函数不会扔出异常,这样避免编译器生成对异常的处理代码,优化生成结果*/
/* Set the log mask level. */
extern int setlogmask (int __mask) __THROW;
/* Generate a log message using FMT string and option arguments. */
extern void syslog (int __pri, __const char *__fmt, ...) __THROW
__attribute__ ((__format__(__printf__, 2, 3)));
#ifdef __USE_BSD
/* Generate a log message using FMT and using arguments pointed to by AP. */
extern void vsyslog (int __pri, __const char *__fmt, __gnuc_va_list __ap)
__THROW __attribute__ ((__format__(__printf__, 2, 0)));
#endif
__END_DECLS
#endif /* sys/syslog.h */
附录:
宏__THROW
Linux/FreeBSD内核的源文件里常会出现这个东东。其实并不复杂,只是简单的宏定义,可以参考以下代码
<sys/cdefs.h>;:
/* GCC can always grok prototypes. For C++ programs we add throw()
to help it optimize the function calls. But this works only with
gcc 2.8.x and egcs. */
# if defined __cplusplus && (__GNUC__ >;= 3 || __GNUC_MINOR__ >;=
# define __THROW throw ()
# else
# define __THROW
# endif
# define __P(args) args __THROW
/* This macro will be used for functions which might take C++ callback
functions. */
# define __PMT(args) args
# define __DOTS , ...
像这个
static void icmp6_errcount __P((struct icmp6errstat *, int, int));
展开后就是
static void icmp6_errcount (struct icmp6errstat *, int, int) throw();
或者
static void icmp6_errcount (struct icmp6errstat *, int, int);
__P在c++调用的情况下,会在函数声明后加入 throw()
表明该函数不会扔出异常,这样避免编译器生成对异常的处理代码,优化生成结果.