about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAurelien Jarno <aurelien@aurel32.net>2015-01-06 08:50:23 -0800
committerH.J. Lu <hjl.tools@gmail.com>2015-01-06 09:00:20 -0800
commit38949026b3600d035281d8eaf833dd327585bdd0 (patch)
tree9331f16fe31c1a68179daeb5fbf502b7a19b8f2d
parent5fe55e9c654be9055d5ee22dce749c0ee8a3bb75 (diff)
downloadglibc-38949026b3600d035281d8eaf833dd327585bdd0.tar.gz
glibc-38949026b3600d035281d8eaf833dd327585bdd0.tar.xz
glibc-38949026b3600d035281d8eaf833dd327585bdd0.zip
resolv: fix rotate option
The rotate option doesn't work correctly, and only send the query to the
same server (the second in the list). The rotation code in itself is not
broken, but the nsaddrs structure is reinitialized each time at the
beginning of __libc_res_nsend unless RES_STAYOPEN is enabled.

This is due to a call to __res_iclose from the end of __libc_res_nsend
when answers from the name server have been received. This function
closes all the sockets, but doesn't free the addresses (it can do that,
but in that case the second argument is false).

This patch change the code of __res_iclose to clear statp->_u._ext.nsinit
 only when the addresses are actually freed.

	* resolv/res_init.c (__res_iclose): Only clear nsinit if the
	addresses have been freed.
-rw-r--r--ChangeLog5
-rw-r--r--resolv/res_init.c3
2 files changed, 7 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 1204575be1..6ba3b8e840 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2015-01-06  Aurelien Jarno  <aurelien@aurel32.net>
 
+	* resolv/res_init.c (__res_iclose): Only clear nsinit if the
+	addresses have been freed.
+
+2015-01-06  Aurelien Jarno  <aurelien@aurel32.net>
+
 	* resolv/res_init.c (__res_vinit): Improve comments about nserv
 	and nservall.
 
diff --git a/resolv/res_init.c b/resolv/res_init.c
index 4c170be684..553ba12a5a 100644
--- a/resolv/res_init.c
+++ b/resolv/res_init.c
@@ -621,7 +621,8 @@ __res_iclose(res_state statp, bool free_addr) {
 				statp->_u._ext.nsaddrs[ns] = NULL;
 			}
 		}
-	statp->_u._ext.nsinit = 0;
+	if (free_addr)
+		statp->_u._ext.nsinit = 0;
 }
 libc_hidden_def (__res_iclose)