88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.60 2008/04/1513:55:11 momjian Exp $
11+ * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.61 2008/04/1520:28:46 momjian Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
2727#include "postmaster/syslogger.h"
2828#include "storage/fd.h"
2929#include "storage/pmsignal.h"
30- #include "storage/proc.h"
3130#include "storage/procarray.h"
3231#include "utils/builtins.h"
3332#include "tcop/tcopprot.h"
@@ -90,7 +89,7 @@ current_query(PG_FUNCTION_ARGS)
9089 * Functions to send signals to other backends.
9190 */
9291static bool
93- pg_signal_check (int pid )
92+ pg_signal_backend (int pid , int sig )
9493{
9594if (!superuser ())
9695ereport (ERROR ,
@@ -107,16 +106,7 @@ pg_signal_check(int pid)
107106(errmsg ("PID %d is not a PostgreSQL server process" ,pid )));
108107return false;
109108}
110- else
111- return true;
112- }
113109
114- /*
115- * Functions to send signals to other backends.
116- */
117- static bool
118- pg_signal_backend (int pid ,int sig )
119- {
120110/* If we have setsid(), signal the backend's whole process group */
121111#ifdef HAVE_SETSID
122112if (kill (- pid ,sig ))
@@ -135,43 +125,7 @@ pg_signal_backend(int pid, int sig)
135125Datum
136126pg_cancel_backend (PG_FUNCTION_ARGS )
137127{
138- int pid = PG_GETARG_INT32 (0 );
139-
140- if (pg_signal_check (pid ))
141- PG_RETURN_BOOL (pg_signal_backend (pid ,SIGINT ));
142- else
143- PG_RETURN_BOOL (false);
144- }
145-
146- /*
147- *To cleanly terminate a backend, we set PGPROC(pid)->terminate
148- *then send a cancel signal. We get ProcArrayLock only when
149- *setting PGPROC->terminate so the function might fail in
150- *several places, but that is fine because in those cases the
151- *backend is already gone.
152- */
153- Datum
154- pg_terminate_backend (PG_FUNCTION_ARGS )
155- {
156- int pid = PG_GETARG_INT32 (0 );
157- volatile PGPROC * term_proc ;
158-
159- /* Is this the super-user, and can we find the PGPROC entry for the pid? */
160- if (pg_signal_check (pid )&& (term_proc = BackendPidGetProc (pid ))!= NULL )
161- {
162- LWLockAcquire (ProcArrayLock ,LW_EXCLUSIVE );
163- /* Recheck now that we have the ProcArray lock. */
164- if (term_proc -> pid == pid )
165- {
166- term_proc -> terminate = true;
167- LWLockRelease (ProcArrayLock );
168- PG_RETURN_BOOL (pg_signal_backend (pid ,SIGINT ));
169- }
170- else
171- LWLockRelease (ProcArrayLock );
172- }
173-
174- PG_RETURN_BOOL (false);
128+ PG_RETURN_BOOL (pg_signal_backend (PG_GETARG_INT32 (0 ),SIGINT ));
175129}
176130
177131Datum
@@ -215,6 +169,17 @@ pg_rotate_logfile(PG_FUNCTION_ARGS)
215169PG_RETURN_BOOL (true);
216170}
217171
172+ #ifdef NOT_USED
173+
174+ /* Disabled in 8.0 due to reliability concerns; FIXME someday */
175+ Datum
176+ pg_terminate_backend (PG_FUNCTION_ARGS )
177+ {
178+ PG_RETURN_INT32 (pg_signal_backend (PG_GETARG_INT32 (0 ),SIGTERM ));
179+ }
180+ #endif
181+
182+
218183/* Function to find out which databases make use of a tablespace */
219184
220185typedef struct