Commit 4df52b28 authored by Tom Lane's avatar Tom Lane

Fix things so that an error occuring during standalone-backend processing

in initdb will result in exit(1), allowing the initdb script to realize
that there's something wrong.
parent aae07819
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.159 2003/05/28 16:03:55 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.160 2003/05/28 18:19:09 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -838,7 +838,7 @@ BootstrapAlreadySeen(Oid id) ...@@ -838,7 +838,7 @@ BootstrapAlreadySeen(Oid id)
* ---------------- * ----------------
*/ */
static void static void
cleanup() cleanup(void)
{ {
static int beenhere = 0; static int beenhere = 0;
...@@ -846,13 +846,13 @@ cleanup() ...@@ -846,13 +846,13 @@ cleanup()
beenhere = 1; beenhere = 1;
else else
{ {
elog(FATAL, "Memory manager fault: cleanup called twice.\n"); elog(FATAL, "Memory manager fault: cleanup called twice");
proc_exit(1); proc_exit(1);
} }
if (boot_reldesc != NULL) if (boot_reldesc != NULL)
closerel(NULL); closerel(NULL);
CommitTransactionCommand(); CommitTransactionCommand();
proc_exit(Warnings); proc_exit(Warnings ? 1 : 0);
} }
/* ---------------- /* ----------------
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.110 2003/05/28 17:25:02 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.111 2003/05/28 18:19:09 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -410,18 +410,28 @@ errfinish(int dummy, ...) ...@@ -410,18 +410,28 @@ errfinish(int dummy, ...)
/* /*
* For a FATAL error, we let proc_exit clean up and exit. * For a FATAL error, we let proc_exit clean up and exit.
* *
* If we have not yet entered the main backend loop (ie, we are in * There are several other cases in which we treat ERROR as FATAL
* the postmaster or in backend startup), we also go directly to * and go directly to proc_exit:
* proc_exit. The same is true if anyone tries to report an error *
* after proc_exit has begun to run. (It's proc_exit's * 1. ExitOnAnyError mode switch is set (initdb uses this).
* responsibility to see that this doesn't turn into infinite *
* recursion!) But in the latter case, we exit with nonzero exit * 2. we have not yet entered the main backend loop (ie, we are in
* code to indicate that something's pretty wrong. We also want * the postmaster or in backend startup); we have noplace to recover.
* to exit with nonzero exit code if not running under the *
* postmaster (for example, if we are being run from the initdb * 3. the error occurred after proc_exit has begun to run. (It's
* script, we'd better return an error status). * proc_exit's responsibility to see that this doesn't turn into
* infinite recursion!)
*
* In the last case, we exit with nonzero exit code to indicate that
* something's pretty wrong. We also want to exit with nonzero exit
* code if not running under the postmaster (for example, if we are
* being run from the initdb script, we'd better return an error
* status).
*/ */
if (elevel == FATAL || !Warn_restart_ready || proc_exit_inprogress) if (elevel == FATAL ||
ExitOnAnyError ||
!Warn_restart_ready ||
proc_exit_inprogress)
{ {
/* /*
* fflush here is just to improve the odds that we get to see * fflush here is just to improve the odds that we get to see
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.70 2003/05/28 17:25:02 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.71 2003/05/28 18:19:09 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
...@@ -61,6 +61,8 @@ Oid MyDatabaseId = InvalidOid; ...@@ -61,6 +61,8 @@ Oid MyDatabaseId = InvalidOid;
bool IsPostmasterEnvironment = false; bool IsPostmasterEnvironment = false;
bool IsUnderPostmaster = false; bool IsUnderPostmaster = false;
bool ExitOnAnyError = false;
int DateStyle = USE_ISO_DATES; int DateStyle = USE_ISO_DATES;
bool EuroDates = false; bool EuroDates = false;
bool HasCTZSet = false; bool HasCTZSet = false;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.126 2003/05/27 17:55:50 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.127 2003/05/28 18:19:09 tgl Exp $
* *
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
...@@ -399,6 +399,12 @@ static struct config_bool ...@@ -399,6 +399,12 @@ static struct config_bool
}, },
#endif #endif
{
/* currently undocumented, so don't show in SHOW ALL */
{"exit_on_error", PGC_USERSET, GUC_NO_SHOW_ALL}, &ExitOnAnyError,
false, NULL, NULL
},
{ {
{"log_statement", PGC_SUSET}, &log_statement, {"log_statement", PGC_SUSET}, &log_statement,
false, NULL, NULL false, NULL, NULL
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.190 2003/05/28 17:25:02 tgl Exp $ # $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.191 2003/05/28 18:19:09 tgl Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -612,7 +612,7 @@ echo "ok" ...@@ -612,7 +612,7 @@ echo "ok"
# To break an SQL command across lines in this script, backslash-escape all # To break an SQL command across lines in this script, backslash-escape all
# internal newlines in the command. # internal newlines in the command.
PGSQL_OPT="$PGSQL_OPT -O -c search_path=pg_catalog" PGSQL_OPT="$PGSQL_OPT -O -c search_path=pg_catalog -c exit_on_error=true"
$ECHO_N "initializing pg_shadow... "$ECHO_C $ECHO_N "initializing pg_shadow... "$ECHO_C
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: miscadmin.h,v 1.122 2003/05/28 17:25:02 tgl Exp $ * $Id: miscadmin.h,v 1.123 2003/05/28 18:19:09 tgl Exp $
* *
* NOTES * NOTES
* some of the information in this file should be moved to * some of the information in this file should be moved to
...@@ -104,8 +104,6 @@ extern void ProcessInterrupts(void); ...@@ -104,8 +104,6 @@ extern void ProcessInterrupts(void);
/* /*
* from postmaster/postmaster.c * from postmaster/postmaster.c
*/ */
extern bool IsPostmasterEnvironment;
extern bool IsUnderPostmaster;
extern bool ClientAuthInProgress; extern bool ClientAuthInProgress;
extern const bool ExecBackend; extern const bool ExecBackend;
...@@ -115,6 +113,11 @@ extern void ClosePostmasterPorts(bool pgstat_too); ...@@ -115,6 +113,11 @@ extern void ClosePostmasterPorts(bool pgstat_too);
/* /*
* from utils/init/globals.c * from utils/init/globals.c
*/ */
extern bool IsPostmasterEnvironment;
extern bool IsUnderPostmaster;
extern bool ExitOnAnyError;
extern bool Noversion; extern bool Noversion;
extern char *DataDir; extern char *DataDir;
......
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