Avoid the need for calling functions that malloc after a vfork().
This commit is contained in:
parent
1339399694
commit
0c372549f6
@ -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 */
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user