Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Dec 1994 20:23:11 -0600 (CST)
From:      Peter da Silva <peter@bonkers.taronga.com>
To:        hackers@freebsd.org
Subject:   Re: syslogd changes, second cut
Message-ID:  <199412290223.UAA13028@bonkers.taronga.com>
In-Reply-To: <199412290157.RAA02273@gndrsh.aac.dev.com> from "Rodney W. Grimes" at Dec 28, 94 05:57:40 pm

next in thread | previous in thread | raw e-mail | index | archive | help
Rod Grimes sent me a few nitpicks, and I eyeballed the sources and found some
more problems, including a file parsing bug (running off the end of a string)
so I've rewrapped the whole thing...

*** syslogd.c.orig	Wed Dec 28 16:08:54 1994
--- syslogd.c	Wed Dec 28 20:03:09 1994
***************
*** 62,67 ****
--- 62,69 ----
   * 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 */
***************
*** 83,88 ****
--- 85,91 ----
  #include <sys/time.h>
  #include <sys/resource.h>
  #include <sys/signal.h>
+ #include <sys/syslimits.h>
  
  #include <netinet/in.h>
  #include <netdb.h>
***************
*** 129,134 ****
--- 132,138 ----
  	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 ****
--- 471,478 ----
  	int omask, msglen;
  	char *timestamp;
  	time_t time();
+ 	char prog[NAME_MAX+1];
+ 	int i;
  
  	dprintf("logmsg: pri %o, flags %x, from %s, msg %s\n",
  	    pri, flags, from, msg);
***************
*** 490,495 ****
--- 496,507 ----
  		msglen -= 16;
  	}
  
+ 	/* skip leading blanks */
+ 	while(isspace(*msg)) {
+ 		msg++;
+ 		msglen--;
+ 	}
+ 
  	/* extract facility and priority level */
  	if (flags & MARK)
  		fac = LOG_NFACILITIES;
***************
*** 497,502 ****
--- 509,522 ----
  		fac = LOG_FAC(pri);
  	prilev = LOG_PRI(pri);
  
+ 	/* extract program name */
+ 	for(i = 0; i < NAME_MAX; i++) {
+ 		if(!isalnum(msg[i]))
+ 			break;
+ 		prog[i] = msg[i];
+ 	}
+ 	prog[i] = 0;
+ 
  	/* log the message to the particular outputs */
  	if (!Initialized) {
  		f = &consfile;
***************
*** 514,519 ****
--- 534,543 ----
  		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 ****
--- 881,887 ----
  	register struct filed *f, *next, **nextp;
  	register char *p;
  	char cline[BUFSIZ];
+ 	char prog[NAME_MAX];
  
  	dprintf("init\n");
  
***************
*** 878,883 ****
--- 903,909 ----
  			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;
  	}
--- 913,921 ----
  	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 */
--- 924,965 ----
  	 *  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 == 0)
  			continue;
+ 		if(*p == '#') {
+ 			p++;
+ 			if(*p!='!')
+ 				continue;
+ 		}
+ 		if(*p=='!') {
+ 			p++;
+ 			while(isspace(*p)) p++;
+ 			if(!*p) {
+ 				strcpy(prog, "*");
+ 				continue;
+ 			}
+ 			for(i = 0; i < NAME_MAX; 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 ****
--- 991,999 ----
  					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;
--- 1006,1015 ----
   * 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 */
  
--- 1019,1025 ----
  	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 ****
--- 1027,1041 ----
  	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';) {
*** syslog.conf.5.orig	Wed Dec 28 16:42:44 1994
--- syslog.conf.5	Wed Dec 28 20:18:06 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,55 ----
  file is the configuration file for the
  .Xr syslogd 8
  program.
! It consists of
! blocks of lines separated by
! .Em program
! specifications,
! with each line containing two fields: the
  .Em selector
  field which specifies the types of messages and priorities to which the
  line applies, and an
***************
*** 99,117 ****
  .Xr syslog
  library routine.
  .Pp
  See
  .Xr syslog 3
  for a further descriptions of both the
  .Em facility
  and
  .Em level
! keywords and their significance.
  .Pp
  If a received message matches the specified
  .Em facility
  and is of the specified
  .Em level
  .Em (or a higher level) ,
  the action specified in the
  .Em action
  field will be taken.
--- 103,142 ----
  .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
+ or
+ .Em !prog
+ (the former is for compatibility with the previous syslogd, if one is sharing
+ syslog.conf files, for example)
+ 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
  .Em facility
  and
  .Em level
! keywords and their significance. It's preferred that selections be made on
! .Em facility
! rather than
! .Em program ,
! since the latter can easily vary in a networked environment. In some cases,
! though, an appropriate
! .Em facility
! simply doesn't exist (for example,
! .Em ftpd
! logs under LOG_DAEMON along with a myriad other programs).
  .Pp
  If a received message matches the specified
  .Em facility
  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
--- 158,167 ----
  .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 ****
--- 234,243 ----
  # Save mail and news errors of level err and higher in a
  # special file.
  uucp,news.crit						/var/log/spoolerr
+ 
+ # Save ftpd transactions along with mail and news
+ !ftpd
+ *.*							/var/log/spoolerr
  .Ed
  .Sh FILES
  .Bl -tag -width /etc/syslog.conf -compact



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