additional-sockets.patch
application/octet-stream
Filename: additional-sockets.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/backend/postmaster/postmaster.c | 87 | 0 |
| src/backend/utils/misc/guc.c | 10 | 0 |
| src/backend/utils/misc/postgresql.conf.sample | 2 | 0 |
| src/include/postmaster/postmaster.h | 1 | 0 |
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index dd7dd55..a4745cc 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -156,9 +156,16 @@ static Backend *ShmemBackendArray;
/* The socket number we are listening for connections on */
int PostPortNumber;
+
+/* UNIX socket directory */
char *UnixSocketDir;
+
+/* Addresses to bind to, for port number above */
char *ListenAddresses;
+/* Additional sockets */
+char *additional_sockets;
+
/*
* ReservedBackends is the number of backends reserved for superuser use.
* This number is taken out of the pool size given by MaxBackends so
@@ -896,6 +903,86 @@ PostmasterMain(int argc, char *argv[])
pfree(rawstring);
}
+ if (additional_sockets)
+ {
+ char *rawstring;
+ List *elemlist;
+ ListCell *l;
+
+ /* Need a modifiable copy of additional_sockets */
+ rawstring = pstrdup(additional_sockets);
+
+ /* Parse string into list of identifiers */
+ if (!SplitIdentifierString(rawstring, ',', &elemlist))
+ {
+ /* syntax error in list */
+ ereport(FATAL,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("invalid list syntax for \"additional_sockets\"")));
+ }
+
+ foreach(l, elemlist)
+ {
+ char *cursocket = (char *) lfirst(l);
+ char *colon;
+ char *host;
+ char *port;
+ int64 portnum;
+ char *endptr;
+ bool bad_strtol;
+
+ /* syntax is port or host:port */
+ colon = strchr(cursocket, ':');
+ if (colon != NULL)
+ {
+ host = cursocket;
+ port = colon + 1;
+ *colon = '\0';
+ }
+ else
+ {
+ host = NULL;
+ port = cursocket;
+ }
+
+ /*
+ * convert port number to integer, ignoring optional trailing
+ * whitespace). strtol should ignore leading whitespace, too.
+ */
+ portnum = strtol(port, &endptr, 0);
+ bad_strtol = (errno == ERANGE);
+ while (isspace((unsigned char) *endptr))
+ endptr++;
+ if (*endptr != '\0')
+ ereport(FATAL,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("port number \"%s\" invalid in \"additional_sockets\"", port)));
+ if (bad_strtol || portnum < 1 || portnum > 65535)
+ ereport(FATAL,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("port number \"%s\" out of range in \"additional_sockets\"", port)));
+
+
+ status = StreamServerPort(AF_UNSPEC, host,
+ (unsigned short) portnum,
+ UnixSocketDir,
+ ListenSocket, MAXLISTEN);
+
+ if (status != STATUS_OK)
+ {
+ /* put the colon back, for error-reporting purposes */
+ if (colon != NULL)
+ *colon = ':';
+ ereport(WARNING,
+ (errmsg("could not create additional socket for \"%s\"",
+ cursocket)));
+ }
+ }
+
+ list_free(elemlist);
+ pfree(rawstring);
+ }
+
#ifdef USE_BONJOUR
/* Register for Bonjour only if we opened TCP socket(s) */
if (enable_bonjour && ListenSocket[0] != PGINVALID_SOCKET)
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index d75ab43..2429011 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -2650,6 +2650,16 @@ static struct config_string ConfigureNamesString[] =
NULL, NULL, NULL
},
+ {
+ {"additional_sockets", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
+ gettext_noop("Listen on additional sockets."),
+ NULL
+ },
+ &additional_sockets,
+ "",
+ NULL, NULL, NULL
+ },
+
/* See main.c about why defaults for LC_foo are not all alike */
{
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index fa75d00..ce1c385 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -61,6 +61,8 @@
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = 5432 # (change requires restart)
+#additional_sockets = '' # comma-separated list of [host:]port
+ # (change requires restart)
#max_connections = 100 # (change requires restart)
# Note: Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).
diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h
index dded0e6..3d9ea41 100644
--- a/src/include/postmaster/postmaster.h
+++ b/src/include/postmaster/postmaster.h
@@ -17,6 +17,7 @@
extern bool EnableSSL;
extern int ReservedBackends;
extern int PostPortNumber;
+extern char *additional_sockets;
extern int Unix_socket_permissions;
extern char *Unix_socket_group;
extern char *UnixSocketDir;