From 6f66434b4f3ccf2ad05c9b816fc9724616d0a323 Mon Sep 17 00:00:00 2001 From: babkin Date: Sun, 13 Jan 2002 14:37:40 +0000 Subject: The fix for >/dev/stdout, including Tor Egge's fix for the bug in the original attempt of the fix. And yes, this time I've tried to build world with it and it succeeded. Submitted by: Tor Egge MFC after: 1 week --- bin/sh/redir.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bin/sh/redir.c') diff --git a/bin/sh/redir.c b/bin/sh/redir.c index ee893f4..b51fa2b 100644 --- a/bin/sh/redir.c +++ b/bin/sh/redir.c @@ -145,11 +145,8 @@ again: } if (!try) { sv->renamed[fd] = i; - close(fd); } INTON; - } else { - close(fd); } if (fd == 0) fd0_redirected++; @@ -186,6 +183,7 @@ openredirect(redir, memory) error("cannot open %s: %s", fname, errmsg(errno, E_OPEN)); movefd: if (f != fd) { + close(fd); copyfd(f, fd); close(f); } @@ -238,8 +236,10 @@ movefd: if (redir->ndup.dupfd >= 0) { /* if not ">&-" */ if (memory[redir->ndup.dupfd]) memory[fd] = 1; - else + else { + close(fd); copyfd(redir->ndup.dupfd, fd); + } } break; case NHERE: -- cgit v1.1