From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eastern.birch.relay.mailchannels.net (eastern.birch.relay.mailchannels.net [23.83.209.55]) by sourceware.org (Postfix) with ESMTPS id 12BE6385700B for ; Fri, 15 Sep 2023 23:48:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12BE6385700B Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=sourceware.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id C8EF23612EC; Fri, 15 Sep 2023 23:48:09 +0000 (UTC) Received: from pdx1-sub0-mail-a222.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 6BC13361EEE; Fri, 15 Sep 2023 23:48:09 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1694821689; a=rsa-sha256; cv=none; b=qhXxxF+MFUgUHuCnk6illNIEOQgwDpzIkPXt+hx9pHIY7k2X+FDCxnbXXrjfNzHWFIij/g 4Irvj7rA6OAmMWA5Lmuoe00UaPrd/hSME3yQHXO0JHmf4oP4M5sOxkX1Sk0kmJ4iPXDWlS 5ZJGCJgfzgCJ0eTPSxkJ7kD1gIkZoWU4i5xBe/xgs9XpkCg0gP31RSv3QCYXmzkAMNCHz7 HGrTFPOQPiqwkuD22TTiMWZLi/DNhCq+ZaFre+pGplrexRcA1j4mU84s1S+UUGq+Ubz6b6 w6Ac43skZvcf2HLnzmBWVPVLWrzq9V2viK9+bJU2o7K5hCPrh/uGDbVwOxKsxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1694821689; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qiIrfTHuSbFdpx6B5hSLNfhcqQIClbSlPS3Hjo/xBpM=; b=pawnXnmXbiDJ5Lo4Ye8gFuOTEWQI424sLQF3fUhhHkSOae23obNBuiyCTK7u5qh1oweJzJ PAWT8THmlzSGfzeDGvPYHNleK3bQKnC53nflvnX0AIj3MWU+xBF2bg0Aiv0/pPDz3HiPfZ pF11QrVJz7hHTGWSnFsW0JinMqrpXX3vFZC7wMTewBr1EWxzbu56lnqA36vLnMrsPrj+Bj b75JvRu+KNJoCvsm7g2rvD3nccZebdD/6tlRINCA2wt/MOfk99KKqlyj4aqJhJRisJ1P1p NbVIXOub1r6cR5bfjGyDUs5L5Wz7xL/xmgOjaDt9H0PsSSx0wgDLvsr2ELjvCg== ARC-Authentication-Results: i=1; rspamd-7c449d4847-6m96r; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MC-Copy: stored-urls X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Arithmetic-Inform: 6d3f081e472b2ed8_1694821689660_4087751669 X-MC-Loop-Signature: 1694821689660:3940318163 X-MC-Ingress-Time: 1694821689659 Received: from pdx1-sub0-mail-a222.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.124.191.124 (trex/6.9.1); Fri, 15 Sep 2023 23:48:09 +0000 Received: from fedora.redhat.com (bras-vprn-toroon4834w-lp130-02-142-113-138-41.dsl.bell.ca [142.113.138.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a222.dreamhost.com (Postfix) with ESMTPSA id 4RnW8n07v0z24; Fri, 15 Sep 2023 16:48:08 -0700 (PDT) From: Siddhesh Poyarekar To: libc-stable@sourceware.org Cc: DJ Delorie Subject: [pushed 2.35 09/13] gaih_inet: make gethosts into a function Date: Fri, 15 Sep 2023 19:47:51 -0400 Message-ID: <20230915234755.1148216-10-siddhesh@sourceware.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230915234755.1148216-1-siddhesh@sourceware.org> References: <20230915234755.1148216-1-siddhesh@sourceware.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1172.0 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_SOFTFAIL,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The macro is quite a pain to debug, so make gethosts into a function to make it easier to maintain. Signed-off-by: Siddhesh Poyarekar Reviewed-by: DJ Delorie (cherry picked from commit cfa3bd48cb19a70e4367a9978dbba09d9df27a72) --- sysdeps/posix/getaddrinfo.c | 117 ++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index f70ce2c76b..bc385dd322 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) { -- 2.41.0