1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/patches/glibc/ports-2.10.1/260-assume-pipe2.patch Wed Feb 01 00:19:04 2012 +0100
1.3 @@ -0,0 +1,54 @@
1.4 +http://bugs.gentoo.org/250342
1.5 +http://sources.redhat.com/bugzilla/show_bug.cgi?id=9685
1.6 +
1.7 +we cant assume sock_cloexec and pipe2 are bound together as the former defines
1.8 +are found in glibc only while the latter are a combo of kernel headers and
1.9 +glibc. so if we do a runtime detection of SOCK_CLOEXEC, but pipe2() is a stub
1.10 +inside of glibc, we hit a problem. for example:
1.11 +
1.12 +#include <grp.h>
1.13 +#include <stdio.h>
1.14 +main()
1.15 +{
1.16 + getgrnam("portage");
1.17 + if (!popen("ls", "r"))
1.18 + perror("popen()");
1.19 +}
1.20 +
1.21 +getgrnam() will detect that the kernel supports SOCK_CLOEXEC and then set both
1.22 +__have_sock_cloexec and __have_pipe2 to true. but if glibc was built against
1.23 +older kernel headers where __NR_pipe2 does not exist, glibc will have a ENOSYS
1.24 +stub for it. so popen() will always fail as glibc assumes pipe2() works.
1.25 +
1.26 +diff -durN glibc-2.10.1.orig/include/unistd.h glibc-2.10.1/include/unistd.h
1.27 +--- glibc-2.10.1.orig/include/unistd.h 2008-07-27 20:23:17.000000000 +0200
1.28 ++++ glibc-2.10.1/include/unistd.h 2009-11-13 00:50:15.000000000 +0100
1.29 +@@ -167,9 +167,6 @@
1.30 + extern int __pause_nocancel (void) attribute_hidden;
1.31 +
1.32 + extern int __have_sock_cloexec;
1.33 +-/* At lot of other functionality became available at the same time as
1.34 +- SOCK_CLOEXEC. Avoid defining separate variables for all of them
1.35 +- unless it is really necessary. */
1.36 +-#define __have_pipe2 __have_sock_cloexec
1.37 ++extern int __have_pipe2;
1.38 +
1.39 + #endif
1.40 +diff -durN glibc-2.10.1.orig/socket/have_sock_cloexec.c glibc-2.10.1/socket/have_sock_cloexec.c
1.41 +--- glibc-2.10.1.orig/socket/have_sock_cloexec.c 2008-07-25 18:46:23.000000000 +0200
1.42 ++++ glibc-2.10.1/socket/have_sock_cloexec.c 2009-11-13 00:50:15.000000000 +0100
1.43 +@@ -16,9 +16,14 @@
1.44 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1.45 + 02111-1307 USA. */
1.46 +
1.47 ++#include <fcntl.h>
1.48 + #include <sys/socket.h>
1.49 + #include <kernel-features.h>
1.50 +
1.51 + #if defined SOCK_CLOEXEC && !defined __ASSUME_SOCK_CLOEXEC
1.52 + int __have_sock_cloexec;
1.53 + #endif
1.54 ++
1.55 ++#if defined O_CLOEXEC && !defined __ASSUME_PIPE2
1.56 ++int __have_pipe2;
1.57 ++#endif