From owner-svn-src-all@FreeBSD.ORG Sat Jan 8 23:08:13 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A2453106564A; Sat, 8 Jan 2011 23:08:13 +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 76DEA8FC0A; Sat, 8 Jan 2011 23:08:13 +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 p08N8Dg9019223; Sat, 8 Jan 2011 23:08:13 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p08N8DkS019218; Sat, 8 Jan 2011 23:08:13 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201101082308.p08N8DkS019218@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 8 Jan 2011 23:08:13 +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: r217175 - in head: bin/sh tools/regression/bin/sh/builtins X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Jan 2011 23:08:13 -0000 Author: jilles Date: Sat Jan 8 23:08:13 2011 New Revision: 217175 URL: http://svn.freebsd.org/changeset/base/217175 Log: sh: Make exit without parameters from EXIT trap POSIX-compliant. It should use the original exit status, just like falling off the end of the trap handler. Outside an EXIT trap, 'exit' is still equivalent to 'exit $?'. Added: head/tools/regression/bin/sh/builtins/exit3.0 (contents, props changed) Modified: head/bin/sh/main.c head/bin/sh/trap.c head/bin/sh/trap.h Modified: head/bin/sh/main.c ============================================================================== --- head/bin/sh/main.c Sat Jan 8 23:06:54 2011 (r217174) +++ head/bin/sh/main.c Sat Jan 8 23:08:13 2011 (r217175) @@ -341,10 +341,7 @@ exitcmd(int argc, char **argv) if (stoppedjobs()) return 0; if (argc > 1) - exitstatus = number(argv[1]); + exitshell(number(argv[1])); else - exitstatus = oexitstatus; - exitshell(exitstatus); - /*NOTREACHED*/ - return 0; + exitshell_savedstatus(); } Modified: head/bin/sh/trap.c ============================================================================== --- head/bin/sh/trap.c Sat Jan 8 23:06:54 2011 (r217174) +++ head/bin/sh/trap.c Sat Jan 8 23:08:13 2011 (r217175) @@ -80,6 +80,9 @@ static volatile sig_atomic_t gotsig[NSIG static int ignore_sigchld; /* Used while handling SIGCHLD traps. */ volatile sig_atomic_t gotwinch; +static int exiting; /* exitshell() has been called */ +static int exiting_exitstatus; /* value passed to exitshell() */ + static int getsigaction(int, sig_t *); @@ -478,10 +481,21 @@ setinteractive(int on) void exitshell(int status) { + TRACE(("exitshell(%d) pid=%d\n", status, getpid())); + exiting = 1; + exiting_exitstatus = status; + exitshell_savedstatus(); +} + +void +exitshell_savedstatus(void) +{ struct jmploc loc1, loc2; char *p; - TRACE(("exitshell(%d) pid=%d\n", status, getpid())); + if (!exiting) + exiting_exitstatus = oexitstatus; + exitstatus = oexitstatus = exiting_exitstatus; if (setjmp(loc1.loc)) { goto l1; } @@ -498,5 +512,5 @@ l1: handler = &loc2; /* probably unn #if JOBS setjobctl(0); #endif -l2: _exit(status); +l2: _exit(exiting_exitstatus); } Modified: head/bin/sh/trap.h ============================================================================== --- head/bin/sh/trap.h Sat Jan 8 23:06:54 2011 (r217174) +++ head/bin/sh/trap.h Sat Jan 8 23:08:13 2011 (r217175) @@ -46,3 +46,4 @@ void onsig(int); void dotrap(void); void setinteractive(int); void exitshell(int) __dead2; +void exitshell_savedstatus(void) __dead2; Added: head/tools/regression/bin/sh/builtins/exit3.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/builtins/exit3.0 Sat Jan 8 23:08:13 2011 (r217175) @@ -0,0 +1,5 @@ +# $FreeBSD$ + +# exit without arguments differs from exit $? in an EXIT trap. + +trap 'false; exit' 0