1 --- popen.c.orig 2003-05-20 15:21:02.000000000 -0700
2 +++ popen.c 2005-09-17 16:08:55.000000000 -0700
7 +#include <sys/socket.h>
12 #include "un-namespace.h"
13 #include "libc_private.h"
15 -extern char **environ;
16 +#include <crt_externs.h>
17 +#define environ (*_NSGetEnviron())
19 +/* 3516149 - store file descriptor and use that to close to prevent blocking */
26 static pthread_mutex_t pidlist_mutex = PTHREAD_MUTEX_INITIALIZER;
32 - * Lite2 introduced two-way popen() pipes using _socketpair().
33 - * FreeBSD's pipe() is bidirectional, so we use that.
35 if (strchr(type, '+')) {
38 + if (socketpair(AF_UNIX, SOCK_STREAM, 0, pdes) < 0)
42 if ((*type != 'r' && *type != 'w') || type[1])
50 if ((cur = malloc(sizeof(struct pid))) == NULL) {
51 (void)_close(pdes[0]);
56 - switch (pid = vfork()) {
57 + switch (pid = fork()) {
60 (void)_close(pdes[0]);
62 (void)_close(pdes[1]);
64 for (p = pidlist; p; p = p->next) {
65 - (void)_close(fileno(p->fp));
66 + (void)_close(p->fd);
68 _execve(_PATH_BSHELL, argv, environ);
71 /* Parent; assume fdopen can't fail. */
73 iop = fdopen(pdes[0], type);
75 (void)_close(pdes[1]);
77 iop = fdopen(pdes[1], type);
79 (void)_close(pdes[0]);