summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2014-01-28 13:48:52 +0100
committerAndreas Schneider <asn@samba.org>2014-01-28 14:11:48 +0100
commit9c03935fc0abb033a32683f5e9d8bd6b2136b8fd (patch)
tree7b3871b31d75dd29f332bb72259a6a7f02a44ef5
parentf8508200e90048523fc7c78467dc8e565744f7f9 (diff)
downloadsocket_wrapper-9c03935fc0abb033a32683f5e9d8bd6b2136b8fd.tar.gz
socket_wrapper-9c03935fc0abb033a32683f5e9d8bd6b2136b8fd.tar.xz
socket_wrapper-9c03935fc0abb033a32683f5e9d8bd6b2136b8fd.zip
src: Add timerfd_create() to handle stale fds.
Reviewed-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r--ConfigureChecks.cmake2
-rw-r--r--config.h.cmake2
-rw-r--r--src/socket_wrapper.c38
3 files changed, 42 insertions, 0 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 35b8edc..c05cbb9 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -50,6 +50,7 @@ endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
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)
+check_include_file(sys/timerfd.h HAVE_SYS_TIMERFD_H)
# FUNCTIONS
check_function_exists(strncpy HAVE_STRNCPY)
@@ -57,6 +58,7 @@ check_function_exists(vsnprintf HAVE_VSNPRINTF)
check_function_exists(snprintf HAVE_SNPRINTF)
check_function_exists(signalfd HAVE_SIGNALFD)
check_function_exists(eventfd HAVE_EVENTFD)
+check_function_exists(timerfd_create HAVE_TIMERFD_CREATE)
if (UNIX)
if (NOT LINUX)
diff --git a/config.h.cmake b/config.h.cmake
index 9632aa6..abbf133 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -17,6 +17,7 @@
#cmakedefine HAVE_SYS_FILIO_H 1
#cmakedefine HAVE_SYS_SIGNALFD_H 1
#cmakedefine HAVE_SYS_EVENTFD_H 1
+#cmakedefine HAVE_SYS_TIMERFD_H 1
/************************ STRUCT MEMBERS *************************/
@@ -29,6 +30,7 @@
#cmakedefine HAVE_GETADDRINFO 1
#cmakedefine HAVE_SIGNALFD 1
#cmakedefine HAVE_EVENTFD 1
+#cmakedefine HAVE_TIMERFD_CREATE 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 941f660..0d74321 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -56,6 +56,9 @@
#ifdef HAVE_SYS_EVENTFD_H
#include <sys/eventfd.h>
#endif
+#ifdef HAVE_SYS_TIMERFD_H
+#include <sys/timerfd.h>
+#endif
#include <sys/uio.h>
#include <errno.h>
#include <sys/un.h>
@@ -335,6 +338,9 @@ struct swrap_libc_fns {
#endif
int (*libc_socket)(int domain, int type, int protocol);
int (*libc_socketpair)(int domain, int type, int protocol, int sv[2]);
+#ifdef HAVE_TIMERFD_CREATE
+ int (*libc_timerfd_create)(int clockid, int flags);
+#endif
ssize_t (*libc_writev)(int fd, const struct iovec *iov, int iovcnt);
};
@@ -701,6 +707,15 @@ static int libc_socketpair(int domain, int type, int protocol, int sv[2])
return swrap.fns.libc_socketpair(domain, type, protocol, sv);
}
+#ifdef HAVE_TIMERFD_CREATE
+static int libc_timerfd_create(int clockid, int flags)
+{
+ swrap_load_lib_function(SWRAP_LIBC, timerfd_create);
+
+ return swrap.fns.libc_timerfd_create(clockid, flags);
+}
+#endif
+
static ssize_t libc_writev(int fd, const struct iovec *iov, int iovcnt)
{
swrap_load_lib_function(SWRAP_LIBSOCKET, writev);
@@ -2159,6 +2174,29 @@ int socketpair(int family, int type, int protocol, int sv[2])
}
/****************************************************************************
+ * SOCKETPAIR
+ ***************************************************************************/
+
+#ifdef HAVE_TIMERFD_CREATE
+static int swrap_timerfd_create(int clockid, int flags)
+{
+ int fd;
+
+ fd = libc_timerfd_create(clockid, flags);
+ if (fd != -1) {
+ swrap_remove_stale(fd);
+ }
+
+ return fd;
+}
+
+int timerfd_create(int clockid, int flags)
+{
+ return swrap_timerfd_create(clockid, flags);
+}
+#endif
+
+/****************************************************************************
* PIPE
***************************************************************************/