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)
This commit is contained in:
Jilles Tjoelker 2010-10-24 20:09:49 +00:00
parent 7aaae32724
commit 3dec7d0c15
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=214290
2 changed files with 9 additions and 2 deletions

View File

@ -217,8 +217,11 @@ openredirect(union node *redir, char memory[10])
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);
}

View File

@ -0,0 +1,4 @@
# $FreeBSD$
{ echo bad 0>&3; } 2>/dev/null 3>/dev/null 3>&-
exit 0