TCP-IP红宝书源代码

源代码在线查看: syslog.c

软件大小: 1091 K
上传用户: gdmichael
关键词: TCP-IP 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				/* syslog.c - syslog */
				
				#include 
				#include 
				#include 
				#include 
				#include 
				#include 
				
				#ifdef	LOGHOST
				char	*loghost = LOGHOST;
				#else
				char	*loghost = 0;
				#endif
				
				static int	logdev = BADDEV;
				static char	logbuf[LOG_MAXLEN+10]; /* mesg. + room for  & null	*/
				
				extern int	currpid;
				
				/*------------------------------------------------------------------------
				 * syslog - log messages to a remote UNIX syslogd or the console
				 *------------------------------------------------------------------------
				 */
				int
				syslog(int where, char *pname, char *fmt, ...)
				{
					va_list	args;
					int	len;
				
					va_start(args, fmt);
					if (loghost == 0) {
						kprintf(fmt, args);
						return OK;
					}
					if (logdev == BADDEV) {
						logdev = open(UDP, LOGHOST, ANYLPORT);
						if (logdev == SYSERR)
							return SYSERR;
						control(logdev, DG_SETMODE, DG_DMODE);
					}
					sprintf(logbuf, "", where);
					len = strlen(logbuf);
					sprintf(&logbuf[len], "%s[%u]: ", pname, currpid);
					len = strlen(logbuf);
					vsprintf(&logbuf[len], fmt, args);
					len = strlen(logbuf);
					logbuf[len++] = '\n';
					logbuf[len] = '\0';
					va_end(args);
					return write(logdev, logbuf, len);
				}
							

相关资源