Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Dec 1994 16:50:14 -0600 (CST)
From:      Peter da Silva <peter@bonkers.taronga.com>
To:        hackers@freebsd.org
Subject:   syslogd changes, first cut
Message-ID:  <199412282250.QAA07957@bonkers.taronga.com>

next in thread | raw e-mail | index | archive | help
To minimize the impact of changing syslog, I use:

#!progname
syslog lines that only apply to progname

This keeps syslog from blowing up if you give the new syslog format to
old syslogd, or confuse the new syslogd with old files. The worst that
will happen is you will log more info than you expected.

Relative to 1.1.5.1 syslogd. I can't imagine the new one is significantly
different.

*** syslog.conf.5.orig	Wed Dec 28 16:42:44 1994
--- syslog.conf.5	Wed Dec 28 16:38:12 1994
***************
*** 45,51 ****
  file is the configuration file for the
  .Xr syslogd 8
  program.
! It consists of lines with two fields: the
  .Em selector
  field which specifies the types of messages and priorities to which the
  line applies, and an
--- 45,53 ----
  file is the configuration file for the
  .Xr syslogd 8
  program.
! It consists of
! blocks of lines separated by #! comments
! lines with two fields: the
  .Em selector
  field which specifies the types of messages and priorities to which the
  line applies, and an
***************
*** 99,104 ****
--- 101,112 ----
  .Xr syslog
  library routine.
  .Pp
+ Each block of lines is separated from the previous block by a tag. The tag
+ is a line beginning with
+ .Em #!prog
+ and each block will be associated with calls to syslog from that specific
+ program.
+ .Pp
  See
  .Xr syslog 3
  for a further descriptions of both the
***************
*** 112,117 ****
--- 120,127 ----
  and is of the specified
  .Em level
  .Em (or a higher level) ,
+ and the first word in the message after the date matches the
+ .Em program ,
  the action specified in the
  .Em action
  field will be taken.
***************
*** 133,140 ****
  .Pp
  An asterisk (``*'') can be used to specify all
  .Em facilities
  or all
! .Em levels .
  .Pp
  The special
  .Em facility
--- 143,152 ----
  .Pp
  An asterisk (``*'') can be used to specify all
  .Em facilities
+ all
+ .Em levels
  or all
! .Em programs .
  .Pp
  The special
  .Em facility
***************
*** 207,212 ****
--- 219,227 ----
  # Save mail and news errors of level err and higher in a
  # special file.
  uucp,news.crit						/var/log/spoolerr
+ 
+ #!ftpd  Log FTP transactions as well
+ daemon							/var/log/spoolerr
  .Ed
  .Sh FILES
  .Bl -tag -width /etc/syslog.conf -compact
*** syslogd.c.orig	Wed Dec 28 16:08:54 1994
--- syslogd.c	Wed Dec 28 16:22:48 1994
***************
*** 58,67 ****
--- 58,70 ----
   * MAXLINE -- the maximimum line length that can be handled.
   * DEFUPRI -- the default priority for user messages
   * DEFSPRI -- the default priority for kernel messages
+  * MAXPROGNAMELEN -- maximum length for a program tag
   *
   * Author: Eric Allman
   * extensive changes by Ralph Campbell
   * more extensive changes by Eric Allman (again)
+  * Extension to log by program name as well as facility and priority
+  *   by Peter da Silva.
   */
  
  #define	MAXLINE		1024		/* maximum line length */
***************
*** 69,74 ****
--- 72,78 ----
  #define DEFUPRI		(LOG_USER|LOG_NOTICE)
  #define DEFSPRI		(LOG_KERN|LOG_CRIT)
  #define TIMERINTVL	30		/* interval for checking flush, mark */
+ #define MAXPROGNAMELEN	256
  
  #include <sys/param.h>
  #include <sys/errno.h>
***************
*** 129,134 ****
--- 133,139 ----
  	short	f_file;			/* file descriptor */
  	time_t	f_time;			/* time this was last written */
  	u_char	f_pmask[LOG_NFACILITIES+1];	/* priority mask */
+ 	char	*f_program;		/* program this applies to */
  	union {
  		char	f_uname[MAXUNAMES][UT_NAMESIZE+1];
  		struct {
***************
*** 467,472 ****
--- 472,479 ----
  	int omask, msglen;
  	char *timestamp;
  	time_t time();
+ 	char prog[MAXPROGNAMELEN+1];
+ 	int i;
  
  	dprintf("logmsg: pri %o, flags %x, from %s, msg %s\n",
  	    pri, flags, from, msg);
***************
*** 490,495 ****
--- 497,508 ----
  		msglen -= 16;
  	}
  
+ 	/* skip leading blanks */
+ 	while(isspace(*msg)) {
+ 		msg++;
+ 		msglen--;
+ 	}
+ 
  	/* extract facility and priority level */
  	if (flags & MARK)
  		fac = LOG_NFACILITIES;
***************
*** 497,502 ****
--- 510,524 ----
  		fac = LOG_FAC(pri);
  	prilev = LOG_PRI(pri);
  
+ 	/* extract program name */
+ 	for(i = 0; i < MAXPROGNAMELEN; i++) {
+ 		if(isalnum(msg[i]))
+ 			prog[i] = msg[i];
+ 		else
+ 			break;
+ 	}
+ 	prog[i] = 0;
+ 
  	/* log the message to the particular outputs */
  	if (!Initialized) {
  		f = &consfile;
***************
*** 514,519 ****
--- 536,545 ----
  		if (f->f_pmask[fac] < prilev ||
  		    f->f_pmask[fac] == INTERNAL_NOPRI)
  			continue;
+ 		/* skip messages with the incorrect program name */
+ 		if(f->f_program)
+ 			if(strcmp(prog, f->f_program) != 0)
+ 				continue;
  
  		if (f->f_type == F_CONSOLE && (flags & IGN_CONS))
  			continue;
***************
*** 857,862 ****
--- 883,889 ----
  	register struct filed *f, *next, **nextp;
  	register char *p;
  	char cline[BUFSIZ];
+ 	char prog[MAXPROGNAMELEN];
  
  	dprintf("init\n");
  
***************
*** 878,883 ****
--- 905,911 ----
  			break;
  		}
  		next = f->f_next;
+ 		if(f->f_program) free(f->f_program);
  		free((char *) f);
  	}
  	Files = NULL;
***************
*** 887,895 ****
  	if ((cf = fopen(ConfFile, "r")) == NULL) {
  		dprintf("cannot open %s\n", ConfFile);
  		*nextp = (struct filed *)calloc(1, sizeof(*f));
! 		cfline("*.ERR\t/dev/console", *nextp);
  		(*nextp)->f_next = (struct filed *)calloc(1, sizeof(*f));
! 		cfline("*.PANIC\t*", (*nextp)->f_next);
  		Initialized = 1;
  		return;
  	}
--- 915,923 ----
  	if ((cf = fopen(ConfFile, "r")) == NULL) {
  		dprintf("cannot open %s\n", ConfFile);
  		*nextp = (struct filed *)calloc(1, sizeof(*f));
! 		cfline("*.ERR\t/dev/console", *nextp, "*");
  		(*nextp)->f_next = (struct filed *)calloc(1, sizeof(*f));
! 		cfline("*.PANIC\t*", (*nextp)->f_next, "*");
  		Initialized = 1;
  		return;
  	}
***************
*** 898,917 ****
  	 *  Foreach line in the conf table, open that file.
  	 */
  	f = NULL;
  	while (fgets(cline, sizeof cline, cf) != NULL) {
  		/*
  		 * check for end-of-section, comments, strip off trailing
! 		 * spaces and newline character.
  		 */
  		for (p = cline; isspace(*p); ++p);
! 		if (*p == NULL || *p == '#')
! 			continue;
  		for (p = index(cline, '\0'); isspace(*--p););
  		*++p = '\0';
  		f = (struct filed *)calloc(1, sizeof(*f));
  		*nextp = f;
  		nextp = &f->f_next;
! 		cfline(cline, f);
  	}
  
  	/* close the configuration file */
--- 926,963 ----
  	 *  Foreach line in the conf table, open that file.
  	 */
  	f = NULL;
+ 	strcpy(prog, "*");
  	while (fgets(cline, sizeof cline, cf) != NULL) {
  		/*
  		 * check for end-of-section, comments, strip off trailing
! 		 * spaces and newline character. #!prog is treated specially:
! 		 * following lines apply only to that program.
  		 */
  		for (p = cline; isspace(*p); ++p);
! 		if (*p == NULL || *p == '#') {
! 			p++;
! 			if(*p=='!') {
! 				p++;
! 				while(isspace(*p)) p++;
! 				if(!*p) {
! 					strcpy(prog, "*");
! 					continue;
! 				}
! 				for(i = 0; i < MAXPROGNAMELEN; i++) {
! 					if(!isalnum(p[i]))
! 						break;
! 					prog[i] = p[i];
! 				}
! 				prog[i] = 0;
! 				continue;
! 			}
! 		}
  		for (p = index(cline, '\0'); isspace(*--p););
  		*++p = '\0';
  		f = (struct filed *)calloc(1, sizeof(*f));
  		*nextp = f;
  		nextp = &f->f_next;
! 		cfline(cline, f, prog);
  	}
  
  	/* close the configuration file */
***************
*** 943,948 ****
--- 989,997 ----
  					printf("%s, ", f->f_un.f_uname[i]);
  				break;
  			}
+ 			if(f->f_program) {
+ 				printf(" (%s)", f->f_program);
+ 			}
  			printf("\n");
  		}
  	}
***************
*** 955,963 ****
   * Crack a configuration file line
   */
  
! cfline(line, f)
  	char *line;
  	register struct filed *f;
  {
  	register char *p;
  	register char *q;
--- 1004,1013 ----
   * Crack a configuration file line
   */
  
! cfline(line, f, prog)
  	char *line;
  	register struct filed *f;
+ 	char *prog;
  {
  	register char *p;
  	register char *q;
***************
*** 967,973 ****
  	struct hostent *hp;
  	char buf[MAXLINE], ebuf[100];
  
! 	dprintf("cfline(%s)\n", line);
  
  	errno = 0;	/* keep strerror() stuff out of logerror messages */
  
--- 1017,1023 ----
  	struct hostent *hp;
  	char buf[MAXLINE], ebuf[100];
  
! 	dprintf("cfline(\"%s\", f, \"%s\")\n", line, prog);
  
  	errno = 0;	/* keep strerror() stuff out of logerror messages */
  
***************
*** 975,980 ****
--- 1025,1039 ----
  	bzero((char *) f, sizeof *f);
  	for (i = 0; i <= LOG_NFACILITIES; i++)
  		f->f_pmask[i] = INTERNAL_NOPRI;
+ 
+ 	/* save program name if any */
+ 	if(prog && *prog=='*') prog = NULL;
+ 	if(prog) {
+ 		f->f_program = calloc(1, strlen(prog)+1);
+ 		if(f->f_program) {
+ 			strcpy(f->f_program, prog);
+ 		}
+ 	}
  
  	/* scan through the list of selectors */
  	for (p = line; *p && *p != '\t';) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199412282250.QAA07957>