Skip to content

Commit 797129e

Browse files
committed
Remove IS_AF_UNIX macro
The AF_UNIX macro was being used unprotected by HAVE_UNIX_SOCKETS, apparently since 2008. So the redirection through IS_AF_UNIX() is apparently no longer necessary. (More generally, all supported platforms are now HAVE_UNIX_SOCKETS, but even if there were a new platform in the future, it seems plausible that it would define the AF_UNIX symbol even without kernel support.) So remove the IS_AF_UNIX() macro and make the code a bit more consistent. Discussion: https://www.postgresql.org/message-id/flat/f2d26815-9832-e333-d52d-72fbc0ade896%40enterprisedb.com
1 parent a59135a commit 797129e

File tree

5 files changed

+23
-29
lines changed

5 files changed

+23
-29
lines changed

src/backend/libpq/hba.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2138,12 +2138,12 @@ check_hba(hbaPort *port)
21382138
/* Check connection type */
21392139
if (hba->conntype == ctLocal)
21402140
{
2141-
if (!IS_AF_UNIX(port->raddr.addr.ss_family))
2141+
if (port->raddr.addr.ss_family != AF_UNIX)
21422142
continue;
21432143
}
21442144
else
21452145
{
2146-
if (IS_AF_UNIX(port->raddr.addr.ss_family))
2146+
if (port->raddr.addr.ss_family == AF_UNIX)
21472147
continue;
21482148

21492149
/* Check SSL state */

src/backend/libpq/pqcomm.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
409409

410410
for (addr = addrs; addr; addr = addr->ai_next)
411411
{
412-
if (!IS_AF_UNIX(family) && IS_AF_UNIX(addr->ai_family))
412+
if (family != AF_UNIX && addr->ai_family == AF_UNIX)
413413
{
414414
/*
415415
* Only set up a unix domain socket when they really asked for it.
@@ -494,7 +494,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
494494
* unpredictable behavior. With no flags at all, win32 behaves as Unix
495495
* with SO_REUSEADDR.
496496
*/
497-
if (!IS_AF_UNIX(addr->ai_family))
497+
if (addr->ai_family != AF_UNIX)
498498
{
499499
if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
500500
(char *) &one, sizeof(one))) == -1)
@@ -546,7 +546,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
546546
errmsg("could not bind %s address \"%s\": %m",
547547
familyDesc, addrDesc),
548548
saved_errno == EADDRINUSE ?
549-
(IS_AF_UNIX(addr->ai_family) ?
549+
(addr->ai_family == AF_UNIX ?
550550
errhint("Is another postmaster already running on port %d?",
551551
(int) portNumber) :
552552
errhint("Is another postmaster already running on port %d?"
@@ -764,7 +764,7 @@ StreamConnection(pgsocket server_fd, Port *port)
764764
}
765765

766766
/* select NODELAY and KEEPALIVE options if it's a TCP connection */
767-
if (!IS_AF_UNIX(port->laddr.addr.ss_family))
767+
if (port->laddr.addr.ss_family != AF_UNIX)
768768
{
769769
int on;
770770
#ifdef WIN32
@@ -1639,7 +1639,7 @@ int
16391639
pq_getkeepalivesidle(Port *port)
16401640
{
16411641
#if defined(PG_TCP_KEEPALIVE_IDLE) || defined(SIO_KEEPALIVE_VALS)
1642-
if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1642+
if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
16431643
return 0;
16441644

16451645
if (port->keepalives_idle != 0)
@@ -1673,7 +1673,7 @@ pq_getkeepalivesidle(Port *port)
16731673
int
16741674
pq_setkeepalivesidle(int idle, Port *port)
16751675
{
1676-
if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1676+
if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
16771677
return STATUS_OK;
16781678

16791679
/* check SIO_KEEPALIVE_VALS here, not just WIN32, as some toolchains lack it */
@@ -1724,7 +1724,7 @@ int
17241724
pq_getkeepalivesinterval(Port *port)
17251725
{
17261726
#if defined(TCP_KEEPINTVL) || defined(SIO_KEEPALIVE_VALS)
1727-
if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1727+
if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
17281728
return 0;
17291729

17301730
if (port->keepalives_interval != 0)
@@ -1758,7 +1758,7 @@ pq_getkeepalivesinterval(Port *port)
17581758
int
17591759
pq_setkeepalivesinterval(int interval, Port *port)
17601760
{
1761-
if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1761+
if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
17621762
return STATUS_OK;
17631763

17641764
#if defined(TCP_KEEPINTVL) || defined(SIO_KEEPALIVE_VALS)
@@ -1808,7 +1808,7 @@ int
18081808
pq_getkeepalivescount(Port *port)
18091809
{
18101810
#ifdef TCP_KEEPCNT
1811-
if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1811+
if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
18121812
return 0;
18131813

18141814
if (port->keepalives_count != 0)
@@ -1837,7 +1837,7 @@ pq_getkeepalivescount(Port *port)
18371837
int
18381838
pq_setkeepalivescount(int count, Port *port)
18391839
{
1840-
if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1840+
if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
18411841
return STATUS_OK;
18421842

18431843
#ifdef TCP_KEEPCNT
@@ -1883,7 +1883,7 @@ int
18831883
pq_gettcpusertimeout(Port *port)
18841884
{
18851885
#ifdef TCP_USER_TIMEOUT
1886-
if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1886+
if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
18871887
return 0;
18881888

18891889
if (port->tcp_user_timeout != 0)
@@ -1912,7 +1912,7 @@ pq_gettcpusertimeout(Port *port)
19121912
int
19131913
pq_settcpusertimeout(int timeout, Port *port)
19141914
{
1915-
if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
1915+
if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
19161916
return STATUS_OK;
19171917

19181918
#ifdef TCP_USER_TIMEOUT

src/backend/postmaster/postmaster.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done)
20852085

20862086
#ifdef USE_SSL
20872087
/* No SSL when disabled or on Unix sockets */
2088-
if (!LoadedSSL || IS_AF_UNIX(port->laddr.addr.ss_family))
2088+
if (!LoadedSSL || port->laddr.addr.ss_family == AF_UNIX)
20892089
SSLok = 'N';
20902090
else
20912091
SSLok = 'S'; /* Support for SSL */
@@ -2134,7 +2134,7 @@ ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done)
21342134

21352135
#ifdef ENABLE_GSS
21362136
/* No GSSAPI encryption when on Unix socket */
2137-
if (!IS_AF_UNIX(port->laddr.addr.ss_family))
2137+
if (port->laddr.addr.ss_family != AF_UNIX)
21382138
GSSok = 'G';
21392139
#endif
21402140

src/include/common/ip.h

-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
#include "libpq/pqcomm.h" /* pgrminclude ignore */
1919

2020

21-
#ifdef HAVE_UNIX_SOCKETS
22-
#define IS_AF_UNIX(fam) ((fam) == AF_UNIX)
23-
#else
24-
#define IS_AF_UNIX(fam) (0)
25-
#endif
26-
2721
extern int pg_getaddrinfo_all(const char *hostname, const char *servname,
2822
const struct addrinfo *hintp,
2923
struct addrinfo **result);

src/interfaces/libpq/fe-connect.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ static void
16941694
emitHostIdentityInfo(PGconn *conn, const char *host_addr)
16951695
{
16961696
#ifdef HAVE_UNIX_SOCKETS
1697-
if (IS_AF_UNIX(conn->raddr.addr.ss_family))
1697+
if (conn->raddr.addr.ss_family == AF_UNIX)
16981698
{
16991699
char service[NI_MAXHOST];
17001700

@@ -1758,7 +1758,7 @@ connectFailureMessage(PGconn *conn, int errorno)
17581758
SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)));
17591759

17601760
#ifdef HAVE_UNIX_SOCKETS
1761-
if (IS_AF_UNIX(conn->raddr.addr.ss_family))
1761+
if (conn->raddr.addr.ss_family == AF_UNIX)
17621762
appendPQExpBufferStr(&conn->errorMessage,
17631763
libpq_gettext("\tIs the server running locally and accepting connections on that socket?\n"));
17641764
else
@@ -2590,7 +2590,7 @@ PQconnectPoll(PGconn *conn)
25902590
* TCP sockets, nonblock mode, close-on-exec. Try the
25912591
* next address if any of this fails.
25922592
*/
2593-
if (!IS_AF_UNIX(addr_cur->ai_family))
2593+
if (addr_cur->ai_family != AF_UNIX)
25942594
{
25952595
if (!connectNoDelay(conn))
25962596
{
@@ -2619,7 +2619,7 @@ PQconnectPoll(PGconn *conn)
26192619
}
26202620
#endif /* F_SETFD */
26212621

2622-
if (!IS_AF_UNIX(addr_cur->ai_family))
2622+
if (addr_cur->ai_family != AF_UNIX)
26232623
{
26242624
#ifndef WIN32
26252625
int on = 1;
@@ -2821,7 +2821,7 @@ PQconnectPoll(PGconn *conn)
28212821
* Unix-domain socket.
28222822
*/
28232823
if (conn->requirepeer && conn->requirepeer[0] &&
2824-
IS_AF_UNIX(conn->raddr.addr.ss_family))
2824+
conn->raddr.addr.ss_family == AF_UNIX)
28252825
{
28262826
#ifndef WIN32
28272827
char *remote_username;
@@ -2867,7 +2867,7 @@ PQconnectPoll(PGconn *conn)
28672867
#endif /* WIN32 */
28682868
}
28692869

2870-
if (IS_AF_UNIX(conn->raddr.addr.ss_family))
2870+
if (conn->raddr.addr.ss_family == AF_UNIX)
28712871
{
28722872
/* Don't request SSL or GSSAPI over Unix sockets */
28732873
#ifdef USE_SSL
@@ -4528,7 +4528,7 @@ PQcancel(PGcancel *cancel, char *errbuf, int errbufsize)
45284528
* This ensures that this function does not block indefinitely when
45294529
* reasonable keepalive and timeout settings have been provided.
45304530
*/
4531-
if (!IS_AF_UNIX(cancel->raddr.addr.ss_family) &&
4531+
if (cancel->raddr.addr.ss_family != AF_UNIX &&
45324532
cancel->keepalives != 0)
45334533
{
45344534
#ifndef WIN32

0 commit comments

Comments
 (0)