From owner-svn-src-head@FreeBSD.ORG Fri Dec 25 20:21:35 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 882C01065670; Fri, 25 Dec 2009 20:21:35 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 75FB38FC22; Fri, 25 Dec 2009 20:21:35 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBPKLZNZ070623; Fri, 25 Dec 2009 20:21:35 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBPKLZhi070618; Fri, 25 Dec 2009 20:21:35 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <200912252021.nBPKLZhi070618@svn.freebsd.org> From: Jilles Tjoelker Date: Fri, 25 Dec 2009 20:21:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200998 - in head: bin/sh tools/regression/bin/sh/builtins X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Dec 2009 20:21:35 -0000 Author: jilles Date: Fri Dec 25 20:21:35 2009 New Revision: 200998 URL: http://svn.freebsd.org/changeset/base/200998 Log: sh: Do not run callers' exception handlers in subshells. Reset the exception handler in the child to main's. This avoids inappropriate double cleanups or shell duplication when the exception is caught, such as 'fc' and future 'command eval' and 'command .'. Added: head/tools/regression/bin/sh/builtins/fc2.0 (contents, props changed) Modified: head/bin/sh/jobs.c head/bin/sh/main.c head/bin/sh/main.h Modified: head/bin/sh/jobs.c ============================================================================== --- head/bin/sh/jobs.c Fri Dec 25 20:07:48 2009 (r200997) +++ head/bin/sh/jobs.c Fri Dec 25 20:21:35 2009 (r200998) @@ -757,6 +757,7 @@ forkshell(struct job *jp, union node *n, TRACE(("Child shell %d\n", (int)getpid())); wasroot = rootshell; rootshell = 0; + handler = &main_handler; closescript(); INTON; clear_traps(); Modified: head/bin/sh/main.c ============================================================================== --- head/bin/sh/main.c Fri Dec 25 20:07:48 2009 (r200997) +++ head/bin/sh/main.c Fri Dec 25 20:21:35 2009 (r200998) @@ -75,6 +75,7 @@ __FBSDID("$FreeBSD$"); int rootpid; int rootshell; +struct jmploc main_handler; STATIC void read_profile(char *); STATIC char *find_dot_file(char *); @@ -90,14 +91,13 @@ STATIC char *find_dot_file(char *); int main(int argc, char *argv[]) { - struct jmploc jmploc; struct stackmark smark; volatile int state; char *shinit; (void) setlocale(LC_ALL, ""); state = 0; - if (setjmp(jmploc.loc)) { + if (setjmp(main_handler.loc)) { /* * When a shell procedure is executed, we raise the * exception EXSHELLPROC to clean up before executing @@ -143,7 +143,7 @@ main(int argc, char *argv[]) else goto state4; } - handler = &jmploc; + handler = &main_handler; #ifdef DEBUG opentrace(); trputs("Shell args: "); trargs(argv); Modified: head/bin/sh/main.h ============================================================================== --- head/bin/sh/main.h Fri Dec 25 20:07:48 2009 (r200997) +++ head/bin/sh/main.h Fri Dec 25 20:21:35 2009 (r200998) @@ -35,6 +35,7 @@ extern int rootpid; /* pid of main shell */ extern int rootshell; /* true if we aren't a child of the main shell */ +extern struct jmploc main_handler; /* top level exception handler */ void readcmdfile(const char *); void cmdloop(int); Added: head/tools/regression/bin/sh/builtins/fc2.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/builtins/fc2.0 Fri Dec 25 20:21:35 2009 (r200998) @@ -0,0 +1,34 @@ +# $FreeBSD$ +set -e +trap 'echo Broken pipe -- test failed' pipe + +P=${TMPDIR:-/tmp} +cd $P +T=$(mktemp -d sh-test.XXXXXX) +cd $T + +mkfifo input output error +HISTFILE=/dev/null sh +m -i output 2>error & +exec 3>input +{ + # Command not found, containing slash + echo '/var/empty/nonexistent' >&3 + # Read error message, shell will read new input now + read dummy <&5 + # Execute bad command again + echo 'fc -e true; echo continued' >&3 + read dummy <&5 + read line <&4 && [ "$line" = continued ] && : ${rc:=0} + exec 3>&- + # Old sh duplicates itself after the fc, producing another line + # of output. + if read line <&4; then + echo "Extraneous output: $line" + rc=1 + fi +} 4&- + +rm input output error +rmdir ${P}/${T} +exit ${rc:-3}