summaryrefslogtreecommitdiffstats
path: root/bin/sh/redir.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-10-24 20:09:49 +0000
committerjilles <jilles@FreeBSD.org>2010-10-24 20:09:49 +0000
commitc487e17b8fb428abe374fa4820d1b3628c383af5 (patch)
treec5c8880c89a62af2e313fd4965a5f0a84648b50e /bin/sh/redir.c
parenta2f958382a8f42c779dc6a8648379e68138a8241 (diff)
downloadFreeBSD-src-c487e17b8fb428abe374fa4820d1b3628c383af5.zip
FreeBSD-src-c487e17b8fb428abe374fa4820d1b3628c383af5.tar.gz
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)
Diffstat (limited to 'bin/sh/redir.c')
-rw-r--r--bin/sh/redir.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/bin/sh/redir.c b/bin/sh/redir.c
index f3ad3af..4f0a40c 100644
--- a/bin/sh/redir.c
+++ b/bin/sh/redir.c
@@ -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);
}
OpenPOWER on IntegriCloud