From shinra@sodans.usata.org  Wed Jul 27 10:24:28 2011
Return-Path: <shinra@sodans.usata.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 7EF28106566B
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Jul 2011 10:24:28 +0000 (UTC)
	(envelope-from shinra@sodans.usata.org)
Received: from sodans.usata.org (sodans.usata.org [49.212.76.31])
	by mx1.freebsd.org (Postfix) with ESMTP id 569F78FC0A
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Jul 2011 10:24:28 +0000 (UTC)
Received: by sodans.usata.org (Postfix, from userid 1010)
	id DCE9D119C0C; Wed, 27 Jul 2011 19:24:27 +0900 (JST)
Message-Id: <20110727102427.DCE9D119C0C@sodans.usata.org>
Date: Wed, 27 Jul 2011 19:24:27 +0900 (JST)
From: AIDA Shinra <shinra@j10n.org>
Reply-To: AIDA Shinra <shinra@j10n.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] Libedit does not always restore its signal handler
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         159226
>Category:       kern
>Synopsis:       [libedit] [patch] libedit does not always restore its signal handler
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 27 10:30:08 UTC 2011
>Closed-Date:    
>Last-Modified:  Thu Jul 12 07:42:41 UTC 2012
>Originator:     AIDA Shinra
>Release:        FreeBSD 7.3-RELEASE-p6 i386
>Organization:
>Environment:
System: FreeBSD sodans.usata.org 7.3-RELEASE-p6 FreeBSD 7.3-RELEASE-p6 #1: Mon Jun 27 01:58:42 JST 2011 wm3@sodans.usata.org:/usr/obj/usr/src/sys/KERNEL_SODANS i386


	
>Description:
If a program gets the same signal twice in a single call to el_gets(), editline's internal signal handler is not used to the second one.

>How-To-Repeat:
I found this bug when testing CURRENT's BSD bc.

You can also reproduce the problem by inserting "printf" or "write" to libedit's sig_handler() and run ftp(1).

>Fix:

	Apply the attached patch.

--- libedit-multisignal.diff begins here ---
--- /usr/src/lib/libedit/sig.c	2010-02-10 09:26:20.000000000 +0900
+++ sig.c	2011-07-17 13:31:47.000000000 +0900
@@ -94,9 +94,18 @@
 		if (signo == sighdl[i])
 			break;
 
-	(void) signal(signo, sel->el_signal[i]);
+	if (sel->el_signal[i] != SIG_IGN && signo != SIGCONT) {
+		/* Deliver the signal to my original handler */
+		(void) signal(signo, sel->el_signal[i]);
+		(void) kill(getpid(), signo);
+		(void) sigfillset(&nset);
+		(void) sigdelset(&nset, signo);
+		(void) sigdelset(&nset, SIGCONT);
+		/* delever and maybe stop here */
+		(void) sigsuspend(&nset);
+		(void) signal(signo, sig_handler);
+	}
 	(void) sigprocmask(SIG_SETMASK, &oset, NULL);
-	(void) kill(0, signo);
 }
 
 
--- libedit-multisignal.diff ends here ---


>Release-Note:
>Audit-Trail:
Date: Mon, 2 Jul 2012 12:53:15 -0700 (PDT)
From: Pedro Giffuni <pfg@freebsd.org>
Reply-To: pfg@freebsd.org
To: bug-followup@FreeBSD.org
Subject: Re: [libedit] [patch] libedit does not always restore its signal handler

 It is likely that this bug was fixed by r237448,=0Awhich merged some update=
 s from NetBSD, among them=0ACVS 1.13:=0A=0Ain order for read() to return EI=
 NTR we need to use sigaction, not signal,=0Aotherwise SA_RESTART is set.=0A=
 =0Ahttp://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libedit/sig.c.diff?r1=3D1.12=
 &r2=3D1.13&only_with_tag=3DMAIN
>Unformatted:
