summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/popen.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1998-10-11 14:11:51 +0000
committerpeter <peter@FreeBSD.org>1998-10-11 14:11:51 +0000
commit67c56d84aa772006b394ef64fc2f83b3ea647a28 (patch)
treef6703572c5388b0c58d397a1689566b1aa5964d0 /lib/libc/gen/popen.c
parent45d3f503c781f7f89136e6ab279086b1e7e27ad6 (diff)
downloadFreeBSD-src-67c56d84aa772006b394ef64fc2f83b3ea647a28.zip
FreeBSD-src-67c56d84aa772006b394ef64fc2f83b3ea647a28.tar.gz
Avoid the need for calling functions that malloc after a vfork().
Diffstat (limited to 'lib/libc/gen/popen.c')
-rw-r--r--lib/libc/gen/popen.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c
index d7ea414..8616671 100644
--- a/lib/libc/gen/popen.c
+++ b/lib/libc/gen/popen.c
@@ -49,6 +49,8 @@ static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 5/3/95";
#include <string.h>
#include <paths.h>
+extern char **environ;
+
static struct pid {
struct pid *next;
FILE *fp;
@@ -62,6 +64,7 @@ popen(command, type)
struct pid *cur;
FILE *iop;
int pdes[2], pid, twoway;
+ char *argv[4];
/*
* Lite2 introduced two-way popen() pipes using socketpair().
@@ -84,7 +87,12 @@ popen(command, type)
return (NULL);
}
- switch (pid = fork()) {
+ argv[0] = "sh";
+ argv[1] = "-c";
+ argv[2] = (char *)command;
+ argv[3] = NULL;
+
+ switch (pid = vfork()) {
case -1: /* Error. */
(void)close(pdes[0]);
(void)close(pdes[1]);
@@ -116,7 +124,7 @@ popen(command, type)
}
(void)close(pdes[1]);
}
- execl(_PATH_BSHELL, "sh", "-c", command, NULL);
+ execve(_PATH_BSHELL, argv, environ);
_exit(127);
/* NOTREACHED */
}
OpenPOWER on IntegriCloud