[net.emacs] subprocess exit bug in emacs #264

glenn@nsc.UUCP (Glenn Skinner) (05/29/84)

There is a bug in emacs #264 that can cause emacs itself to exit when one
of its subprocesses exits.  If you've been plagued by having emacs vanish
after doing a compile-it or after exiting from a shell window, then this
fix is for you.

The problem is in the FillKeyboard routine of mchan.c.  It does a select
to determine which input sources actually have something available and
then goes on to process the ones that do.  This select can be interrupted
by the SIGCHLD signal generated when a subprocess exits.  In this case,
it returns with error status and errno == EINTR.  The bug is that the old
code doesn't check for this case and instead just packs it in and returns
-1, causing GetChar to return -1, which in turn causes ProcessKeys to exit.
Bang!  No more emacs session.

A diff -c giving the fix follows.  Line numbers undoubtedly won't match yours.

		-- Glenn Skinner
		National Semiconductor, Microprocessor Systems Division
		(408) 733-2600 x 335


*** /tmp/d23028	Tue May 29 11:33:14 1984
--- mchan.c	Mon May 28 23:09:08 1984
***************
*** 292,297
  	    Available = InputChannels | ShareClients;
  	    nfds = select (20, &Available, 0, 0, 0);
  	    if (nfds < 0) {
  		KeyboardCount = -1;
  		return -1;
  	    }

--- 292,303 -----
  	    Available = InputChannels | ShareClients;
  	    nfds = select (20, &Available, 0, 0, 0);
  	    if (nfds < 0) {
+ 		/* Don't let SIGCHLDs elsewhere mess us up.... */
+ 		if (errno == EINTR) {
+ 		    errno = 0;
+ 		    Available = 0;
+ 		    continue;
+ 		}
  		KeyboardCount = -1;
  		return -1;
  	    }