From 67c56d84aa772006b394ef64fc2f83b3ea647a28 Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 11 Oct 1998 14:11:51 +0000 Subject: Avoid the need for calling functions that malloc after a vfork(). --- lib/libc/gen/popen.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib') 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 #include +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 */ } -- cgit v1.1