[182] in Zephyr_Bugs

home help back first fref pref prev next nref lref last post

zephyr syslogd with COMPAT42 doesn't supplant /etc/syslog

daemon@ATHENA.MIT.EDU (John T Kohl)
Fri Dec 7 10:50:56 1990

Date: Fri, 7 Dec 90 10:50:26 -0500
From: John T Kohl <jtkohl@MIT.EDU>
To: bugs@MIT.EDU, zephyr-bugs@MIT.EDU

The zephyr syslogd, while it has some COMPAT42 hacks, doesn't completely
replace the old 4.2BSD /etc/syslog.  Attached is a patch to the current
zephyr sources to make it do so.

Also cleaned up:
	use POSIX_SIGHANDLERS rather than ultrix to select void signal handlers
	use NO_KLOG rather than ultrix to disable /dev/klog code
	some junk variable usage caught by saber

*** /mit/zephyr/src/clients/syslogd/syslogd.c	Fri Nov 16 15:40:12 1990
--- syslogd.c	Fri Dec  7 10:37:28 1990
***************
*** 73,79 ****
  #include <sys/wait.h>
  #include <sys/socket.h>
  #include <sys/file.h>
! #ifndef COMPAT42
  #include <sys/msgbuf.h>
  #endif
  #include <sys/uio.h>
--- 73,79 ----
  #include <sys/wait.h>
  #include <sys/socket.h>
  #include <sys/file.h>
! #ifndef NO_KLOG
  #include <sys/msgbuf.h>
  #endif
  #include <sys/uio.h>
***************
*** 91,96 ****
--- 91,97 ----
  #ifdef COMPAT42
  char	*ConfFile = "/etc/nsyslog.conf";
  char	*PidFile = "/etc/nsyslog.pid";
+ struct in_addr localhostaddr;
  #else /* !COMPAT42 */
  char	*ConfFile = "/etc/syslog.conf";
  char	*PidFile = "/etc/syslog.pid";
***************
*** 235,241 ****
  	"reserved",     -1,
  	"reserved",     -1,
  	"reserved",     -1,
! 	"reserved",     -1,
  	"local0",	LOG_LOCAL0,
  	"local1",	LOG_LOCAL1,
  	"local2",	LOG_LOCAL2,
--- 236,242 ----
  	"reserved",     -1,
  	"reserved",     -1,
  	"reserved",     -1,
! 	"compat",     	LOG_COMPAT,
  	"local0",	LOG_LOCAL0,
  	"local1",	LOG_LOCAL1,
  	"local2",	LOG_LOCAL2,
***************
*** 249,254 ****
--- 250,259 ----
  	NULL,		-1
  };
  
+ #ifndef max
+ #define max(a,b) ((a) > (b) ? (a) : (b))
+ #endif
+ 
  main(argc, argv)
  	int argc;
  	char **argv;
***************
*** 259,275 ****
  	struct sockaddr_un sunx, fromunix;
  	struct sockaddr_in sin, frominet;
  	FILE *fp;
! #ifdef COMPAT42
! 	char line[BUFSIZ + 1];
  #else
! 	char line[MSG_BSIZE + 1];
! #endif /* COMPAT42 */
! #ifdef ultrix
  	extern void die(), domark(), reapchild();
  #else
  	extern int die(), domark(), reapchild();
! #endif /* ultrix */
! 
  	while (--argc > 0) {
  		p = *++argv;
  		if (p[0] != '-')
--- 264,282 ----
  	struct sockaddr_un sunx, fromunix;
  	struct sockaddr_in sin, frominet;
  	FILE *fp;
! #ifdef MSG_BSIZE
! 	char line[max(MSG_BSIZE,BUFSIZ) + 1];
  #else
! 	char line[BUFSIZ + 1];
! #endif
! #ifdef POSIX_SIGHANDLERS
  	extern void die(), domark(), reapchild();
  #else
  	extern int die(), domark(), reapchild();
! #endif
! #ifdef COMPAT42
! 	localhostaddr.s_addr = htonl(0x7f000001L); /* 127.0.0.1 */
! #endif
  	while (--argc > 0) {
  		p = *++argv;
  		if (p[0] != '-')
***************
*** 367,389 ****
  		}
  		sin.sin_family = AF_INET;
  		sin.sin_port = LogPort = sp->s_port;
! #ifdef COMPAT42
! 		(void) close(finet);
! #else
  		if (bind(finet, &sin, sizeof(sin)) < 0) {
  			logerror("bind");
  			if (!Debug)
  				die(0);
  		} else {
  			inetm = FDMASK(finet);
  			InetInuse = 1;
  		}
- #endif /* COMPAT42 */
  	}
! #ifdef COMPAT42
! 	InetInuse = 1;
! 	inetm = 0;
  	klogm = 0;
  #else
  	if ((fklog = open("/dev/klog", O_RDONLY)) >= 0)
  		klogm = FDMASK(fklog);
--- 374,394 ----
  		}
  		sin.sin_family = AF_INET;
  		sin.sin_port = LogPort = sp->s_port;
! 		sin.sin_addr.s_addr = 0;
  		if (bind(finet, &sin, sizeof(sin)) < 0) {
  			logerror("bind");
  			if (!Debug)
  				die(0);
+ 			else
+ 			    inetm = 0;
  		} else {
  			inetm = FDMASK(finet);
  			InetInuse = 1;
  		}
  	}
! #ifdef NO_KLOG
  	klogm = 0;
+ 	fklog = 0;
  #else
  	if ((fklog = open("/dev/klog", O_RDONLY)) >= 0)
  		klogm = FDMASK(fklog);
***************
*** 391,397 ****
  		dprintf("can't open /dev/klog (%d)\n", errno);
  		klogm = 0;
  	}
! #endif /* COMPAT42 */
  
  	/* tuck my process id away */
  	fp = fopen(PidFile, "w");
--- 396,402 ----
  		dprintf("can't open /dev/klog (%d)\n", errno);
  		klogm = 0;
  	}
! #endif /* NO_KLOG */
  
  	/* tuck my process id away */
  	fp = fopen(PidFile, "w");
***************
*** 445,451 ****
  				     (struct sockaddr *) &fromunix, &len);
  			if (i > 0) {
  				line[i] = '\0';
! 				printline(LocalHostName, line);
  			} else if (i < 0 && errno != EINTR)
  				logerror("recvfrom unix");
  		}
--- 450,456 ----
  				     (struct sockaddr *) &fromunix, &len);
  			if (i > 0) {
  				line[i] = '\0';
! 				printline(LocalHostName, line, 0);
  			} else if (i < 0 && errno != EINTR)
  				logerror("recvfrom unix");
  		}
***************
*** 454,462 ****
  			i = recvfrom(finet, line, MAXLINE, 0, &frominet, &len);
  			if (i > 0) {
  				extern char *cvthname();
! 
  				line[i] = '\0';
! 				printline(cvthname(&frominet), line);
  			} else if (i < 0 && errno != EINTR)
  				logerror("recvfrom inet");
  		} 
--- 459,475 ----
  			i = recvfrom(finet, line, MAXLINE, 0, &frominet, &len);
  			if (i > 0) {
  				extern char *cvthname();
! 				
  				line[i] = '\0';
! #ifdef COMPAT42
! 				/* if it matches the localhost loopback,
! 				   this is an old client, so humor him. */
! 				if (frominet.sin_addr.s_addr ==
! 				    localhostaddr.s_addr)
! 				    printline(cvthname(&frominet), line, 1);
! 				else
! #endif
! 				    printline(cvthname(&frominet), line, 0);
  			} else if (i < 0 && errno != EINTR)
  				logerror("recvfrom inet");
  		} 
***************
*** 482,495 ****
  	}
  }
  
  /*
   * Take a raw input line, decode the message, and print the message
   * on the appropriate log files.
   */
  
! printline(hname, msg)
  	char *hname;
  	char *msg;
  {
  	register char *p, *q;
  	register int c;
--- 495,525 ----
  	}
  }
  
+ #ifdef COMPAT42
+ int convert_oldpri[] = {
+     LOG_COMPAT|LOG_EMERG,		/* there is no 0 */
+     LOG_COMPAT|LOG_ALERT,		/* old LOG_ALERT */
+     LOG_COMPAT|LOG_ALERT,		/* old LOG_SALERT */
+     LOG_COMPAT|LOG_CRIT,		/* old LOG_EMERG */
+     LOG_COMPAT|LOG_ERR,			/* old LOG_ERROR */
+     LOG_COMPAT|LOG_WARNING,		/* old LOG_CRIT */
+     LOG_COMPAT|LOG_WARNING,		/* old LOG_WARNING */
+     LOG_COMPAT|LOG_NOTICE,		/* old LOG_NOTICE */
+     LOG_COMPAT|LOG_INFO,		/* old LOG_INFO */
+     LOG_COMPAT|LOG_DEBUG,		/* old LOG_DEBUG */
+ };
+ int noldpri = sizeof(convert_oldpri)/sizeof(convert_oldpri[0]);
+ #endif
+ 
  /*
   * Take a raw input line, decode the message, and print the message
   * on the appropriate log files.
   */
  
! printline(hname, msg, oldcompat)
  	char *hname;
  	char *msg;
+ 	int oldcompat;
  {
  	register char *p, *q;
  	register int c;
***************
*** 506,511 ****
--- 536,549 ----
  		if (*p == '>')
  			++p;
  	}
+ #ifdef COMPAT42
+ 	if (oldcompat) {
+ 	    if (pri > 0 && pri < noldpri)
+ 		pri = convert_oldpri[pri];
+ 	    else
+ 		pri = LOG_MAKEPRI(LOG_COMPAT, LOG_ERR);
+ 	}
+ #endif
  	if (pri &~ (LOG_FACMASK|LOG_PRIMASK))
  		pri = DEFUPRI;
  
***************
*** 738,748 ****
  		l = strlen(line);
  		if (l > MAXLINE)
  			l = MAXLINE;
- #ifdef COMPAT42
- 		if (sendto(f->f_file, line, l, 0, &f->f_un.f_forw.f_addr,
- #else
  		if (sendto(finet, line, l, 0, &f->f_un.f_forw.f_addr,
- #endif
  		    sizeof f->f_un.f_forw.f_addr) != l) {
  			int e = errno;
  			(void) close(f->f_file);
--- 776,782 ----
***************
*** 937,943 ****
  	reenter = 0;
  }
  
! #ifdef ultrix
  void
  #endif
  reapchild()
--- 971,977 ----
  	reenter = 0;
  }
  
! #ifdef POSIX_SIGHANDLERS
  void
  #endif
  reapchild()
***************
*** 965,970 ****
--- 999,1009 ----
  		dprintf("Malformed from address\n");
  		return ("???");
  	}
+ #ifdef COMPAT42
+ 	/* don't bother looking up 127.0.0.1, it's us. */
+ 	if (f->sin_addr.s_addr == localhostaddr.s_addr)
+ 	    return(LocalHostName);
+ #endif
  	hp = gethostbyaddr(&f->sin_addr, sizeof(struct in_addr), f->sin_family);
  	if (hp == 0) {
  		dprintf("Host name for your address (%s) unknown\n",
***************
*** 976,982 ****
  	return (hp->h_name);
  }
  
! #ifdef ultrix
  void
  #endif
  domark()
--- 1015,1021 ----
  	return (hp->h_name);
  }
  
! #ifdef POSIX_SIGHANDLERS
  void
  #endif
  domark()
***************
*** 1022,1028 ****
  	logmsg(LOG_SYSLOG|LOG_ERR, buf, LocalHostName, ADDDATE);
  }
  
! #ifdef ultrix
  void
  #endif
  die(sig)
--- 1061,1067 ----
  	logmsg(LOG_SYSLOG|LOG_ERR, buf, LocalHostName, ADDDATE);
  }
  
! #ifdef POSIX_SIGHANDLERS
  void
  #endif
  die(sig)
***************
*** 1074,1082 ****
  		  case F_FILE:
  		  case F_TTY:
  		  case F_CONSOLE:
- #ifdef COMPAT42
- 		  case F_FORW:
- #endif
  			(void) close(f->f_file);
  			break;
  		}
--- 1113,1118 ----
***************
*** 1257,1269 ****
  		f->f_un.f_forw.f_addr.sin_family = AF_INET;
  		f->f_un.f_forw.f_addr.sin_port = LogPort;
  		bcopy(hp->h_addr, (char *) &f->f_un.f_forw.f_addr.sin_addr, hp->h_length);
- #ifdef COMPAT42
- 		f->f_file = socket(AF_INET, SOCK_DGRAM, 0);
- 		if (f->f_file < 0) {
- 		    logerror("socket");
- 		    break;
- 		}
- #endif
  		f->f_type = F_FORW;
  		break;
  
--- 1293,1298 ----
*** /mit/zephyr/src/clients/syslogd/syslog.h	Mon Nov 14 11:53:05 1988
--- syslog.h	Fri Dec  7 09:39:55 1990
***************
*** 19,24 ****
--- 19,25 ----
  #define LOG_LPR		(6<<3)	/* line printer subsystem */
  #define LOG_NEWS	(7<<3)	/* network news subsystem */
  #define LOG_UUCP	(8<<3)	/* UUCP subsystem */
+ #define LOG_COMPAT	(15<<3)	/* compatibility with 4.2 syslog */
  	/* other codes through 15 reserved for system use */
  #define LOG_LOCAL0	(16<<3)	/* reserved for local use */
  #define LOG_LOCAL1	(17<<3)	/* reserved for local use */

home help back first fref pref prev next nref lref last post