summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2014-01-28 13:42:38 +0100
committerAndreas Schneider <asn@samba.org>2014-01-28 14:11:43 +0100
commitf8508200e90048523fc7c78467dc8e565744f7f9 (patch)
treec6e1ec24bdd926628f92bfd2e19a9e5f0fd58a75 /src
parentdc0023293292d5247a5984e78fc10de9399da5f5 (diff)
downloadsocket_wrapper-f8508200e90048523fc7c78467dc8e565744f7f9.tar.gz
socket_wrapper-f8508200e90048523fc7c78467dc8e565744f7f9.tar.xz
socket_wrapper-f8508200e90048523fc7c78467dc8e565744f7f9.zip
src: Add eventfd() 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 f78f4a5..941f660 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -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)
@@ -3935,6 +3950,29 @@ int dup2(int fd, int 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
***************************/