From 96accebc049a48754a33c00d7d5dd7ff361cd66e Mon Sep 17 00:00:00 2001 From: chriskl Date: Thu, 8 Jul 2004 03:23:01 +0000 Subject: [PATCH] Support cancelling and killing backend processes in 7.5 --- HISTORY | 1 + classes/Misc.php | 4 +-- classes/database/BaseDB.php | 3 ++- classes/database/Postgres75.php | 31 ++++++++++++++++++++++- database.php | 45 ++++++++++++++++++++++++++++----- lang/english.php | 5 +++- lang/recoded/english.php | 5 +++- 7 files changed, 82 insertions(+), 12 deletions(-) diff --git a/HISTORY b/HISTORY index 09b7c218..cf137e4e 100644 --- a/HISTORY +++ b/HISTORY @@ -8,6 +8,7 @@ Features * Context-sensitive online help system * Use language preferencies from browser (Markus Bertheau, Nicola Soranzo) * Tablespace support for 7.5 +* Support cancelling and killing backend processes in 7.5 Translations * Arabic from Zaki diff --git a/classes/Misc.php b/classes/Misc.php index 44564ed2..a2bf4155 100644 --- a/classes/Misc.php +++ b/classes/Misc.php @@ -2,7 +2,7 @@ /** * Class to hold various commonly used functions * - * $Id: Misc.php,v 1.67 2004/07/07 03:00:01 chriskl Exp $ + * $Id: Misc.php,v 1.68 2004/07/08 03:23:01 chriskl Exp $ */ class Misc { @@ -691,7 +691,7 @@ function printTable(&$tabledata, &$columns, &$actions, $nodata = null, $pre_fn = null) { global $data, $conf, $misc; global $PHP_SELF; - + if ($tabledata->recordCount() > 0) { // Remove the 'comment' column if they have been disabled diff --git a/classes/database/BaseDB.php b/classes/database/BaseDB.php index 4f355873..7b337b3a 100644 --- a/classes/database/BaseDB.php +++ b/classes/database/BaseDB.php @@ -4,7 +4,7 @@ * A class that implements the DB interface for Postgres * Note: This class uses ADODB and returns RecordSets. * - * $Id: BaseDB.php,v 1.49 2004/07/04 15:02:35 chriskl Exp $ + * $Id: BaseDB.php,v 1.50 2004/07/08 03:23:02 chriskl Exp $ */ include_once('./classes/database/ADODB_base.php'); @@ -283,6 +283,7 @@ class BaseDB extends ADODB_base { function hasForeignKeysInfo() { return false; } function hasViewColumnRename() { return false; } function hasTablespaces() { return false; } + function hasSignals() { return false; } } diff --git a/classes/database/Postgres75.php b/classes/database/Postgres75.php index c71cefa2..42f37da6 100755 --- a/classes/database/Postgres75.php +++ b/classes/database/Postgres75.php @@ -3,7 +3,7 @@ /** * PostgreSQL 7.5 support * - * $Id: Postgres75.php,v 1.9 2004/07/07 03:00:07 chriskl Exp $ + * $Id: Postgres75.php,v 1.10 2004/07/08 03:23:02 chriskl Exp $ */ include_once('./classes/database/Postgres74.php'); @@ -267,11 +267,40 @@ class Postgres75 extends Postgres74 { return $this->endTransaction(); } + + // Backend process signalling functions + + /** + * Sends a cancel or kill command to a process + * @param $pid The ID of the backend process + * @param $signal 'CANCEL' or 'KILL' + * @return 0 success + * @return -1 invalid signal type + */ + function sendSignal($pid, $signal) { + // Clean + $pid = (int)$pid; + + if ($signal == 'CANCEL') + $sql = "SELECT pg_catalog.pg_cancel_backend({$pid}) AS val"; + elseif ($signal == 'KILL') + $sql = "SELECT pg_catalog.pg_terminate_backend({$pid}) AS val"; + else + return -1; + + // Execute the query + $val = $this->selectField($sql, 'val'); + if ($val === -1) return -1; + elseif ($val == '1') return 0; + else return -1; + } + function hasAlterColumnType() { return true; } function hasTablespaces() { $platform = $this->getPlatform(); return $platform != 'MINGW'; } + function hasSignals() { return true; } } diff --git a/database.php b/database.php index ca45b444..ab590706 100755 --- a/database.php +++ b/database.php @@ -3,7 +3,7 @@ /** * Manage schemas within a database * - * $Id: database.php,v 1.50 2004/07/07 02:59:56 chriskl Exp $ + * $Id: database.php,v 1.51 2004/07/08 03:23:01 chriskl Exp $ */ // Include application functions @@ -17,6 +17,19 @@ return str_replace($term, "{$term}", $string); } + /** + * Sends a signal to a process + */ + function doSignal() { + global $data, $lang; + + $status = $data->sendSignal($_REQUEST['procpid'], $_REQUEST['signal']); + if ($status == 0) + doProcesses($lang['strsignalsent']); + else + doProcesses($lang['strsignalsentbad']); + } + /** * Searches for a named database object */ @@ -314,7 +327,7 @@ * Show all current database connections and any queries they * are running. */ - function doProcesses() { + function doProcesses($msg = '') { global $PHP_SELF, $data, $misc; global $lang; @@ -322,8 +335,9 @@ $processes = &$data->getProcesses($_REQUEST['database']); $misc->printDatabaseNav(); - $misc->printTitle(array($misc->printVal($_REQUEST['database']),$lang['strprocesses']),'processes'); - + $misc->printTitle(array($misc->printVal($_REQUEST['database']), $lang['strprocesses']), 'processes'); + $misc->printMsg($msg); + $columns = array( 'user' => array( 'title' => $lang['strusername'], @@ -342,8 +356,24 @@ 'field' => 'query_start', ), ); - - $actions = array(); + + if ($data->hasSignals()) { + $columns['actions'] = array('title' => $lang['stractions']); + + $actions = array( + 'cancel' => array( + 'title' => $lang['strcancel'], + 'url' => "{$PHP_SELF}?action=signal&signal=CANCEL&database=" . urlencode($_REQUEST['database']) . "&", + 'vars' => array('procpid' => 'procpid') + ), + 'kill' => array( + 'title' => $lang['strkill'], + 'url' => "{$PHP_SELF}?action=signal&signal=KILL&database=" . urlencode($_REQUEST['database']) . "&", + 'vars' => array('procpid' => 'procpid') + ) + ); + } + else $actions = array(); // Remove query start time for <7.4 if (!isset($processes->f['query_start'])) unset($columns['start_time']); @@ -713,6 +743,9 @@ case 'export': doExport(); break; + case 'signal': + doSignal(); + break; default: if ($data->hasSchemas()) doDefault(); diff --git a/lang/english.php b/lang/english.php index 7d2335a9..246bcfc6 100755 --- a/lang/english.php +++ b/lang/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.151 2004/07/07 03:00:07 chriskl Exp $ + * $Id: english.php,v 1.152 2004/07/08 03:23:02 chriskl Exp $ */ // Language and character set @@ -124,6 +124,7 @@ $lang['strstarttime'] = 'Start Time'; $lang['strfile'] = 'File'; $lang['strfileimported'] = 'File imported.'; + $lang['strkill'] = 'Kill'; // Error handling $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.'; @@ -286,6 +287,8 @@ $lang['strfull'] = 'Full'; $lang['strfreeze'] = 'Freeze'; $lang['strforce'] = 'Force'; + $lang['strsignalsent'] = 'Signal sent.'; + $lang['strsignalsentbad'] = 'Failed sending signal.'; // Views $lang['strview'] = 'View'; diff --git a/lang/recoded/english.php b/lang/recoded/english.php index f157b41a..0b4a9590 100644 --- a/lang/recoded/english.php +++ b/lang/recoded/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.104 2004/07/07 03:00:07 chriskl Exp $ + * $Id: english.php,v 1.105 2004/07/08 03:23:02 chriskl Exp $ */ // Language and character set @@ -124,6 +124,7 @@ $lang['strstarttime'] = 'Start Time'; $lang['strfile'] = 'File'; $lang['strfileimported'] = 'File imported.'; + $lang['strkill'] = 'Kill'; // Error handling $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.'; @@ -286,6 +287,8 @@ $lang['strfull'] = 'Full'; $lang['strfreeze'] = 'Freeze'; $lang['strforce'] = 'Force'; + $lang['strsignalsent'] = 'Signal sent.'; + $lang['strsignalsentbad'] = 'Failed sending signal.'; // Views $lang['strview'] = 'View'; -- 2.39.5