From 7e1d51ad005851584e6aa021d6d0763cd57acc9a Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Sun, 1 Aug 2021 15:25:25 -0700
Subject: [PATCH v1 07/10] process startup: Remove bootstrap / checker modes
 from AuxProcType.

Neither is actually initialized as an auxiliary process, so it doesn't make
sense to reserve a PGPROC etc for them.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:
---
 src/include/bootstrap/bootstrap.h   |  2 +-
 src/include/miscadmin.h             |  4 +---
 src/backend/bootstrap/bootstrap.c   | 24 ++++++------------------
 src/backend/main/main.c             |  8 +++++---
 src/backend/postmaster/auxprocess.c |  5 -----
 src/bin/initdb/initdb.c             |  6 +++---
 6 files changed, 16 insertions(+), 33 deletions(-)

diff --git a/src/include/bootstrap/bootstrap.h b/src/include/bootstrap/bootstrap.h
index a9829124104..5bef4f56244 100644
--- a/src/include/bootstrap/bootstrap.h
+++ b/src/include/bootstrap/bootstrap.h
@@ -32,7 +32,7 @@ extern Form_pg_attribute attrtypes[MAXATTR];
 extern int	numattr;
 
 
-extern void BootstrapModeMain(int argc, char *argv[]) pg_attribute_noreturn();
+extern void BootstrapModeMain(int argc, char *argv[], bool check_mode) pg_attribute_noreturn();
 
 extern void closerel(char *name);
 extern void boot_openrel(char *name);
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index 1b7422d6366..58f7fd28c95 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -427,9 +427,7 @@ extern ProcessingMode Mode;
 typedef enum
 {
 	NotAnAuxProcess = -1,
-	CheckerProcess = 0,
-	BootstrapProcess,
-	StartupProcess,
+	StartupProcess = 0,
 	BgWriterProcess,
 	ArchiverProcess,
 	CheckpointerProcess,
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 5c736bb7786..80c90ea9d9b 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -195,7 +195,7 @@ CheckerModeMain(void)
  *	 commands in a special bootstrap language.
  */
 void
-BootstrapModeMain(int argc, char *argv[])
+BootstrapModeMain(int argc, char *argv[], bool check_mode)
 {
 	int			i;
 	char	   *progname = argv[0];
@@ -209,16 +209,14 @@ BootstrapModeMain(int argc, char *argv[])
 	/* Set defaults, to be overridden by explicit options below */
 	InitializeGUCOptions();
 
-	/* an initial --boot should be present */
+	/* an initial --boot or --check should be present */
 	Assert(argc == 1
-		   || strcmp(argv[1], "--boot") != 0);
+		   || strcmp(argv[1], "--boot") != 0
+		   || strcmp(argv[1], "--check") != 0);
 	argv++;
 	argc--;
 
-	/* If no -x argument, we are a CheckerProcess */
-	MyAuxProcType = CheckerProcess;
-
-	while ((flag = getopt(argc, argv, "B:c:d:D:Fkr:x:X:-:")) != -1)
+	while ((flag = getopt(argc, argv, "B:c:d:D:Fkr:X:-:")) != -1)
 	{
 		switch (flag)
 		{
@@ -250,16 +248,6 @@ BootstrapModeMain(int argc, char *argv[])
 			case 'r':
 				strlcpy(OutputFileName, optarg, MAXPGPATH);
 				break;
-			case 'x':
-				MyAuxProcType = atoi(optarg);
-				if (MyAuxProcType != CheckerProcess &&
-					MyAuxProcType != BootstrapProcess)
-				{
-						ereport(ERROR,
-								(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-								 errmsg("-x %s is invalid", optarg)));
-				}
-				break;
 			case 'X':
 				{
 					int			WalSegSz = strtoul(optarg, NULL, 0);
@@ -334,7 +322,7 @@ BootstrapModeMain(int argc, char *argv[])
 	BaseInit();
 
 	/* FIXME: Move out. New top-level mode? */
-	if (MyAuxProcType == CheckerProcess)
+	if (check_mode)
 	{
 		SetProcessingMode(NormalProcessing);
 		CheckerModeMain();
diff --git a/src/backend/main/main.c b/src/backend/main/main.c
index 51494f6cc4b..3a2a0d598cd 100644
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -181,8 +181,10 @@ main(int argc, char *argv[])
 	 * Dispatch to one of various subprograms depending on first argument.
 	 */
 
-	if (argc > 1 && strcmp(argv[1], "--boot") == 0)
-		BootstrapModeMain(argc, argv);
+	if (argc > 1 && strcmp(argv[1], "--check") == 0)
+		BootstrapModeMain(argc, argv, true);
+	else if (argc > 1 && strcmp(argv[1], "--boot") == 0)
+		BootstrapModeMain(argc, argv, false);
 #ifdef EXEC_BACKEND
 	else if (argc > 1 && strncmp(argv[1], "--fork", 6) == 0)
 		SubPostmasterMain(argc, argv);
@@ -339,9 +341,9 @@ help(const char *progname)
 
 	printf(_("\nOptions for bootstrapping mode:\n"));
 	printf(_("  --boot             selects bootstrapping mode (must be first argument)\n"));
+	printf(_("  --check            selects check mode (must be first argument)\n"));
 	printf(_("  DBNAME             database name (mandatory argument in bootstrapping mode)\n"));
 	printf(_("  -r FILENAME        send stdout and stderr to given file\n"));
-	printf(_("  -x NUM             internal use\n"));
 
 	printf(_("\nPlease read the documentation for the complete list of run-time\n"
 			 "configuration settings and how to set them on the command line or in\n"
diff --git a/src/backend/postmaster/auxprocess.c b/src/backend/postmaster/auxprocess.c
index e580ad7cbf9..7906c327923 100644
--- a/src/backend/postmaster/auxprocess.c
+++ b/src/backend/postmaster/auxprocess.c
@@ -144,11 +144,6 @@ AuxiliaryProcessMain(AuxProcType auxtype)
 
 	switch (MyAuxProcType)
 	{
-		case CheckerProcess:
-		case BootstrapProcess:
-			pg_unreachable();
-			break;
-
 		case StartupProcess:
 			StartupProcessMain();
 			proc_exit(1);
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 994bf07f3ba..5e84c7bb20e 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -965,7 +965,7 @@ test_config_settings(void)
 		test_buffs = MIN_BUFS_FOR_CONNS(test_conns);
 
 		snprintf(cmd, sizeof(cmd),
-				 "\"%s\" --boot -x0 %s %s "
+				 "\"%s\" --check %s %s "
 				 "-c max_connections=%d "
 				 "-c shared_buffers=%d "
 				 "-c dynamic_shared_memory_type=%s "
@@ -1001,7 +1001,7 @@ test_config_settings(void)
 		}
 
 		snprintf(cmd, sizeof(cmd),
-				 "\"%s\" --boot -x0 %s %s "
+				 "\"%s\" --check %s %s "
 				 "-c max_connections=%d "
 				 "-c shared_buffers=%d "
 				 "-c dynamic_shared_memory_type=%s "
@@ -1406,7 +1406,7 @@ bootstrap_template1(void)
 	unsetenv("PGCLIENTENCODING");
 
 	snprintf(cmd, sizeof(cmd),
-			 "\"%s\" --boot -x1 -X %u %s %s %s %s",
+			 "\"%s\" --boot -X %u %s %s %s %s",
 			 backend_exec,
 			 wal_segment_size_mb * (1024 * 1024),
 			 data_checksums ? "-k" : "",
-- 
2.32.0.rc2

