]> git.saurik.com Git - apple/libc.git/blob - gen/FreeBSD/popen.c.patch
e0ce5b853e5739e0295f5abba9d862755446c837
[apple/libc.git] / gen / FreeBSD / popen.c.patch
1 --- popen.c.orig Mon May 24 23:50:41 2004
2 +++ popen.c Tue May 25 00:09:39 2004
3 @@ -43,6 +43,7 @@
4 #include "namespace.h"
5 #include <sys/param.h>
6 #include <sys/wait.h>
7 +#include <sys/socket.h>
8
9 #include <signal.h>
10 #include <errno.h>
11 @@ -55,11 +56,14 @@
12 #include "un-namespace.h"
13 #include "libc_private.h"
14
15 -extern char **environ;
16 +#include <crt_externs.h>
17 +#define environ (*_NSGetEnviron())
18
19 +/* 3516149 - store file descriptor and use that to close to prevent blocking */
20 static struct pid {
21 struct pid *next;
22 FILE *fp;
23 + int fd;
24 pid_t pid;
25 } *pidlist;
26 static pthread_mutex_t pidlist_mutex = PTHREAD_MUTEX_INITIALIZER;
27 @@ -77,20 +81,18 @@
28 char *argv[4];
29 struct pid *p;
30
31 - /*
32 - * Lite2 introduced two-way popen() pipes using _socketpair().
33 - * FreeBSD's pipe() is bidirectional, so we use that.
34 - */
35 if (strchr(type, '+')) {
36 twoway = 1;
37 type = "r+";
38 + if (socketpair(AF_UNIX, SOCK_STREAM, 0, pdes) < 0)
39 + return (NULL);
40 } else {
41 twoway = 0;
42 if ((*type != 'r' && *type != 'w') || type[1])
43 return (NULL);
44 + if (pipe(pdes) < 0)
45 + return (NULL);
46 }
47 - if (pipe(pdes) < 0)
48 - return (NULL);
49
50 if ((cur = malloc(sizeof(struct pid))) == NULL) {
51 (void)_close(pdes[0]);
52 @@ -138,7 +140,7 @@
53 (void)_close(pdes[1]);
54 }
55 for (p = pidlist; p; p = p->next) {
56 - (void)_close(fileno(p->fp));
57 + (void)_close(p->fd);
58 }
59 _execve(_PATH_BSHELL, argv, environ);
60 _exit(127);
61 @@ -149,9 +151,11 @@
62 /* Parent; assume fdopen can't fail. */
63 if (*type == 'r') {
64 iop = fdopen(pdes[0], type);
65 + cur->fd = pdes[0];
66 (void)_close(pdes[1]);
67 } else {
68 iop = fdopen(pdes[1], type);
69 + cur->fd = pdes[1];
70 (void)_close(pdes[0]);
71 }
72