Skip to content

Commit f558088

Browse files
committed
Remove HAVE_UNIX_SOCKETS.
Since HAVE_UNIX_SOCKETS is now defined unconditionally, remove the macro and drop a small amount of dead code. The last known systems not to have them (as far as I know at least) were QNX, which we de-supported years ago, and Windows, which now has them. If a new OS ever shows up with the POSIX sockets API but without working AF_UNIX, it'll presumably still be able to compile the code, and fail at runtime with an unsupported address family error. We might want to consider adding a HINT that you should turn off the option to use it if your network stack doesn't support it at that point, but it doesn't seem worth making the relevant code conditional at compile time. Also adjust a couple of places in the docs and comments that referred to builds without Unix-domain sockets, since there aren't any. Windows still gets a special mention in those places, though, because we don't try to use them by default there yet. Reviewed-by: Tom Lane <[email protected]> Reviewed-by: Andres Freund <[email protected]> Reviewed-by: Peter Eisentraut <[email protected]> Discussion: https://postgr.es/m/CA%2BhUKG%2BL_3brvh%3D8e0BW_VfX9h7MtwgN%3DnFHP5o7X2oZucY9dg%40mail.gmail.com
1 parent e07ebd4 commit f558088

File tree

13 files changed

+12
-130
lines changed

13 files changed

+12
-130
lines changed

doc/src/sgml/libpq.sgml

+4-5
Original file line numberDiff line numberDiff line change
@@ -1070,9 +1070,8 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
10701070
specified, or is empty, is to connect to a Unix-domain
10711071
socket<indexterm><primary>Unix domain socket</primary></indexterm> in
10721072
<filename>/tmp</filename> (or whatever socket directory was specified
1073-
when <productname>PostgreSQL</productname> was built). On Windows and
1074-
on machines without Unix-domain sockets, the default is to connect to
1075-
<literal>localhost</literal>.
1073+
when <productname>PostgreSQL</productname> was built). On Windows,
1074+
the default is to connect to <literal>localhost</literal>.
10761075
</para>
10771076
<para>
10781077
A comma-separated list of host names is also accepted, in which case
@@ -1152,8 +1151,8 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
11521151
<para>
11531152
Without either a host name or host address,
11541153
<application>libpq</application> will connect using a local
1155-
Unix-domain socket; or on Windows and on machines without Unix-domain
1156-
sockets, it will attempt to connect to <literal>localhost</literal>.
1154+
Unix-domain socket; or on Windows, it will attempt to connect to
1155+
<literal>localhost</literal>.
11571156
</para>
11581157
</listitem>
11591158
</varlistentry>

doc/src/sgml/ref/psql-ref.sgml

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ EOF
656656
of these options are required; there are useful defaults. If you omit the host
657657
name, <application>psql</application> will connect via a Unix-domain socket
658658
to a server on the local host, or via TCP/IP to <literal>localhost</literal> on
659-
machines that don't have Unix-domain sockets. The default port number is
659+
Windows. The default port number is
660660
determined at compile time.
661661
Since the database server uses the same default, you will not have
662662
to specify the port in most cases. The default user name is your

src/backend/libpq/hba.c

-10
Original file line numberDiff line numberDiff line change
@@ -973,17 +973,7 @@ parse_hba_line(TokenizedAuthLine *tok_line, int elevel)
973973
token = linitial(tokens);
974974
if (strcmp(token->string, "local") == 0)
975975
{
976-
#ifdef HAVE_UNIX_SOCKETS
977976
parsedline->conntype = ctLocal;
978-
#else
979-
ereport(elevel,
980-
(errcode(ERRCODE_CONFIG_FILE_ERROR),
981-
errmsg("local connections are not supported by this build"),
982-
errcontext("line %d of configuration file \"%s\"",
983-
line_num, HbaFileName)));
984-
*err_msg = "local connections are not supported by this build";
985-
return NULL;
986-
#endif
987977
}
988978
else if (strcmp(token->string, "host") == 0 ||
989979
strcmp(token->string, "hostssl") == 0 ||

src/backend/libpq/pqcomm.c

-18
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,8 @@ static void socket_putmessage_noblock(char msgtype, const char *s, size_t len);
149149
static int internal_putbytes(const char *s, size_t len);
150150
static int internal_flush(void);
151151

152-
#ifdef HAVE_UNIX_SOCKETS
153152
static int Lock_AF_UNIX(const char *unixSocketDir, const char *unixSocketPath);
154153
static int Setup_AF_UNIX(const char *sock_path);
155-
#endif /* HAVE_UNIX_SOCKETS */
156154

157155
static const PQcommMethods PqCommSocketMethods = {
158156
socket_comm_reset,
@@ -334,10 +332,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
334332
struct addrinfo hint;
335333
int listen_index = 0;
336334
int added = 0;
337-
338-
#ifdef HAVE_UNIX_SOCKETS
339335
char unixSocketPath[MAXPGPATH];
340-
#endif
341336
#if !defined(WIN32) || defined(IPV6_V6ONLY)
342337
int one = 1;
343338
#endif
@@ -348,7 +343,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
348343
hint.ai_flags = AI_PASSIVE;
349344
hint.ai_socktype = SOCK_STREAM;
350345

351-
#ifdef HAVE_UNIX_SOCKETS
352346
if (family == AF_UNIX)
353347
{
354348
/*
@@ -369,7 +363,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
369363
service = unixSocketPath;
370364
}
371365
else
372-
#endif /* HAVE_UNIX_SOCKETS */
373366
{
374367
snprintf(portNumberStr, sizeof(portNumberStr), "%d", portNumber);
375368
service = portNumberStr;
@@ -427,11 +420,9 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
427420
familyDesc = _("IPv6");
428421
break;
429422
#endif
430-
#ifdef HAVE_UNIX_SOCKETS
431423
case AF_UNIX:
432424
familyDesc = _("Unix");
433425
break;
434-
#endif
435426
default:
436427
snprintf(familyDescBuf, sizeof(familyDescBuf),
437428
_("unrecognized address family %d"),
@@ -441,11 +432,9 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
441432
}
442433

443434
/* set up text form of address for log messages */
444-
#ifdef HAVE_UNIX_SOCKETS
445435
if (addr->ai_family == AF_UNIX)
446436
addrDesc = unixSocketPath;
447437
else
448-
#endif
449438
{
450439
pg_getnameinfo_all((const struct sockaddr_storage *) addr->ai_addr,
451440
addr->ai_addrlen,
@@ -540,7 +529,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
540529
continue;
541530
}
542531

543-
#ifdef HAVE_UNIX_SOCKETS
544532
if (addr->ai_family == AF_UNIX)
545533
{
546534
if (Setup_AF_UNIX(service) != STATUS_OK)
@@ -549,7 +537,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
549537
break;
550538
}
551539
}
552-
#endif
553540

554541
/*
555542
* Select appropriate accept-queue length limit. PG_SOMAXCONN is only
@@ -572,13 +559,11 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
572559
continue;
573560
}
574561

575-
#ifdef HAVE_UNIX_SOCKETS
576562
if (addr->ai_family == AF_UNIX)
577563
ereport(LOG,
578564
(errmsg("listening on Unix socket \"%s\"",
579565
addrDesc)));
580566
else
581-
#endif
582567
ereport(LOG,
583568
/* translator: first %s is IPv4 or IPv6 */
584569
(errmsg("listening on %s address \"%s\", port %d",
@@ -597,8 +582,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
597582
}
598583

599584

600-
#ifdef HAVE_UNIX_SOCKETS
601-
602585
/*
603586
* Lock_AF_UNIX -- configure unix socket file path
604587
*/
@@ -699,7 +682,6 @@ Setup_AF_UNIX(const char *sock_path)
699682
}
700683
return STATUS_OK;
701684
}
702-
#endif /* HAVE_UNIX_SOCKETS */
703685

704686

705687
/*

src/backend/postmaster/postmaster.c

-2
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,6 @@ PostmasterMain(int argc, char *argv[])
12971297
}
12981298
#endif
12991299

1300-
#ifdef HAVE_UNIX_SOCKETS
13011300
if (Unix_socket_directories)
13021301
{
13031302
char *rawstring;
@@ -1347,7 +1346,6 @@ PostmasterMain(int argc, char *argv[])
13471346
list_free_deep(elemlist);
13481347
pfree(rawstring);
13491348
}
1350-
#endif
13511349

13521350
/*
13531351
* check that we have some socket to listen on

src/backend/utils/misc/guc.c

-4
Original file line numberDiff line numberDiff line change
@@ -4452,11 +4452,7 @@ static struct config_string ConfigureNamesString[] =
44524452
GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
44534453
},
44544454
&Unix_socket_directories,
4455-
#ifdef HAVE_UNIX_SOCKETS
44564455
DEFAULT_PGSOCKET_DIR,
4457-
#else
4458-
"",
4459-
#endif
44604456
NULL, NULL, NULL
44614457
},
44624458

src/bin/initdb/initdb.c

-41
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,6 @@ static char backend_exec[MAXPGPATH];
242242
static char **replace_token(char **lines,
243243
const char *token, const char *replacement);
244244

245-
#ifndef HAVE_UNIX_SOCKETS
246-
static char **filter_lines_with_token(char **lines, const char *token);
247-
#endif
248245
static char **readfile(const char *path);
249246
static void writefile(char *path, char **lines);
250247
static FILE *popen_check(const char *command, const char *mode);
@@ -418,36 +415,6 @@ replace_token(char **lines, const char *token, const char *replacement)
418415
return result;
419416
}
420417

421-
/*
422-
* make a copy of lines without any that contain the token
423-
*
424-
* a sort of poor man's grep -v
425-
*/
426-
#ifndef HAVE_UNIX_SOCKETS
427-
static char **
428-
filter_lines_with_token(char **lines, const char *token)
429-
{
430-
int numlines = 1;
431-
int i,
432-
src,
433-
dst;
434-
char **result;
435-
436-
for (i = 0; lines[i]; i++)
437-
numlines++;
438-
439-
result = (char **) pg_malloc(numlines * sizeof(char *));
440-
441-
for (src = 0, dst = 0; src < numlines; src++)
442-
{
443-
if (lines[src] == NULL || strstr(lines[src], token) == NULL)
444-
result[dst++] = lines[src];
445-
}
446-
447-
return result;
448-
}
449-
#endif
450-
451418
/*
452419
* get the lines from a text file
453420
*/
@@ -1045,12 +1012,8 @@ setup_config(void)
10451012
n_buffers * (BLCKSZ / 1024));
10461013
conflines = replace_token(conflines, "#shared_buffers = 128MB", repltok);
10471014

1048-
#ifdef HAVE_UNIX_SOCKETS
10491015
snprintf(repltok, sizeof(repltok), "#unix_socket_directories = '%s'",
10501016
DEFAULT_PGSOCKET_DIR);
1051-
#else
1052-
snprintf(repltok, sizeof(repltok), "#unix_socket_directories = ''");
1053-
#endif
10541017
conflines = replace_token(conflines, "#unix_socket_directories = '/tmp'",
10551018
repltok);
10561019

@@ -1210,11 +1173,7 @@ setup_config(void)
12101173

12111174
conflines = readfile(hba_file);
12121175

1213-
#ifndef HAVE_UNIX_SOCKETS
1214-
conflines = filter_lines_with_token(conflines, "@remove-line-for-nolocal@");
1215-
#else
12161176
conflines = replace_token(conflines, "@remove-line-for-nolocal@", "");
1217-
#endif
12181177

12191178
#ifdef HAVE_IPV6
12201179

src/bin/pg_upgrade/option.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ adjust_data_dir(ClusterInfo *cluster)
444444
void
445445
get_sock_dir(ClusterInfo *cluster, bool live_check)
446446
{
447-
#if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32)
447+
#if !defined(WIN32)
448448
if (!live_check)
449449
cluster->sockdir = user_opts.socketdir;
450450
else
@@ -490,7 +490,7 @@ get_sock_dir(ClusterInfo *cluster, bool live_check)
490490
pg_log(PG_WARNING, "user-supplied old port number %hu corrected to %hu",
491491
orig_port, cluster->port);
492492
}
493-
#else /* !HAVE_UNIX_SOCKETS || WIN32 */
493+
#else /* WIN32 */
494494
cluster->sockdir = NULL;
495495
#endif
496496
}

src/bin/pg_upgrade/server.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ start_postmaster(ClusterInfo *cluster, bool report_and_exit_on_error)
212212

213213
socket_string[0] = '\0';
214214

215-
#if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32)
215+
#if !defined(WIN32)
216216
/* prevent TCP/IP connections, restrict socket access */
217217
strcat(socket_string,
218218
" -c listen_addresses='' -c unix_socket_permissions=0700");

src/common/ip.c

-11
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939

4040

41-
#ifdef HAVE_UNIX_SOCKETS
4241
static int getaddrinfo_unix(const char *path,
4342
const struct addrinfo *hintsp,
4443
struct addrinfo **result);
@@ -47,7 +46,6 @@ static int getnameinfo_unix(const struct sockaddr_un *sa, int salen,
4746
char *node, int nodelen,
4847
char *service, int servicelen,
4948
int flags);
50-
#endif
5149

5250

5351
/*
@@ -62,10 +60,8 @@ pg_getaddrinfo_all(const char *hostname, const char *servname,
6260
/* not all versions of getaddrinfo() zero *result on failure */
6361
*result = NULL;
6462

65-
#ifdef HAVE_UNIX_SOCKETS
6663
if (hintp->ai_family == AF_UNIX)
6764
return getaddrinfo_unix(servname, hintp, result);
68-
#endif
6965

7066
/* NULL has special meaning to getaddrinfo(). */
7167
rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
@@ -87,7 +83,6 @@ pg_getaddrinfo_all(const char *hostname, const char *servname,
8783
void
8884
pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
8985
{
90-
#ifdef HAVE_UNIX_SOCKETS
9186
if (hint_ai_family == AF_UNIX)
9287
{
9388
/* struct was built by getaddrinfo_unix (see pg_getaddrinfo_all) */
@@ -101,7 +96,6 @@ pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
10196
}
10297
}
10398
else
104-
#endif /* HAVE_UNIX_SOCKETS */
10599
{
106100
/* struct was built by getaddrinfo() */
107101
if (ai != NULL)
@@ -126,14 +120,12 @@ pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen,
126120
{
127121
int rc;
128122

129-
#ifdef HAVE_UNIX_SOCKETS
130123
if (addr && addr->ss_family == AF_UNIX)
131124
rc = getnameinfo_unix((const struct sockaddr_un *) addr, salen,
132125
node, nodelen,
133126
service, servicelen,
134127
flags);
135128
else
136-
#endif
137129
rc = getnameinfo((const struct sockaddr *) addr, salen,
138130
node, nodelen,
139131
service, servicelen,
@@ -151,8 +143,6 @@ pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen,
151143
}
152144

153145

154-
#if defined(HAVE_UNIX_SOCKETS)
155-
156146
/* -------
157147
* getaddrinfo_unix - get unix socket info using IPv6-compatible API
158148
*
@@ -286,4 +276,3 @@ getnameinfo_unix(const struct sockaddr_un *sa, int salen,
286276

287277
return 0;
288278
}
289-
#endif /* HAVE_UNIX_SOCKETS */

src/include/port.h

-3
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,4 @@ extern bool wait_result_is_any_signal(int exit_status, bool include_command_not_
503503
#define HAVE_SYMLINK 1
504504
#endif
505505

506-
/* Interfaces that we assume that all systems have. */
507-
#define HAVE_UNIX_SOCKETS 1
508-
509506
#endif /* PG_PORT_H */

0 commit comments

Comments
 (0)