From nobody@FreeBSD.org  Mon Jul  1 03:07:52 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id C7D88C25
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  1 Jul 2013 03:07:52 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	by mx1.freebsd.org (Postfix) with ESMTP id BAE9018FF
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  1 Jul 2013 03:07:52 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r6137qNw054947
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 1 Jul 2013 03:07:52 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r6137quZ054938;
	Mon, 1 Jul 2013 03:07:52 GMT
	(envelope-from nobody)
Message-Id: <201307010307.r6137quZ054938@oldred.freebsd.org>
Date: Mon, 1 Jul 2013 03:07:52 GMT
From: Grant Watson <grant_watson@yahoo.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: /bin/sh: Early SIGWINCH can end process
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         180146
>Category:       bin
>Synopsis:       /bin/sh: Early SIGWINCH can end process
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jilles
>State:          patched
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 01 03:10:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Tue Feb 04 22:25:32 UTC 2014
>Originator:     Grant Watson
>Release:        9.1-RELEASE
>Organization:
>Environment:
FreeBSD awesome-bsd 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243825: Tue Dec 4 09:23:10 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
>Description:
There appears to be a race condition in /bin/sh where receiving
SIGWINCH too early will cause the process to end.  Bugs ports/178194
and ports/178651, which I filed, are occurrences of this bug.
>How-To-Repeat:
Way to Reproduce #1:

Install termit and paste the following into ~/.config/termit/rc.lua:

    defaults = {
        showScrollbar = false,
        hideMenubar = true
    }
    setOptions(defaults)

Then run "termit -e /bin/sh".  Running "termit -e 'truss -o shlog.txt /bin/sh'" does not surpress the bug for me.

Way to Reproduce #2:

Install the awesome window manager, create a user whose shell is /bin/sh, and ensure that this user does not have a ~/.config/awesome/rc.lua file that would override the default configuration.

Log in as this user.  Left click the box in the upper-right corner of the screen to switch to a tiling layout.  Press super+return (that is, windows+return) four or five times; each time an xterm should open.  Many will close, but one or two may remain open.  Running "truss xterm -e /bin/sh" does not surpress the bug for me, but running truss between xterm and sh does.
>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: ak 
Responsible-Changed-When: Fri Oct 11 04:19:08 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=180146 

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, grant_watson@yahoo.com
Cc:  
Subject: Re: bin/180146: /bin/sh: Early SIGWINCH can end process
Date: Fri, 11 Oct 2013 12:44:55 +0200

 In PR bin/180146, you wrote:
 > There appears to be a race condition in /bin/sh where receiving
 > SIGWINCH too early will cause the process to end. Bugs ports/178194
 > and ports/178651, which I filed, are occurrences of this bug.
 
 Although I cannot reproduce this bug using the termit reproducer, I can
 imagine libedit contains this kind of bug since it is of a low quality
 in general (see also
 http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/169773 ).
 
 Perhaps the below patch will work around your issue (while delaying the
 response to a true SIGWINCH until <Enter> is pressed).
 
 commit 548c429eea82f483d56181115451f70146d9b948
 Author: Jilles Tjoelker <jilles@stack.nl>
 Date:   Sun Sep 1 18:22:24 2013 +0200
 
     sh: Enable system call restart for the default SIGWINCH handler.
     
     This makes it apply later than it should but avoids libedit bugs.
 
 diff --git a/bin/sh/trap.c b/bin/sh/trap.c
 index 3fc8566..73e156b 100644
 --- a/bin/sh/trap.c
 +++ b/bin/sh/trap.c
 @@ -260,6 +260,7 @@ setsignal(int signo)
  	struct sigaction sa;
  	char *t;
  
 +	sa.sa_flags = 0;
  	if ((t = trap[signo]) == NULL)
  		action = S_DFL;
  	else if (*t != '\0')
 @@ -297,6 +298,7 @@ setsignal(int signo)
  		case SIGWINCH:
  			if (rootshell && iflag)
  				action = S_CATCH;
 +			sa.sa_flags |= SA_RESTART;
  			break;
  #endif
  		}
 @@ -334,7 +336,6 @@ setsignal(int signo)
  	}
  	*t = action;
  	sa.sa_handler = sigact;
 -	sa.sa_flags = 0;
  	sigemptyset(&sa.sa_mask);
  	sigaction(signo, &sa, NULL);
  }
 
 -- 
 Jilles Tjoelker

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/180146: commit references a PR
Date: Tue, 14 Jan 2014 22:56:38 +0000 (UTC)

 Author: jilles
 Date: Tue Jan 14 22:56:25 2014
 New Revision: 260654
 URL: http://svnweb.freebsd.org/changeset/base/260654
 
 Log:
   sh: Remove SIGWINCH handler and just check for resize before every read.
   
   The SIGWINCH handler triggers breakage in libedit which is hard to fix; see
   PR bin/169773.
   
   Also, window size changes while a program is in foreground (and it rather
   than sh will receive SIGWINCH) will now be picked up automatically.
   
   Downside: it is now certain that a resize is only processed after pressing
   <Enter>. If libedit is fixed, sh will most likely have to be changed also.
   
   PR:		bin/180146
 
 Modified:
   head/bin/sh/input.c
   head/bin/sh/trap.c
   head/bin/sh/trap.h
 
 Modified: head/bin/sh/input.c
 ==============================================================================
 --- head/bin/sh/input.c	Tue Jan 14 22:46:23 2014	(r260653)
 +++ head/bin/sh/input.c	Tue Jan 14 22:56:25 2014	(r260654)
 @@ -162,20 +162,16 @@ preadfd(void)
  	int nr;
  	parsenextc = parsefile->buf;
  
 -#ifndef NO_HISTORY
 -	if (el != NULL && gotwinch) {
 -		gotwinch = 0;
 -		el_resize(el);
 -	}
 -#endif
  retry:
  #ifndef NO_HISTORY
  	if (parsefile->fd == 0 && el) {
  		static const char *rl_cp;
  		static int el_len;
  
 -		if (rl_cp == NULL)
 +		if (rl_cp == NULL) {
 +			el_resize(el);
  			rl_cp = el_gets(el, &el_len);
 +		}
  		if (rl_cp == NULL)
  			nr = el_len == 0 ? 0 : -1;
  		else {
 
 Modified: head/bin/sh/trap.c
 ==============================================================================
 --- head/bin/sh/trap.c	Tue Jan 14 22:46:23 2014	(r260653)
 +++ head/bin/sh/trap.c	Tue Jan 14 22:56:25 2014	(r260654)
 @@ -80,7 +80,6 @@ static char *volatile trap[NSIG];	/* tra
  static volatile sig_atomic_t gotsig[NSIG];
  				/* indicates specified signal received */
  static int ignore_sigchld;	/* Used while handling SIGCHLD traps. */
 -volatile sig_atomic_t gotwinch;
  static int last_trapsig;
  
  static int exiting;		/* exitshell() has been called */
 @@ -293,12 +292,6 @@ setsignal(int signo)
  				action = S_IGN;
  			break;
  #endif
 -#ifndef NO_HISTORY
 -		case SIGWINCH:
 -			if (rootshell && iflag)
 -				action = S_CATCH;
 -			break;
 -#endif
  		}
  	}
  
 @@ -400,11 +393,6 @@ onsig(int signo)
  		gotsig[signo] = 1;
  		pendingsig = signo;
  	}
 -
 -#ifndef NO_HISTORY
 -	if (signo == SIGWINCH)
 -		gotwinch = 1;
 -#endif
  }
  
  
 @@ -490,9 +478,6 @@ setinteractive(int on)
  	setsignal(SIGINT);
  	setsignal(SIGQUIT);
  	setsignal(SIGTERM);
 -#ifndef NO_HISTORY
 -	setsignal(SIGWINCH);
 -#endif
  	is_interactive = on;
  }
  
 
 Modified: head/bin/sh/trap.h
 ==============================================================================
 --- head/bin/sh/trap.h	Tue Jan 14 22:46:23 2014	(r260653)
 +++ head/bin/sh/trap.h	Tue Jan 14 22:56:25 2014	(r260654)
 @@ -36,7 +36,6 @@
  extern volatile sig_atomic_t pendingsig;
  extern volatile sig_atomic_t pendingsig_waitcmd;
  extern int in_dotrap;
 -extern volatile sig_atomic_t gotwinch;
  
  void clear_traps(void);
  int have_traps(void);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jilles 
State-Changed-When: Tue Feb 4 22:24:45 UTC 2014 
State-Changed-Why:  
I have applied a workaround for libedit breakage in 11-current 
in SVN r260654. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=180146 
>Unformatted:
