about summary refs log tree commit diff
path: root/include/unistd.h
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2012-08-17 22:03:56 -0400
committerMike Frysinger <vapier@gentoo.org>2012-08-18 00:35:47 -0400
commita277af22ea038ff963355b603ade8d0a8a98eb5d (patch)
tree2c15ae9829a1f5a9d949e4bc48b8a77abe4ece3e /include/unistd.h
parentfdab8fd3351de83f0d4a513552318f337e14c4cb (diff)
downloadglibc-a277af22ea038ff963355b603ade8d0a8a98eb5d.tar.gz
glibc-a277af22ea038ff963355b603ade8d0a8a98eb5d.tar.xz
glibc-a277af22ea038ff963355b603ade8d0a8a98eb5d.zip
split assume pipe2/dup3/sock_cloexec knobs
We can't assume sock_cloexec and pipe2 are bound together as the former
defines are found in glibc only while the latter are a combo of kernel
headers and glibc.  So if we do a runtime detection of SOCK_CLOEXEC, but
pipe2() is a stub inside of glibc, we hit a problem.  For example:

main()
{
	getgrnam("portage");
	if (!popen("ls", "r"))
		perror("popen()");
}

getgrnam() will detect that the kernel supports SOCK_CLOEXEC and then set
both __have_sock_cloexec and __have_pipe2 to true.  But if glibc was built
against older kernel headers where __NR_pipe2 does not exist, glibc will
have a ENOSYS stub for it.  So popen() will always fail as glibc assumes
pipe2() works.

While this isn't too much of an issue for some arches as they added the
functionality to the kernel at the same time, not all arches are that
lucky.

Since the code already has dedicated names for each feature, delete the
defines wiring these three features together and make each one a proper
dedicated knob.

We've been carrying this in Gentoo since glibc-2.9.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'include/unistd.h')
-rw-r--r--include/unistd.h7
1 files changed, 2 insertions, 5 deletions
diff --git a/include/unistd.h b/include/unistd.h
index e4bff80fc7..9d74fb49e8 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -174,11 +174,8 @@ extern int __libc_pause (void);
 extern int __pause_nocancel (void) attribute_hidden;
 
 extern int __have_sock_cloexec;
-/* At lot of other functionality became available at the same time as
-   SOCK_CLOEXEC.  Avoid defining separate variables for all of them
-   unless it is really necessary.  */
-#define __have_pipe2 __have_sock_cloexec
-#define __have_dup3 __have_sock_cloexec
+extern int __have_pipe2;
+extern int __have_dup3;
 
 extern int __getlogin_r_loginuid (char *name, size_t namesize)
      attribute_hidden;