diff options
| author | Andreas Schneider <asn@samba.org> | 2014-01-28 13:33:23 +0100 |
|---|---|---|
| committer | Andreas Schneider <asn@samba.org> | 2014-01-28 14:11:37 +0100 |
| commit | dc0023293292d5247a5984e78fc10de9399da5f5 (patch) | |
| tree | 9eaba70f3650a616de44739a78898111dd6b8a3a | |
| parent | 95520f672f3cbf311b503d61e2ac9e2a22d209e9 (diff) | |
| download | socket_wrapper-dc0023293292d5247a5984e78fc10de9399da5f5.tar.gz socket_wrapper-dc0023293292d5247a5984e78fc10de9399da5f5.tar.xz socket_wrapper-dc0023293292d5247a5984e78fc10de9399da5f5.zip | |
src: Add signalfd() to handle stale fds.
Reviewed-by: Stefan Metzmacher <metze@samba.org>
| -rw-r--r-- | ConfigureChecks.cmake | 9 | ||||
| -rw-r--r-- | config.h.cmake | 3 | ||||
| -rw-r--r-- | src/socket_wrapper.c | 38 |
3 files changed, 43 insertions, 7 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 2d8e690..65f8b1a 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -48,18 +48,13 @@ 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) # FUNCTIONS check_function_exists(strncpy HAVE_STRNCPY) check_function_exists(vsnprintf HAVE_VSNPRINTF) check_function_exists(snprintf HAVE_SNPRINTF) - -if (WIN32) - check_function_exists(_vsnprintf_s HAVE__VSNPRINTF_S) - check_function_exists(_vsnprintf HAVE__VSNPRINTF) - check_function_exists(_snprintf HAVE__SNPRINTF) - check_function_exists(_snprintf_s HAVE__SNPRINTF_S) -endif (WIN32) +check_function_exists(signalfd HAVE_SIGNALFD) if (UNIX) if (NOT LINUX) diff --git a/config.h.cmake b/config.h.cmake index 63bbdb4..6b29d5b 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -15,6 +15,7 @@ /************************** HEADER FILES *************************/ #cmakedefine HAVE_SYS_FILIO_H 1 +#cmakedefine HAVE_SYS_SIGNALFD_H 1 /************************ STRUCT MEMBERS *************************/ @@ -25,6 +26,8 @@ /* Define to 1 if you have the `getaddrinfo' function. */ #cmakedefine HAVE_GETADDRINFO 1 +#cmakedefine HAVE_SIGNALFD 1 + #cmakedefine HAVE_ACCEPT_PSOCKLEN_T 1 #cmakedefine HAVE_IOCTL_INT 1 diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index 41b9923..f78f4a5 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -50,6 +50,9 @@ #ifdef HAVE_SYS_FILIO_H #include <sys/filio.h> #endif +#ifdef HAVE_SYS_SIGNALFD_H +#include <sys/signalfd.h> +#endif #include <sys/uio.h> #include <errno.h> #include <sys/un.h> @@ -321,6 +324,9 @@ struct swrap_libc_fns { int optname, const void *optval, socklen_t optlen); +#ifdef HAVE_SIGNALFD + int (*libc_signalfd)(int fd, const sigset_t *mask, int flags); +#endif int (*libc_socket)(int domain, int type, int protocol); int (*libc_socketpair)(int domain, int type, int protocol, int sv[2]); ssize_t (*libc_writev)(int fd, const struct iovec *iov, int iovcnt); @@ -657,6 +663,15 @@ static int libc_setsockopt(int sockfd, return swrap.fns.libc_setsockopt(sockfd, level, optname, optval, optlen); } +#ifdef HAVE_SIGNALFD +static int libc_signalfd(int fd, const sigset_t *mask, int flags) +{ + swrap_load_lib_function(SWRAP_LIBSOCKET, signalfd); + + return swrap.fns.libc_signalfd(fd, mask, flags); +} +#endif + static int libc_socket(int domain, int type, int protocol) { swrap_load_lib_function(SWRAP_LIBSOCKET, socket); @@ -1966,6 +1981,29 @@ static void swrap_dump_packet(struct socket_info *si, } /**************************************************************************** + * SIGNALFD + ***************************************************************************/ + +#ifdef HAVE_SIGNALFD +static int swrap_signalfd(int fd, const sigset_t *mask, int flags) +{ + int rc; + + rc = libc_signalfd(fd, mask, flags); + if (rc != -1) { + swrap_remove_stale(fd); + } + + return rc; +} + +int signalfd(int fd, const sigset_t *mask, int flags) +{ + return swrap_signalfd(fd, mask, flags); +} +#endif + +/**************************************************************************** * SOCKET ***************************************************************************/ |
