88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.198 2000/12/20 21:51:52 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.199 2001/01/07 04:17:29 tgl Exp $
1212 *
1313 * NOTES
1414 * this is the "main" module of the postgres backend and
@@ -94,7 +94,7 @@ DLLIMPORT sigjmp_buf Warn_restart;
9494
9595bool Warn_restart_ready = false;
9696bool InError = false;
97- bool ProcDiePending = false;
97+ volatile bool ProcDiePending = false;
9898
9999static bool EchoQuery = false;/* default don't echo */
100100char pg_pathname [MAXPGPATH ];
@@ -920,7 +920,10 @@ finish_xact_command(void)
920920void
921921handle_warn (SIGNAL_ARGS )
922922{
923- /* Don't joggle the elbow of a critical section */
923+ /* Don't joggle the elbow of proc_exit */
924+ if (proc_exit_inprogress )
925+ return ;
926+ /* Don't joggle the elbow of a critical section, either */
924927if (CritSectionCount > 0 )
925928{
926929QueryCancel = true;
@@ -956,28 +959,38 @@ quickdie(SIGNAL_ARGS)
956959void
957960die (SIGNAL_ARGS )
958961{
962+ int save_errno = errno ;
963+
959964PG_SETMASK (& BlockSig );
960965
961- /* Don't joggle the elbow of a critical section */
966+ /* Don't joggle the elbow of proc_exit */
967+ if (proc_exit_inprogress )
968+ {
969+ errno = save_errno ;
970+ return ;
971+ }
972+ /* Don't joggle the elbow of a critical section, either */
962973if (CritSectionCount > 0 )
963974{
964- QueryCancel = true;
965975ProcDiePending = true;
976+ errno = save_errno ;
966977return ;
967978}
968- /* Don't joggle the elbow of proc_exit, either */
969- if (proc_exit_inprogress )
970- return ;
971- elog (FATAL ,"The system is shutting down" );
979+ /* Otherwise force immediate proc_exit */
980+ ForceProcDie ();
972981}
973982
974- /* signal handler for floating point exception */
975- static void
976- FloatExceptionHandler (SIGNAL_ARGS )
983+ /*
984+ * This is split out of die() so that it can be invoked later from
985+ * END_CRIT_CODE.
986+ */
987+ void
988+ ForceProcDie (void )
977989{
978- elog (ERROR ,"floating point exception!"
979- " The last floating point operation either exceeded legal ranges"
980- " or was a divide by zero" );
990+ /* Reset flag to avoid another elog() during shutdown */
991+ ProcDiePending = false;
992+ /* Send error message and do proc_exit() */
993+ elog (FATAL ,"The system is shutting down" );
981994}
982995
983996/* signal handler for query cancel signal from postmaster */
@@ -986,22 +999,41 @@ QueryCancelHandler(SIGNAL_ARGS)
986999{
9871000int save_errno = errno ;
9881001
1002+ /* Don't joggle the elbow of proc_exit, nor an already-in-progress abort */
1003+ if (proc_exit_inprogress || InError )
1004+ {
1005+ errno = save_errno ;
1006+ return ;
1007+ }
1008+
1009+ /* Set flag to cause CancelQuery to be called when it's safe */
9891010QueryCancel = true;
1011+
1012+ /* If we happen to be waiting for a lock, get out of that */
9901013LockWaitCancel ();
1014+
1015+ /* Otherwise, bide our time... */
9911016errno = save_errno ;
9921017}
9931018
9941019void
9951020CancelQuery (void )
9961021{
997-
998- /*
999- * QueryCancel flag will be reset in main loop, which we reach by
1000- * longjmp from elog().
1001- */
1022+ /* Reset flag to avoid another elog() during error recovery */
1023+ QueryCancel = false;
1024+ /* Create an artificial error condition to get out of query */
10021025elog (ERROR ,"Query was cancelled." );
10031026}
10041027
1028+ /* signal handler for floating point exception */
1029+ static void
1030+ FloatExceptionHandler (SIGNAL_ARGS )
1031+ {
1032+ elog (ERROR ,"floating point exception!"
1033+ " The last floating point operation either exceeded legal ranges"
1034+ " or was a divide by zero" );
1035+ }
1036+
10051037static void
10061038SigHupHandler (SIGNAL_ARGS )
10071039{
@@ -1651,7 +1683,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
16511683if (!IsUnderPostmaster )
16521684{
16531685puts ("\nPOSTGRES backend interactive interface " );
1654- puts ("$Revision: 1.198 $ $Date:2000/12/20 21:51:52 $\n" );
1686+ puts ("$Revision: 1.199 $ $Date:2001/01/07 04:17:29 $\n" );
16551687}
16561688
16571689/*