Improve reporting errors from getaddrinfo(3)
authorŁukasz Stelmach <l.stelmach@samsung.com>
Tue, 22 Jan 2013 12:15:31 +0000 (13:15 +0100)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Tue, 22 Jan 2013 13:05:54 +0000 (14:05 +0100)
Change-Id: I32b8c5bed14e74e8495ca7fb19d4337810036f4c
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
src/emuld.c

index 4bb60e6b233b1ca81ca5dce086a6232f53f89f5c..b2e6fe9a86d59d9699b95cb30d0c06f47cc50109 100644 (file)
@@ -457,6 +457,7 @@ void udp_init(void)
        char emul_ip[HOST_NAME_MAX+1];
        struct addrinfo *res;
        struct addrinfo hints;
+       int rc;
 
        LOG("start");
 
@@ -472,9 +473,12 @@ void udp_init(void)
        hints.ai_socktype=SOCK_DGRAM;
        hints.ai_protocol=IPPROTO_UDP;
 
-       if (getaddrinfo(emul_ip, STR(SENSORD_PORT), &hints, &res) != 0)
+       if ((rc=getaddrinfo(emul_ip, STR(SENSORD_PORT), &hints, &res)) != 0)
        {
-               LOG("getaddrinfo(sensord): %s", strerror(errno));
+               if (rc == EAI_SYSTEM)
+                       LOG("getaddrinfo(sensord): %s", strerror(errno));
+               else
+                       LOG("getaddrinfo(sensord): %s", gai_strerror(rc));
                assert(0);
        }
 
@@ -485,15 +489,19 @@ void udp_init(void)
        if (res->ai_addrlen > sizeof(si_sensord_other))
        {
                LOG("sockaddr structure too big");
+               /* XXX: if you `return' remember to clean up */
                assert(0);
        }
        memset((char *) &si_sensord_other, 0, sizeof(si_sensord_other));
        memcpy((char *) &si_sensord_other, res->ai_addr, res->ai_addrlen);
        freeaddrinfo(res);
 
-       if (getaddrinfo(emul_ip, STR(GPSD_PORT), &hints, &res) != 0)
+       if ((rc=getaddrinfo(emul_ip, STR(GPSD_PORT), &hints, &res)) != 0)
        {
-               LOG("getaddrinfo(gpsd): %s", strerror(errno));
+               if (rc == EAI_SYSTEM)
+                       LOG("getaddrinfo(gpsd): %s", strerror(errno));
+               else
+                       LOG("getaddrinfo(gpsd): %s", gai_strerror(rc));
                assert(0);
        }