test-strerror: make debugging EAI_SYSTEM easier
authorEric Blake <ebb9@byu.net>
Fri, 27 Mar 2009 14:16:39 +0000 (08:16 -0600)
committerEric Blake <ebb9@byu.net>
Fri, 27 Mar 2009 19:03:06 +0000 (13:03 -0600)
* modules/getaddrinfo-tests (Depends-on): Add strerror.
* test-getaddrinfo.c (simple) [ENABLE_DEBUGGING]: Report errno if
failure was EAI_SYSTEM.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
modules/getaddrinfo-tests
tests/test-getaddrinfo.c

index 47dba3d..ccc0e4e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-03-27  Eric Blake  <ebb9@byu.net>
+
+       test-strerror: make debugging EAI_SYSTEM easier
+       * modules/getaddrinfo-tests (Depends-on): Add strerror.
+       * test-getaddrinfo.c (simple) [ENABLE_DEBUGGING]: Report errno if
+       failure was EAI_SYSTEM.
+
 2009-03-25  Bruno Haible  <bruno@clisp.org>
 
        Fix a problem with --enable-relocatable on Solaris 7.
index 5f80523..a21fe6f 100644 (file)
@@ -3,6 +3,7 @@ tests/test-getaddrinfo.c
 
 Depends-on:
 inet_ntop
+strerror
 
 configure.ac:
 
index 5e33bb2..4816920 100644 (file)
@@ -19,7 +19,9 @@
 
 #include <config.h>
 #include <netdb.h>
+
 #include <arpa/inet.h>
+#include <errno.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <string.h>
@@ -49,6 +51,7 @@ int simple (char *host, char *service)
   struct addrinfo hints;
   struct addrinfo *ai0, *ai;
   int res;
+  int err;
 
   /* Once we skipped the test, do not try anything else */
   if (skip)
@@ -64,6 +67,7 @@ int simple (char *host, char *service)
   hints.ai_socktype = SOCK_STREAM;
 
   res = getaddrinfo (host, service, 0, &ai0);
+  err = errno;
 
   dbgprintf ("res %d: %s\n", res, gai_strerror (res));
 
@@ -90,6 +94,9 @@ int simple (char *host, char *service)
         merely because of this.  */
       if (res == EAI_NODATA)
        return 0;
+      /* Provide details if errno was set.  */
+      if (res == EAI_SYSTEM)
+         dbgprintf ("system error: %s\n", strerror (err));
 
       return 1;
     }