summary refs log tree commit diff
path: root/src/redir.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2009-06-27 20:38:23 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2009-06-27 20:38:23 +0800
commit6c0398654015de53269a2ef32eae3c7b560875dd (patch)
treebbfe4fd062df4cc0d0bb9d2c589f135a0de9e42e /src/redir.c
parent[MAN] Update manual page to differentiate dash from ash (diff)
downloaddash-6c0398654015de53269a2ef32eae3c7b560875dd.tar.gz
dash-6c0398654015de53269a2ef32eae3c7b560875dd.zip
[REDIR] Fix incorrect savefd conversions
When I added savefd we may end up closing stderr if that is how
we get to the tty.  This patch fixes by adding a second argument
to indicate what fd should be closed which lets jobs.c get around
the problem.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to '')
-rw-r--r--src/redir.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/redir.c b/src/redir.c
index ce34db0..b01237d 100644
--- a/src/redir.c
+++ b/src/redir.c
@@ -145,7 +145,7 @@ redirect(union node *redir, int flags)
 			if (likely(i == EMPTY)) {
 				i = CLOSED;
 				if (fd != newfd) {
-					i = savefd(fd);
+					i = savefd(fd, fd);
 					fd = -1;
 				}
 			}
@@ -399,7 +399,7 @@ RESET {
  */
 
 int
-savefd(int from)
+savefd(int from, int ofd)
 {
 	int newfd;
 	int err;
@@ -407,7 +407,7 @@ savefd(int from)
 	newfd = fcntl(from, F_DUPFD, 10);
 	err = newfd < 0 ? errno : 0;
 	if (err != EBADF) {
-		close(from);
+		close(ofd);
 		if (err)
 			sh_error("%d: %s", from, strerror(err));
 		else