Subject: Small race condition with SIGWINCH

From: Chuck Goodhart <[email-masked]>
Date: Wed, 9 Dec 1998 11:47:05 -0800 (PST)

The following patch fixes a small race condition in the handling of the
SIGWINCH signal:

======== begin patch ========
*** pine4.05/pine/osdep/termin.unx.orig	Tue Mar 31 12:09:12 1998
--- pine4.05/pine/osdep/termin.unx	Sun Dec  6 12:19:58 1998
***************
*** 194,215 ****
      fflush(stdout);
  
  #ifdef RESIZING
!     if(winch_occured || setjmp(winch_state) != 0){
! 	ready_for_winch = 0;
! 	fix_windsize(ps_global);
  
! 	/*
! 	 * May need to unblock signal after longjmp from handler, because
! 	 * signal is normally unblocked upon routine exit from the handler.
! 	 */
! 	if(!winch_occured)
! 	  our_sigunblock(SIGWINCH);
  
  	winch_occured = 0;
  	return(KEY_RESIZE);
      }
-     else
-       ready_for_winch = 1;
  #endif /* RESIZING */
  
      switch(res=input_ready(time_out)){
--- 194,220 ----
      fflush(stdout);
  
  #ifdef RESIZING
!     if(!winch_occured){
! 	if(setjmp(winch_state) != 0){
! 	    winch_occured = 1;
! 	    ready_for_winch = 0;
  
! 	    /*
! 	     * Need to unblock signal after longjmp from handler, because
! 	     * signal is normally unblocked upon routine exit from the handler.
! 	     */
! 	    our_sigunblock(SIGWINCH);
! 	}
! 	else
! 	  ready_for_winch = 1;
!     }
  
+     if(winch_occured){
  	winch_occured = 0;
+ 	ready_for_winch = 0;
+ 	fix_windsize(ps_global);
  	return(KEY_RESIZE);
      }
  #endif /* RESIZING */
  
      switch(res=input_ready(time_out)){
======== end patch ========

Refering to the original code, if a SIGWINCH signal should be received
after the test of "winch_occured" on line 197, but before the setting of
"ready_for_winch" on line 212, the signal handler will simply set
"winch_occured" and return, delaying the KEY_RESIZE return until after the
next keystroke or mail-check-interval timeout.

The patch corrects this by checking "winch_occured" again after setting up
the jmp_buf "winch_state" and enabling it via "ready_for_winch".

-- 
Chuck Goodhart <[email-masked]>

-----------------------------------------------------------------
 For information about this mailing list, and its archives, see: 
 http://www.washington.edu/pine/pine-info/
-----------------------------------------------------------------