On Mon, Jul 07, 2003 at 12:38:57AM +0900, [EMAIL PROTECTED] wrote:
> 
> 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:
[...]

> +     for (; addr != NULL; addr = addr->ai_next)
> +             if ((pgStatSock = socket(addr->ai_family,
> +                     addr->ai_socktype, addr->ai_protocol)) >= 0)
> +                     break;

This will break.  You should use a pointer to the addr, and go
over the list using that.

freeaddrinfo() needs to have the original addr back.

He seems to have 2 problems:
- On Mac OS X getaddrinfo() returns something it shouldn't.
  A patch like that could fix it.
- On Linux Redhat 6.2 (and 6.0) getaddrinfo() seems to have a
  problem with AI_ADDRCONFIG.  Which is also used in
  StreamServerPort().  So he won't be able to listen to any
  socket there either.

Not being able to use AI_ADDRCONFIG is rather annoying, but I
guess if we just try all the returned addresses until 1 works
will have to do.

Try the attached patch 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:27:20 -0000
@@ -146,6 +146,7 @@
 {
        ACCEPT_TYPE_ARG3        alen;
        struct  addrinfo        *addr, hints;
+       struct  addrinfo        *addrp;
        int                     ret;
 
        /*
@@ -188,15 +189,38 @@
        hints.ai_canonname = NULL;
        hints.ai_next = NULL;
        ret = getaddrinfo2("localhost", NULL, &hints, &addr);
-       if (ret || !addr)
+
+       addrp = addr;
+
+#ifdef HAVE_UNIX_SOCKETS
+       /* Skip AF_UNIX sockets. */
+       if (!ret)
+       {
+               while (addrp && addrp->ai_family == AF_UNIX)
+               {
+                       addrp = addrp->ai_next;
+               }
+       }
+#endif
+
+       if (ret || !addrp)
        {
                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 (; addrp; addrp = addrp->ai_next)
+       {
+               if ((pgStatSock = socket(addrp->ai_family,
+                       addrp->ai_socktype, addrp->ai_protocol)) >= 0)
+               {
+                       break;
+               }
+       }
+
+       if (!addrp)
        {
                elog(LOG, "PGSTAT: socket() failed: %m");
                goto startup_failed;
@@ -206,7 +230,7 @@
         * Bind it to a kernel assigned port on localhost and get the assigned
         * port via getsockname().
         */
-       if (bind(pgStatSock, addr->ai_addr, addr->ai_addrlen) < 0)
+       if (bind(pgStatSock, addrp->ai_addr, addrp->ai_addrlen) < 0)
        {
                elog(LOG, "PGSTAT: bind() failed: %m");
                goto startup_failed;
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:28:01 -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 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to