summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2014-01-28 13:33:23 +0100
committerAndreas Schneider <asn@samba.org>2014-01-28 14:11:37 +0100
commitdc0023293292d5247a5984e78fc10de9399da5f5 (patch)
tree9eaba70f3650a616de44739a78898111dd6b8a3a /src
parent95520f672f3cbf311b503d61e2ac9e2a22d209e9 (diff)
downloadsocket_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>
Diffstat (limited to 'src')
-rw-r--r--src/socket_wrapper.c38
1 files changed, 38 insertions, 0 deletions
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
***************************************************************************/