Loading...
gen/FreeBSD/popen.c.patch Libc-763.13 Libc-594.9.4
--- Libc/Libc-763.13/gen/FreeBSD/popen.c.patch
+++ Libc/Libc-594.9.4/gen/FreeBSD/popen.c.patch
@@ -1,6 +1,6 @@
---- popen.c.orig	2009-12-02 15:21:37.000000000 -0800
-+++ popen.c	2009-12-02 15:36:51.000000000 -0800
-@@ -30,6 +30,10 @@
+--- popen.c.orig	2009-03-03 02:04:57.000000000 -0800
++++ popen.c	2009-03-03 15:28:31.000000000 -0800
+@@ -34,6 +34,10 @@
   * SUCH DAMAGE.
   */
  
@@ -11,9 +11,9 @@
  #if defined(LIBC_SCCS) && !defined(lint)
  static char sccsid[] = "@(#)popen.c	8.3 (Berkeley) 5/3/95";
  #endif /* LIBC_SCCS and not lint */
-@@ -40,7 +44,8 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/pop
+@@ -43,7 +47,8 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/pop
+ #include "namespace.h"
  #include <sys/param.h>
- #include <sys/queue.h>
  #include <sys/wait.h>
 -
 +#include <sys/socket.h>
@@ -21,7 +21,7 @@
  #include <signal.h>
  #include <errno.h>
  #include <unistd.h>
-@@ -49,18 +54,39 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/pop
+@@ -52,17 +57,29 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/pop
  #include <string.h>
  #include <paths.h>
  #include <pthread.h>
@@ -32,39 +32,30 @@
 -extern char **environ;
 +#include <crt_externs.h>
 +#define environ (*_NSGetEnviron())
-+
-+/* Our queue.h doesn't have SLIST_REMOVE_AFTER in it yet
-+ * <rdar://problem/7431558> API: Add SLIST_REMOVE_AFTER to sys/queue.h (from FreeBSD)
-+ */
-+#ifndef SLIST_REMOVE_AFTER
-+#define SLIST_REMOVE_AFTER(elm, field) do {                             \
-+        SLIST_NEXT(elm, field) =                                        \
-+            SLIST_NEXT(SLIST_NEXT(elm, field), field);                  \
-+} while (0)
-+#endif
- 
+ 
+-static struct pid {
 +/* 3516149 - store file descriptor and use that to close to prevent blocking */
- struct pid {
- 	SLIST_ENTRY(pid) next;
++struct pid {
+ 	struct pid *next;
  	FILE *fp;
 +	int fd;
  	pid_t pid;
- };
--static SLIST_HEAD(, pid) pidlist = SLIST_HEAD_INITIALIZER(pidlist);
+-} *pidlist;
 -static pthread_mutex_t pidlist_mutex = PTHREAD_MUTEX_INITIALIZER;
++};
 +#define pidlist		__popen_pidlist
 +#define pidlist_mutex	__popen_pidlist_mutex
 +#ifndef BUILDING_VARIANT
-+__private_extern__ SLIST_HEAD(, pid) pidlist = SLIST_HEAD_INITIALIZER(pidlist);
++__private_extern__ struct pid *pidlist = NULL;
 +__private_extern__ pthread_mutex_t pidlist_mutex = PTHREAD_MUTEX_INITIALIZER;
 +#else /* BUILDING_VARIANT */
-+extern SLIST_HEAD(, pid) pidlist;
++extern struct pid *pidlist;
 +extern pthread_mutex_t pidlist_mutex;
 +#endif /* !BUILDING_VARIANT */
  
  #define	THREAD_LOCK()	if (__isthreaded) _pthread_mutex_lock(&pidlist_mutex)
  #define	THREAD_UNLOCK()	if (__isthreaded) _pthread_mutex_unlock(&pidlist_mutex)
-@@ -71,84 +97,108 @@ popen(command, type)
+@@ -73,85 +90,109 @@ popen(command, type)
  {
  	struct pid *cur;
  	FILE *iop;
@@ -154,8 +145,9 @@
 +		}
 +		(void)posix_spawn_file_actions_addclose(&file_actions, pdes[1]);
 +	}
-+	SLIST_FOREACH(p, &pidlist, next)
++	for (p = pidlist; p; p = p->next) {
 +		(void)posix_spawn_file_actions_addclose(&file_actions, p->fd);
++	}
 +
  	argv[0] = "sh";
  	argv[1] = "-c";
@@ -203,8 +195,9 @@
 -			}
 -			(void)_close(pdes[1]);
 -		}
--		SLIST_FOREACH(p, &pidlist, next)
+-		for (p = pidlist; p; p = p->next) {
 -			(void)_close(fileno(p->fp));
+-		}
 -		_execve(_PATH_BSHELL, argv, environ);
 -		_exit(127);
 -		/* NOTREACHED */
@@ -224,9 +217,9 @@
  		(void)_close(pdes[0]);
  	}
  
-@@ -158,10 +208,11 @@ popen(command, type)
- 	THREAD_LOCK();
- 	SLIST_INSERT_HEAD(&pidlist, cur, next);
+@@ -162,10 +203,11 @@ popen(command, type)
+ 	cur->next = pidlist;
+ 	pidlist = cur;
  	THREAD_UNLOCK();
 -
 +	fwide(iop, -1);		/* byte stream */
@@ -237,7 +230,7 @@
  /*
   * pclose --
   *	Pclose returns -1 if stream is not associated with a `popened' command,
-@@ -196,6 +247,10 @@ pclose(iop)
+@@ -198,6 +240,10 @@ pclose(iop)
  
  	(void)fclose(iop);
  
@@ -248,7 +241,7 @@
  	do {
  		pid = _wait4(cur->pid, &pstat, 0, (struct rusage *)0);
  	} while (pid == -1 && errno == EINTR);
-@@ -204,3 +259,4 @@ pclose(iop)
+@@ -206,3 +252,4 @@ pclose(iop)
  
  	return (pid == -1 ? -1 : pstat);
  }