From 4032a515d26eb2772c0f929db1dd8c38fcab3f92 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Tue, 6 Jun 2000 16:04:32 +0000
Subject: [PATCH] PGPORT envar was erroneously ignored by the backend

---
 src/backend/libpq/pqcomm.c          | 15 +--------------
 src/backend/postmaster/postmaster.c | 10 +++++-----
 src/include/libpq/libpq.h           |  3 +--
 3 files changed, 7 insertions(+), 21 deletions(-)

diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index cc2d0c27548..5238865e760 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -29,7 +29,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- *	$Id: pqcomm.c,v 1.95 2000/06/04 01:44:30 petere Exp $
+ *	$Id: pqcomm.c,v 1.96 2000/06/06 16:04:29 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -118,19 +118,6 @@ pq_init(void)
 		debug_port = stderr;
 }
 
-/* --------------------------------
- *		pq_getport - return the PGPORT setting
- * --------------------------------
- */
-int
-pq_getport(void)
-{
-	char	   *envport = getenv("PGPORT");
-
-	if (envport)
-		return atoi(envport);
-	return DEF_PGPORT;
-}
 
 /* --------------------------------
  *		pq_close - shutdown libpq at backend exit
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index b578bc038f7..161b832c320 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.146 2000/06/04 01:44:31 petere Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.147 2000/06/06 16:04:29 petere Exp $
  *
  * NOTES
  *
@@ -129,7 +129,7 @@ static Dllist *BackendList;
 /* list of ports associated with still open, but incomplete connections */
 static Dllist *PortList;
 
-int PostPortName = DEF_PGPORT;
+int PostPortName;
 
  /*
   * This is a boolean indicating that there is at least one backend that
@@ -381,6 +381,9 @@ PostmasterMain(int argc, char *argv[])
 	MyProcPid = getpid();
 	DataDir = getenv("PGDATA"); /* default value */
 
+	if (getenv("PGPORT"))
+		PostPortName = atoi(getenv("PGPORT"));
+
 	/*
 	 * First we must scan for a -D argument to get the data dir. Then
 	 * read the config file. Finally, scan all the other arguments.
@@ -543,9 +546,6 @@ PostmasterMain(int argc, char *argv[])
 		}
 	}
 
-	if (PostPortName == 0)
-		PostPortName = pq_getport();
-
 	/*
 	 * Check for invalid combinations of switches
 	 */
diff --git a/src/include/libpq/libpq.h b/src/include/libpq/libpq.h
index 22df644905d..78e34f0d4ae 100644
--- a/src/include/libpq/libpq.h
+++ b/src/include/libpq/libpq.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: libpq.h,v 1.37 2000/06/04 01:44:37 petere Exp $
+ * $Id: libpq.h,v 1.38 2000/06/06 16:04:32 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -240,7 +240,6 @@ extern int	StreamServerPort(int family, unsigned short portName, int *fdP);
 extern int	StreamConnection(int server_fd, Port *port);
 extern void StreamClose(int sock);
 extern void pq_init(void);
-extern int	pq_getport(void);
 extern void pq_close(void);
 extern int	pq_getbytes(char *s, size_t len);
 extern int	pq_getstring(StringInfo s);
-- 
GitLab