From owner-svn-src-head@FreeBSD.ORG Wed Sep 4 22:10:18 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 2494D80C; Wed, 4 Sep 2013 22:10:18 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1190A29ED; Wed, 4 Sep 2013 22:10:18 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r84MAHpm091448; Wed, 4 Sep 2013 22:10:17 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r84MAHXh091439; Wed, 4 Sep 2013 22:10:17 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201309042210.r84MAHXh091439@svn.freebsd.org> From: Jilles Tjoelker Date: Wed, 4 Sep 2013 22:10:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r255215 - in head: bin/sh tools/regression/bin/sh/builtins X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 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: Wed, 04 Sep 2013 22:10:18 -0000 Author: jilles Date: Wed Sep 4 22:10:16 2013 New Revision: 255215 URL: http://svnweb.freebsd.org/changeset/base/255215 Log: sh: Make return return from the closest function or dot script. Formerly, return always returned from a function if it was called from a function, even if there was a closer dot script. This was for compatibility with the Bourne shell which only allowed returning from functions. Other modern shells and POSIX return from the function or the dot script, whichever is closest. Git 1.8.4's rebase --continue depends on the POSIX behaviour. Reported by: Christoph Mallon, avg Added: head/tools/regression/bin/sh/builtins/return8.0 (contents, props changed) Modified: head/bin/sh/eval.c head/bin/sh/eval.h head/bin/sh/main.c head/bin/sh/sh.1 Modified: head/bin/sh/eval.c ============================================================================== --- head/bin/sh/eval.c Wed Sep 4 20:55:56 2013 (r255214) +++ head/bin/sh/eval.c Wed Sep 4 22:10:16 2013 (r255215) @@ -324,7 +324,7 @@ skipping: if (evalskip == SKIPCONT && } if (evalskip == SKIPBREAK && --skipcount <= 0) evalskip = 0; - if (evalskip == SKIPFUNC || evalskip == SKIPFILE) + if (evalskip == SKIPRETURN) status = exitstatus; break; } @@ -1068,7 +1068,7 @@ evalcommand(union node *cmd, int flags, funcnest--; popredir(); INTON; - if (evalskip == SKIPFUNC) { + if (evalskip == SKIPRETURN) { evalskip = 0; skipcount = 0; } @@ -1305,14 +1305,8 @@ returncmd(int argc, char **argv) { int ret = argc > 1 ? number(argv[1]) : oexitstatus; - if (funcnest) { - evalskip = SKIPFUNC; - skipcount = 1; - } else { - /* skip the rest of the file */ - evalskip = SKIPFILE; - skipcount = 1; - } + evalskip = SKIPRETURN; + skipcount = 1; return ret; } Modified: head/bin/sh/eval.h ============================================================================== --- head/bin/sh/eval.h Wed Sep 4 20:55:56 2013 (r255214) +++ head/bin/sh/eval.h Wed Sep 4 22:10:16 2013 (r255215) @@ -67,5 +67,4 @@ extern int skipcount; /* reasons for skipping commands (see comment on breakcmd routine) */ #define SKIPBREAK 1 #define SKIPCONT 2 -#define SKIPFUNC 3 -#define SKIPFILE 4 +#define SKIPRETURN 3 Modified: head/bin/sh/main.c ============================================================================== --- head/bin/sh/main.c Wed Sep 4 20:55:56 2013 (r255214) +++ head/bin/sh/main.c Wed Sep 4 22:10:16 2013 (r255215) @@ -231,7 +231,7 @@ cmdloop(int top) popstackmark(&smark); setstackmark(&smark); if (evalskip != 0) { - if (evalskip == SKIPFILE) + if (evalskip == SKIPRETURN) evalskip = 0; break; } Modified: head/bin/sh/sh.1 ============================================================================== --- head/bin/sh/sh.1 Wed Sep 4 20:55:56 2013 (r255214) +++ head/bin/sh/sh.1 Wed Sep 4 22:10:16 2013 (r255215) @@ -1145,8 +1145,10 @@ command is .Pp .D1 Ic return Op Ar exitstatus .Pp -It terminates the current executional scope, returning from the previous -nested function, sourced script, or shell instance, in that order. +It terminates the current executional scope, returning from the closest +nested function or sourced script; +if no function or sourced script is being executed, +it exits the shell instance. The .Ic return command is implemented as a special built-in command. Added: head/tools/regression/bin/sh/builtins/return8.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/builtins/return8.0 Wed Sep 4 22:10:16 2013 (r255215) @@ -0,0 +1,13 @@ +# $FreeBSD$ + +if [ "$1" = nested ]; then + return 17 +fi + +f() { + set -- nested + . "$0" + return $(($? ^ 1)) +} +f +exit $(($? ^ 16))