Commit 09c5e840 authored by Tom Lane's avatar Tom Lane

Change elog(ERROR) to get back to main loop via a plain sigsetjmp,

instead of doing a kill(self, SIGQUIT) and expecting the signal handler
to do it.  Also, clean up inconsistent definitions of the sigjmp buffer
in the several files that already referenced it.
parent d30e2ac3
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.57 1999/03/25 03:49:25 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.58 1999/04/20 02:19:53 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -184,24 +184,6 @@ static char *values[MAXATTR]; /* cooresponding attribute values */ ...@@ -184,24 +184,6 @@ static char *values[MAXATTR]; /* cooresponding attribute values */
int numattr; /* number of attributes for cur. rel */ int numattr; /* number of attributes for cur. rel */
extern bool disableFsync; /* do not fsync the database */ extern bool disableFsync; /* do not fsync the database */
/* The test for HAVE_SIGSETJMP fails on Linux 2.0.x because the test
* explicitly disallows sigsetjmp being a #define, which is how it
* is declared in Linux. So, to avoid compiler warnings about
* sigsetjmp() being redefined, let's not redefine unless necessary.
* - thomas 1997-12-27
*/
#if !defined(HAVE_SIGSETJMP) && !defined(sigsetjmp)
static jmp_buf Warn_restart;
#define sigsetjmp(x,y) setjmp(x)
#define siglongjmp longjmp
#else
static sigjmp_buf Warn_restart;
#endif
int DebugMode; int DebugMode;
static GlobalMemory nogc = (GlobalMemory) NULL; /* special no-gc mem static GlobalMemory nogc = (GlobalMemory) NULL; /* special no-gc mem
* context */ * context */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.106 1999/03/22 16:45:27 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.107 1999/04/20 02:19:53 tgl Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <time.h> #include <time.h>
#include <setjmp.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -136,15 +135,8 @@ static bool IsEmptyQuery = false; ...@@ -136,15 +135,8 @@ static bool IsEmptyQuery = false;
char relname[80]; /* current relation name */ char relname[80]; /* current relation name */
#if defined(nextstep) /* note: these declarations had better match tcopprot.h */
jmp_buf Warn_restart;
#define sigsetjmp(x,y) setjmp(x)
#define siglongjmp longjmp
#else
DLLIMPORT sigjmp_buf Warn_restart; DLLIMPORT sigjmp_buf Warn_restart;
#endif /* defined(nextstep) */
bool InError; bool InError;
extern int NBuffers; extern int NBuffers;
...@@ -829,8 +821,15 @@ pg_exec_query_dest(char *query_string, /* string to execute */ ...@@ -829,8 +821,15 @@ pg_exec_query_dest(char *query_string, /* string to execute */
/* -------------------------------- /* --------------------------------
* signal handler routines used in PostgresMain() * signal handler routines used in PostgresMain()
* *
* handle_warn() is used to catch kill(getpid(),SIGQUIT) which * handle_warn() catches SIGQUIT. It forces control back to the main
* occurs when elog(ERROR) is called. * loop, just as if an internal error (elog(ERROR,...)) had occurred.
* elog() used to actually use kill(2) to induce a SIGQUIT to get here!
* But that's not 100% reliable on some systems, so now it does its own
* siglongjmp() instead.
* We still provide the signal catcher so that an error quit can be
* forced externally. This should be done only with great caution,
* however, since an asynchronous signal could leave the system in
* who-knows-what inconsistent state.
* *
* quickdie() occurs when signalled by the postmaster. * quickdie() occurs when signalled by the postmaster.
* Some backend has bought the farm, * Some backend has bought the farm,
...@@ -1531,7 +1530,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1531,7 +1530,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.106 $ $Date: 1999/03/22 16:45:27 $\n"); puts("$Revision: 1.107 $ $Date: 1999/04/20 02:19:53 $\n");
} }
/* ---------------- /* ----------------
...@@ -1543,8 +1542,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1543,8 +1542,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
* so that the slaves signal the master to abort the transaction * so that the slaves signal the master to abort the transaction
* rather than calling AbortCurrentTransaction() themselves. * rather than calling AbortCurrentTransaction() themselves.
* *
* Note: elog(ERROR) causes a kill(getpid(),SIGQUIT) to occur * Note: elog(ERROR) does a siglongjmp() to transfer control here.
* sending us back here.
* ---------------- * ----------------
*/ */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.40 1999/04/16 06:38:17 ishii Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.41 1999/04/20 02:19:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "miscadmin.h" #include "miscadmin.h"
#include "libpq/libpq.h" #include "libpq/libpq.h"
#include "storage/proc.h" #include "storage/proc.h"
#include "tcop/tcopprot.h"
#include "utils/trace.h" #include "utils/trace.h"
#ifdef USE_SYSLOG #ifdef USE_SYSLOG
...@@ -216,24 +217,12 @@ elog(int lev, const char *fmt,...) ...@@ -216,24 +217,12 @@ elog(int lev, const char *fmt,...)
if (lev == ERROR) if (lev == ERROR)
{ {
extern bool InError;
ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */ ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */
if (!InError) if (!InError)
{ {
if (MyProcPid == 0) { /* exit to main loop */
kill(getpid(), SIGQUIT); siglongjmp(Warn_restart, 1);
} else {
kill(MyProcPid, SIGQUIT); /* abort to traffic cop */
}
pause();
} }
/*
* The pause(3) is just to avoid race conditions where the thread
* of control on an MP system gets past here (i.e., the signal is
* not received instantaneously).
*/
} }
if (lev == FATAL) if (lev == FATAL)
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: tcopprot.h,v 1.17 1999/02/13 23:22:13 momjian Exp $ * $Id: tcopprot.h,v 1.18 1999/04/20 02:19:55 tgl Exp $
* *
* OLD COMMENTS * OLD COMMENTS
* This file was created so that other c files could get the two * This file was created so that other c files could get the two
...@@ -18,8 +18,26 @@ ...@@ -18,8 +18,26 @@
#ifndef TCOPPROT_H #ifndef TCOPPROT_H
#define TCOPPROT_H #define TCOPPROT_H
#include <executor/execdesc.h> #include <setjmp.h>
#include <parser/parse_node.h> #include "executor/execdesc.h"
#include "parser/parse_node.h"
/* Autoconf's test for HAVE_SIGSETJMP fails on Linux 2.0.x because the test
* explicitly disallows sigsetjmp being a #define, which is how it
* is declared in Linux. So, to avoid compiler warnings about
* sigsetjmp() being redefined, let's not redefine unless necessary.
* - thomas 1997-12-27
* Autoconf really ought to be brighter about macro-ized system functions...
* and this code really ought to be in config.h ...
*/
#if !defined(HAVE_SIGSETJMP) && !defined(sigsetjmp)
#define sigjmp_buf jmp_buf
#define sigsetjmp(x,y) setjmp(x)
#define siglongjmp longjmp
#endif
extern DLLIMPORT sigjmp_buf Warn_restart;
extern bool InError;
#ifndef BOOTSTRAP_INCLUDE #ifndef BOOTSTRAP_INCLUDE
extern List *pg_parse_and_plan(char *query_string, Oid *typev, int nargs, extern List *pg_parse_and_plan(char *query_string, Oid *typev, int nargs,
...@@ -30,7 +48,7 @@ extern void pg_exec_query_acl_override(char *query_string); ...@@ -30,7 +48,7 @@ extern void pg_exec_query_acl_override(char *query_string);
extern void extern void
pg_exec_query_dest(char *query_string, CommandDest dest, bool aclOverride); pg_exec_query_dest(char *query_string, CommandDest dest, bool aclOverride);
#endif /* BOOTSTRAP_HEADER */ #endif /* BOOTSTRAP_INCLUDE */
extern void handle_warn(SIGNAL_ARGS); extern void handle_warn(SIGNAL_ARGS);
extern void quickdie(SIGNAL_ARGS); extern void quickdie(SIGNAL_ARGS);
...@@ -42,4 +60,4 @@ extern int PostgresMain(int argc, char *argv[], ...@@ -42,4 +60,4 @@ extern int PostgresMain(int argc, char *argv[],
extern void ResetUsage(void); extern void ResetUsage(void);
extern void ShowUsage(void); extern void ShowUsage(void);
#endif /* tcopprotIncluded */ #endif /* TCOPPROT_H */
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.8 1999/03/22 16:45:30 momjian Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.9 1999/04/20 02:19:57 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -55,28 +55,12 @@ ...@@ -55,28 +55,12 @@
#include "fmgr.h" #include "fmgr.h"
#include "access/heapam.h" #include "access/heapam.h"
#include "tcop/tcopprot.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
/************************************************************
* Make Warn_restart from tcop/postgres.c visible for us.
* The longjmp() mechanism of the elog(ERROR,...) makes it
* impossible for us to call exceptions. But at least I
* would like some suggestions about where in the PL function
* the error occured.
*
* It's ugly - Jan
************************************************************/
#if defined(nextstep)
#define sigjmp_buf jmp_buf
#define sigsetjmp(x,y) setjmp(x)
#define siglongjmp longjmp
#endif
extern DLLIMPORT sigjmp_buf Warn_restart; /* in tcop/postgres.c */
static PLpgSQL_function *error_info_func = NULL; static PLpgSQL_function *error_info_func = NULL;
static PLpgSQL_stmt *error_info_stmt = NULL; static PLpgSQL_stmt *error_info_stmt = NULL;
static char *error_info_text = NULL; static char *error_info_text = NULL;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* procedural language (PL) * procedural language (PL)
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.8 1998/11/27 20:05:27 vadim Exp $ * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.9 1999/04/20 02:19:59 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "fmgr.h" #include "fmgr.h"
#include "access/heapam.h" #include "access/heapam.h"
#include "tcop/tcopprot.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
...@@ -90,23 +91,6 @@ typedef struct pltcl_query_desc ...@@ -90,23 +91,6 @@ typedef struct pltcl_query_desc
} pltcl_query_desc; } pltcl_query_desc;
/************************************************************
* Make Warn_restart from tcop/postgres.c visible for us.
* The longjmp() mechanism of the elog(ERROR,...) restart let's
* interpreter levels lay around. So we must tidy up in that
* case and thus, we have to catch the longjmp's sometimes to
* return though all the interpreter levels back.
*
* It's ugly - Jan
************************************************************/
#if defined(nextstep)
#define sigjmp_buf jmp_buf
#define sigsetjmp(x,y) setjmp(x)
#define siglongjmp longjmp
#endif
extern sigjmp_buf Warn_restart; /* in tcop/postgres.c */
/********************************************************************** /**********************************************************************
* Global data * Global data
**********************************************************************/ **********************************************************************/
......
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