diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1999-06-23 10:30:52 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1999-06-23 10:30:52 +0000 |
commit | 338f6707afdac1410bce8cef709b165d3eb44332 (patch) | |
tree | 6c65660adedf25d9e4b99c342fb5d9b7e4b244be | |
parent | eaa0c2c3bca10b1b334eb58cb246ad50b3a2b0c2 (diff) |
When redirecting to a file with stdout closed, don't blithely reuse
fd 1 since that will cause future output on stdout to go to the file
that was redirected. There is probably a better fix for this.
-rw-r--r-- | bin/ksh/exec.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/bin/ksh/exec.c b/bin/ksh/exec.c index 236da3efbfd..d59b5062926 100644 --- a/bin/ksh/exec.c +++ b/bin/ksh/exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.c,v 1.17 1999/06/15 01:18:33 millert Exp $ */ +/* $OpenBSD: exec.c,v 1.18 1999/06/23 10:30:51 millert Exp $ */ /* * execute command tree @@ -1359,11 +1359,21 @@ iosetup(iop, tp) } } if (do_open) { + int nfd; + if (Flag(FRESTRICTED) && (flags & O_CREAT)) { warningf(TRUE, "%s: restricted", cp); return -1; } u = open(cp, flags, 0666); + if (u >= 0 && u < 3) { + /* Don't reuse stdin/stdout/stderr */ + nfd = ksh_dupbase(u, 3); + if (nfd != -1) { + close(u); + u = nfd; + } + } #ifdef OS2 if (u < 0 && strcmp(cp, "/dev/null") == 0) u = open("nul", flags, 0666); |