all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* fix latent bug in process.c
@ 2012-08-13 19:25 Tom Tromey
  2012-08-13 20:45 ` Andreas Schwab
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2012-08-13 19:25 UTC (permalink / raw)
  To: Emacs discussions

While looking into making process.c thread-friendly, I found an oddity
in process.c.  It looks like a latent bug to me, but I was hoping that
somebody more familiar with the code could take a look.

The appended patch shows the issue.

First, we unconditionally set Writeok, even if SELECT_CANT_DO_WRITE_MASK
is set.  It seems to me that in one branch we ought to clear Writeok;
and only set it in the other.

Second, and more importantly, in the loop after the select completes, we
check if an fd is in write_mask.  But, I think this will always be true
for any fd for which add_write_fd has been called -- meaning that the
callback will be called even if the fd is not in fact available for
writing.

The fix here is to check Writeok rather than write_mask (and this is
what necessitated the first change -- to ensure Writeok is always set
correctly).

Comments?

Tom

    fix latent bug in process.c
    
    	* process.c (wait_reading_process_output): Handle Writeok
    	depending on SELECT_CANT_DO_WRITE_MASK.  Check Writeok bits,
    	not write_mask.

diff --git a/src/process.c b/src/process.c
index 0be624a..278d143 100644
--- a/src/process.c
+++ b/src/process.c
@@ -4522,11 +4522,12 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
 	    Available = non_keyboard_wait_mask;
 	  else
 	    Available = input_wait_mask;
-          Writeok = write_mask;
 #ifdef SELECT_CANT_DO_WRITE_MASK
           check_write = 0;
+	  FD_ZERO (&Writeok);
 #else
           check_write = 1;
+          Writeok = write_mask;
 #endif
  	  check_delay = wait_channel >= 0 ? 0 : process_output_delay_count;
 	}
@@ -4792,7 +4793,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
               && d->func != 0
               && (d->condition & FOR_READ) != 0)
             d->func (channel, d->data, 1);
-          if (FD_ISSET (channel, &write_mask)
+          if (FD_ISSET (channel, &Writeok)
               && d->func != 0
               && (d->condition & FOR_WRITE) != 0)
             d->func (channel, d->data, 0);



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-08-15 15:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-13 19:25 fix latent bug in process.c Tom Tromey
2012-08-13 20:45 ` Andreas Schwab
2012-08-13 21:04   ` Tom Tromey
2012-08-13 21:19     ` Andreas Schwab
2012-08-14 14:45       ` Tom Tromey
2012-08-15 15:01         ` Andreas Schwab
2012-08-14  6:05   ` Michael Albinus
2012-08-14  7:44     ` Jan Djärv

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.