Avoid the need for calling functions that malloc after a vfork().

This commit is contained in:
Peter Wemm 1998-10-11 14:11:51 +00:00
parent 1339399694
commit 0c372549f6

View File

@ -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 */
}