This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2.1][BZ #15339] Avoid returning EAI_SYSTEM when there's a network error


On Fri, May 17, 2013 at 03:26:04AM +0400, Dmitry V. Levin wrote:
> Yes, it works, thanks.

Thanks for testing.

> BTW, Pádraig Brady supposed 
> (in http://lists.gnu.org/archive/html/bug-gnulib/2013-04/msg00047.html)
> that "there are glibc units tests that should be updated",
> and I see no reason why they shouldn't.  How about this one:
> 
> diff --git a/posix/Makefile b/posix/Makefile
> index 8265e76..54c6354 100644
> --- a/posix/Makefile
> +++ b/posix/Makefile
> @@ -86,7 +86,7 @@ tests		:= tstgetopt testfnm runtests runptests	     \
>  		   tst-getaddrinfo3 tst-fnmatch2 tst-cpucount tst-cpuset \
>  		   bug-getopt1 bug-getopt2 bug-getopt3 bug-getopt4 \
>  		   bug-getopt5 tst-getopt_long1 bug-regex34 bug-regex35 \
> -		   tst-pathconf
> +		   tst-pathconf tst-getaddrinfo4
>  xtests		:= bug-ga2
>  ifeq (yes,$(build-shared))
>  test-srcs	:= globtest
> diff --git a/posix/tst-getaddrinfo4.c b/posix/tst-getaddrinfo4.c
> new file mode 100644
> index 0000000..6d67fe1
> --- /dev/null
> +++ b/posix/tst-getaddrinfo4.c
> @@ -0,0 +1,48 @@
> +/* Test for [BZ #15339]. */

Please add the copyright header.  This test is not specific to 15339
btw, since 15339 needs some system failure to trigger an EAI_SYSTEM
instead of an EAI_NONAME.  This is definitely a good start for a
generic test.  Maybe we could add an unshare() to simulate the absence
of network as an incremental patch.  If the unshare() fails, we simply
skip that part of the test.

> +#include <stdio.h>
> +#include <string.h>
> +#include <netdb.h>
> +
> +static int
> +try (const char *service, int family, int flags)
> +{
> +  struct addrinfo hints, *h, *ai;
> +  int res;
> +
> +  memset(&hints, 0, sizeof hints);
> +  hints.ai_family = family;
> +  hints.ai_flags = flags;
> +
> +  h = (family || flags) ? &hints : NULL;
> +  res = getaddrinfo ("example.net", service, h, &ai);

You could expand this to include tests for non-existing domains,
invalid domains, etc. but you could do those too as increments on this
test if you wish.

> +  switch (res)
> +    {
> +    case 0:
> +    case EAI_AGAIN:
> +    case EAI_NONAME:
> +      printf ("SUCCESS getaddrinfo(service=%s, family=%d, flags=%d): %s: %m\n",
> +              service ?: "NULL", family, flags, gai_strerror (res));
> +      return 0;
> +    }
> +  printf ("FAIL getaddrinfo(service=%s, family=%d, flags=%d): %s: %m\n",
> +          service ?: "NULL", family, flags, gai_strerror (res));
> +  return 1;
> +}
> +
> +static int
> +do_test (void)
> +{
> +  int err = 0;
> +  err |= try(NULL, 0, 0);
> +  err |= try(NULL, AF_UNSPEC, AI_ADDRCONFIG);
> +  err |= try(NULL, AF_INET, 0);
> +  err |= try(NULL, AF_INET6, 0);
> +  err |= try("http", 0, 0);
> +  err |= try("http", AF_UNSPEC, AI_ADDRCONFIG);
> +  err |= try("http", AF_INET, 0);
> +  err |= try("http", AF_INET6, 0);
> +  return err;
> +}
> +
> +#define TEST_FUNCTION do_test ()
> +#include "../test-skeleton.c"

Siddhesh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]