summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-09-11 18:51:05 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-09-11 18:51:05 +0000
commit5ab5cd68c8a65d395645781f69c3573ead54f80f (patch)
treee4a3b7e7661b0c25aef391e7a270001177ab4488 /lib
parent9ac843e6f4236e4300c4d2570c5ebe9e18238e8f (diff)
make popen() safe for a real vfork()
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/popen.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c
index 21dac231b59..561a45e9bba 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.8 1997/08/24 21:25:46 millert Exp $";
+static char rcsid[] = "$OpenBSD: popen.c,v 1.9 1997/09/11 18:51:04 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -89,12 +89,14 @@ popen(program, type)
return (NULL);
/* NOTREACHED */
case 0: /* Child. */
+ {
+ struct pid *pcur;
/*
* 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));
+ for (pcur = pidlist; pcur; pcur = pcur->next)
+ close(fileno(pcur->fp));
if (*type == 'r') {
int tpdes1 = pdes[1];
@@ -119,6 +121,7 @@ popen(program, type)
execl(_PATH_BSHELL, "sh", "-c", program, NULL);
_exit(127);
/* NOTREACHED */
+ }
}
/* Parent; assume fdopen can't fail. */