[PATCH] [BZ 24816] Fix nss/tst-nss-files-hosts-long and tst-nss-files-hosts-multi when there is no IPv6 support

Romain GEISSLER romain.geissler@amadeus.com
Tue Aug 10 01:03:38 GMT 2021


Hi,

This is an updated version of a patch I posted some years ago already:
https://sourceware.org/pipermail/libc-alpha/2019-July/105107.html

With glibc 2.34, now tst-nss-files-hosts-multi also needs to be updated
as well, as it seems my docker container I use to build/test glibc lacks
proper ipv6 configuration.

I tested this on x86-64.

Cheers,
Romain

>From 04f5a832acd7417190d272c10db0c47e55fc3a16 Mon Sep 17 00:00:00 2001
From: Romain Geissler <romain.geissler@amadeus.com>
Date: Wed, 17 Jul 2019 12:29:21 +0000
Subject: [PATCH] [BZ 24816] Fix nss/tst-nss-files-hosts-long and
 tst-nss-files-hosts-multi when there is no IPv6 support.

---
 nss/tst-nss-files-hosts-long.c  | 47 +++++++++++++++++++++++++++------
 nss/tst-nss-files-hosts-multi.c | 34 ++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 8 deletions(-)

diff --git a/nss/tst-nss-files-hosts-long.c b/nss/tst-nss-files-hosts-long.c
index 00f8bea409e..52f21dc1faf 100644
--- a/nss/tst-nss-files-hosts-long.c
+++ b/nss/tst-nss-files-hosts-long.c
@@ -22,6 +22,31 @@
 #include <stdlib.h>
 #include <nss.h>
 #include <support/check.h>
+#include <ifaddrs.h>
+
+static int
+supports_inet_family(int family)
+{
+  struct ifaddrs *ifaddr, *ifa;
+  int ret = 0;
+
+  if (getifaddrs(&ifaddr) == -1)
+    FAIL_EXIT1("getifaddrs failed");
+
+  for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+    if (ifa->ifa_addr == NULL)
+      continue;
+
+    if (ifa->ifa_addr->sa_family == family) {
+      ret = 1;
+      break;
+    }
+  }
+
+  freeifaddrs(ifaddr);
+
+  return ret;
+}
 
 static int
 do_test (void)
@@ -30,14 +55,20 @@ do_test (void)
 
   /* Run getent to fetch the IPv4 address for host test4.
      This forces /etc/hosts to be parsed.  */
-  ret = system("getent ahostsv4 test4");
-  if (ret != 0)
-    FAIL_EXIT1("ahostsv4 failed");
-
-  /* Likewise for IPv6.  */
-  ret = system("getent ahostsv6 test6");
-  if (ret != 0)
-    FAIL_EXIT1("ahostsv6 failed");
+  if (supports_inet_family(AF_INET))
+  {
+    ret = system("getent ahostsv4 test4");
+    if (ret != 0)
+      FAIL_EXIT1("ahostsv4 failed");
+  }
+
+    /* Likewise for IPv6.  */
+  if (supports_inet_family(AF_INET6))
+  {
+    ret = system("getent ahostsv6 test6");
+    if (ret != 0)
+      FAIL_EXIT1("ahostsv6 failed");
+  }
 
   exit (0);
 }
diff --git a/nss/tst-nss-files-hosts-multi.c b/nss/tst-nss-files-hosts-multi.c
index 87986d95342..8ce6a8c2cec 100644
--- a/nss/tst-nss-files-hosts-multi.c
+++ b/nss/tst-nss-files-hosts-multi.c
@@ -19,6 +19,7 @@
 #include <dlfcn.h>
 #include <errno.h>
 #include <gnu/lib-names.h>
+#include <ifaddrs.h>
 #include <netdb.h>
 #include <nss.h>
 #include <stdbool.h>
@@ -37,6 +38,30 @@
 
 struct support_chroot *chroot_env;
 
+static int
+supports_inet_family(int family)
+{
+  struct ifaddrs *ifaddr, *ifa;
+  int ret = 0;
+
+  if (getifaddrs(&ifaddr) == -1)
+    FAIL_EXIT1("getifaddrs failed");
+
+  for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+    if (ifa->ifa_addr == NULL)
+      continue;
+
+    if (ifa->ifa_addr->sa_family == family) {
+      ret = 1;
+      break;
+    }
+  }
+
+  freeifaddrs(ifaddr);
+
+  return ret;
+}
+
 static void
 prepare (int argc, char **argv)
 {
@@ -204,6 +229,15 @@ run_gbhn_gai (struct test_params *params)
   if (test_verbose > 0)
     printf ("info: %s\n", ctx);
 
+  if (!supports_inet_family(params->family))
+  {
+    printf("Test %s is not supported, skipping this inet family", ctx);
+    free (ctx);
+
+    return;
+  }
+
+
   /* Check gethostbyname, gethostbyname2.  */
   if (params->family == AF_INET)
     {
-- 
2.25.1


More information about the Libc-alpha mailing list