This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2.1][BZ #15339] Avoid returning EAI_SYSTEM when there's a network error
- From: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Fri, 17 May 2013 10:57:35 +0530
- Subject: Re: [PATCH v2.1][BZ #15339] Avoid returning EAI_SYSTEM when there's a network error
- References: <20130408174239 dot GA26714 at altlinux dot org> <20130409113848 dot GL15689 at spoyarek dot pnq dot redhat dot com> <20130415120657 dot GG14422 at spoyarek dot pnq dot redhat dot com> <20130422050226 dot GD1412 at spoyarek dot pnq dot redhat dot com> <20130430054726 dot GN1330 at spoyarek dot pnq dot redhat dot com> <20130507102602 dot GE5741 at spoyarek dot pnq dot redhat dot com> <20130510061441 dot GK19683 at spoyarek dot pnq dot redhat dot com> <20130513074609 dot GF25336 at spoyarek dot pnq dot redhat dot com> <20130516033932 dot GA28292 at spoyarek dot pnq dot redhat dot com> <20130516232604 dot GA3090 at altlinux dot org>
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