[gnu.emacs.bug] emacs hangs with 100% CPU after [r]wall

ojr@itk.unit.no (04/13/89)

Description:
We are running SUN OS4.0.1 and emacs 18.53.3. When a broadcast message
arrives at a terminal/window where emacs is running, emacs stops
accepting input and hangs with 100% cpu being used. ^G does not work.
It is possible to restart emacs with an INT signal to the emacs
process from another window.

What I found:
Something strange happens with the SUN i/o system when a broadcast is
delivered. I looks as if no signals are delivered to the emacs process
when the signal originates in keyboard events (neither SIGINT or
SIGIO). The function 'wait_reading_process' loops forever because
select (line 1373) returns with bit 0 in 'Available' set, instead of
delivering the SIGIO signal. As this bit is ignored in the function
the result is an eternal active wait.

Solution (hack?):
What I did was checking on bit 0 in 'wait_reading_process' and sending
the missing SIGIO to emacs if the bit is set. This looks as if it
fixes the problem. The diff is listed below:

lisa% diff -c2 process.c~ process.c
*** process.c~  Sat Oct  8 17:24:20 1988
--- process.c   Thu Apr 13 11:53:26 1989
***************
*** 1399,1402 ****
--- 1399,1413 ----
            error("select error: %s", sys_errlist[xerrno]);
        }
+ #ifdef SUN_REGTEK
+       else if (nfds > 0 && (Available & 1))
+       {
+           /*
+            *  Input from standard input should go to
+            *  interrupthandler.
+            */
+ 
+           kill(getpid(), SIGIO);
+       }
+ #endif
  
        /* Check for keyboard input */

You have to have -DSUN_REGTEK in the compiler command when compiling.
process.c.

Best regards
  ojr@itk.unit.no	Ornulf Jan Rodseth
			SINTEF Dep. of Automatic Control, N-7034 TRONDHEIM
			NORWAY

sdry@vax5.CIT.CORNELL.EDU (04/20/89)

Ornulf Rodseth <ojr@itk.unit.no> recently submitted an analysis of a problem
involving emacs and [r]wall, together with a fix.
We had encountered the same problem here, and I agree with the analysis given.
(Actually, we first detected the problem with 18.52. The same fix applies
to both 18.52 and 18.53.)
I don't see the need for -DSUN_REGTEK, however - my own fix doesn't use it.
So here is an alternate solution (pick your favorite):

*** process.c.old1853	Sat Aug 20 13:27:41 1988
--- process.c	Wed Apr 12 17:00:56 1989
***************
*** 1400,1403 ****
--- 1400,1415 ----
  	}
  
+       /* Bug Fix on 14 March 1989 by S.Gelato, Cornell Astronomy Dept.
+        * --
+        * select(2) keeps returning "stdin ready for read|exception" until
+        * something is done with the descriptor (at the very least, an
+        * ioctl(0, FIONREAD) should be attempted).
+        * get_input_pending() is too lazy, and won't do this unless there
+        * has been an interrupt.
+        * wall(1) apparently causes this condition to be set without any
+        * SIGIO, so we need to do something about it... */
+       
+       if ((Available | Exception) & input_wait_mask) gobble_input();
+       
        /* Check for keyboard input */
        /* If there is any, return immediately

-----------------------------------------------------------------------
Sergio Gelato			gelato@astrosun.tn.cornell.edu
			or	sdry@crnlvax5.bitnet