[RFC,4/4] resolv: fix rotate option
diff mbox

Message ID 1401838603-22101-5-git-send-email-aurelien@aurel32.net
State New
Headers show

Commit Message

Aurelien Jarno June 3, 2014, 11:36 p.m. UTC
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 nameserver 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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch
diff mbox

diff --git a/resolv/res_init.c b/resolv/res_init.c
index 95564af..42e16b6 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)