This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
BZ#15722: create all sockets with SOCK_CLOEXEC
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Thu, 13 Nov 2014 19:57:05 -0200
- Subject: BZ#15722: create all sockets with SOCK_CLOEXEC
- Authentication-results: sourceware.org; auth=none
Having got feedback on how to introduce best-practice wrappers, I've
untangled the recursive headers mess by introducing __need_sockaddr_in,
so that I could move __socket_cloexec back to include/sys/socket.h.
I've tested this both with and without __ASSUME_SOCK_CLOEXEC in
kernel-features.h; the latter required sometweaks to test programs.
While at that, I factored out the common rfc3484 testing infrastructure
into a header, now included by the 3 rfc3484 tests.
No regressions on x86_64-linux-gnu. Ok to install?
for ChangeLog
[BZ #15722]
* NEWS: Updated.
* include/sys/socket.h (__socket_cloexec): New. Include
required headers.
* inet/netinet/in.h (__need_sockaddr_in,
__sockaddr_in_defined): New, support partial include.
* resolv/resolv.h (__need_sockaddr_in): Define before
including netinet/in.h.
* include/netinet/in.h: Only declare hidden protos if the
entire public header was processed.
* resolv/res_hconf.c (_res_hconf_reorder_addrs): Use
__socket_cloexec.
* socket/opensock.c: Likewise.
* sunrpc/clnt_tcp.c (clnttcp_create): Likewise.
* sunrpc/clnt_unix.c (clntunix_create): Likewise.
* sunrpc/pm_getport.c (__get_socket): Likewise.
* sunrpc/pmap_rmt.c (clnt_broadcast): Likewise.
* sunrpc/rtime.c (rtime): Likewise.
* sunrpc/svc_tcp.c (svctcp_create): Likewise.
* sunrpc/svc_udp.c (svcudp_bufcreate): Likewise.
* sunrpc/svc_unix.c (svcunix_create): Likewise.
* sysdeps/gnu/ifaddrs.c (getifaddrs): Likewise.
* sysdeps/posix/getaddrinfo.c (getaddrinfo): Likewise.
* sysdeps/unix/sysv/linux/check_native.c (__check_native):
Likewise.
* sysdeps/unix/sysv/linux/check_pf.c (__check_pf): Likewise.
* sysdeps/unix/sysv/linux/ifaddrs.c (__netlink_open):
Likewise.
* nscd/gai.c: Include socket/have_sock_cloexec.c.
* posix/tst-rfc3484.c, posix/tst-rfc3484-2.c,
posix/tst-rfc3484-3.c: Factor out common getaddrinfo testing
infrastructure into...
* posix/tst-rfc3484.h: ... this new header. Include
socket/have_sock_cloexec.c. Define __f into f before
including headers.
---
NEWS | 8 ++-
include/netinet/in.h | 2 -
include/sys/socket.h | 44 ++++++++++++++++++
inet/netinet/in.h | 22 ++++++++-
nscd/gai.c | 1
posix/tst-rfc3484-2.c | 80 --------------------------------
posix/tst-rfc3484-3.c | 80 --------------------------------
posix/tst-rfc3484.c | 80 --------------------------------
posix/tst-rfc3484.h | 77 +++++++++++++++++++++++++++++++
resolv/res_hconf.c | 2 -
resolv/resolv.h | 1
socket/opensock.c | 14 +++---
sunrpc/clnt_tcp.c | 2 -
sunrpc/clnt_unix.c | 2 -
sunrpc/pm_getport.c | 2 -
sunrpc/pmap_rmt.c | 2 -
sunrpc/rtime.c | 2 -
sunrpc/svc_tcp.c | 2 -
sunrpc/svc_udp.c | 2 -
sunrpc/svc_unix.c | 2 -
sysdeps/gnu/ifaddrs.c | 2 -
sysdeps/posix/getaddrinfo.c | 2 -
sysdeps/unix/sysv/linux/check_native.c | 3 +
sysdeps/unix/sysv/linux/check_pf.c | 2 -
sysdeps/unix/sysv/linux/ifaddrs.c | 2 -
25 files changed, 173 insertions(+), 265 deletions(-)
create mode 100644 posix/tst-rfc3484.h
diff --git a/NEWS b/NEWS
index af86a93..bf1e591 100644
--- a/NEWS
+++ b/NEWS
@@ -9,10 +9,10 @@ Version 2.21
* The following bugs are resolved with this release:
- 6652, 12926, 14132, 14138, 14171, 14498, 15215, 15819, 15884, 17266,
- 17344, 17363, 17370, 17371, 17411, 17460, 17475, 17485, 17501, 17506,
- 17508, 17522, 17555, 17570, 17571, 17572, 17573, 17574, 17582, 17583,
- 17584, 17585, 17589.
+ 6652, 12926, 14132, 14138, 14171, 14498, 15215, 15722, 15819, 15884,
+ 17266, 17344, 17363, 17370, 17371, 17411, 17460, 17475, 17485, 17501,
+ 17506, 17508, 17522, 17555, 17570, 17571, 17572, 17573, 17574, 17582,
+ 17583, 17584, 17585, 17589.
* New locales: tu_IN, bh_IN.
diff --git a/include/netinet/in.h b/include/netinet/in.h
index 6fb5c86..6b9f7ec 100644
--- a/include/netinet/in.h
+++ b/include/netinet/in.h
@@ -2,7 +2,7 @@
#include <inet/netinet/in.h>
-#ifndef _ISOMAC
+#if defined _NETINET_IN_H && !defined _ISOMAC
libc_hidden_proto (bindresvport)
libc_hidden_proto (in6addr_loopback)
libc_hidden_proto (in6addr_any)
diff --git a/include/sys/socket.h b/include/sys/socket.h
index 9caf1bbd..81064b2 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -159,5 +159,49 @@ extern int __have_sock_cloexec attribute_hidden;
# define __have_paccept __have_sock_cloexec
#endif
+#include <kernel-features.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+/* Like socket, but with SOCK_CLOEXEC set if available. If it's not,
+ try to set the FD_CLOEXEC flag, and if that fails, close the socket
+ and fail unless __tolerant. */
+static inline int
+__socket_cloexec (int __domain, int __type, int __protocol)
+{
+ int __ret;
+#ifdef SOCK_CLOEXEC
+# ifdef __ASSUME_SOCK_CLOEXEC
+ int __have_sock_cloexec = 1;
+# endif /* __ASSUME_SOCK_CLOEXEC */
+ if (__have_sock_cloexec >= 0)
+ {
+ __ret = __socket (__domain, __type | SOCK_CLOEXEC, __protocol);
+ if (__have_sock_cloexec == 0)
+ __have_sock_cloexec = (__ret == -1 && errno == EINVAL ? -1 : 1);
+ if (__have_sock_cloexec > 0)
+ return __ret;
+ }
+#endif /* SOCK_CLOEXEC */
+ __ret = __socket (__domain, __type, __protocol);
+
+#ifdef FD_CLOEXEC
+ if (__ret != -1)
+ {
+ int __flags = __fcntl (__ret, F_GETFD, 0);
+ if (__flags == -1
+ || __fcntl (__ret, F_SETFD, __flags | FD_CLOEXEC) == -1)
+ {
+ __close (__ret);
+ __ret = -1;
+ errno = EINVAL;
+ }
+ }
+#endif /* FD_CLOEXEC */
+
+ return __ret;
+}
+
#endif
#endif
diff --git a/inet/netinet/in.h b/inet/netinet/in.h
index ca491be..f49b59c 100644
--- a/inet/netinet/in.h
+++ b/inet/netinet/in.h
@@ -16,16 +16,21 @@
<http://www.gnu.org/licenses/>. */
#ifndef _NETINET_IN_H
-#define _NETINET_IN_H 1
#include <features.h>
#include <stdint.h>
#include <sys/socket.h>
#include <bits/types.h>
+#ifndef __need_sockaddr_in
+# define _NETINET_IN_H
+#endif
__BEGIN_DECLS
+#ifndef __sockaddr_in_defined
+# define __sockaddr_in_defined
+
/* Internet address. */
typedef uint32_t in_addr_t;
struct in_addr
@@ -33,8 +38,14 @@ struct in_addr
in_addr_t s_addr;
};
+#ifdef _NETINET_IN_H
/* Get system-specific definitions. */
-#include <bits/in.h>
+# include <bits/in.h>
+#else
+# define _NETINET_IN_H
+# include <bits/in.h>
+# undef _NETINET_IN_H
+#endif
/* Standard well-defined IP protocols. */
enum
@@ -259,6 +270,11 @@ struct sockaddr_in6
};
#endif /* !__USE_KERNEL_IPV6_DEFS */
+# undef __need_sockaddr_in
+#endif /* __sockaddr_in_defined */
+
+#ifdef _NETINET_IN_H
+
#ifdef __USE_MISC
/* IPv4 multicast request. */
struct ip_mreq
@@ -625,6 +641,8 @@ extern int setsourcefilter (int __s, uint32_t __interface_addr,
const struct sockaddr_storage *__slist) __THROW;
#endif /* use GNU */
+#endif /* _NETINET_IN_H */
+
__END_DECLS
#endif /* netinet/in.h */
diff --git a/nscd/gai.c b/nscd/gai.c
index c159c0b..5661c54 100644
--- a/nscd/gai.c
+++ b/nscd/gai.c
@@ -38,6 +38,7 @@
#include <getaddrinfo.c>
/* Support code. */
+#include <socket/have_sock_cloexec.c>
#include <check_pf.c>
#include <check_native.c>
#ifdef HAVE_LIBIDN
diff --git a/posix/tst-rfc3484-2.c b/posix/tst-rfc3484-2.c
index ee92813..4701226 100644
--- a/posix/tst-rfc3484-2.c
+++ b/posix/tst-rfc3484-2.c
@@ -1,86 +1,8 @@
-#include <stdbool.h>
-#include <stdio.h>
-#include <ifaddrs.h>
-#include <stdint.h>
-
-/* Internal definitions used in the libc code. */
-#define __getservbyname_r getservbyname_r
-#define __socket socket
-#define __getsockname getsockname
-#define __inet_aton inet_aton
-#define __gethostbyaddr_r gethostbyaddr_r
-#define __gethostbyname2_r gethostbyname2_r
-#define __qsort_r qsort_r
-
-void
-attribute_hidden
-__check_pf (bool *p1, bool *p2, struct in6addrinfo **in6ai, size_t *in6ailen)
-{
- *p1 = *p2 = true;
- *in6ai = NULL;
- *in6ailen = 0;
-}
-
-void
-attribute_hidden
-__free_in6ai (struct in6addrinfo *ai)
-{
-}
-
-void
-attribute_hidden
-__check_native (uint32_t a1_index, int *a1_native,
- uint32_t a2_index, int *a2_native)
-{
-}
-
-int
-attribute_hidden
-__idna_to_ascii_lz (const char *input, char **output, int flags)
-{
- return 0;
-}
-
-int
-attribute_hidden
-__idna_to_unicode_lzlz (const char *input, char **output, int flags)
-{
- *output = NULL;
- return 0;
-}
-
-void
-attribute_hidden
-_res_hconf_init (void)
-{
-}
-
-#undef USE_NSCD
-#include "../sysdeps/posix/getaddrinfo.c"
-
-service_user *__nss_hosts_database attribute_hidden;
-
+#include "tst-rfc3484.h"
/* This is the beginning of the real test code. The above defines
(among other things) the function rfc3484_sort. */
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define h(n) n
-#else
-# define h(n) __bswap_constant_32 (n)
-#endif
-
-
-ssize_t
-__getline (char **lineptr, size_t *n, FILE *s)
-{
- *lineptr = NULL;
- *n = 0;
- return 0;
-}
-
-
static int
do_test (void)
{
diff --git a/posix/tst-rfc3484-3.c b/posix/tst-rfc3484-3.c
index c987366..e41a649 100644
--- a/posix/tst-rfc3484-3.c
+++ b/posix/tst-rfc3484-3.c
@@ -1,76 +1,8 @@
-#include <stdbool.h>
-#include <stdio.h>
-#include <ifaddrs.h>
-#include <stdint.h>
-
-/* Internal definitions used in the libc code. */
-#define __getservbyname_r getservbyname_r
-#define __socket socket
-#define __getsockname getsockname
-#define __inet_aton inet_aton
-#define __gethostbyaddr_r gethostbyaddr_r
-#define __gethostbyname2_r gethostbyname2_r
-#define __qsort_r qsort_r
-
-void
-attribute_hidden
-__check_pf (bool *p1, bool *p2, struct in6addrinfo **in6ai, size_t *in6ailen)
-{
- *p1 = *p2 = true;
- *in6ai = NULL;
- *in6ailen = 0;
-}
-
-void
-attribute_hidden
-__free_in6ai (struct in6addrinfo *ai)
-{
-}
-
-void
-attribute_hidden
-__check_native (uint32_t a1_index, int *a1_native,
- uint32_t a2_index, int *a2_native)
-{
-}
-
-int
-attribute_hidden
-__idna_to_ascii_lz (const char *input, char **output, int flags)
-{
- return 0;
-}
-
-int
-attribute_hidden
-__idna_to_unicode_lzlz (const char *input, char **output, int flags)
-{
- *output = NULL;
- return 0;
-}
-
-void
-attribute_hidden
-_res_hconf_init (void)
-{
-}
-
-#undef USE_NSCD
-#include "../sysdeps/posix/getaddrinfo.c"
-
-service_user *__nss_hosts_database attribute_hidden;
-
+#include "tst-rfc3484.h"
/* This is the beginning of the real test code. The above defines
(among other things) the function rfc3484_sort. */
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define h(n) n
-#else
-# define h(n) __bswap_constant_32 (n)
-#endif
-
struct sockaddr_in addrs[] =
{
{ .sin_family = AF_INET, .sin_addr = { h (0xa0a86d1d) } },
@@ -102,16 +34,6 @@ static const struct scopeentry new_scopes[] =
{ { { 0, 0, 0, 0 } }, h (0x00000000), 14 }
};
-
-ssize_t
-__getline (char **lineptr, size_t *n, FILE *s)
-{
- *lineptr = NULL;
- *n = 0;
- return 0;
-}
-
-
static int
do_test (void)
{
diff --git a/posix/tst-rfc3484.c b/posix/tst-rfc3484.c
index 73c4dff..0c6de89 100644
--- a/posix/tst-rfc3484.c
+++ b/posix/tst-rfc3484.c
@@ -1,76 +1,8 @@
-#include <stdbool.h>
-#include <stdio.h>
-#include <ifaddrs.h>
-#include <stdint.h>
-
-/* Internal definitions used in the libc code. */
-#define __getservbyname_r getservbyname_r
-#define __socket socket
-#define __getsockname getsockname
-#define __inet_aton inet_aton
-#define __gethostbyaddr_r gethostbyaddr_r
-#define __gethostbyname2_r gethostbyname2_r
-#define __qsort_r qsort_r
-
-void
-attribute_hidden
-__check_pf (bool *p1, bool *p2, struct in6addrinfo **in6ai, size_t *in6ailen)
-{
- *p1 = *p2 = true;
- *in6ai = NULL;
- *in6ailen = 0;
-}
-
-void
-attribute_hidden
-__free_in6ai (struct in6addrinfo *ai)
-{
-}
-
-void
-attribute_hidden
-__check_native (uint32_t a1_index, int *a1_native,
- uint32_t a2_index, int *a2_native)
-{
-}
-
-int
-attribute_hidden
-__idna_to_ascii_lz (const char *input, char **output, int flags)
-{
- return 0;
-}
-
-int
-attribute_hidden
-__idna_to_unicode_lzlz (const char *input, char **output, int flags)
-{
- *output = NULL;
- return 0;
-}
-
-void
-attribute_hidden
-_res_hconf_init (void)
-{
-}
-
-#undef USE_NSCD
-#include "../sysdeps/posix/getaddrinfo.c"
-
-service_user *__nss_hosts_database attribute_hidden;
-
+#include "tst-rfc3484.h"
/* This is the beginning of the real test code. The above defines
(among other things) the function rfc3484_sort. */
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define h(n) n
-#else
-# define h(n) __bswap_constant_32 (n)
-#endif
-
struct sockaddr_in addrs[] =
{
{ .sin_family = AF_INET, .sin_addr = { h (0x0aa85f19) } },
@@ -94,16 +26,6 @@ static int expected[naddrs] =
9, 4, 3, 6, 5, 7, 8, 2, 0, 1
};
-
-ssize_t
-__getline (char **lineptr, size_t *n, FILE *s)
-{
- *lineptr = NULL;
- *n = 0;
- return 0;
-}
-
-
static int
do_test (void)
{
diff --git a/posix/tst-rfc3484.h b/posix/tst-rfc3484.h
new file mode 100644
index 0000000..33c2d9c
--- /dev/null
+++ b/posix/tst-rfc3484.h
@@ -0,0 +1,77 @@
+/* Internal definitions used in the libc code. */
+#define __getservbyname_r getservbyname_r
+#define __socket socket
+#define __getsockname getsockname
+#define __inet_aton inet_aton
+#define __gethostbyaddr_r gethostbyaddr_r
+#define __gethostbyname2_r gethostbyname2_r
+#define __qsort_r qsort_r
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <ifaddrs.h>
+#include <stdint.h>
+
+#include "../socket/have_sock_cloexec.c"
+
+void
+attribute_hidden
+__check_pf (bool *p1, bool *p2, struct in6addrinfo **in6ai, size_t *in6ailen)
+{
+ *p1 = *p2 = true;
+ *in6ai = NULL;
+ *in6ailen = 0;
+}
+
+void
+attribute_hidden
+__free_in6ai (struct in6addrinfo *ai)
+{
+}
+
+void
+attribute_hidden
+__check_native (uint32_t a1_index, int *a1_native,
+ uint32_t a2_index, int *a2_native)
+{
+}
+
+int
+attribute_hidden
+__idna_to_ascii_lz (const char *input, char **output, int flags)
+{
+ return 0;
+}
+
+int
+attribute_hidden
+__idna_to_unicode_lzlz (const char *input, char **output, int flags)
+{
+ *output = NULL;
+ return 0;
+}
+
+void
+attribute_hidden
+_res_hconf_init (void)
+{
+}
+
+#undef USE_NSCD
+#include "../sysdeps/posix/getaddrinfo.c"
+
+service_user *__nss_hosts_database attribute_hidden;
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+# define h(n) n
+#else
+# define h(n) __bswap_constant_32 (n)
+#endif
+
+ssize_t
+__getline (char **lineptr, size_t *n, FILE *s)
+{
+ *lineptr = NULL;
+ *n = 0;
+ return 0;
+}
diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c
index b4c86227..573ca48 100644
--- a/resolv/res_hconf.c
+++ b/resolv/res_hconf.c
@@ -410,7 +410,7 @@ _res_hconf_reorder_addrs (struct hostent *hp)
/* Initialize interface table. */
/* The SIOCGIFNETMASK ioctl will only work on an AF_INET socket. */
- sd = __socket (AF_INET, SOCK_DGRAM, 0);
+ sd = __socket_cloexec (AF_INET, SOCK_DGRAM, 0);
if (sd < 0)
return;
diff --git a/resolv/resolv.h b/resolv/resolv.h
index 53c3bba..18ec731 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -54,6 +54,7 @@
/* These headers are needed for types used in the `struct res_state'
declaration. */
#include <sys/types.h>
+#define __need_sockaddr_in
#include <netinet/in.h>
#ifndef __need_res_state
diff --git a/socket/opensock.c b/socket/opensock.c
index 8dd8906..d2f0333 100644
--- a/socket/opensock.c
+++ b/socket/opensock.c
@@ -32,7 +32,7 @@ __opensock (void)
if (sock_af != -1)
{
- fd = __socket (sock_af, SOCK_DGRAM, 0);
+ fd = __socket_cloexec (sock_af, SOCK_DGRAM, 0);
if (fd != -1)
return fd;
}
@@ -40,28 +40,28 @@ __opensock (void)
__libc_lock_lock (lock);
if (sock_af != -1)
- fd = __socket (sock_af, SOCK_DGRAM, 0);
+ fd = __socket_cloexec (sock_af, SOCK_DGRAM, 0);
if (fd == -1)
{
#ifdef AF_INET
- fd = __socket (sock_af = AF_INET, SOCK_DGRAM, 0);
+ fd = __socket_cloexec (sock_af = AF_INET, SOCK_DGRAM, 0);
#endif
#ifdef AF_INET6
if (fd < 0)
- fd = __socket (sock_af = AF_INET6, SOCK_DGRAM, 0);
+ fd = __socket_cloexec (sock_af = AF_INET6, SOCK_DGRAM, 0);
#endif
#ifdef AF_IPX
if (fd < 0)
- fd = __socket (sock_af = AF_IPX, SOCK_DGRAM, 0);
+ fd = __socket_cloexec (sock_af = AF_IPX, SOCK_DGRAM, 0);
#endif
#ifdef AF_AX25
if (fd < 0)
- fd = __socket (sock_af = AF_AX25, SOCK_DGRAM, 0);
+ fd = __socket_cloexec (sock_af = AF_AX25, SOCK_DGRAM, 0);
#endif
#ifdef AF_APPLETALK
if (fd < 0)
- fd = __socket (sock_af = AF_APPLETALK, SOCK_DGRAM, 0);
+ fd = __socket_cloexec (sock_af = AF_APPLETALK, SOCK_DGRAM, 0);
#endif
}
diff --git a/sunrpc/clnt_tcp.c b/sunrpc/clnt_tcp.c
index f4ba0ef..7dc3f42 100644
--- a/sunrpc/clnt_tcp.c
+++ b/sunrpc/clnt_tcp.c
@@ -146,7 +146,7 @@ clnttcp_create (struct sockaddr_in *raddr, u_long prog, u_long vers,
*/
if (*sockp < 0)
{
- *sockp = __socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ *sockp = __socket_cloexec (AF_INET, SOCK_STREAM, IPPROTO_TCP);
(void) bindresvport (*sockp, (struct sockaddr_in *) 0);
if ((*sockp < 0)
|| (__connect (*sockp, (struct sockaddr *) raddr,
diff --git a/sunrpc/clnt_unix.c b/sunrpc/clnt_unix.c
index aff6fa5..49864f8 100644
--- a/sunrpc/clnt_unix.c
+++ b/sunrpc/clnt_unix.c
@@ -132,7 +132,7 @@ clntunix_create (struct sockaddr_un *raddr, u_long prog, u_long vers,
*/
if (*sockp < 0)
{
- *sockp = __socket (AF_UNIX, SOCK_STREAM, 0);
+ *sockp = __socket_cloexec (AF_UNIX, SOCK_STREAM, 0);
len = strlen (raddr->sun_path) + sizeof (raddr->sun_family) + 1;
if (*sockp < 0
|| __connect (*sockp, (struct sockaddr *) raddr, len) < 0)
diff --git a/sunrpc/pm_getport.c b/sunrpc/pm_getport.c
index d9df0cc..d698bc6 100644
--- a/sunrpc/pm_getport.c
+++ b/sunrpc/pm_getport.c
@@ -48,7 +48,7 @@ int
internal_function
__get_socket (struct sockaddr_in *saddr)
{
- int so = __socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ int so = __socket_cloexec (AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (so < 0)
return -1;
diff --git a/sunrpc/pmap_rmt.c b/sunrpc/pmap_rmt.c
index fd8de85..592dbc4 100644
--- a/sunrpc/pmap_rmt.c
+++ b/sunrpc/pmap_rmt.c
@@ -238,7 +238,7 @@ clnt_broadcast (prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
* initialization: create a socket, a broadcast address, and
* preserialize the arguments into a send buffer.
*/
- if ((sock = __socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
+ if ((sock = __socket_cloexec (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
{
perror (_("Cannot create socket for broadcast rpc"));
stat = RPC_CANTSEND;
diff --git a/sunrpc/rtime.c b/sunrpc/rtime.c
index 79d55d1..071cfac 100644
--- a/sunrpc/rtime.c
+++ b/sunrpc/rtime.c
@@ -84,7 +84,7 @@ rtime (struct sockaddr_in *addrp, struct rpc_timeval *timep,
else
type = SOCK_DGRAM;
- s = __socket (AF_INET, type, 0);
+ s = __socket_cloexec (AF_INET, type, 0);
if (s < 0)
return (-1);
diff --git a/sunrpc/svc_tcp.c b/sunrpc/svc_tcp.c
index 92886f0..cba747f 100644
--- a/sunrpc/svc_tcp.c
+++ b/sunrpc/svc_tcp.c
@@ -159,7 +159,7 @@ svctcp_create (int sock, u_int sendsize, u_int recvsize)
if (sock == RPC_ANYSOCK)
{
- if ((sock = __socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
+ if ((sock = __socket_cloexec (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
{
perror (_("svc_tcp.c - tcp socket creation problem"));
return (SVCXPRT *) NULL;
diff --git a/sunrpc/svc_udp.c b/sunrpc/svc_udp.c
index 411234a..cafeed0 100644
--- a/sunrpc/svc_udp.c
+++ b/sunrpc/svc_udp.c
@@ -132,7 +132,7 @@ svcudp_bufcreate (sock, sendsz, recvsz)
if (sock == RPC_ANYSOCK)
{
- if ((sock = __socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
+ if ((sock = __socket_cloexec (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
{
perror (_("svcudp_create: socket creation problem"));
return (SVCXPRT *) NULL;
diff --git a/sunrpc/svc_unix.c b/sunrpc/svc_unix.c
index 6d93c5f..ed55055 100644
--- a/sunrpc/svc_unix.c
+++ b/sunrpc/svc_unix.c
@@ -157,7 +157,7 @@ svcunix_create (int sock, u_int sendsize, u_int recvsize, char *path)
if (sock == RPC_ANYSOCK)
{
- if ((sock = __socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
+ if ((sock = __socket_cloexec (AF_UNIX, SOCK_STREAM, 0)) < 0)
{
perror (_("svc_unix.c - AF_UNIX socket creation problem"));
return (SVCXPRT *) NULL;
diff --git a/sysdeps/gnu/ifaddrs.c b/sysdeps/gnu/ifaddrs.c
index 1b8775f..f605e8f 100644
--- a/sysdeps/gnu/ifaddrs.c
+++ b/sysdeps/gnu/ifaddrs.c
@@ -37,7 +37,7 @@ getifaddrs (struct ifaddrs **ifap)
/* This implementation handles only IPv4 interfaces.
The various ioctls below will only work on an AF_INET socket.
Some different mechanism entirely must be used for IPv6. */
- int fd = __socket (AF_INET, SOCK_DGRAM, 0);
+ int fd = __socket_cloexec (AF_INET, SOCK_DGRAM, 0);
struct ifreq *ifreqs;
int nifs;
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 31bb7e6..68ffac4 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -2512,7 +2512,7 @@ getaddrinfo (const char *name, const char *service,
close_retry:
close_not_cancel_no_status (fd);
af = q->ai_family;
- fd = __socket (af, SOCK_DGRAM, IPPROTO_IP);
+ fd = __socket_cloexec (af, SOCK_DGRAM, IPPROTO_IP);
}
else
{
diff --git a/sysdeps/unix/sysv/linux/check_native.c b/sysdeps/unix/sysv/linux/check_native.c
index 68adeb8..a119eec 100644
--- a/sysdeps/unix/sysv/linux/check_native.c
+++ b/sysdeps/unix/sysv/linux/check_native.c
@@ -28,6 +28,7 @@
#include <net/if.h>
#include <net/if_arp.h>
#include <sys/ioctl.h>
+#include <sys/socket.h>
#include <asm/types.h>
#include <linux/netlink.h>
@@ -40,7 +41,7 @@ void
__check_native (uint32_t a1_index, int *a1_native,
uint32_t a2_index, int *a2_native)
{
- int fd = __socket (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+ int fd = __socket_cloexec (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
struct sockaddr_nl nladdr;
memset (&nladdr, '\0', sizeof (nladdr));
diff --git a/sysdeps/unix/sysv/linux/check_pf.c b/sysdeps/unix/sysv/linux/check_pf.c
index 976f249e..1516861 100644
--- a/sysdeps/unix/sysv/linux/check_pf.c
+++ b/sysdeps/unix/sysv/linux/check_pf.c
@@ -353,7 +353,7 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6,
}
else
{
- int fd = __socket (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+ int fd = __socket_cloexec (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (__glibc_likely (fd >= 0))
{
diff --git a/sysdeps/unix/sysv/linux/ifaddrs.c b/sysdeps/unix/sysv/linux/ifaddrs.c
index a47b2ed..0eb04e0 100644
--- a/sysdeps/unix/sysv/linux/ifaddrs.c
+++ b/sysdeps/unix/sysv/linux/ifaddrs.c
@@ -251,7 +251,7 @@ __netlink_open (struct netlink_handle *h)
{
struct sockaddr_nl nladdr;
- h->fd = __socket (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+ h->fd = __socket_cloexec (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (h->fd < 0)
goto out;
--
Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/ FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer