summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2014-01-28 13:20:20 +0100
committerAndreas Schneider <asn@samba.org>2014-01-28 14:11:34 +0100
commit95520f672f3cbf311b503d61e2ac9e2a22d209e9 (patch)
tree4c4f406c5ddf335764ab46bf554a7d7bfdcb5721 /src
parentea45102993c0800a8a62137da09dbb2787834ed4 (diff)
downloadsocket_wrapper-95520f672f3cbf311b503d61e2ac9e2a22d209e9.tar.gz
socket_wrapper-95520f672f3cbf311b503d61e2ac9e2a22d209e9.tar.xz
socket_wrapper-95520f672f3cbf311b503d61e2ac9e2a22d209e9.zip
src: Add socketpair() to handle stale fds.
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'src')
-rw-r--r--src/socket_wrapper.c30
1 files changed, 30 insertions, 0 deletions
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);
@@ -2076,6 +2084,28 @@ int socket(int family, int type, int 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
***************************************************************************/