summaryrefslogtreecommitdiff
path: root/bin/ksh
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-11-10 21:26:40 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-11-10 21:26:40 +0000
commitde8e8de6b77224e8b2ac3c698fbc2dabb934f77b (patch)
treed900abc4c52849fcd9a047dec413fa759453d5c3 /bin/ksh
parent507ab8275b041b65d552f065abafff05c014342e (diff)
If "from fd" == "to fd" don't call dup2() or close "from fd".
Diffstat (limited to 'bin/ksh')
-rw-r--r--bin/ksh/eval.c8
-rw-r--r--bin/ksh/exec.c8
-rw-r--r--bin/ksh/io.c4
-rw-r--r--bin/ksh/jobs.c8
4 files changed, 17 insertions, 11 deletions
diff --git a/bin/ksh/eval.c b/bin/ksh/eval.c
index 8f998cf2283..cf29ff9fee4 100644
--- a/bin/ksh/eval.c
+++ b/bin/ksh/eval.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eval.c,v 1.13 2003/04/16 23:11:52 tdeval Exp $ */
+/* $OpenBSD: eval.c,v 1.14 2003/11/10 21:26:39 millert Exp $ */
/*
* Expansion - quoting, separation, substitution, globbing
@@ -874,8 +874,10 @@ comsub(xp, cp)
openpipe(pv);
shf = shf_fdopen(pv[0], SHF_RD, (struct shf *) 0);
ofd1 = savefd(1, 0); /* fd 1 may be closed... */
- ksh_dup2(pv[1], 1, FALSE);
- close(pv[1]);
+ if (pv[1] != 1) {
+ ksh_dup2(pv[1], 1, FALSE);
+ close(pv[1]);
+ }
execute(t, XFORK|XXCOM|XPIPEO);
restfd(1, ofd1);
startlast();
diff --git a/bin/ksh/exec.c b/bin/ksh/exec.c
index f3192a516c8..995a8a2df9f 100644
--- a/bin/ksh/exec.c
+++ b/bin/ksh/exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec.c,v 1.29 2003/11/10 21:24:30 millert Exp $ */
+/* $OpenBSD: exec.c,v 1.30 2003/11/10 21:26:39 millert Exp $ */
/*
* execute command tree
@@ -230,8 +230,10 @@ execute(t, flags)
e->savefd[1] = savefd(1, 0);
openpipe(pv);
- ksh_dup2(pv[0], 0, FALSE);
- close(pv[0]);
+ if (pv[0] != 0) {
+ ksh_dup2(pv[0], 0, FALSE);
+ close(pv[0]);
+ }
coproc.write = pv[1];
coproc.job = (void *) 0;
diff --git a/bin/ksh/io.c b/bin/ksh/io.c
index 283488656a5..a20ceed3d8b 100644
--- a/bin/ksh/io.c
+++ b/bin/ksh/io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: io.c,v 1.12 2003/03/10 03:48:16 david Exp $ */
+/* $OpenBSD: io.c,v 1.13 2003/11/10 21:26:39 millert Exp $ */
/*
* shell buffered IO and formatted output
@@ -321,7 +321,7 @@ restfd(fd, ofd)
shf_flush(&shf_iob[fd]);
if (ofd < 0) /* original fd closed */
close(fd);
- else {
+ else if (fd != ofd) {
ksh_dup2(ofd, fd, TRUE); /* XXX: what to do if this fails? */
close(ofd);
}
diff --git a/bin/ksh/jobs.c b/bin/ksh/jobs.c
index d64042415e7..f233efd0d26 100644
--- a/bin/ksh/jobs.c
+++ b/bin/ksh/jobs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: jobs.c,v 1.20 2003/10/22 07:40:38 jmc Exp $ */
+/* $OpenBSD: jobs.c,v 1.21 2003/11/10 21:26:39 millert Exp $ */
/*
* Process and job control
@@ -629,8 +629,10 @@ exchild(t, flags, close_fd)
SS_RESTORE_IGN|SS_FORCE);
if (!(flags & (XPIPEI | XCOPROC))) {
int fd = open("/dev/null", 0);
- (void) ksh_dup2(fd, 0, TRUE);
- close(fd);
+ if (fd != 0) {
+ (void) ksh_dup2(fd, 0, TRUE);
+ close(fd);
+ }
}
}
remove_job(j, "child"); /* in case of `jobs` command */