summary refs log tree commit diff
path: root/resolv/res_send.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2015-10-17 12:02:37 +0200
committerFlorian Weimer <fweimer@redhat.com>2015-10-17 12:02:37 +0200
commit52fb79d6cdecb89a6f0375091e7c12ed79ae6760 (patch)
treee4885bfee90d7fe9f584518d3bc242050c725ef0 /resolv/res_send.c
parentf546f87c4ffb1642ffc96b8d614c329ed35252c3 (diff)
downloadglibc-52fb79d6cdecb89a6f0375091e7c12ed79ae6760.tar.gz
glibc-52fb79d6cdecb89a6f0375091e7c12ed79ae6760.tar.xz
glibc-52fb79d6cdecb89a6f0375091e7c12ed79ae6760.zip
Assume that SOCK_CLOEXEC is available and works
This fixes (harmless) data races when accessing the various
__have_sock_cloexec variables.
Diffstat (limited to 'resolv/res_send.c')
-rw-r--r--resolv/res_send.c49
1 files changed, 4 insertions, 45 deletions
diff --git a/resolv/res_send.c b/resolv/res_send.c
index 5e53cc2df6..6137e4d788 100644
--- a/resolv/res_send.c
+++ b/resolv/res_send.c
@@ -104,14 +104,6 @@ static const char rcsid[] = "$BINDId: res_send.c,v 8.38 2000/03/30 20:16:51 vixi
 #define MAXPACKET       65536
 #endif
 
-
-#ifndef __ASSUME_SOCK_CLOEXEC
-static int __have_o_nonblock;
-#else
-# define __have_o_nonblock 0
-#endif
-
-
 /* From ev_streams.c.  */
 
 static inline void
@@ -927,38 +919,14 @@ reopen (res_state statp, int *terrno, int ns)
 
 		/* only try IPv6 if IPv6 NS and if not failed before */
 		if (nsap->sa_family == AF_INET6 && !statp->ipv6_unavail) {
-			if (__glibc_likely (__have_o_nonblock >= 0))       {
-				EXT(statp).nssocks[ns] =
-				  socket(PF_INET6, SOCK_DGRAM|SOCK_NONBLOCK,
-					 0);
-#ifndef __ASSUME_SOCK_CLOEXEC
-				if (__have_o_nonblock == 0)
-					__have_o_nonblock
-					  = (EXT(statp).nssocks[ns] == -1
-					     && errno == EINVAL ? -1 : 1);
-#endif
-			}
-			if (__glibc_unlikely (__have_o_nonblock < 0))
-				EXT(statp).nssocks[ns] =
-				  socket(PF_INET6, SOCK_DGRAM, 0);
+			EXT(statp).nssocks[ns]
+				= socket(PF_INET6, SOCK_DGRAM|SOCK_NONBLOCK, 0);
 			if (EXT(statp).nssocks[ns] < 0)
 			    statp->ipv6_unavail = errno == EAFNOSUPPORT;
 			slen = sizeof (struct sockaddr_in6);
 		} else if (nsap->sa_family == AF_INET) {
-			if (__glibc_likely (__have_o_nonblock >= 0))       {
-				EXT(statp).nssocks[ns]
-				  = socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK,
-					   0);
-#ifndef __ASSUME_SOCK_CLOEXEC
-				if (__have_o_nonblock == 0)
-					__have_o_nonblock
-					  = (EXT(statp).nssocks[ns] == -1
-					     && errno == EINVAL ? -1 : 1);
-#endif
-			}
-			if (__glibc_unlikely (__have_o_nonblock < 0))
-				EXT(statp).nssocks[ns]
-				  = socket(PF_INET, SOCK_DGRAM, 0);
+			EXT(statp).nssocks[ns]
+				= socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, 0);
 			slen = sizeof (struct sockaddr_in);
 		}
 		if (EXT(statp).nssocks[ns] < 0) {
@@ -983,15 +951,6 @@ reopen (res_state statp, int *terrno, int ns)
 			__res_iclose(statp, false);
 			return (0);
 		}
-		if (__glibc_unlikely (__have_o_nonblock < 0))       {
-			/* Make socket non-blocking.  */
-			int fl = __fcntl (EXT(statp).nssocks[ns], F_GETFL);
-			if  (fl != -1)
-				__fcntl (EXT(statp).nssocks[ns], F_SETFL,
-					 fl | O_NONBLOCK);
-			Dprint(statp->options & RES_DEBUG,
-			       (stdout, ";; new DG socket\n"))
-		}
 	}
 
 	return 1;