🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99139

emacs process false close (v18.54 and above)

#99139
From: "Jonathan I. Kamens"
Date: Mon, 05 Nov 1990 22:02
90 lines
3986 bytes
(NOTE: We could *really* use some feedback about the patch proposed
below, since we want to include it in our next workstation software
release (coming in about a month and a half), but we don't have
anybody here who knows enough about emacs to verify its correctness.
Therefore, if you examine the fix and think it's correct, please send
me E-mail and let me know; if you think there's something wrong with
it, please me me know about that too.  Thanks.)

(Original fix by Mark Eichin, eichin@ATHENA.MIT.EDU.)

		      *************************

BACKGROUND:
In process.c, wait_reading_process_input is structured
  while (1) {
    select(32,&Available,0,&Exception,&timeout);
    for(channel = 3; Available && channel < 32; channel++)
      {
        m = ChannelMask(channel);
        if (m & Available) {
           Available &= ~m;
           if(read_process_output(proc[channel], channel) > 0)
               /* got some data, deal with it */
               do display;
           else
               /* select woke up, but read didn't get data, so
                  the connection must have closed on us... */
              deactivate_process(proc);
         }
      }
   }

read_process_output is essentially
   nchars = read(channel, chars, 1024);
   if(nchars <=0) return 0;
   call2(proc->filter, proc, make_string(chars));

THE PROBLEM:
 read_process_output can call wait_reading_process_input recursively.

THE SCENARIO:
 Two channels provide output "simultaneously". The one with the lower channel
number has a "filter" which does an (accept-process-output), which calls
wait_reading_process_input. wait_reading_process_input does another select,
and sees the input for the higher channel, and calls read_process_output on
it.
 Eventually, wait_reading_process_input and (accept-process-output) return,
so the proc->filter finishes. Then the wait_reading_process_input loop
continues, sees the higher bit in Available still set, so calls
read_process_output again. This time, there isn't any output, so read gets an
EWOULDBLOCK and returns, causing wait_reading_process_input to *incorrectly*
deactivate the process.

THE FIX:
 A surprisingly simple fix is to make Available static, so that the recursive
call to wait_reading_process_input changes it... after all, the channels are
global, the mask representing them should be too.

ps. The line numbers for the patch below is for 18.54, but the line
numbers are only slightly different for 18.55.

% diff -c process.c /mit/emacs/src/process.c
*** process.c   Fri Oct 19 22:36:16 1990
--- /mit/emacs/src/process.c    Fri May 26 22:11:19 1989
***************
*** 1274,1281 ****
       int time_limit, read_kbd, do_display;
  {
    register int channel, nfds, m;
!   static int Available = 0;
!   static int Exception;
    int xerrno;
    Lisp_Object proc;
  #ifdef HAVE_TIMEVAL
--- 1274,1281 ----
       int time_limit, read_kbd, do_display;
  {
    register int channel, nfds, m;
!   int Available = 0;
!   int Exception;
    int xerrno;
    Lisp_Object proc;
  #ifdef HAVE_TIMEVAL

		      *************************

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710
Technical Details
Message-ID: <9011052202.AA12246@pit-manager.MIT.EDU>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!PIT-MANAGER.MIT.EDU!jik

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,75a3d3c8cbc85c6d,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-11-05 14:02:00 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!PIT-MANAGER.MIT.EDU!jik
From: jik@PIT-MANAGER.MIT.EDU ("Jonathan I. Kamens")
Newsgroups: gnu.emacs.bug
Subject: emacs process false close (v18.54 and above)
Message-ID: <9011052202.AA12246@pit-manager.MIT.EDU>
Date: 5 Nov 90 22:02:00 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 90
Approved: bug-gnu-emacs@prep.ai.mit.edu
Posted: Mon Nov  5 23:02:00 1990