Simon Josefsson wrote: > no objection from me. OK, I've added the module and applied the support for old kernels:
2009-08-24 Bruno Haible <br...@clisp.org> Tolerate declared but missing accept4 syscall. * lib/accept4.c (accept4): Invoke original accept4 function first, if available. * lib/sys_socket.in.h (accept4): If the function is already present, override it. * m4/accept4.m4 (gl_FUNC_ACCEPT4): Remove AC_LIBOBJ invocation. * modules/accept4 (Makefile.am): Compile accept4.c always. Reported by Paolo Bonzini and Eric Blake. --- lib/accept4.c.orig 2009-08-25 02:25:10.000000000 +0200 +++ lib/accept4.c 2009-08-25 02:22:35.000000000 +0200 @@ -33,6 +33,26 @@ { int fd; +#if HAVE_ACCEPT4 +# undef accept4 + /* Try the system call first, if it exists. (We may be running with a glibc + that has the function but with an older kernel that lacks it.) */ + { + /* Cache the information whether the system call really exists. */ + static int have_accept4_really; /* 0 = unknown, 1 = yes, -1 = no */ + if (have_accept4_really >= 0) + { + int result = accept4 (sockfd, addr, addrlen, flags); + if (!(result < 0 && errno == ENOSYS)) + { + have_accept4_really = 1; + return result; + } + have_accept4_really = -1; + } + } +#endif + /* Check the supported flags. */ if ((flags & ~(SOCK_CLOEXEC | O_TEXT | O_BINARY)) != 0) { --- lib/sys_socket.in.h.orig 2009-08-25 02:25:10.000000000 +0200 +++ lib/sys_socket.in.h 2009-08-25 02:23:26.000000000 +0200 @@ -428,15 +428,16 @@ #endif #if @GNULIB_ACCEPT4@ -# if !...@have_accept4@ /* Accept a connection on a socket, with specific opening flags. The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>) and O_TEXT, O_BINARY (defined in "binary-io.h"). See also the Linux man page at <http://www.kernel.org/doc/man-pages/online/pages/man2/accept4.2.html>. */ +# if @HAVE_ACCEPT4@ +# define accept4 rpl_accept4 +# endif extern int accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags); -# endif #elif defined GNULIB_POSIXCHECK # undef accept4 # define accept4(s,a,l,f) \ --- m4/accept4.m4.orig 2009-08-25 02:25:10.000000000 +0200 +++ m4/accept4.m4 2009-08-25 02:23:48.000000000 +0200 @@ -1,4 +1,4 @@ -# accept4.m4 serial 1 +# accept4.m4 serial 2 dnl Copyright (C) 2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -14,6 +14,5 @@ AC_CHECK_FUNCS_ONCE([accept4]) if test $ac_cv_func_accept4 != yes; then HAVE_ACCEPT4=0 - AC_LIBOBJ([accept4]) fi ]) --- modules/accept4.orig 2009-08-25 02:25:10.000000000 +0200 +++ modules/accept4 2009-08-25 02:24:04.000000000 +0200 @@ -17,6 +17,7 @@ gl_SYS_SOCKET_MODULE_INDICATOR([accept4]) Makefile.am: +lib_SOURCES += accept4.c Include: <sys/socket.h>