Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Oct 2010 20:09:49 +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: r214290 - in head: bin/sh tools/regression/bin/sh/execution
Message-ID:  <201010242009.o9OK9nQ3038628@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sun Oct 24 20:09:49 2010
New Revision: 214290
URL: http://svn.freebsd.org/changeset/base/214290

Log:
  sh: Check whether dup2 was successful for >&FD and <&FD.
  
  A failure (usually caused by FD not being open) is a redirection error.
  
  Exp-run done by:	pav (with some other sh(1) changes)

Added:
  head/tools/regression/bin/sh/execution/redir4.0   (contents, props changed)
Modified:
  head/bin/sh/redir.c

Modified: head/bin/sh/redir.c
==============================================================================
--- head/bin/sh/redir.c	Sun Oct 24 19:56:34 2010	(r214289)
+++ head/bin/sh/redir.c	Sun Oct 24 20:09:49 2010	(r214290)
@@ -217,8 +217,11 @@ movefd:
 		if (redir->ndup.dupfd >= 0) {	/* if not ">&-" */
 			if (memory[redir->ndup.dupfd])
 				memory[fd] = 1;
-			else
-				dup2(redir->ndup.dupfd, fd);
+			else {
+				if (dup2(redir->ndup.dupfd, fd) < 0)
+					error("%d: %s", redir->ndup.dupfd,
+							strerror(errno));
+			}
 		} else {
 			close(fd);
 		}

Added: head/tools/regression/bin/sh/execution/redir4.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/execution/redir4.0	Sun Oct 24 20:09:49 2010	(r214290)
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+{ echo bad 0>&3; } 2>/dev/null 3>/dev/null 3>&-
+exit 0



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