src: Add eventfd() to handle stale fds.
authorAndreas Schneider <asn@samba.org>
Tue, 28 Jan 2014 12:42:38 +0000 (13:42 +0100)
committerAndreas Schneider <asn@samba.org>
Tue, 28 Jan 2014 13:11:43 +0000 (14:11 +0100)
Reviewed-by: Stefan Metzmacher <metze@samba.org>
ConfigureChecks.cmake
config.h.cmake
src/socket_wrapper.c

index 65f8b1a0a07b708f4a8e7aea1aef37708d1fc956..35b8edc15f77ebeacf9be45f37c988a9ead5ced6 100644 (file)
@@ -49,12 +49,14 @@ endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
 # HEADERS
 check_include_file(sys/filio.h HAVE_SYS_FILIO_H)
 check_include_file(sys/signalfd.h HAVE_SYS_SIGNALFD_H)
+check_include_file(sys/eventfd.h HAVE_SYS_EVENTFD_H)
 
 # FUNCTIONS
 check_function_exists(strncpy HAVE_STRNCPY)
 check_function_exists(vsnprintf HAVE_VSNPRINTF)
 check_function_exists(snprintf HAVE_SNPRINTF)
 check_function_exists(signalfd HAVE_SIGNALFD)
+check_function_exists(eventfd HAVE_EVENTFD)
 
 if (UNIX)
     if (NOT LINUX)
index 6b29d5b372b2d79b43c804a1bafcee265776b732..9632aa6f8073b4e5c77c2397970f98bd40e3f794 100644 (file)
@@ -16,6 +16,7 @@
 
 #cmakedefine HAVE_SYS_FILIO_H 1
 #cmakedefine HAVE_SYS_SIGNALFD_H 1
+#cmakedefine HAVE_SYS_EVENTFD_H 1
 
 /************************ STRUCT MEMBERS *************************/
 
@@ -27,6 +28,7 @@
 /* Define to 1 if you have the `getaddrinfo' function. */
 #cmakedefine HAVE_GETADDRINFO 1
 #cmakedefine HAVE_SIGNALFD 1
+#cmakedefine HAVE_EVENTFD 1
 
 #cmakedefine HAVE_ACCEPT_PSOCKLEN_T 1
 #cmakedefine HAVE_IOCTL_INT 1
index f78f4a5a0970baba87dec1e663513f4db686f2b8..941f66047ba81e8dcfb596651a426d94a4f01579 100644 (file)
@@ -53,6 +53,9 @@
 #ifdef HAVE_SYS_SIGNALFD_H
 #include <sys/signalfd.h>
 #endif
+#ifdef HAVE_SYS_EVENTFD_H
+#include <sys/eventfd.h>
+#endif
 #include <sys/uio.h>
 #include <errno.h>
 #include <sys/un.h>
@@ -286,6 +289,9 @@ struct swrap_libc_fns {
                            socklen_t addrlen);
        int (*libc_dup)(int fd);
        int (*libc_dup2)(int oldfd, int newfd);
+#ifdef HAVE_EVENTFD
+       int (*libc_eventfd)(int count, int flags);
+#endif
        int (*libc_getpeername)(int sockfd,
                                struct sockaddr *addr,
                                socklen_t *addrlen);
@@ -514,6 +520,15 @@ static int libc_dup2(int oldfd, int newfd)
        return swrap.fns.libc_dup2(oldfd, newfd);
 }
 
+#ifdef HAVE_EVENTFD
+static int libc_eventfd(int count, int flags)
+{
+       swrap_load_lib_function(SWRAP_LIBC, eventfd);
+
+       return swrap.fns.libc_eventfd(count, flags);
+}
+#endif
+
 static int libc_getpeername(int sockfd,
                            struct sockaddr *addr,
                            socklen_t *addrlen)
@@ -3934,6 +3949,29 @@ int dup2(int fd, int newfd)
        return swrap_dup2(fd, newfd);
 }
 
+/****************************
+ * DUP2
+ ***************************/
+
+#ifdef HAVE_EVENTFD
+static int swrap_eventfd(int count, int flags)
+{
+       int fd;
+
+       fd = libc_eventfd(count, flags);
+       if (fd != -1) {
+               swrap_remove_stale(fd);
+       }
+
+       return fd;
+}
+
+int eventfd(int count, int flags)
+{
+       return swrap_eventfd(count, flags);
+}
+#endif
+
 /****************************
  * DESTRUCTOR
  ***************************/