postfix 代码生存手册

需要输出调试信息用 msg_info 函数,语法同 printf。
日志打在 syslog 里,Ubuntu 默认路径为 /var/log/mail.log

改造 msg_info,使其能够输出文件名及行号。msg.h 的函数声明改成:
#ifdef NO_LINE_NUMBER
extern void PRINTFLIKE(1, 2) msg_info(const char *,...);
#else
extern void msg_info_ext(const char *, const unsigned int, const char *,...);
#define msg_info(fmt,args...) msg_info_ext(__FILE__,__LINE__,(fmt),##args)
#endif

原来的函数定义 msg.c:msg_info 改成
void    msg_info_ext( const char *file
                    , const unsigned int line_number
                    , const char *fmt,...)
{

    char buff[1024*5] = {0};

    snprintf(buff, sizeof(buff), "(%s:%d) ", file, line_number);
    strncat(buff, fmt, sizeof(buff)-strlen(buff)-1);

    va_list ap;

    va_start(ap, fmt);
    msg_vprintf(MSG_INFO, buff, ap);
    va_end(ap);
}

借助 mantools 下的工具从源代码生成 man 手册。
postfix@ami-nda:~/postfix-2.8.2/src/util$ ../../mantools/srctoman vstream.c | head
.TH VSTREAM 3 
.ad
.fi
.SH NAME
vstream
\-
light-weight buffered I/O package
.SH "SYNOPSIS"
.na
.nf
postfix@ami-nda:~/postfix-2.8.2/src/util$ ../../mantools/srctoman vstream.c > VSTREAM.3
postfix@ami-nda:~/postfix-2.8.2/src/util$ man ./VSTREAM.3 

猜你喜欢

转载自ma3310.iteye.com/blog/1007287