From f982bc8df29c417d1c5c4a46866a1bc41ded65f6 Mon Sep 17 00:00:00 2001
From: Pino Toscano <ptoscano@redhat.com>
Date: Mon, 12 Oct 2015 12:27:10 +0100
Subject: [PATCH] accept4-tests: fix to avoid non portable flags

* tests/test-accept4.c (main): Pass only SOCK_* flags to accept4(),
as they are the only documented ones, and passing others may trigger
EINVAL (seen on FreeBSD 10.1-RELEASE).
* doc/glibc-functions/accept4.texi: Mention that we don't provide
the SOCK_CLOEXEC or SOCK_NONBLOCK defines.
---
 ChangeLog                        | 9 +++++++++
 doc/glibc-functions/accept4.texi | 3 +++
 tests/test-accept4.c             | 8 ++++++--
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 02d8bf822f..d0c3557c2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2015-10-12  Pino Toscano  <ptoscano@redhat.com>
+
+	accept4-tests: fix to avoid non portable flags
+	* tests/test-accept4.c (main): Pass only SOCK_* flags to accept4(),
+	as they are the only documented ones, and passing others may trigger
+	EINVAL (seen on FreeBSD 10.1-RELEASE).
+	* doc/glibc-functions/accept4.texi: Mention that we don't provide
+	the SOCK_CLOEXEC or SOCK_NONBLOCK defines.
+
 2015-10-06  Pavel Raiskup  <praiskup@redhat.com>
 
 	gnulib-tool: fix tests of 'extensions' module
diff --git a/doc/glibc-functions/accept4.texi b/doc/glibc-functions/accept4.texi
index 20386e94d8..b4114db187 100644
--- a/doc/glibc-functions/accept4.texi
+++ b/doc/glibc-functions/accept4.texi
@@ -16,4 +16,7 @@ programs that spawn child processes.
 
 Portability problems not fixed by Gnulib:
 @itemize
+@item
+SOCK_CLOEXEC and SOCK_NONBLOCK may not be defined
+as they're also significant to the socket() function.
 @end itemize
diff --git a/tests/test-accept4.c b/tests/test-accept4.c
index b24af0bed0..e900b48fbc 100644
--- a/tests/test-accept4.c
+++ b/tests/test-accept4.c
@@ -31,6 +31,10 @@ SIGNATURE_CHECK (accept4, int, (int, struct sockaddr *, socklen_t *, int));
 
 #include "macros.h"
 
+#ifndef SOCK_CLOEXEC
+# define SOCK_CLOEXEC 0
+#endif
+
 int
 main (void)
 {
@@ -43,7 +47,7 @@ main (void)
 
     errno = 0;
     ASSERT (accept4 (-1, (struct sockaddr *) &addr, &addrlen,
-                     O_CLOEXEC | O_BINARY)
+                     SOCK_CLOEXEC)
             == -1);
     ASSERT (errno == EBADF);
   }
@@ -54,7 +58,7 @@ main (void)
     close (99);
     errno = 0;
     ASSERT (accept4 (99, (struct sockaddr *) &addr, &addrlen,
-                     O_CLOEXEC | O_BINARY)
+                     SOCK_CLOEXEC)
             == -1);
     ASSERT (errno == EBADF);
   }
-- 
2.39.5