Re: PostgreSQL 7.4devel - LOG: PGSTAT: socket() failed: Invalid argument

From: qhwt(at)myrealbox(dot)com
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PostgreSQL 7.4devel - LOG: PGSTAT: socket() failed: Invalid argument
Date: 2003-07-06 15:55:06
Message-ID: 20030706155506.GA4050@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jul 07, 2003 at 12:38:57AM +0900, qhwt(at)myrealbox(dot)com 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)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Francisco Figueiredo Jr. 2003-07-06 15:56:13 Re: Receiving data in binary format how is it encoded?
Previous Message qhwt 2003-07-06 15:38:57 Re: PostgreSQL 7.4devel - LOG: PGSTAT: socket() failed: Invalid argument