[net.bugs.4bsd] BRL Release 3 BSD4.2 /etc/syslogd forgets about its children

terry@msdc.UUCP (Terry Countryman) (02/12/86)

	In the last week or so I have been configuring the syslog daemon(s)
for our 4.2 systems so that we can be notified quickly of possible system
problems (there isn't an operator in the computer room all of the time).
Using the ability to "network" the log messages over to our development
system and having 4 or 5 people in the notify list started putting
/etc/syslogd through its' paces.  Then I started noticing large numbers
of zombies with syslogd as the parent.  Going to the code, I found that
syslogd forks a process for each person/logfile that gets the log messages.
But it never waits on those children; an excellent way to generate zombie
processes.

	Below is the fix that I came up with.

-------------------------------------------------------------------------
*** /tmp/,RCSt1006581	Wed Jan 29 20:23:22 1986
--- syslogd.c	Tue Jan 28 18:55:58 1986
***************
*** 49,54
  #include <sys/msgbuf.h>
  #include <sys/uio.h>
  #include <sys/un.h>
  
  #include <netinet/in.h>
  #include <netdb.h>

--- 49,57 -----
  #include <sys/msgbuf.h>
  #include <sys/uio.h>
  #include <sys/un.h>
+ #include <sys/wait.h>
+ #include <sys/time.h>
+ #include <sys/resource.h>
  
  #include <netinet/in.h>
  #include <netdb.h>
***************
*** 685,690
  	struct utmp ut;
  	long now;
  	char line[MAXLINE + 100];
  
  	/* open the user login file */
  	if ((uf = fopen("/etc/utmp", "r")) == NULL) {

--- 688,694 -----
  	struct utmp ut;
  	long now;
  	char line[MAXLINE + 100];
+ 	union wait waitbuf;
  
  	/* open the user login file */
  	if ((uf = fopen("/etc/utmp", "r")) == NULL) {
***************
*** 759,764
  
  	/* close the user login file */
  	(void) fclose(uf);
  }
  
  /*

--- 763,772 -----
  
  	/* close the user login file */
  	(void) fclose(uf);
+ 
+ 	/* cleanup after ourself; collect the children that are ready */
+ 	while (wait3(&waitbuf, WNOHANG, (struct rusage *)0) > 0)
+ 		continue;
  }
  
  /*
-----------------------------------------------------------------------------