提交 1f56dffa 编写于 作者: H Heikki Linnakangas

Remove ancient Mac OS X name resolution hacks.

These were added back in 2009 to work around DNS issues on Mac OS X. The
comment there says it shouldn't really be needed, and should be removed
once we gain confidence that it's not needed. I'm feeling confident now;
there are no hacks like this in the upstream, and I don't recall any
reports of issues like this.
上级 db3cbda7
......@@ -78,112 +78,6 @@ pg_getaddrinfo_all(const char *hostname, const char *servname,
rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
servname, hintp, result);
#if defined(__darwin__)
/*
* Attempt to work around some issues on OSX.
*
* There are times when a process can be in a state where it can no longer call for name resolution services.
* This can happen if the processes was forked into the background, and then the interactive session (or ssh session)
* was logged off. This is because the Mach kernel garbage collects the security context for the session.
*
* The real fix is to make sure we always start the postmasters with launchctl, so they get started in the
* right security context. pg_ctl has been updated to do this, which should solve the problem.
*
* But, there is always a chance I missed something in how that is supposed to work.
* It really makes for strange errors if "localhost" can't be resolved to an IP address, and
* if we can resolve "localhost" plus our own machine name, that's good enough for the
* GPDB single-node-edition to run.
*
*
* So to make life easier, let's do our own resolution if the hostname is our own machine's name,
* or if the hostname is "localhost", and we got an error from getaddrinfo() trying to resolve them the
* "normal" way. This code really shouldn't ever get run, so in the future, when we have confidence
* it isn't needed any more, we can take this hack out.
*
*
*/
if (hostname != NULL && (rc == EAI_AGAIN || rc == EAI_NONAME))
{
struct addrinfo *ai;
struct sockaddr_in *psin;
char myhostname[255];
myhostname[0] = '\0';
if (gethostname(myhostname, sizeof(myhostname)) == 0)
{
/*
* If we got a valid hostname, and the name we are looking up is our own hostname,
* we know we are really localhost, and can give back the loopback address.
*
* "localhost" should have resolved by getaddrinfo, but if not, it too is a safe
* host name to convert to the loopback address.
*/
if (((strlen(myhostname) > 0) && (strncmp(myhostname,hostname,255) == 0)) ||
(strcmp("localhost",hostname) == 0))
{
/*
* This is a little dangerous... If we later call freeaddrinfo(), there is no guarantee that
* the memory getaddrinfo allocates was done this way, so freeaddrinfo might try some other
* way to release the memory beside the two free() calls.
* But it probably does, and we are only worried about one OS here: OSX.
* So testing should show up any issue.
*/
ai = malloc(sizeof(*ai));
if (!ai)
return EAI_MEMORY;
psin = malloc(sizeof(*psin));
if (!psin)
{
free(ai);
return EAI_MEMORY;
}
memset(psin, 0, sizeof(struct sockaddr_in));
#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
psin->sin_len = sizeof(struct sockaddr_in);
#endif
psin->sin_family = AF_INET;
/* This only fills in sin_port if servname was numeric. If it was a name from /etc/services, it returns 0 */
if (servname)
psin->sin_port = htons((unsigned short) atoi(servname));
psin->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
ai->ai_flags = 0;
ai->ai_family = AF_INET;
ai->ai_socktype = SOCK_STREAM;
ai->ai_protocol = 0;
ai->ai_addrlen = sizeof(*psin);
ai->ai_addr = (struct sockaddr *) psin;
ai->ai_canonname = NULL;
ai->ai_next = NULL;
*result = ai;
rc = 0;
}
}
}
#endif
/*
* If we get EAI_AGAIN, the error might be temporary. Retry it to see.
* Note: Mac OSX Leopard seems to give this error for NXDOMAIN errors, which aren't
* really temporary, but retrying doesn't cause any real issue.
*/
if (rc == EAI_AGAIN)
{
#ifndef FRONTEND
pg_usleep(1000);
#endif
rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
servname, hintp, result);
}
return rc;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册