summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorBruce Momjian2008-04-15 20:28:47 +0000
committerBruce Momjian2008-04-15 20:28:47 +0000
commit76365960d229dca0ad8454040233e3eaaeb413bb (patch)
treebabcf9c5edbe051dcd83178c7459fcd7ad0f5e5e /src/backend
parent2b8a795738ee6885044a5d022a4bc1418190c011 (diff)
Revert addition of pg_terminate_backend() because of race conditions.
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/tcop/postgres.c12
-rw-r--r--src/backend/utils/adt/misc.c63
2 files changed, 16 insertions, 59 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 60519bd8a9..d4f84d549b 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.549 2008/04/15 13:55:11 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.550 2008/04/15 20:28:46 momjian Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@@ -2541,8 +2541,7 @@ StatementCancelHandler(SIGNAL_ARGS)
* waiting for input, however.
*/
if (ImmediateInterruptOK && InterruptHoldoffCount == 0 &&
- CritSectionCount == 0 &&
- (!DoingCommandRead || MyProc->terminate))
+ CritSectionCount == 0 && !DoingCommandRead)
{
/* bump holdoff count to make ProcessInterrupts() a no-op */
/* until we are done getting ready for it */
@@ -2622,10 +2621,6 @@ ProcessInterrupts(void)
ereport(ERROR,
(errcode(ERRCODE_QUERY_CANCELED),
errmsg("canceling autovacuum task")));
- else if (MyProc->terminate)
- ereport(ERROR,
- (errcode(ERRCODE_ADMIN_SHUTDOWN),
- errmsg("terminating backend due to administrator command")));
else
ereport(ERROR,
(errcode(ERRCODE_QUERY_CANCELED),
@@ -3464,9 +3459,6 @@ PostgresMain(int argc, char *argv[], const char *username)
/* We don't have a transaction command open anymore */
xact_started = false;
- if (MyProc->terminate)
- die(SIGINT);
-
/* Now we can allow interrupts again */
RESUME_INTERRUPTS();
}
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index d5e794abee..5542f87744 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.60 2008/04/15 13:55:11 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.61 2008/04/15 20:28:46 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -27,7 +27,6 @@
#include "postmaster/syslogger.h"
#include "storage/fd.h"
#include "storage/pmsignal.h"
-#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/builtins.h"
#include "tcop/tcopprot.h"
@@ -90,7 +89,7 @@ current_query(PG_FUNCTION_ARGS)
* Functions to send signals to other backends.
*/
static bool
-pg_signal_check(int pid)
+pg_signal_backend(int pid, int sig)
{
if (!superuser())
ereport(ERROR,
@@ -107,16 +106,7 @@ pg_signal_check(int pid)
(errmsg("PID %d is not a PostgreSQL server process", pid)));
return false;
}
- else
- return true;
-}
-/*
- * Functions to send signals to other backends.
- */
-static bool
-pg_signal_backend(int pid, int sig)
-{
/* If we have setsid(), signal the backend's whole process group */
#ifdef HAVE_SETSID
if (kill(-pid, sig))
@@ -135,43 +125,7 @@ pg_signal_backend(int pid, int sig)
Datum
pg_cancel_backend(PG_FUNCTION_ARGS)
{
- int pid = PG_GETARG_INT32(0);
-
- if (pg_signal_check(pid))
- PG_RETURN_BOOL(pg_signal_backend(pid, SIGINT));
- else
- PG_RETURN_BOOL(false);
-}
-
-/*
- * To cleanly terminate a backend, we set PGPROC(pid)->terminate
- * then send a cancel signal. We get ProcArrayLock only when
- * setting PGPROC->terminate so the function might fail in
- * several places, but that is fine because in those cases the
- * backend is already gone.
- */
-Datum
-pg_terminate_backend(PG_FUNCTION_ARGS)
-{
- int pid = PG_GETARG_INT32(0);
- volatile PGPROC *term_proc;
-
- /* Is this the super-user, and can we find the PGPROC entry for the pid? */
- if (pg_signal_check(pid) && (term_proc = BackendPidGetProc(pid)) != NULL)
- {
- LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
- /* Recheck now that we have the ProcArray lock. */
- if (term_proc->pid == pid)
- {
- term_proc->terminate = true;
- LWLockRelease(ProcArrayLock);
- PG_RETURN_BOOL(pg_signal_backend(pid, SIGINT));
- }
- else
- LWLockRelease(ProcArrayLock);
- }
-
- PG_RETURN_BOOL(false);
+ PG_RETURN_BOOL(pg_signal_backend(PG_GETARG_INT32(0), SIGINT));
}
Datum
@@ -215,6 +169,17 @@ pg_rotate_logfile(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(true);
}
+#ifdef NOT_USED
+
+/* Disabled in 8.0 due to reliability concerns; FIXME someday */
+Datum
+pg_terminate_backend(PG_FUNCTION_ARGS)
+{
+ PG_RETURN_INT32(pg_signal_backend(PG_GETARG_INT32(0), SIGTERM));
+}
+#endif
+
+
/* Function to find out which databases make use of a tablespace */
typedef struct