From 2fbdb6a514e97125d4c46a84a821e8016774c634 Mon Sep 17 00:00:00 2001 From: Love Hornquist Astrand Date: Mon, 25 Jan 2010 23:01:18 -0800 Subject: [PATCH] rewrite socket to rk_socket of there is SOCK_CLOEXEC and there is linux, prompted by Harald Barth --- lib/roken/roken.h.in | 5 +++++ lib/roken/socket.c | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/roken/roken.h.in b/lib/roken/roken.h.in index 0492db4d6..33918d37b 100644 --- a/lib/roken/roken.h.in +++ b/lib/roken/roken.h.in @@ -1033,6 +1033,11 @@ void rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *)); #endif +#if defined(__LINUX__) && SOCK_CLOEXEC && !defined(SOCKET_WRAPPER_REPLACE) +#undef socket +#define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot) +#endif + #ifdef SOCKET_WRAPPER_REPLACE #include #endif diff --git a/lib/roken/socket.c b/lib/roken/socket.c index bfc4b7102..a19281c13 100644 --- a/lib/roken/socket.c +++ b/lib/roken/socket.c @@ -315,3 +315,23 @@ socket_to_fd(rk_socket_t sock, int flags) return _open_osfhandle((intptr_t) sock, flags); #endif } + +#ifndef HEIMAL_SMALLER + +int rk_socket(int, int, int); + +int +rk_socket(int domain, int type, int protocol) +{ + int s; + s = socket (domain, type, protocol); +#ifdef SOCK_CLOEXEC + if ((SOCK_CLOEXEC & protocol) && s < 0 && errno == EINVAL) { + protocol &= ~SOCK_CLOEXEC; + s = socket (domain, type, protocol); + } +#endif + return s; +} + +#endif