8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
* NOTES
14
14
* this is the "main" module of the postgres backend and
@@ -94,7 +94,7 @@ DLLIMPORT sigjmp_buf Warn_restart;
94
94
95
95
bool Warn_restart_ready = false;
96
96
bool InError = false;
97
- bool ProcDiePending = false;
97
+ volatile bool ProcDiePending = false;
98
98
99
99
static bool EchoQuery = false; /* default don't echo */
100
100
char pg_pathname [MAXPGPATH ];
@@ -920,7 +920,10 @@ finish_xact_command(void)
920
920
void
921
921
handle_warn (SIGNAL_ARGS )
922
922
{
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 */
924
927
if (CritSectionCount > 0 )
925
928
{
926
929
QueryCancel = true;
@@ -956,28 +959,38 @@ quickdie(SIGNAL_ARGS)
956
959
void
957
960
die (SIGNAL_ARGS )
958
961
{
962
+ int save_errno = errno ;
963
+
959
964
PG_SETMASK (& BlockSig );
960
965
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 */
962
973
if (CritSectionCount > 0 )
963
974
{
964
- QueryCancel = true;
965
975
ProcDiePending = true;
976
+ errno = save_errno ;
966
977
return ;
967
978
}
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 ();
972
981
}
973
982
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 )
977
989
{
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" );
981
994
}
982
995
983
996
/* signal handler for query cancel signal from postmaster */
@@ -986,22 +999,41 @@ QueryCancelHandler(SIGNAL_ARGS)
986
999
{
987
1000
int save_errno = errno ;
988
1001
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 */
989
1010
QueryCancel = true;
1011
+
1012
+ /* If we happen to be waiting for a lock, get out of that */
990
1013
LockWaitCancel ();
1014
+
1015
+ /* Otherwise, bide our time... */
991
1016
errno = save_errno ;
992
1017
}
993
1018
994
1019
void
995
1020
CancelQuery (void )
996
1021
{
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 */
1002
1025
elog (ERROR , "Query was cancelled." );
1003
1026
}
1004
1027
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
+
1005
1037
static void
1006
1038
SigHupHandler (SIGNAL_ARGS )
1007
1039
{
@@ -1651,7 +1683,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
1651
1683
if (!IsUnderPostmaster )
1652
1684
{
1653
1685
puts ("\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" );
1655
1687
}
1656
1688
1657
1689
/*
0 commit comments