summaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
authorThorsten Lockert <tholo@cvs.openbsd.org>1997-06-22 20:01:49 +0000
committerThorsten Lockert <tholo@cvs.openbsd.org>1997-06-22 20:01:49 +0000
commitd23f4916cdd3a76bfd8a069d05516d9592291be4 (patch)
treef467047193ff38440426d1405de0f32a7c416def /lib/libc/gen
parent8df8eb796864632cf00e375215fd6dc512f88f37 (diff)
Close pipes before dup'ing file descriptors in the child, not after.
From NetBSD PR #3673 by Dave Sainty <David.Sainty@MCS.VUW.AC.NZ>
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/popen.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c
index 2b667606941..414d61befdf 100644
--- a/lib/libc/gen/popen.c
+++ b/lib/libc/gen/popen.c
@@ -35,7 +35,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: popen.c,v 1.4 1997/04/16 21:59:04 millert Exp $";
+static char rcsid[] = "$OpenBSD: popen.c,v 1.5 1997/06/22 20:01:48 tholo Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -85,7 +85,15 @@ popen(program, type)
return (NULL);
/* NOTREACHED */
case 0: /* Child. */
+ /*
+ * because vfork() instead of fork(), must leak FILE *,
+ * but luckily we are terminally headed for an execl()
+ */
+ for (cur = pidlist; cur; cur = cur->next)
+ close(fileno(cur->fp));
+
if (*type == 'r') {
+ (void) close(pdes[0]);
/*
* We must NOT modify pdes, due to the
* semantics of vfork.
@@ -96,20 +104,13 @@ popen(program, type)
(void)close(tpdes1);
tpdes1 = STDOUT_FILENO;
}
- (void) close(pdes[0]);
} else {
+ (void)close(pdes[1]);
if (pdes[0] != STDIN_FILENO) {
(void)dup2(pdes[0], STDIN_FILENO);
(void)close(pdes[0]);
}
- (void)close(pdes[1]);
}
- /*
- * because vfork() instead of fork(), must leak FILE *,
- * but luckily we are terminally headed for an execl()
- */
- for (cur = pidlist; cur; cur = cur->next)
- close(fileno(cur->fp));
execl(_PATH_BSHELL, "sh", "-c", program, NULL);
_exit(127);
/* NOTREACHED */