Remove HAVE_UNIX_SOCKETS.
authorThomas Munro <tmunro@postgresql.org>
Sat, 13 Aug 2022 20:46:53 +0000 (08:46 +1200)
committerThomas Munro <tmunro@postgresql.org>
Sat, 13 Aug 2022 20:46:53 +0000 (08:46 +1200)
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 <tgl@sss.pgh.pa.us>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Discussion: https://postgr.es/m/CA%2BhUKG%2BL_3brvh%3D8e0BW_VfX9h7MtwgN%3DnFHP5o7X2oZucY9dg%40mail.gmail.com

13 files changed:
doc/src/sgml/libpq.sgml
doc/src/sgml/ref/psql-ref.sgml
src/backend/libpq/hba.c
src/backend/libpq/pqcomm.c
src/backend/postmaster/postmaster.c
src/backend/utils/misc/guc.c
src/bin/initdb/initdb.c
src/bin/pg_upgrade/option.c
src/bin/pg_upgrade/server.c
src/common/ip.c
src/include/port.h
src/interfaces/libpq/fe-connect.c
src/test/regress/pg_regress.c

index fab602b37e74aef2e25a7ae3511518cbe7a31799..840ca71f39d7f2ef9763f7592c49c9cee0fb62c9 100644 (file)
@@ -1070,9 +1070,8 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
         specified, or is empty, is to connect to a Unix-domain
         socket<indexterm><primary>Unix domain socket</primary></indexterm> in
         <filename>/tmp</filename> (or whatever socket directory was specified
-        when <productname>PostgreSQL</productname> was built).  On Windows and
-        on machines without Unix-domain sockets, the default is to connect to
-        <literal>localhost</literal>.
+        when <productname>PostgreSQL</productname> was built).  On Windows,
+        the default is to connect to <literal>localhost</literal>.
        </para>
        <para>
         A comma-separated list of host names is also accepted, in which case
@@ -1152,8 +1151,8 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
        <para>
         Without either a host name or host address,
         <application>libpq</application> will connect using a local
-        Unix-domain socket; or on Windows and on machines without Unix-domain
-        sockets, it will attempt to connect to <literal>localhost</literal>.
+        Unix-domain socket; or on Windows, it will attempt to connect to
+        <literal>localhost</literal>.
        </para>
        </listitem>
       </varlistentry>
index 7ba6e4efcb9e3fb3a6a3565337063cd320c7ea22..dd559d62d28bd2439c72849b5ee09ccdab3fe572 100644 (file)
@@ -656,7 +656,7 @@ EOF
     of these options are required; there are useful defaults. If you omit the host
     name, <application>psql</application> will connect via a Unix-domain socket
     to a server on the local host, or via TCP/IP to <literal>localhost</literal> on
-    machines that don't have Unix-domain sockets. The default port number is
+    Windows. The default port number is
     determined at compile time.
     Since the database server uses the same default, you will not have
     to specify the port in most cases. The default user name is your
index deee05c19795ab5e5d209b32db58b15c14b789fb..66f2156cdedb752dc6a98df552ffedaa6cd29883 100644 (file)
@@ -973,17 +973,7 @@ parse_hba_line(TokenizedAuthLine *tok_line, int elevel)
    token = linitial(tokens);
    if (strcmp(token->string, "local") == 0)
    {
-#ifdef HAVE_UNIX_SOCKETS
        parsedline->conntype = ctLocal;
-#else
-       ereport(elevel,
-               (errcode(ERRCODE_CONFIG_FILE_ERROR),
-                errmsg("local connections are not supported by this build"),
-                errcontext("line %d of configuration file \"%s\"",
-                           line_num, HbaFileName)));
-       *err_msg = "local connections are not supported by this build";
-       return NULL;
-#endif
    }
    else if (strcmp(token->string, "host") == 0 ||
             strcmp(token->string, "hostssl") == 0 ||
index 75392a8bb7c61419b7879e5f224447807a9649b7..3ec4328613b95cfae62847db440f8fca4c948cb1 100644 (file)
@@ -149,10 +149,8 @@ static void socket_putmessage_noblock(char msgtype, const char *s, size_t len);
 static int internal_putbytes(const char *s, size_t len);
 static int internal_flush(void);
 
-#ifdef HAVE_UNIX_SOCKETS
 static int Lock_AF_UNIX(const char *unixSocketDir, const char *unixSocketPath);
 static int Setup_AF_UNIX(const char *sock_path);
-#endif                         /* HAVE_UNIX_SOCKETS */
 
 static const PQcommMethods PqCommSocketMethods = {
    socket_comm_reset,
@@ -334,10 +332,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
    struct addrinfo hint;
    int         listen_index = 0;
    int         added = 0;
-
-#ifdef HAVE_UNIX_SOCKETS
    char        unixSocketPath[MAXPGPATH];
-#endif
 #if !defined(WIN32) || defined(IPV6_V6ONLY)
    int         one = 1;
 #endif
@@ -348,7 +343,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
    hint.ai_flags = AI_PASSIVE;
    hint.ai_socktype = SOCK_STREAM;
 
-#ifdef HAVE_UNIX_SOCKETS
    if (family == AF_UNIX)
    {
        /*
@@ -369,7 +363,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
        service = unixSocketPath;
    }
    else
-#endif                         /* HAVE_UNIX_SOCKETS */
    {
        snprintf(portNumberStr, sizeof(portNumberStr), "%d", portNumber);
        service = portNumberStr;
@@ -427,11 +420,9 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
                familyDesc = _("IPv6");
                break;
 #endif
-#ifdef HAVE_UNIX_SOCKETS
            case AF_UNIX:
                familyDesc = _("Unix");
                break;
-#endif
            default:
                snprintf(familyDescBuf, sizeof(familyDescBuf),
                         _("unrecognized address family %d"),
@@ -441,11 +432,9 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
        }
 
        /* set up text form of address for log messages */
-#ifdef HAVE_UNIX_SOCKETS
        if (addr->ai_family == AF_UNIX)
            addrDesc = unixSocketPath;
        else
-#endif
        {
            pg_getnameinfo_all((const struct sockaddr_storage *) addr->ai_addr,
                               addr->ai_addrlen,
@@ -540,7 +529,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
            continue;
        }
 
-#ifdef HAVE_UNIX_SOCKETS
        if (addr->ai_family == AF_UNIX)
        {
            if (Setup_AF_UNIX(service) != STATUS_OK)
@@ -549,7 +537,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
                break;
            }
        }
-#endif
 
        /*
         * Select appropriate accept-queue length limit.  PG_SOMAXCONN is only
@@ -572,13 +559,11 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
            continue;
        }
 
-#ifdef HAVE_UNIX_SOCKETS
        if (addr->ai_family == AF_UNIX)
            ereport(LOG,
                    (errmsg("listening on Unix socket \"%s\"",
                            addrDesc)));
        else
-#endif
            ereport(LOG,
            /* translator: first %s is IPv4 or IPv6 */
                    (errmsg("listening on %s address \"%s\", port %d",
@@ -597,8 +582,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
 }
 
 
-#ifdef HAVE_UNIX_SOCKETS
-
 /*
  * Lock_AF_UNIX -- configure unix socket file path
  */
@@ -699,7 +682,6 @@ Setup_AF_UNIX(const char *sock_path)
    }
    return STATUS_OK;
 }
-#endif                         /* HAVE_UNIX_SOCKETS */
 
 
 /*
index 227bd9891ec208fe054354146aac19d2e88f702b..8a038d1b2aee11a5389626b5d83bd45b6e841860 100644 (file)
@@ -1297,7 +1297,6 @@ PostmasterMain(int argc, char *argv[])
    }
 #endif
 
-#ifdef HAVE_UNIX_SOCKETS
    if (Unix_socket_directories)
    {
        char       *rawstring;
@@ -1347,7 +1346,6 @@ PostmasterMain(int argc, char *argv[])
        list_free_deep(elemlist);
        pfree(rawstring);
    }
-#endif
 
    /*
     * check that we have some socket to listen on
index 5db5df62854737d2ab0382c95ff55ab02f44e9c5..9fbbfb1be5432a0b6f62577608f095ffd2c7ec73 100644 (file)
@@ -4452,11 +4452,7 @@ static struct config_string ConfigureNamesString[] =
            GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
        },
        &Unix_socket_directories,
-#ifdef HAVE_UNIX_SOCKETS
        DEFAULT_PGSOCKET_DIR,
-#else
-       "",
-#endif
        NULL, NULL, NULL
    },
 
index 2c93ffe8114cfa3861a1f8f1ca8045eaf47bedf0..4feb5db3faae7d854c721612579bf8731081396c 100644 (file)
@@ -242,9 +242,6 @@ static char backend_exec[MAXPGPATH];
 static char **replace_token(char **lines,
                            const char *token, const char *replacement);
 
-#ifndef HAVE_UNIX_SOCKETS
-static char **filter_lines_with_token(char **lines, const char *token);
-#endif
 static char **readfile(const char *path);
 static void writefile(char *path, char **lines);
 static FILE *popen_check(const char *command, const char *mode);
@@ -418,36 +415,6 @@ replace_token(char **lines, const char *token, const char *replacement)
    return result;
 }
 
-/*
- * make a copy of lines without any that contain the token
- *
- * a sort of poor man's grep -v
- */
-#ifndef HAVE_UNIX_SOCKETS
-static char **
-filter_lines_with_token(char **lines, const char *token)
-{
-   int         numlines = 1;
-   int         i,
-               src,
-               dst;
-   char      **result;
-
-   for (i = 0; lines[i]; i++)
-       numlines++;
-
-   result = (char **) pg_malloc(numlines * sizeof(char *));
-
-   for (src = 0, dst = 0; src < numlines; src++)
-   {
-       if (lines[src] == NULL || strstr(lines[src], token) == NULL)
-           result[dst++] = lines[src];
-   }
-
-   return result;
-}
-#endif
-
 /*
  * get the lines from a text file
  */
@@ -1045,12 +1012,8 @@ setup_config(void)
                 n_buffers * (BLCKSZ / 1024));
    conflines = replace_token(conflines, "#shared_buffers = 128MB", repltok);
 
-#ifdef HAVE_UNIX_SOCKETS
    snprintf(repltok, sizeof(repltok), "#unix_socket_directories = '%s'",
             DEFAULT_PGSOCKET_DIR);
-#else
-   snprintf(repltok, sizeof(repltok), "#unix_socket_directories = ''");
-#endif
    conflines = replace_token(conflines, "#unix_socket_directories = '/tmp'",
                              repltok);
 
@@ -1210,11 +1173,7 @@ setup_config(void)
 
    conflines = readfile(hba_file);
 
-#ifndef HAVE_UNIX_SOCKETS
-   conflines = filter_lines_with_token(conflines, "@remove-line-for-nolocal@");
-#else
    conflines = replace_token(conflines, "@remove-line-for-nolocal@", "");
-#endif
 
 #ifdef HAVE_IPV6
 
index 0954b75ec07a2c9ac0366b2b4d2ea64d942664e6..fbab1c4fb72c4924417fa7b8819675acc3fe7492 100644 (file)
@@ -444,7 +444,7 @@ adjust_data_dir(ClusterInfo *cluster)
 void
 get_sock_dir(ClusterInfo *cluster, bool live_check)
 {
-#if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32)
+#if !defined(WIN32)
    if (!live_check)
        cluster->sockdir = user_opts.socketdir;
    else
@@ -490,7 +490,7 @@ get_sock_dir(ClusterInfo *cluster, bool live_check)
            pg_log(PG_WARNING, "user-supplied old port number %hu corrected to %hu",
                   orig_port, cluster->port);
    }
-#else                          /* !HAVE_UNIX_SOCKETS || WIN32 */
+#else                          /* WIN32 */
    cluster->sockdir = NULL;
 #endif
 }
index 79479edc0eecf258551af5bd0e7a171104b8f8be..9a1a20fb27ac648a2041cb61aca5ad9582bba4a9 100644 (file)
@@ -212,7 +212,7 @@ start_postmaster(ClusterInfo *cluster, bool report_and_exit_on_error)
 
    socket_string[0] = '\0';
 
-#if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32)
+#if !defined(WIN32)
    /* prevent TCP/IP connections, restrict socket access */
    strcat(socket_string,
           " -c listen_addresses='' -c unix_socket_permissions=0700");
index 267103efb9975135e7cb7f79dd5fcebb2af8c88a..dd9193feb1bcee554f1ca37f28cd533a6361d43a 100644 (file)
@@ -38,7 +38,6 @@
 
 
 
-#ifdef HAVE_UNIX_SOCKETS
 static int getaddrinfo_unix(const char *path,
                             const struct addrinfo *hintsp,
                             struct addrinfo **result);
@@ -47,7 +46,6 @@ static int    getnameinfo_unix(const struct sockaddr_un *sa, int salen,
                             char *node, int nodelen,
                             char *service, int servicelen,
                             int flags);
-#endif
 
 
 /*
@@ -62,10 +60,8 @@ pg_getaddrinfo_all(const char *hostname, const char *servname,
    /* not all versions of getaddrinfo() zero *result on failure */
    *result = NULL;
 
-#ifdef HAVE_UNIX_SOCKETS
    if (hintp->ai_family == AF_UNIX)
        return getaddrinfo_unix(servname, hintp, result);
-#endif
 
    /* NULL has special meaning to getaddrinfo(). */
    rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
@@ -87,7 +83,6 @@ pg_getaddrinfo_all(const char *hostname, const char *servname,
 void
 pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
 {
-#ifdef HAVE_UNIX_SOCKETS
    if (hint_ai_family == AF_UNIX)
    {
        /* struct was built by getaddrinfo_unix (see pg_getaddrinfo_all) */
@@ -101,7 +96,6 @@ pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
        }
    }
    else
-#endif                         /* HAVE_UNIX_SOCKETS */
    {
        /* struct was built by getaddrinfo() */
        if (ai != NULL)
@@ -126,14 +120,12 @@ pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen,
 {
    int         rc;
 
-#ifdef HAVE_UNIX_SOCKETS
    if (addr && addr->ss_family == AF_UNIX)
        rc = getnameinfo_unix((const struct sockaddr_un *) addr, salen,
                              node, nodelen,
                              service, servicelen,
                              flags);
    else
-#endif
        rc = getnameinfo((const struct sockaddr *) addr, salen,
                         node, nodelen,
                         service, servicelen,
@@ -151,8 +143,6 @@ pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen,
 }
 
 
-#if defined(HAVE_UNIX_SOCKETS)
-
 /* -------
  * getaddrinfo_unix - get unix socket info using IPv6-compatible API
  *
@@ -286,4 +276,3 @@ getnameinfo_unix(const struct sockaddr_un *sa, int salen,
 
    return 0;
 }
-#endif                         /* HAVE_UNIX_SOCKETS */
index 80dcfb7dfee387c096391ff038c9ed4f31a54397..cec41eae713232fe0069da2c765e7cdad0d20f47 100644 (file)
@@ -503,7 +503,4 @@ extern bool wait_result_is_any_signal(int exit_status, bool include_command_not_
 #define HAVE_SYMLINK 1
 #endif
 
-/* Interfaces that we assume that all systems have. */
-#define HAVE_UNIX_SOCKETS 1
-
 #endif                         /* PG_PORT_H */
index dc49387d6c5c64c3bab56ab959843fa3042de065..730e79a31d246a37470e90e54311c3cf2009579e 100644 (file)
@@ -1102,10 +1102,8 @@ connectOptions2(PGconn *conn)
        else if (ch->host != NULL && ch->host[0] != '\0')
        {
            ch->type = CHT_HOST_NAME;
-#ifdef HAVE_UNIX_SOCKETS
            if (is_unixsock_path(ch->host))
                ch->type = CHT_UNIX_SOCKET;
-#endif
        }
        else
        {
@@ -1115,14 +1113,12 @@ connectOptions2(PGconn *conn)
             * This bit selects the default host location.  If you change
             * this, see also pg_regress.
             */
-#ifdef HAVE_UNIX_SOCKETS
            if (DEFAULT_PGSOCKET_DIR[0])
            {
                ch->host = strdup(DEFAULT_PGSOCKET_DIR);
                ch->type = CHT_UNIX_SOCKET;
            }
            else
-#endif
            {
                ch->host = strdup(DefaultHost);
                ch->type = CHT_HOST_NAME;
@@ -1684,7 +1680,6 @@ getHostaddr(PGconn *conn, char *host_addr, int host_addr_len)
 static void
 emitHostIdentityInfo(PGconn *conn, const char *host_addr)
 {
-#ifdef HAVE_UNIX_SOCKETS
    if (conn->raddr.addr.ss_family == AF_UNIX)
    {
        char        service[NI_MAXHOST];
@@ -1698,7 +1693,6 @@ emitHostIdentityInfo(PGconn *conn, const char *host_addr)
                          service);
    }
    else
-#endif                         /* HAVE_UNIX_SOCKETS */
    {
        const char *displayed_host;
        const char *displayed_port;
@@ -1748,12 +1742,10 @@ connectFailureMessage(PGconn *conn, int errorno)
                      "%s\n",
                      SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)));
 
-#ifdef HAVE_UNIX_SOCKETS
    if (conn->raddr.addr.ss_family == AF_UNIX)
        appendPQExpBufferStr(&conn->errorMessage,
                             libpq_gettext("\tIs the server running locally and accepting connections on that socket?\n"));
    else
-#endif
        appendPQExpBufferStr(&conn->errorMessage,
                             libpq_gettext("\tIs the server running on that host and accepting TCP/IP connections?\n"));
 }
@@ -2415,7 +2407,6 @@ keep_going:                       /* We will come back to here until there is
                break;
 
            case CHT_UNIX_SOCKET:
-#ifdef HAVE_UNIX_SOCKETS
                conn->addrlist_family = hint.ai_family = AF_UNIX;
                UNIXSOCK_PATH(portstr, thisport, ch->host);
                if (strlen(portstr) >= UNIXSOCK_PATH_BUFLEN)
@@ -2440,9 +2431,6 @@ keep_going:                       /* We will come back to here until there is
                                      portstr, gai_strerror(ret));
                    goto keep_going;
                }
-#else
-               Assert(false);
-#endif
                break;
        }
 
index e015a11c21721bf2a137e2c5754a5e25a438610e..9ca1a8d90636877e7a383e1c060f41f28977157a 100644 (file)
@@ -99,11 +99,9 @@ static char *logfilename;
 static FILE *logfile;
 static char *difffilename;
 static const char *sockdir;
-#ifdef HAVE_UNIX_SOCKETS
 static const char *temp_sockdir;
 static char sockself[MAXPGPATH];
 static char socklock[MAXPGPATH];
-#endif
 
 static _resultmap *resultmap = NULL;
 
@@ -285,7 +283,6 @@ stop_postmaster(void)
    }
 }
 
-#ifdef HAVE_UNIX_SOCKETS
 /*
  * Remove the socket temporary directory.  pg_regress never waits for a
  * postmaster exit, so it is indeterminate whether the postmaster has yet to
@@ -360,7 +357,6 @@ make_temp_sockdir(void)
 
    return temp_sockdir;
 }
-#endif                         /* HAVE_UNIX_SOCKETS */
 
 /*
  * Check whether string matches pattern
@@ -683,7 +679,6 @@ initialize_environment(void)
        /* PGPORT, see below */
        /* PGHOST, see below */
 
-#ifdef HAVE_UNIX_SOCKETS
        if (hostname != NULL)
            setenv("PGHOST", hostname, 1);
        else
@@ -693,10 +688,6 @@ initialize_environment(void)
                sockdir = make_temp_sockdir();
            setenv("PGHOST", sockdir, 1);
        }
-#else
-       Assert(hostname != NULL);
-       setenv("PGHOST", hostname, 1);
-#endif
        unsetenv("PGHOSTADDR");
        if (port != -1)
        {
@@ -746,11 +737,9 @@ initialize_environment(void)
        if (!pghost)
        {
            /* Keep this bit in sync with libpq's default host location: */
-#ifdef HAVE_UNIX_SOCKETS
            if (DEFAULT_PGSOCKET_DIR[0])
                 /* do nothing, we'll print "Unix socket" below */ ;
            else
-#endif
                pghost = "localhost";   /* DefaultHost in fe-connect.c */
        }
 
@@ -2068,14 +2057,11 @@ regression_main(int argc, char *argv[],
 
    atexit(stop_postmaster);
 
-#if !defined(HAVE_UNIX_SOCKETS)
-   use_unix_sockets = false;
-#elif defined(WIN32)
+#if defined(WIN32)
 
    /*
-    * We don't use Unix-domain sockets on Windows by default, even if the
-    * build supports them.  (See comment at remove_temp() for a reason.)
-    * Override at your own risk.
+    * We don't use Unix-domain sockets on Windows by default (see comment at
+    * remove_temp() for a reason).  Override at your own risk.
     */
    use_unix_sockets = getenv("PG_TEST_USE_UNIX_SOCKETS") ? true : false;
 #else
@@ -2209,7 +2195,7 @@ regression_main(int argc, char *argv[],
        /*
         * To reduce chances of interference with parallel installations, use
         * a port number starting in the private range (49152-65535)
-        * calculated from the version number.  This aids !HAVE_UNIX_SOCKETS
+        * calculated from the version number.  This aids non-Unix socket mode
         * systems; elsewhere, the use of a private socket directory already
         * prevents interference.
         */
@@ -2329,8 +2315,6 @@ regression_main(int argc, char *argv[],
            snprintf(buf, sizeof(buf), "%s/data", temp_instance);
            config_sspi_auth(buf, NULL);
        }
-#elif !defined(HAVE_UNIX_SOCKETS)
-#error Platform has no means to secure the test installation.
 #endif
 
        /*