*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.198 2000/12/20 21:51:52 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.199 2001/01/07 04:17:29 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
bool Warn_restart_ready = false;
bool InError = false;
-bool ProcDiePending = false;
+volatile bool ProcDiePending = false;
static bool EchoQuery = false; /* default don't echo */
char pg_pathname[MAXPGPATH];
void
handle_warn(SIGNAL_ARGS)
{
- /* Don't joggle the elbow of a critical section */
+ /* Don't joggle the elbow of proc_exit */
+ if (proc_exit_inprogress)
+ return;
+ /* Don't joggle the elbow of a critical section, either */
if (CritSectionCount > 0)
{
QueryCancel = true;
void
die(SIGNAL_ARGS)
{
+ int save_errno = errno;
+
PG_SETMASK(&BlockSig);
- /* Don't joggle the elbow of a critical section */
+ /* Don't joggle the elbow of proc_exit */
+ if (proc_exit_inprogress)
+ {
+ errno = save_errno;
+ return;
+ }
+ /* Don't joggle the elbow of a critical section, either */
if (CritSectionCount > 0)
{
- QueryCancel = true;
ProcDiePending = true;
+ errno = save_errno;
return;
}
- /* Don't joggle the elbow of proc_exit, either */
- if (proc_exit_inprogress)
- return;
- elog(FATAL, "The system is shutting down");
+ /* Otherwise force immediate proc_exit */
+ ForceProcDie();
}
-/* signal handler for floating point exception */
-static void
-FloatExceptionHandler(SIGNAL_ARGS)
+/*
+ * This is split out of die() so that it can be invoked later from
+ * END_CRIT_CODE.
+ */
+void
+ForceProcDie(void)
{
- elog(ERROR, "floating point exception!"
- " The last floating point operation either exceeded legal ranges"
- " or was a divide by zero");
+ /* Reset flag to avoid another elog() during shutdown */
+ ProcDiePending = false;
+ /* Send error message and do proc_exit() */
+ elog(FATAL, "The system is shutting down");
}
/* signal handler for query cancel signal from postmaster */
{
int save_errno = errno;
+ /* Don't joggle the elbow of proc_exit, nor an already-in-progress abort */
+ if (proc_exit_inprogress || InError)
+ {
+ errno = save_errno;
+ return;
+ }
+
+ /* Set flag to cause CancelQuery to be called when it's safe */
QueryCancel = true;
+
+ /* If we happen to be waiting for a lock, get out of that */
LockWaitCancel();
+
+ /* Otherwise, bide our time... */
errno = save_errno;
}
void
CancelQuery(void)
{
-
- /*
- * QueryCancel flag will be reset in main loop, which we reach by
- * longjmp from elog().
- */
+ /* Reset flag to avoid another elog() during error recovery */
+ QueryCancel = false;
+ /* Create an artificial error condition to get out of query */
elog(ERROR, "Query was cancelled.");
}
+/* signal handler for floating point exception */
+static void
+FloatExceptionHandler(SIGNAL_ARGS)
+{
+ elog(ERROR, "floating point exception!"
+ " The last floating point operation either exceeded legal ranges"
+ " or was a divide by zero");
+}
+
static void
SigHupHandler(SIGNAL_ARGS)
{
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.198 $ $Date: 2000/12/20 21:51:52 $\n");
+ puts("$Revision: 1.199 $ $Date: 2001/01/07 04:17:29 $\n");
}
/*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: elog.h,v 1.21 2000/12/18 00:44:50 tgl Exp $
+ * $Id: elog.h,v 1.22 2001/01/07 04:17:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* If CritSectionCount > 0, signal handlers mustn't do
* elog(ERROR|FATAL), instead remember what action is
- * required with QueryCancel & ProcDiePending.
+ * required with QueryCancel or ProcDiePending.
+ * ProcDiePending will be honored at critical section exit,
+ * but QueryCancel is only checked at specified points.
*/
extern uint32 CritSectionCount; /* duplicates access/xlog.h */
-extern bool QueryCancel; /* duplicates miscadmin.h */
-extern bool ProcDiePending;
+extern volatile bool ProcDiePending;
+extern void ForceProcDie(void); /* in postgres.c */
#define START_CRIT_CODE (CritSectionCount++)
if (CritSectionCount == 0) \
elog(STOP, "Not in critical section"); \
CritSectionCount--; \
- if (CritSectionCount == 0 && QueryCancel) \
- { \
- if (ProcDiePending) \
- elog(FATAL, "The system is shutting down"); \
- else \
- elog(ERROR, "Query was cancelled."); \
- } \
+ if (CritSectionCount == 0 && ProcDiePending) \
+ ForceProcDie(); \
} while(0)
extern bool Log_timestamp;