Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Dec 1994 12:25:51 -0600
From:      Peter da Silva <peter@bonkers.taronga.com>
To:        Wankle Rotary Engine <wpaul@skynet.ctr.columbia.edu>
Cc:        hackers@freebsd.org, current@freebsd.org
Subject:   Re: syslogd changes, second cut 
Message-ID:  <199412291825.MAA03581@bonkers.taronga.com>
In-Reply-To: Your message of "Thu, 29 Dec 94 12:03:51 EST." <199412291703.MAA02510@skynet.ctr.columbia.edu> 

next in thread | previous in thread | raw e-mail | index | archive | help
OK, here's the same set of changes with respect to the 2.0-current syslogd.

UNTESTED.

Changing the code from

        (void)strcpy(line, "kernel: ");

To using getbootfile() should be a piece of cake, if you have specs on 
getbootfile(). As I said, getbootfile isn't in 1.1 or 4.4 and it's kinda
hard to find the docco over FTP. The 2.0-current syslogd doesn't compile 
vanilla on 1.1.5.1 but this one produces the same warnings as the 2.0-current 
one so I assume it's OK.

*** syslogd.c.orig	Sat Aug  6 00:09:00 1994
--- syslogd.c	Thu Dec 29 12:17:33 1994
***************
*** 61,66 ****
--- 61,68 ----
   * 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 */
***************
*** 79,84 ****
--- 81,87 ----
  #include <sys/un.h>
  #include <sys/time.h>
  #include <sys/resource.h>
+ #include <sys/syslimits.h>
  
  #include <netinet/in.h>
  #include <netdb.h>
***************
*** 130,135 ****
--- 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 {
***************
*** 186,192 ****
  int	MarkInterval = 20 * 60;	/* interval between marks in seconds */
  int	MarkSeq = 0;		/* mark sequence number */
  
! void	cfline __P((char *, struct filed *));
  char   *cvthname __P((struct sockaddr_in *));
  int	decode __P((const char *, CODE *));
  void	die __P((int));
--- 190,196 ----
  int	MarkInterval = 20 * 60;	/* interval between marks in seconds */
  int	MarkSeq = 0;		/* mark sequence number */
  
! void	cfline __P((char *, struct filed *, char *));
  char   *cvthname __P((struct sockaddr_in *));
  int	decode __P((const char *, CODE *));
  void	die __P((int));
***************
*** 469,474 ****
--- 473,480 ----
  	struct filed *f;
  	int fac, msglen, omask, prilev;
  	char *timestamp;
+  	char prog[NAME_MAX+1];
+  	int i;
  
  	dprintf("logmsg: pri %o, flags %x, from %s, msg %s\n",
  	    pri, flags, from, msg);
***************
*** 492,497 ****
--- 498,509 ----
  		msglen -= 16;
  	}
  
+ 	/* skip leading blanks */
+ 	while(isspace(*msg)) {
+ 		msg++;
+ 		msglen--;
+ 	}
+ 
  	/* extract facility and priority level */
  	if (flags & MARK)
  		fac = LOG_NFACILITIES;
***************
*** 499,504 ****
--- 511,524 ----
  		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;
***************
*** 516,521 ****
--- 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;
***************
*** 866,871 ****
--- 890,896 ----
  	struct filed *f, *next, **nextp;
  	char *p;
  	char cline[LINE_MAX];
+  	char prog[NAME_MAX+1];
  
  	dprintf("init\n");
  
***************
*** 887,892 ****
--- 912,918 ----
  			break;
  		}
  		next = f->f_next;
+ 		if(f->f_program) free(f->f_program);
  		free((char *)f);
  	}
  	Files = NULL;
***************
*** 896,904 ****
  	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;
  	}
--- 922,930 ----
  	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;
  	}
***************
*** 907,928 ****
  	 *  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)
  			continue;
! 		if (*p == NULL || *p == '#')
  			continue;
  		for (p = strchr(cline, '\0'); isspace(*--p);)
  			continue;
  		*++p = '\0';
  		f = (struct filed *)calloc(1, sizeof(*f));
  		*nextp = f;
  		nextp = &f->f_next;
! 		cfline(cline, f);
  	}
  
  	/* close the configuration file */
--- 933,976 ----
  	 *  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)
  			continue;
! 		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 = strchr(cline, '\0'); isspace(*--p);)
  			continue;
  		*++p = '\0';
  		f = (struct filed *)calloc(1, sizeof(*f));
  		*nextp = f;
  		nextp = &f->f_next;
! 		cfline(cline, f, prog);
  	}
  
  	/* close the configuration file */
***************
*** 954,959 ****
--- 1002,1010 ----
  					printf("%s, ", f->f_un.f_uname[i]);
  				break;
  			}
+ 			if(f->f_program) {
+ 				printf(" (%s)", f->f_program);
+ 			}
  			printf("\n");
  		}
  	}
***************
*** 966,981 ****
   * Crack a configuration file line
   */
  void
! cfline(line, f)
  	char *line;
  	struct filed *f;
  {
  	struct hostent *hp;
  	int i, pri;
  	char *bp, *p, *q;
  	char buf[MAXLINE], ebuf[100];
  
! 	dprintf("cfline(%s)\n", line);
  
  	errno = 0;	/* keep strerror() stuff out of logerror messages */
  
--- 1017,1033 ----
   * Crack a configuration file line
   */
  void
! cfline(line, f, prog)
  	char *line;
  	struct filed *f;
+ 	char *prog;
  {
  	struct hostent *hp;
  	int i, pri;
  	char *bp, *p, *q;
  	char buf[MAXLINE], ebuf[100];
  
! 	dprintf("cfline(\"%s\", f, \"%s\")\n", line, prog);
  
  	errno = 0;	/* keep strerror() stuff out of logerror messages */
  
***************
*** 983,988 ****
--- 1035,1049 ----
  	memset(f, 0, 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?199412291825.MAA03581>