From patchwork Tue Aug 8 17:01:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 799362 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-82872-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="NSacolnY"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xRgfv3fFxz9s65 for ; Wed, 9 Aug 2017 03:01:59 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= DGDdyeO9QLn+AlVMPPkgmlikQgVVvdrnPyJ/VSGeywwdgp+ztLbiEZ6RJE8qGD2w JLjdY2eXmYd1lcw5bMPD6Tewj+rOhkc3NfN0wY6iHp9ekaqOD2wQDk0VuAgPWz3e /EMaXxrxwS3vsULKY5ADFtoAt6t7E/af5OKvUo4OaW0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=K77v3T 9X4GuitS1GJOcaSICKNiI=; b=NSacolnYJZV72QdSelaPsI6Lbb4gJQH0CwpvLq iOXcP9EgaTDserIeSx61z3tOhzI/NtF1i+AUftT7idpqogdIaqapAu+Wic/rb32N vMjFWExksmZhK9sIZCfqsSvsj8jlRkAS7mXJMGxfgRzwF083Jtwc8rvHGuiy984G DMiaE= Received: (qmail 36524 invoked by alias); 8 Aug 2017 17:01:43 -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 36174 invoked by uid 89); 8 Aug 2017 17:01:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 013358124A Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=fweimer@redhat.com Date: Tue, 08 Aug 2017 19:01:37 +0200 To: libc-alpha@sourceware.org Subject: [PATCH] getaddrinfo: Use &h_errno has the h_errno pointer User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20170808170137.EDD3C4029923B@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) This simplifies the code because it is not necessary to propagate the temporary h_errno value to the thread-local variable. It also increases compatibility with NSS modules which update only one of the two places. 2017-08-08 Florian Weimer * sysdeps/posix/getaddrinfo.c (gethosts): Use h_errno directly. (getcanonname): Likewise. (gaih_inet): Likewise. diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 1a16820..076e1fa 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -241,7 +241,6 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, #define gethosts(_family, _type) \ { \ - int herrno; \ struct hostent th; \ struct hostent *h; \ char *localcanon = NULL; \ @@ -249,8 +248,8 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, while (1) { \ status = DL_CALL_FCT (fct, (name, _family, &th, \ tmpbuf->data, tmpbuf->length, \ - &errno, &herrno, NULL, &localcanon)); \ - if (errno != ERANGE || herrno != NETDB_INTERNAL) \ + &errno, &h_errno, NULL, &localcanon)); \ + if (errno != ERANGE || h_errno != NETDB_INTERNAL) \ break; \ if (!scratch_buffer_grow (tmpbuf)) \ { \ @@ -266,18 +265,17 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, h = NULL; \ if (errno != 0) \ { \ - if (herrno == NETDB_INTERNAL) \ + if (h_errno == NETDB_INTERNAL) \ { \ - __set_h_errno (herrno); \ __resolv_context_enable_inet6 (res_ctx, res_enable_inet6); \ __resolv_context_put (res_ctx); \ result = -EAI_SYSTEM; \ goto free_and_return; \ } \ - if (herrno == TRY_AGAIN) \ + if (h_errno == TRY_AGAIN) \ no_data = EAI_AGAIN; \ else \ - no_data = herrno == NO_DATA; \ + no_data = h_errno == NO_DATA; \ } \ else if (h != NULL) \ { \ @@ -333,9 +331,8 @@ getcanonname (service_user *nip, struct gaih_addrtuple *at, const char *name) if (cfct != NULL) { char buf[256]; - int herrno; if (DL_CALL_FCT (cfct, (at->name ?: name, buf, sizeof (buf), - &s, &errno, &herrno)) != NSS_STATUS_SUCCESS) + &s, &errno, &h_errno)) != NSS_STATUS_SUCCESS) /* If the canonical name cannot be determined, use the passed string. */ s = (char *) name; @@ -594,14 +591,13 @@ gaih_inet (const char *name, const struct gaih_service *service, int rc; struct hostent th; struct hostent *h; - int herrno; while (1) { rc = __gethostbyname2_r (name, AF_INET, &th, tmpbuf->data, tmpbuf->length, - &h, &herrno); - if (rc != ERANGE || herrno != NETDB_INTERNAL) + &h, &h_errno); + if (rc != ERANGE || h_errno != NETDB_INTERNAL) break; if (!scratch_buffer_grow (tmpbuf)) { @@ -626,12 +622,9 @@ gaih_inet (const char *name, const struct gaih_service *service, } else { - if (herrno == NETDB_INTERNAL) - { - __set_h_errno (herrno); - result = -EAI_SYSTEM; - } - else if (herrno == TRY_AGAIN) + if (h_errno == NETDB_INTERNAL) + result = -EAI_SYSTEM; + else if (h_errno == TRY_AGAIN) result = -EAI_AGAIN; else /* We made requests but they turned out no data. @@ -654,8 +647,7 @@ gaih_inet (const char *name, const struct gaih_service *service, { /* Try to use nscd. */ struct nscd_ai_result *air = NULL; - int herrno; - int err = __nscd_getai (name, &air, &herrno); + int err = __nscd_getai (name, &air, &h_errno); if (air != NULL) { /* Transform into gaih_addrtuple list. */ @@ -746,9 +738,9 @@ gaih_inet (const char *name, const struct gaih_service *service, goto free_and_return; else if (__nss_not_use_nscd_hosts == 0) { - if (herrno == NETDB_INTERNAL && errno == ENOMEM) + if (h_errno == NETDB_INTERNAL && errno == ENOMEM) result = -EAI_MEMORY; - else if (herrno == TRY_AGAIN) + else if (h_errno == TRY_AGAIN) result = -EAI_AGAIN; else result = -EAI_SYSTEM; @@ -787,23 +779,21 @@ gaih_inet (const char *name, const struct gaih_service *service, if (fct4 != NULL) { - int herrno; - while (1) { status = DL_CALL_FCT (fct4, (name, pat, tmpbuf->data, tmpbuf->length, - &errno, &herrno, + &errno, &h_errno, NULL)); if (status == NSS_STATUS_SUCCESS) break; if (status != NSS_STATUS_TRYAGAIN - || errno != ERANGE || herrno != NETDB_INTERNAL) + || errno != ERANGE || h_errno != NETDB_INTERNAL) { - if (herrno == TRY_AGAIN) + if (h_errno == TRY_AGAIN) no_data = EAI_AGAIN; else - no_data = herrno == NO_DATA; + no_data = h_errno == NO_DATA; break; }