From owner-svn-src-head@FreeBSD.ORG Sun Aug 15 21:06:54 2010 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 067DB1065695; Sun, 15 Aug 2010 21:06:54 +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 CEB8A8FC08; Sun, 15 Aug 2010 21:06:53 +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 o7FL6rjO071754; Sun, 15 Aug 2010 21:06:53 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7FL6r9B071750; Sun, 15 Aug 2010 21:06:53 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201008152106.o7FL6r9B071750@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 15 Aug 2010 21:06:53 +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: r211349 - 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: Sun, 15 Aug 2010 21:06:54 -0000 Author: jilles Date: Sun Aug 15 21:06:53 2010 New Revision: 211349 URL: http://svn.freebsd.org/changeset/base/211349 Log: sh: Fix break/continue/return sometimes not skipping the rest of dot script. In our implementation and most others, a break or continue in a dot script can break or continue a loop outside the dot script. This should cause all further commands in the dot script to be skipped. However, cmdloop() did not know about this and continued to parse and execute commands from the dot script. As described in the man page, a return in a dot script in a function returns from the function, not only from the dot script. There was a similar issue as with break and continue. In various other shells, the return appears to return from the dot script, but POSIX seems not very clear about this. Added: head/tools/regression/bin/sh/builtins/break1.0 (contents, props changed) head/tools/regression/bin/sh/builtins/return5.0 (contents, props changed) Modified: head/bin/sh/main.c Modified: head/bin/sh/main.c ============================================================================== --- head/bin/sh/main.c Sun Aug 15 20:56:13 2010 (r211348) +++ head/bin/sh/main.c Sun Aug 15 21:06:53 2010 (r211349) @@ -232,8 +232,9 @@ cmdloop(int top) } popstackmark(&smark); setstackmark(&smark); - if (evalskip == SKIPFILE) { - evalskip = 0; + if (evalskip != 0) { + if (evalskip == SKIPFILE) + evalskip = 0; break; } } Added: head/tools/regression/bin/sh/builtins/break1.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/builtins/break1.0 Sun Aug 15 21:06:53 2010 (r211349) @@ -0,0 +1,16 @@ +# $FreeBSD$ + +if [ "$1" != nested ]; then + while :; do + set -- nested + . "$0" + echo bad2 + exit 2 + done + exit 0 +fi +# To trigger the bug, the following commands must be at the top level, +# with newlines in between. +break +echo bad1 +exit 1 Added: head/tools/regression/bin/sh/builtins/return5.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/builtins/return5.0 Sun Aug 15 21:06:53 2010 (r211349) @@ -0,0 +1,17 @@ +# $FreeBSD$ + +if [ "$1" != nested ]; then + f() { + set -- nested + . "$0" + # Allow return to return from the function or the dot script. + return 4 + } + f + exit $(($? ^ 4)) +fi +# To trigger the bug, the following commands must be at the top level, +# with newlines in between. +return 4 +echo bad +exit 1