On Mon, Jul 07, 2003 at 12:38:57AM +0900, [EMAIL PROTECTED] wrote:
> Hi,
> 
> On Wed, Jul 02, 2003 at 03:49:19PM +0900, Kenji Sugita wrote:
> > It seems that a value of addr->ai_socktype returned by getaddrinfo in
> > pg_stat.c is not SOCK_DGRAM.
> 
> Please try the following untested patch:

No, please disregard the previous mail and try this one.

When hints.ai_family is PF_UNSPEC, getaddrinfo() returns two entries,
first one being IPv6 one, and the second one is IPv4 one, even if
IPv6 support is not compiled in the kernel(this is true at least on
my FreeBSD box).

--- pgstat.c    Thu Jun 12 16:36:51 2003
+++ pgstat.c    Mon Jul  7 00:49:07 2003
@@ -145,7 +145,7 @@
 pgstat_init(void)
 {
        ACCEPT_TYPE_ARG3        alen;
-       struct  addrinfo        *addr, hints;
+       struct  addrinfo        *addr0, addr, hints;
        int                     ret;
 
        /*
@@ -187,17 +187,19 @@
        hints.ai_addr = NULL;
        hints.ai_canonname = NULL;
        hints.ai_next = NULL;
-       ret = getaddrinfo2("localhost", NULL, &hints, &addr);
-       if (ret || !addr)
+       ret = getaddrinfo2("localhost", NULL, &hints, &addr0);
+       if (ret || !addr0)
        {
                elog(LOG, "PGSTAT: getaddrinfo2() failed: %s",
                        gai_strerror(ret));
                goto startup_failed;
        }
-       
-       if ((pgStatSock = socket(addr->ai_family,
-               addr->ai_socktype, addr->ai_protocol)) < 0)
-       {
+
+       for (addr = addr0; addr != NULL; addr = addr->ai_next)
+               if ((pgStatSock = socket(addr->ai_family,
+                       addr->ai_socktype, addr->ai_protocol)) >= 0)
+                       break;
+       if (pgStatSock < 0) {
                elog(LOG, "PGSTAT: socket() failed: %m");
                goto startup_failed;
        }
@@ -211,8 +213,8 @@
                elog(LOG, "PGSTAT: bind() failed: %m");
                goto startup_failed;
        }
-       freeaddrinfo2(hints.ai_family, addr);
-       addr = NULL;
+       freeaddrinfo2(hints.ai_family, addr0);
+       addr0 = addr = NULL;
 
        alen = sizeof(pgStatAddr);
        if (getsockname(pgStatSock, (struct sockaddr *)&pgStatAddr, &alen) < 0)



---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Reply via email to