Commit 2f0d43b2 authored by Tom Lane's avatar Tom Lane

Review uses of IsUnderPostmaster, change some tests to look at

whereToSendOutput instead because they are really inquiring about
the correct client communication protocol.  Update some comments.
This is pointing towards supporting regular FE/BE client protocol
in a standalone backend, per discussion a month or so back.
parent b3ead7c0
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.9 2004/01/26 22:35:31 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.10 2004/01/28 21:02:39 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -184,14 +184,12 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir) ...@@ -184,14 +184,12 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir)
shared = (SlruShared) ptr; shared = (SlruShared) ptr;
#ifdef EXEC_BACKEND #ifdef EXEC_BACKEND
/* /*
* Locks are in shared memory * Locks are in shared memory
*/ */
locks = (SlruLock) (ptr + MAXALIGN(sizeof(SlruSharedData)) + locks = (SlruLock) (ptr + MAXALIGN(sizeof(SlruSharedData)) +
BLCKSZ * NUM_CLOG_BUFFERS); BLCKSZ * NUM_CLOG_BUFFERS);
#else #else
/* /*
* Locks are in private memory * Locks are in private memory
*/ */
...@@ -200,10 +198,9 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir) ...@@ -200,10 +198,9 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir)
Assert(locks); Assert(locks);
#endif #endif
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
/* Initialize locks and shared memory area */
{ {
/* Initialize locks and shared memory area */
char *bufptr; char *bufptr;
int slotno; int slotno;
...@@ -229,11 +226,9 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir) ...@@ -229,11 +226,9 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir)
else else
Assert(found); Assert(found);
ctl->locks = locks; ctl->locks = locks;
ctl->shared = shared; ctl->shared = shared;
/* Init directory path */ /* Init directory path */
snprintf(ctl->Dir, MAXPGPATH, "%s/%s", DataDir, subdir); snprintf(ctl->Dir, MAXPGPATH, "%s/%s", DataDir, subdir);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.225 2004/01/07 18:56:25 neilc Exp $ * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.226 2004/01/28 21:02:39 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -508,8 +508,9 @@ index_create(Oid heapRelationId, ...@@ -508,8 +508,9 @@ index_create(Oid heapRelationId,
* We cannot allow indexing a shared relation after initdb (because * We cannot allow indexing a shared relation after initdb (because
* there's no way to make the entry in other databases' pg_class). * there's no way to make the entry in other databases' pg_class).
* Unfortunately we can't distinguish initdb from a manually started * Unfortunately we can't distinguish initdb from a manually started
* standalone backend. However, we can at least prevent this mistake * standalone backend (toasting of shared rels happens after the bootstrap
* under normal multi-user operation. * phase, so checking IsBootstrapProcessingMode() won't work). However,
* we can at least prevent this mistake under normal multi-user operation.
*/ */
if (shared_relation && IsUnderPostmaster) if (shared_relation && IsUnderPostmaster)
ereport(ERROR, ereport(ERROR,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.216 2004/01/26 22:35:31 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.217 2004/01/28 21:02:39 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -829,7 +829,7 @@ DoCopy(const CopyStmt *stmt) ...@@ -829,7 +829,7 @@ DoCopy(const CopyStmt *stmt)
} }
if (pipe) if (pipe)
{ {
if (IsUnderPostmaster) if (whereToSendOutput == Remote)
ReceiveCopyBegin(binary, length(attnumlist)); ReceiveCopyBegin(binary, length(attnumlist));
else else
copy_file = stdin; copy_file = stdin;
...@@ -879,7 +879,7 @@ DoCopy(const CopyStmt *stmt) ...@@ -879,7 +879,7 @@ DoCopy(const CopyStmt *stmt)
} }
if (pipe) if (pipe)
{ {
if (IsUnderPostmaster) if (whereToSendOutput == Remote)
SendCopyBegin(binary, length(attnumlist)); SendCopyBegin(binary, length(attnumlist));
else else
copy_file = stdout; copy_file = stdout;
...@@ -929,7 +929,7 @@ DoCopy(const CopyStmt *stmt) ...@@ -929,7 +929,7 @@ DoCopy(const CopyStmt *stmt)
errmsg("could not write to file \"%s\": %m", errmsg("could not write to file \"%s\": %m",
filename))); filename)));
} }
else if (IsUnderPostmaster && !is_from) else if (whereToSendOutput == Remote && !is_from)
SendCopyEnd(binary); SendCopyEnd(binary);
pfree(attribute_buf.data); pfree(attribute_buf.data);
pfree(line_buf.data); pfree(line_buf.data);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.96 2004/01/23 02:13:11 neilc Exp $ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.97 2004/01/28 21:02:39 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -4027,8 +4027,9 @@ AlterTableCreateToastTable(Oid relOid, bool silent) ...@@ -4027,8 +4027,9 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
* We cannot allow toasting a shared relation after initdb (because * We cannot allow toasting a shared relation after initdb (because
* there's no way to mark it toasted in other databases' pg_class). * there's no way to mark it toasted in other databases' pg_class).
* Unfortunately we can't distinguish initdb from a manually started * Unfortunately we can't distinguish initdb from a manually started
* standalone backend. However, we can at least prevent this mistake * standalone backend (toasting happens after the bootstrap phase,
* under normal multi-user operation. * so checking IsBootstrapProcessingMode() won't work). However, we can
* at least prevent this mistake under normal multi-user operation.
*/ */
shared_relation = rel->rd_rel->relisshared; shared_relation = rel->rd_rel->relisshared;
if (shared_relation && IsUnderPostmaster) if (shared_relation && IsUnderPostmaster)
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* Copyright (c) 2001-2003, PostgreSQL Global Development Group * Copyright (c) 2001-2003, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.56 2004/01/26 22:59:53 momjian Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.57 2004/01/28 21:02:40 tgl Exp $
* ---------- * ----------
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -1339,6 +1339,12 @@ pgstat_mainInit(void) ...@@ -1339,6 +1339,12 @@ pgstat_mainInit(void)
{ {
IsUnderPostmaster = true; /* we are a postmaster subprocess now */ IsUnderPostmaster = true; /* we are a postmaster subprocess now */
#ifdef EXEC_BACKEND
/* In EXEC case we will not have inherited these settings */
IsPostmasterEnvironment = true;
whereToSendOutput = None;
#endif
MyProcPid = getpid(); /* reset MyProcPid */ MyProcPid = getpid(); /* reset MyProcPid */
/* Lose the postmaster's on-exit routines */ /* Lose the postmaster's on-exit routines */
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.363 2004/01/27 00:45:26 momjian Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.364 2004/01/28 21:02:40 tgl Exp $
* *
* NOTES * NOTES
* *
...@@ -2697,6 +2697,10 @@ SubPostmasterMain(int argc, char* argv[]) ...@@ -2697,6 +2697,10 @@ SubPostmasterMain(int argc, char* argv[])
/* Do this sooner rather than later... */ /* Do this sooner rather than later... */
IsUnderPostmaster = true; /* we are a postmaster subprocess now */ IsUnderPostmaster = true; /* we are a postmaster subprocess now */
/* In EXEC case we will not have inherited these settings */
IsPostmasterEnvironment = true;
whereToSendOutput = None;
/* Setup global context */ /* Setup global context */
MemoryContextInit(); MemoryContextInit();
InitializeGUCOptions(); InitializeGUCOptions();
...@@ -2994,6 +2998,14 @@ SSDataBaseInit(int xlop) ...@@ -2994,6 +2998,14 @@ SSDataBaseInit(int xlop)
IsUnderPostmaster = true; /* we are a postmaster subprocess IsUnderPostmaster = true; /* we are a postmaster subprocess
* now */ * now */
#ifdef EXEC_BACKEND
/* In EXEC case we will not have inherited these settings */
IsPostmasterEnvironment = true;
whereToSendOutput = None;
#endif
MyProcPid = getpid(); /* reset MyProcPid */
/* Lose the postmaster's on-exit routines and port connections */ /* Lose the postmaster's on-exit routines and port connections */
on_exit_reset(); on_exit_reset();
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.386 2004/01/26 22:59:53 momjian Exp $ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.387 2004/01/28 21:02:40 tgl Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -392,7 +392,7 @@ ReadCommand(StringInfo inBuf) ...@@ -392,7 +392,7 @@ ReadCommand(StringInfo inBuf)
{ {
int result; int result;
if (IsUnderPostmaster) if (whereToSendOutput == Remote)
result = SocketBackend(inBuf); result = SocketBackend(inBuf);
else else
result = InteractiveBackend(inBuf); result = InteractiveBackend(inBuf);
...@@ -2627,8 +2627,8 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -2627,8 +2627,8 @@ PostgresMain(int argc, char *argv[], const char *username)
/* Need not flush since ReadyForQuery will do it. */ /* Need not flush since ReadyForQuery will do it. */
} }
/* Welcome banner for non-frontend case */ /* Welcome banner for standalone case */
if (!IsUnderPostmaster) if (whereToSendOutput == Debug)
printf("\nPostgreSQL stand-alone backend %s\n", PG_VERSION); printf("\nPostgreSQL stand-alone backend %s\n", PG_VERSION);
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.80 2004/01/26 22:59:53 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.81 2004/01/28 21:02:40 tgl Exp $
* *
* NOTES * NOTES
* Globals used all over the place should be declared here and not * Globals used all over the place should be declared here and not
...@@ -53,9 +53,19 @@ BackendId MyBackendId; ...@@ -53,9 +53,19 @@ BackendId MyBackendId;
char *DatabasePath = NULL; char *DatabasePath = NULL;
Oid MyDatabaseId = InvalidOid; Oid MyDatabaseId = InvalidOid;
pid_t PostmasterPid = 0; pid_t PostmasterPid = 0;
/* these are initialized for the bootstrap/standalone case: */ /*
* IsPostmasterEnvironment is true in a postmaster process and any postmaster
* child process; it is false in a standalone process (bootstrap or
* standalone backend). IsUnderPostmaster is true in postmaster child
* processes. Note that "child process" includes all children, not only
* regular backends. These should be set correctly as early as possible
* in the execution of a process, so that error handling will do the right
* things if an error should occur during process initialization.
*
* These are initialized for the bootstrap/standalone case.
*/
bool IsPostmasterEnvironment = false; bool IsPostmasterEnvironment = false;
bool IsUnderPostmaster = false; bool IsUnderPostmaster = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment