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 E9CD63858413 for ; Thu, 17 Mar 2022 21:47:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E9CD63858413 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-380-_rsFb-aXMpiD8GAdTIp-QQ-1; Thu, 17 Mar 2022 17:47:38 -0400 X-MC-Unique: _rsFb-aXMpiD8GAdTIp-QQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 49BCE85A5A8; Thu, 17 Mar 2022 21:47:38 +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 34FD5C53741; Thu, 17 Mar 2022 21:47:38 +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 22HLlbbS1762884; Thu, 17 Mar 2022 17:47:37 -0400 From: DJ Delorie To: Siddhesh Poyarekar Cc: libc-alpha@sourceware.org Subject: Re: [PATCH v3 01/12] Simplify allocations and fix merge and continue actions [BZ #28931] In-Reply-To: <20220317081140.3098156-2-siddhesh@sourceware.org> (message from Siddhesh Poyarekar on Thu, 17 Mar 2022 13:41:29 +0530) Date: Thu, 17 Mar 2022 17:47:37 -0400 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 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, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham 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 21:47:43 -0000 LGTM. I expected multiple test cases (one per nsswitch) but forgot about the hot reloading, so we're testing that too :-) Reviewed-by: DJ Delorie Siddhesh Poyarekar writes: > diff --git a/nss/Makefile b/nss/Makefile > + tst-nss-gai-actions \ Ok. > diff --git a/nss/tst-nss-gai-actions.c b/nss/tst-nss-gai-actions.c > +/* Test continue and merge NSS actions for getaddrinfo. > + Copyright The GNU Toolchain Authors. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include Ok. > +enum > +{ > + ACTION_MERGE = 0, > + ACTION_CONTINUE, > +}; > + > +static const char * > +family_str (int family) > +{ > + switch (family) > + { > + case AF_UNSPEC: > + return "AF_UNSPEC"; > + case AF_INET: > + return "AF_INET"; > + default: > + __builtin_unreachable (); > + } > +} > + > +static const char * > +action_str (int action) > +{ > + switch (action) > + { > + case ACTION_MERGE: > + return "merge"; > + case ACTION_CONTINUE: > + return "continue"; > + default: > + __builtin_unreachable (); > + } > +} Ok. > +static void > +do_one_test (int action, int family, bool canon) > +{ > + struct addrinfo hints = > + { > + .ai_family = family, > + }; > + > + struct addrinfo *ai; > + > + if (canon) > + hints.ai_flags = AI_CANONNAME; > + > + printf ("***** Testing \"files [SUCCESS=%s] files\" for family %s, %s\n", > + action_str (action), family_str (family), > + canon ? "AI_CANONNAME" : ""); Ok. > + int ret = getaddrinfo ("example.org", "80", &hints, &ai); Ok. Do we need an /etc/services? Probably not. > + switch (action) > + { > + case ACTION_MERGE: > + if (ret == 0) > + { > + char *formatted = support_format_addrinfo (ai, ret); > + > + printf ("merge unexpectedly succeeded:\n %s\n", formatted); > + support_record_failure (); > + free (formatted); > + } > + else > + return; Ok. > + case ACTION_CONTINUE: > + { > + char *formatted = support_format_addrinfo (ai, ret); > + > + /* Verify that the result appears exactly once. */ > + const char *expected = "address: STREAM/TCP 192.0.0.1 80\n" > + "address: DGRAM/UDP 192.0.0.1 80\n" > + "address: RAW/IP 192.0.0.1 80\n"; > + > + const char *contains = strstr (formatted, expected); > + const char *contains2 = NULL; > + > + if (contains != NULL) > + contains2 = strstr (contains + strlen (expected), expected); > + > + if (contains == NULL || contains2 != NULL) > + { > + printf ("continue failed:\n%s\n", formatted); > + support_record_failure (); > + } > + > + free (formatted); > + break; Ok. > + } > + default: > + __builtin_unreachable (); > + } > +} Ok. > +static void > +do_one_test_set (int action) > +{ > + char buf[32]; > + > + snprintf (buf, sizeof (buf), "files [SUCCESS=%s] files", > + action_str (action)); > + __nss_configure_lookup ("hosts", buf); > + > + do_one_test (action, AF_UNSPEC, false); > + do_one_test (action, AF_INET, false); > + do_one_test (action, AF_INET, true); > +} > + > +static int > +do_test (void) > +{ > + do_one_test_set (ACTION_CONTINUE); > + do_one_test_set (ACTION_MERGE); > + return 0; > +} > + > +#include Ok. > diff --git a/nss/tst-nss-gai-actions.root/etc/host.conf b/nss/tst-nss-gai-actions.root/etc/host.conf > +multi on Ok. > diff --git a/nss/tst-nss-gai-actions.root/etc/hosts b/nss/tst-nss-gai-actions.root/etc/hosts > +192.0.0.1 example.org > +192.0.0.2 example.org > + . . . > +192.0.1.252 example.org > +192.0.1.253 example.org > +192.0.1.254 example.org Ok. > diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c Unchanged from v2, ok.