From 20f2f3141788fe10111c280445c344f179f83ecf 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 ecb177f6a..3bf953b13 100644 --- a/lib/roken/roken.h.in +++ b/lib/roken/roken.h.in @@ -819,6 +819,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 ab1b7ff34..36fbd3821 100644 --- a/lib/roken/socket.c +++ b/lib/roken/socket.c @@ -297,3 +297,23 @@ socket_set_ipv6only (int sock, int val) setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&val, sizeof(val)); #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 -- 2.11.4.GIT