Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Mar 2013 17:34:00 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r247720 - in head: bin/sh tools/regression/bin/sh/builtins
Message-ID:  <201303031734.r23HY00n021423@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sun Mar  3 17:33:59 2013
New Revision: 247720
URL: http://svnweb.freebsd.org/changeset/base/247720

Log:
  sh: When executing a trap, keep exit status along with evalskip.
  
  This ensures 'return' in a trap returns the correct status to the caller.
  
  If evalskip is not set or if it is overridden by a previous evalskip, keep
  the old behaviour of restoring the exit status from before the trap.

Added:
  head/tools/regression/bin/sh/builtins/trap12.0   (contents, props changed)
Modified:
  head/bin/sh/trap.c

Modified: head/bin/sh/trap.c
==============================================================================
--- head/bin/sh/trap.c	Sun Mar  3 16:17:09 2013	(r247719)
+++ head/bin/sh/trap.c	Sun Mar  3 17:33:59 2013	(r247720)
@@ -455,7 +455,6 @@ dotrap(void)
 					last_trapsig = i;
 					savestatus = exitstatus;
 					evalstring(trap[i], 0);
-					exitstatus = savestatus;
 
 					/*
 					 * If such a command was not
@@ -464,9 +463,11 @@ dotrap(void)
 					 * trap action to have an effect
 					 * outside of it.
 					 */
-					if (prev_evalskip != 0) {
+					if (evalskip == 0 ||
+					    prev_evalskip != 0) {
 						evalskip  = prev_evalskip;
 						skipcount = prev_skipcount;
+						exitstatus = savestatus;
 					}
 
 					if (i == SIGCHLD)

Added: head/tools/regression/bin/sh/builtins/trap12.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/builtins/trap12.0	Sun Mar  3 17:33:59 2013	(r247720)
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+f() {
+	trap 'return 42' USR1
+	kill -USR1 $$
+	return 3
+}
+f
+r=$?
+[ "$r" = 42 ]



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201303031734.r23HY00n021423>