From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D16DF395201A for ; Thu, 17 Mar 2022 04:44:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D16DF395201A Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-206-oS0WT_uIMGum4jE8q8E_ow-1; Thu, 17 Mar 2022 00:44:47 -0400 X-MC-Unique: oS0WT_uIMGum4jE8q8E_ow-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 377A5185A79C; Thu, 17 Mar 2022 04:44:47 +0000 (UTC) Received: from greed.delorie.com (ovpn-112-4.rdu2.redhat.com [10.10.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 22CAD4B8D46; Thu, 17 Mar 2022 04:44:47 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 22H4ik4U1745028; Thu, 17 Mar 2022 00:44:46 -0400 From: DJ Delorie To: Siddhesh Poyarekar Cc: libc-alpha@sourceware.org Subject: Re: [PATCH v2 09/12] gaih_inet: make gethosts into a function In-Reply-To: <20220314094835.1159523-10-siddhesh@sourceware.org> (message from Siddhesh Poyarekar via Libc-alpha on Mon, 14 Mar 2022 15:18:32 +0530) Date: Thu, 17 Mar 2022 00:44:46 -0400 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Mar 2022 04:44:52 -0000 Siddhesh Poyarekar via Libc-alpha writes: > The macro is quite a pain to debug, so make gethosts into a function to > make it easier to maintain. LGTM Reviewed-by: DJ Delorie > diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c > index c33cc2507b..e71f21f3c9 100644 > --- a/sysdeps/posix/getaddrinfo.c > +++ b/sysdeps/posix/getaddrinfo.c > @@ -268,63 +268,54 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, int family, > return true; > } > > -#define gethosts(_family) \ > - { \ > - struct hostent th; \ > - char *localcanon = NULL; \ > - no_data = 0; \ > - while (1) \ > - { \ > - status = DL_CALL_FCT (fct, (name, _family, &th, \ > - tmpbuf->data, tmpbuf->length, \ > - &errno, &h_errno, NULL, &localcanon)); \ > - if (status != NSS_STATUS_TRYAGAIN || h_errno != NETDB_INTERNAL \ > - || errno != ERANGE) \ > - break; \ > - if (!scratch_buffer_grow (tmpbuf)) \ > - { \ > - __resolv_context_put (res_ctx); \ > - result = -EAI_MEMORY; \ > - goto out; \ > - } \ > - } \ > - if (status == NSS_STATUS_NOTFOUND \ > - || status == NSS_STATUS_TRYAGAIN || status == NSS_STATUS_UNAVAIL) \ > - { \ > - if (h_errno == NETDB_INTERNAL) \ > - { \ > - __resolv_context_put (res_ctx); \ > - result = -EAI_SYSTEM; \ > - goto out; \ > - } \ > - if (h_errno == TRY_AGAIN) \ > - no_data = EAI_AGAIN; \ > - else \ > - no_data = h_errno == NO_DATA; \ > - } \ > - else if (status == NSS_STATUS_SUCCESS) \ > - { \ > - if (!convert_hostent_to_gaih_addrtuple (req, _family, &th, res)) \ > - { \ > - __resolv_context_put (res_ctx); \ > - result = -EAI_SYSTEM; \ > - goto out; \ > - } \ > - \ > - if (localcanon != NULL && res->canon == NULL) \ > - { \ > - char *canonbuf = __strdup (localcanon); \ > - if (canonbuf == NULL) \ > - { \ > - __resolv_context_put (res_ctx); \ > - result = -EAI_SYSTEM; \ > - goto out; \ > - } \ > - res->canon = canonbuf; \ > - } \ > - } \ > - } > +static int > +gethosts (nss_gethostbyname3_r fct, int family, const char *name, > + const struct addrinfo *req, struct scratch_buffer *tmpbuf, > + struct gaih_result *res, enum nss_status *statusp, int *no_datap) > +{ > + struct hostent th; > + char *localcanon = NULL; > + enum nss_status status; > + > + *no_datap = 0; > + while (1) > + { > + *statusp = status = DL_CALL_FCT (fct, (name, family, &th, > + tmpbuf->data, tmpbuf->length, > + &errno, &h_errno, NULL, > + &localcanon)); > + if (status != NSS_STATUS_TRYAGAIN || h_errno != NETDB_INTERNAL > + || errno != ERANGE) > + break; > + if (!scratch_buffer_grow (tmpbuf)) > + return -EAI_MEMORY; > + } > + if (status == NSS_STATUS_NOTFOUND > + || status == NSS_STATUS_TRYAGAIN || status == NSS_STATUS_UNAVAIL) > + { > + if (h_errno == NETDB_INTERNAL) > + return -EAI_SYSTEM; > + if (h_errno == TRY_AGAIN) > + *no_datap = EAI_AGAIN; > + else > + *no_datap = h_errno == NO_DATA; > + } > + else if (status == NSS_STATUS_SUCCESS) > + { > + if (!convert_hostent_to_gaih_addrtuple (req, family, &th, res)) > + return -EAI_SYSTEM; > + > + if (localcanon != NULL && res->canon == NULL) > + { > + char *canonbuf = __strdup (localcanon); > + if (canonbuf == NULL) > + return -EAI_SYSTEM; > + res->canon = canonbuf; > + } > + } > > + return 0; > +} > > /* This function is called if a canonical name is requested, but if > the service function did not provide it. It tries to obtain the > @@ -741,7 +732,12 @@ get_nss_addresses (const char *name, const struct addrinfo *req, > if (req->ai_family == AF_INET6 > || req->ai_family == AF_UNSPEC) > { > - gethosts (AF_INET6); > + if ((result = gethosts (fct, AF_INET6, name, req, tmpbuf, > + res, &status, &no_data)) != 0) > + { > + __resolv_context_put (res_ctx); > + goto out; > + } > no_inet6_data = no_data; > inet6_status = status; > } > @@ -753,7 +749,12 @@ get_nss_addresses (const char *name, const struct addrinfo *req, > know we are not going to need them. */ > && ((req->ai_flags & AI_ALL) || !res->got_ipv6))) > { > - gethosts (AF_INET); > + if ((result = gethosts (fct, AF_INET, name, req, tmpbuf, > + res, &status, &no_data)) != 0) > + { > + __resolv_context_put (res_ctx); > + goto out; > + } > > if (req->ai_family == AF_INET) > {