On Sun, Jul 06, 2003 at 06:30:04PM +0200, Kurt Roeckx wrote:
> Try the attached patch instead.

Oops, that one was a little broken. I change it.

Try the attached one instead.


Kurt

Index: ./src/backend/postmaster/pgstat.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/pgstat.c,v
retrieving revision 1.37
diff -u -r1.37 pgstat.c
--- ./src/backend/postmaster/pgstat.c   12 Jun 2003 07:36:51 -0000      1.37
+++ ./src/backend/postmaster/pgstat.c   6 Jul 2003 16:42:52 -0000
@@ -145,7 +145,7 @@
 pgstat_init(void)
 {
        ACCEPT_TYPE_ARG3        alen;
-       struct  addrinfo        *addr, hints;
+       struct  addrinfo        *addrs, *addr, hints;
        int                     ret;
 
        /*
@@ -187,16 +187,32 @@
        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, &addrs);
+
+       if (ret || !addrs)
        {
                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 = addrs; addr; addr = addr->ai_next)
+       {
+#ifdef HAVE_UNIX_SOCKETS
+               /* Skip AF_UNIX sockets. */
+               while (addr && addr->ai_family == AF_UNIX)
+               {
+                       continue;
+               }
+#endif
+               if ((pgStatSock = socket(addr->ai_family,
+                       addr->ai_socktype, addr->ai_protocol)) >= 0)
+               {
+                       break;
+               }
+       }
+
+       if (!addr || pgStatSock < 0)
        {
                elog(LOG, "PGSTAT: socket() failed: %m");
                goto startup_failed;
@@ -211,8 +227,8 @@
                elog(LOG, "PGSTAT: bind() failed: %m");
                goto startup_failed;
        }
-       freeaddrinfo2(hints.ai_family, addr);
-       addr = NULL;
+       freeaddrinfo2(hints.ai_family, addrs);
+       addrs = NULL;
 
        alen = sizeof(pgStatAddr);
        if (getsockname(pgStatSock, (struct sockaddr *)&pgStatAddr, &alen) < 0)
@@ -257,9 +273,9 @@
        return;
 
 startup_failed:
-       if (addr)
+       if (addrs)
        {
-               freeaddrinfo2(hints.ai_family, addr);
+               freeaddrinfo2(hints.ai_family, addrs);
        }
 
        if (pgStatSock >= 0)
Index: ./src/backend/libpq/pqcomm.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/pqcomm.c,v
retrieving revision 1.157
diff -u -r1.157 pqcomm.c
--- ./src/backend/libpq/pqcomm.c        12 Jun 2003 07:36:51 -0000      1.157
+++ ./src/backend/libpq/pqcomm.c        6 Jul 2003 16:42:58 -0000
@@ -216,7 +216,7 @@
        /* Initialize hint structure */
        MemSet(&hint, 0, sizeof(hint));
        hint.ai_family = family;
-       hint.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
+       hint.ai_flags = AI_PASSIVE;
        hint.ai_socktype = SOCK_STREAM;
 
 #ifdef HAVE_UNIX_SOCKETS
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to