[2/2] nss: Fix tst-nss-files-hosts-long on single-stack hosts (bug 24816)

Message ID 468dff5f8914e9db91785b32683ac0af1f4c731b.1663079342.git.fweimer@redhat.com
State Committed
Commit c75d20b5b27b0a60f0678236f51a4d3b0b058c00
Headers
Series Fix nss/tst-nss-files-hosts-long on single-stack hosts (bug 24816) |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Florian Weimer Sept. 13, 2022, 2:35 p.m. UTC
  getent implicitly passes AI_ADDRCONFIG to getaddrinfo by default.
Use --no-addrconfig to suppress that, so that both IPv4 and IPv6
lookups succeed even if the address family is not supported by the
host.
---
 nss/tst-nss-files-hosts-long.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
  

Comments

Carlos O'Donell Sept. 14, 2022, 10:35 p.m. UTC | #1
On Tue, Sep 13, 2022 at 04:35:48PM +0200, Florian Weimer via Libc-alpha wrote:
> getent implicitly passes AI_ADDRCONFIG to getaddrinfo by default.
> Use --no-addrconfig to suppress that, so that both IPv4 and IPv6
> lookups succeed even if the address family is not supported by the
> host.

LGTM.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> ---
>  nss/tst-nss-files-hosts-long.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/nss/tst-nss-files-hosts-long.c b/nss/tst-nss-files-hosts-long.c
> index 3942cf5fca..a7697e3143 100644
> --- a/nss/tst-nss-files-hosts-long.c
> +++ b/nss/tst-nss-files-hosts-long.c
> @@ -28,14 +28,15 @@ do_test (void)
>  {
>    int ret;
>  
> -  /* Run getent to fetch the IPv4 address for host test4.
> -     This forces /etc/hosts to be parsed.  */
> -  ret = system("getent ahostsv4 test4");
> +  /* Run getent to fetch the IPv4 address for host test4.  This forces
> +     /etc/hosts to be parsed.  Use --no-addrconfig to return addresses
> +     even in an IPv6-only environment.  */
> +  ret = system("getent --no-addrconfig ahostsv4 test4");

OK.

>    if (ret != 0)
>      FAIL_EXIT1("ahostsv4 failed");
>  
>    /* Likewise for IPv6.  */
> -  ret = system("getent ahostsv6 test6");
> +  ret = system("getent --no-addrconfig  ahostsv6 test6");

OK.

>    if (ret != 0)
>      FAIL_EXIT1("ahostsv6 failed");
>  
> -- 
> 2.37.2
>
  

Patch

diff --git a/nss/tst-nss-files-hosts-long.c b/nss/tst-nss-files-hosts-long.c
index 3942cf5fca..a7697e3143 100644
--- a/nss/tst-nss-files-hosts-long.c
+++ b/nss/tst-nss-files-hosts-long.c
@@ -28,14 +28,15 @@  do_test (void)
 {
   int ret;
 
-  /* Run getent to fetch the IPv4 address for host test4.
-     This forces /etc/hosts to be parsed.  */
-  ret = system("getent ahostsv4 test4");
+  /* Run getent to fetch the IPv4 address for host test4.  This forces
+     /etc/hosts to be parsed.  Use --no-addrconfig to return addresses
+     even in an IPv6-only environment.  */
+  ret = system("getent --no-addrconfig ahostsv4 test4");
   if (ret != 0)
     FAIL_EXIT1("ahostsv4 failed");
 
   /* Likewise for IPv6.  */
-  ret = system("getent ahostsv6 test6");
+  ret = system("getent --no-addrconfig  ahostsv6 test6");
   if (ret != 0)
     FAIL_EXIT1("ahostsv6 failed");