Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Jan 2011 23:17:29 +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: r217035 - in head: bin/sh tools/regression/bin/sh/builtins
Message-ID:  <201101052317.p05NHTL1094327@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Wed Jan  5 23:17:29 2011
New Revision: 217035
URL: http://svn.freebsd.org/changeset/base/217035

Log:
  sh: Do not call exitshell() from evalcommand() unless evalcommand() forked
  itself.
  
  This ensures that certain traps caused by builtins are executed.

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

Modified: head/bin/sh/eval.c
==============================================================================
--- head/bin/sh/eval.c	Wed Jan  5 23:15:22 2011	(r217034)
+++ head/bin/sh/eval.c	Wed Jan  5 23:17:29 2011	(r217035)
@@ -671,6 +671,7 @@ safe_builtin(int idx, int argc, char **a
 
 /*
  * Execute a simple command.
+ * Note: This may or may not return if (flags & EV_EXIT).
  */
 
 static void
@@ -707,6 +708,7 @@ evalcommand(union node *cmd, int flags, 
 	arglist.lastp = &arglist.list;
 	varlist.lastp = &varlist.list;
 	varflag = 1;
+	jp = NULL;
 	do_clearcmdentry = 0;
 	oexitstatus = exitstatus;
 	exitstatus = 0;
@@ -965,7 +967,7 @@ evalcommand(union node *cmd, int flags, 
 			evalskip = 0;
 			skipcount = 0;
 		}
-		if (flags & EV_EXIT)
+		if (jp)
 			exitshell(exitstatus);
 	} else if (cmdentry.cmdtype == CMDBUILTIN) {
 #ifdef DEBUG
@@ -1013,13 +1015,12 @@ cmddone:
 		out1 = &output;
 		out2 = &errout;
 		freestdout();
+		handler = savehandler;
 		if (e != EXSHELLPROC) {
 			commandname = savecmdname;
-			if (flags & EV_EXIT) {
+			if (jp)
 				exitshell(exitstatus);
-			}
 		}
-		handler = savehandler;
 		if (flags == EV_BACKCMD) {
 			backcmd->buf = memout.buf;
 			backcmd->nleft = memout.nextc - memout.buf;

Added: head/tools/regression/bin/sh/builtins/trap4.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/builtins/trap4.0	Wed Jan  5 23:17:29 2011	(r217035)
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX)
+trap 'rm -rf $T' 0
+cd $T || exit 3
+mkfifo fifo1
+
+v=$(
+	exec 3>&1
+	: <fifo1 &
+	{
+		wait $!
+		trap 'trap "" PIPE; echo trapped >&3 2>/dev/null' PIPE
+		echo x 2>/dev/null
+	} >fifo1
+)
+test "$v" = trapped



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