From 95520f672f3cbf311b503d61e2ac9e2a22d209e9 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 28 Jan 2014 13:20:20 +0100 Subject: src: Add socketpair() to handle stale fds. Reviewed-by: Stefan Metzmacher --- src/socket_wrapper.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src') diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index fad9475..41b9923 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -322,6 +322,7 @@ struct swrap_libc_fns { const void *optval, socklen_t optlen); 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); }; @@ -663,6 +664,13 @@ static int libc_socket(int domain, int type, int protocol) return swrap.fns.libc_socket(domain, type, protocol); } +static int libc_socketpair(int domain, int type, int protocol, int sv[2]) +{ + swrap_load_lib_function(SWRAP_LIBSOCKET, socketpair); + + return swrap.fns.libc_socketpair(domain, type, protocol, sv); +} + static ssize_t libc_writev(int fd, const struct iovec *iov, int iovcnt) { swrap_load_lib_function(SWRAP_LIBSOCKET, writev); @@ -2075,6 +2083,28 @@ int socket(int family, int type, int protocol) return swrap_socket(family, type, protocol); } +/**************************************************************************** + * SOCKETPAIR + ***************************************************************************/ + +static int swrap_socketpair(int family, int type, int protocol, int sv[2]) +{ + int rc; + + rc = libc_socketpair(family, type, protocol, sv); + if (rc != -1) { + swrap_remove_stale(sv[0]); + swrap_remove_stale(sv[1]); + } + + return rc; +} + +int socketpair(int family, int type, int protocol, int sv[2]) +{ + return swrap_socketpair(family, type, protocol, sv); +} + /**************************************************************************** * PIPE ***************************************************************************/ -- cgit