From dc0023293292d5247a5984e78fc10de9399da5f5 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 28 Jan 2014 13:33:23 +0100 Subject: src: Add signalfd() to handle stale fds. Reviewed-by: Stefan Metzmacher --- src/socket_wrapper.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src') 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 #endif +#ifdef HAVE_SYS_SIGNALFD_H +#include +#endif #include #include #include @@ -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); @@ -1965,6 +1980,29 @@ static void swrap_dump_packet(struct socket_info *si, free(packet); } +/**************************************************************************** + * 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 ***************************************************************************/ -- cgit