From patchwork Tue Jun 3 23:36:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 1276 Received: (qmail 10163 invoked by alias); 3 Jun 2014 23:36:55 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 10003 invoked by uid 89); 3 Jun 2014 23:36:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: hall.aurel32.net From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: Aurelien Jarno Subject: [RFC PATCH 4/4] resolv: fix rotate option Date: Wed, 4 Jun 2014 01:36:43 +0200 Message-Id: <1401838603-22101-5-git-send-email-aurelien@aurel32.net> In-Reply-To: <1401838603-22101-1-git-send-email-aurelien@aurel32.net> References: <1401838603-22101-1-git-send-email-aurelien@aurel32.net> 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(-) 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)