Skip to content

Commit c424d0d

Browse files
committed
Remove redundant code for getnameinfo() replacement
Our getnameinfo() replacement implementation in getaddrinfo.c failed unless NI_NUMERICHOST and NI_NUMERICSERV were given as flags, because it doesn't resolve host names, only numeric IPs. But per standard, when those flags are not given, an implementation can still degrade to not returning host names, so this restriction is unnecessary. When we remove it, we can eliminate some code in postmaster.c that apparently tried to work around that.
1 parent e1e6069 commit c424d0d

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3437,6 +3437,7 @@ static void
34373437
BackendInitialize(Port *port)
34383438
{
34393439
int status;
3440+
int ret;
34403441
char remote_host[NI_MAXHOST];
34413442
char remote_port[NI_MAXSERV];
34423443
char remote_ps_data[NI_MAXHOST];
@@ -3498,21 +3499,13 @@ BackendInitialize(Port *port)
34983499
*/
34993500
remote_host[0] = '\0';
35003501
remote_port[0] = '\0';
3501-
if (pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
3502+
if ((ret = pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
35023503
remote_host, sizeof(remote_host),
35033504
remote_port, sizeof(remote_port),
3504-
(log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV) != 0)
3505-
{
3506-
int ret = pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
3507-
remote_host, sizeof(remote_host),
3508-
remote_port, sizeof(remote_port),
3509-
NI_NUMERICHOST | NI_NUMERICSERV);
3510-
3511-
if (ret != 0)
3512-
ereport(WARNING,
3513-
(errmsg_internal("pg_getnameinfo_all() failed: %s",
3514-
gai_strerror(ret))));
3515-
}
3505+
(log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV)) != 0)
3506+
ereport(WARNING,
3507+
(errmsg_internal("pg_getnameinfo_all() failed: %s",
3508+
gai_strerror(ret))));
35163509
if (remote_port[0] == '\0')
35173510
snprintf(remote_ps_data, sizeof(remote_ps_data), "%s", remote_host);
35183511
else

src/port/getaddrinfo.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,6 @@ getnameinfo(const struct sockaddr * sa, int salen,
373373
if (sa == NULL || (node == NULL && service == NULL))
374374
return EAI_FAIL;
375375

376-
/* We don't support those. */
377-
if ((node && !(flags & NI_NUMERICHOST))
378-
|| (service && !(flags & NI_NUMERICSERV)))
379-
return EAI_FAIL;
380-
381376
#ifdef HAVE_IPV6
382377
if (sa->sa_family == AF_INET6)
383378
return EAI_FAMILY;

0 commit comments

Comments
 (0)