Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4df52b2

Browse files
committed
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.
1 parent aae0781 commit 4df52b2

File tree

6 files changed

+44
-23
lines changed

6 files changed

+44
-23
lines changed

src/backend/bootstrap/bootstrap.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.159 2003/05/28 16:03:55 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.160 2003/05/28 18:19:09 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -838,21 +838,21 @@ BootstrapAlreadySeen(Oid id)
838838
* ----------------
839839
*/
840840
static void
841-
cleanup()
841+
cleanup(void)
842842
{
843843
static int beenhere = 0;
844844

845845
if (!beenhere)
846846
beenhere = 1;
847847
else
848848
{
849-
elog(FATAL, "Memory manager fault: cleanup called twice.\n");
849+
elog(FATAL, "Memory manager fault: cleanup called twice");
850850
proc_exit(1);
851851
}
852852
if (boot_reldesc != NULL)
853853
closerel(NULL);
854854
CommitTransactionCommand();
855-
proc_exit(Warnings);
855+
proc_exit(Warnings ? 1 : 0);
856856
}
857857

858858
/* ----------------

src/backend/utils/error/elog.c

+22-12
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.110 2003/05/28 17:25:02 tgl Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.111 2003/05/28 18:19:09 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -410,18 +410,28 @@ errfinish(int dummy, ...)
410410
/*
411411
* For a FATAL error, we let proc_exit clean up and exit.
412412
*
413-
* If we have not yet entered the main backend loop (ie, we are in
414-
* the postmaster or in backend startup), we also go directly to
415-
* proc_exit. The same is true if anyone tries to report an error
416-
* after proc_exit has begun to run. (It's proc_exit's
417-
* responsibility to see that this doesn't turn into infinite
418-
* recursion!) But in the latter case, we exit with nonzero exit
419-
* code to indicate that something's pretty wrong. We also want
420-
* to exit with nonzero exit code if not running under the
421-
* postmaster (for example, if we are being run from the initdb
422-
* script, we'd better return an error status).
413+
* There are several other cases in which we treat ERROR as FATAL
414+
* and go directly to proc_exit:
415+
*
416+
* 1. ExitOnAnyError mode switch is set (initdb uses this).
417+
*
418+
* 2. we have not yet entered the main backend loop (ie, we are in
419+
* the postmaster or in backend startup); we have noplace to recover.
420+
*
421+
* 3. the error occurred after proc_exit has begun to run. (It's
422+
* proc_exit's responsibility to see that this doesn't turn into
423+
* infinite recursion!)
424+
*
425+
* In the last case, we exit with nonzero exit code to indicate that
426+
* something's pretty wrong. We also want to exit with nonzero exit
427+
* code if not running under the postmaster (for example, if we are
428+
* being run from the initdb script, we'd better return an error
429+
* status).
423430
*/
424-
if (elevel == FATAL || !Warn_restart_ready || proc_exit_inprogress)
431+
if (elevel == FATAL ||
432+
ExitOnAnyError ||
433+
!Warn_restart_ready ||
434+
proc_exit_inprogress)
425435
{
426436
/*
427437
* fflush here is just to improve the odds that we get to see

src/backend/utils/init/globals.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.70 2003/05/28 17:25:02 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.71 2003/05/28 18:19:09 tgl Exp $
1212
*
1313
* NOTES
1414
* Globals used all over the place should be declared here and not
@@ -61,6 +61,8 @@ Oid MyDatabaseId = InvalidOid;
6161
bool IsPostmasterEnvironment = false;
6262
bool IsUnderPostmaster = false;
6363

64+
bool ExitOnAnyError = false;
65+
6466
int DateStyle = USE_ISO_DATES;
6567
bool EuroDates = false;
6668
bool HasCTZSet = false;

src/backend/utils/misc/guc.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.126 2003/05/27 17:55:50 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.127 2003/05/28 18:19:09 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -399,6 +399,12 @@ static struct config_bool
399399
},
400400
#endif
401401

402+
{
403+
/* currently undocumented, so don't show in SHOW ALL */
404+
{"exit_on_error", PGC_USERSET, GUC_NO_SHOW_ALL}, &ExitOnAnyError,
405+
false, NULL, NULL
406+
},
407+
402408
{
403409
{"log_statement", PGC_SUSET}, &log_statement,
404410
false, NULL, NULL

src/bin/initdb/initdb.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
2828
# Portions Copyright (c) 1994, Regents of the University of California
2929
#
30-
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.190 2003/05/28 17:25:02 tgl Exp $
30+
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.191 2003/05/28 18:19:09 tgl Exp $
3131
#
3232
#-------------------------------------------------------------------------
3333

@@ -612,7 +612,7 @@ echo "ok"
612612
# To break an SQL command across lines in this script, backslash-escape all
613613
# internal newlines in the command.
614614

615-
PGSQL_OPT="$PGSQL_OPT -O -c search_path=pg_catalog"
615+
PGSQL_OPT="$PGSQL_OPT -O -c search_path=pg_catalog -c exit_on_error=true"
616616

617617
$ECHO_N "initializing pg_shadow... "$ECHO_C
618618

src/include/miscadmin.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: miscadmin.h,v 1.122 2003/05/28 17:25:02 tgl Exp $
15+
* $Id: miscadmin.h,v 1.123 2003/05/28 18:19:09 tgl Exp $
1616
*
1717
* NOTES
1818
* some of the information in this file should be moved to
@@ -104,8 +104,6 @@ extern void ProcessInterrupts(void);
104104
/*
105105
* from postmaster/postmaster.c
106106
*/
107-
extern bool IsPostmasterEnvironment;
108-
extern bool IsUnderPostmaster;
109107
extern bool ClientAuthInProgress;
110108
extern const bool ExecBackend;
111109

@@ -115,6 +113,11 @@ extern void ClosePostmasterPorts(bool pgstat_too);
115113
/*
116114
* from utils/init/globals.c
117115
*/
116+
extern bool IsPostmasterEnvironment;
117+
extern bool IsUnderPostmaster;
118+
119+
extern bool ExitOnAnyError;
120+
118121
extern bool Noversion;
119122
extern char *DataDir;
120123

0 commit comments

Comments
 (0)