Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 Dec 2010 18:20:18 +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: r216851 - in head: bin/sh tools/regression/bin/sh/errors
Message-ID:  <201012311820.oBVIKIof084715@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Fri Dec 31 18:20:17 2010
New Revision: 216851
URL: http://svn.freebsd.org/changeset/base/216851

Log:
  sh: Check if dup2 for redirection from/to a file succeeds.
  
  A failure (e.g. caused by ulimit -n being set very low) is a redirection
  error.
  
  Example:
    ulimit -n 9; exec 9<.

Added:
  head/tools/regression/bin/sh/errors/redirection-error7.0   (contents, props changed)
Modified:
  head/bin/sh/redir.c

Modified: head/bin/sh/redir.c
==============================================================================
--- head/bin/sh/redir.c	Fri Dec 31 18:16:44 2010	(r216850)
+++ head/bin/sh/redir.c	Fri Dec 31 18:20:17 2010	(r216851)
@@ -155,6 +155,7 @@ openredirect(union node *redir, char mem
 	int fd = redir->nfile.fd;
 	char *fname;
 	int f;
+	int e;
 
 	/*
 	 * We suppress interrupts so that we won't leave open file
@@ -173,7 +174,11 @@ openredirect(union node *redir, char mem
 			error("cannot open %s: %s", fname, strerror(errno));
 movefd:
 		if (f != fd) {
-			dup2(f, fd);
+			if (dup2(f, fd) == -1) {
+				e = errno;
+				close(f);
+				error("%d: %s", fd, strerror(e));
+			}
 			close(f);
 		}
 		break;

Added: head/tools/regression/bin/sh/errors/redirection-error7.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/errors/redirection-error7.0	Fri Dec 31 18:20:17 2010	(r216851)
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+! dummy=$(
+	exec 3>&1 >&2 2>&3
+	ulimit -n 9
+	exec 9<.
+) && [ -n "$dummy" ]



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