summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-06-25 17:28:59 -0400
committerEudyptula <eitan@mosenkis.net>2009-06-25 17:28:59 -0400
commitb164ea1e21bf01817ae690703640b0ac7fef615e (patch)
tree5a2c1f38d43059b6b01917be599729328a3086c8 /shared
parentAdded logout and user self-registration with email confirmation; Updates to s... (diff)
downloadingenue-b164ea1e21bf01817ae690703640b0ac7fef615e.tar.gz
ingenue-b164ea1e21bf01817ae690703640b0ac7fef615e.tar.bz2
ingenue-b164ea1e21bf01817ae690703640b0ac7fef615e.zip
Added signal handling and logging; wrote init script; added other nice daemon-like behavior to backend
Diffstat (limited to 'shared')
-rw-r--r--shared/classes/0sql_row_obj.php1
-rw-r--r--shared/classes/pdo.php8
-rw-r--r--shared/classes/task.php52
-rw-r--r--shared/classes/user.php3
-rw-r--r--shared/include/dbinit.php4
5 files changed, 47 insertions, 21 deletions
diff --git a/shared/classes/0sql_row_obj.php b/shared/classes/0sql_row_obj.php
index 5c55a62..1db8703 100644
--- a/shared/classes/0sql_row_obj.php
+++ b/shared/classes/0sql_row_obj.php
@@ -47,7 +47,6 @@ abstract class sql_row_obj { // If the name of this class changes, it must be up
// Makes an SQL query using $sql and returns the resulting object
private static function sql_query($q) {
self::check_pdo_obj();
- debug('sql_row_obj::query', $q);
return self::$pdo->query($q);
}
public static function sql_quote_string($s) {
diff --git a/shared/classes/pdo.php b/shared/classes/pdo.php
deleted file mode 100644
index daf71ba..0000000
--- a/shared/classes/pdo.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-class pdo_debug extends PDO {
- function query($q, $a1=null, $a2=null, $a3=null) {
- debug('pdo::query', $q);
- return parent::query($q, $a1, $a2, $a3);
- }
-}
-?>
diff --git a/shared/classes/task.php b/shared/classes/task.php
index 73bde43..ba8db5e 100644
--- a/shared/classes/task.php
+++ b/shared/classes/task.php
@@ -31,8 +31,7 @@ class sql_task extends sql_row_obj {
),
'exit' => array (
'type' => 'TINYINT',
- 'length' => 3,
- 'unsigned' => true
+ 'length' => 3
)
);
@@ -40,7 +39,19 @@ class sql_task extends sql_row_obj {
$html='<div class="task">[<a href="'.url('logs/task'.$this->id).'">log</a>] <span class="command">'.htmlentities($this->command).'</span> ';
if (isset($this->start)) {
if (isset($this->finish)) {
- $html.='<span class="status '.($this->exit==0?'successful">[successful]':'failed">[exit status '.$this->exit.']').'</span> <span class="time">Finished in <span class="time">'.display_time($this->finish-$this->start).'</span></span>';
+ $html.='<span class="status ';
+ if ($this->exit == 0) {
+ $html.='successful">[successful';
+ } else {
+ $html.='failed">[';
+ if ($this->exit > 0)
+ $html.='exit status '.$this->exit;
+ elseif ($this->exit == -128)
+ $html.='got unknown signal';
+ else
+ $html.='got signal '.-$this->exit;
+ }
+ $html.=']</span> <span class="time">Finished in <span class="time">'.display_time($this->finish-$this->start).'</span></span>';
} else {
$html.='<span class="status running">[running]</span> <span class="time">Running for <span class="time">'.display_time(time()-$this->start).'</span></span>';
}
@@ -72,9 +83,9 @@ class sql_task extends sql_row_obj {
}
$msg=0;
while (true) {
- $status=proc_get_status($p);
$null=null; // We have to set these all to variables because stream_select requires pass by reference
- $outs=array($pipes[1], $pipes[2]);
+ $outs=array_slice($pipes, 1);
+ $status=proc_get_status($p); // Get status before the wait so we're sure to get all the output
$s=stream_select($outs, $null, $null, 1);
if ($s) {
$c=stream_get_contents($pipes[2]);
@@ -91,7 +102,16 @@ class sql_task extends sql_row_obj {
}
}
if ($status['running'] === false) {
- $this->exit=$status['exitcode'];
+ if ($status['signaled']) {
+ if ($status['termsig'])
+ $this->exit=-$status['termsig'];
+ elseif ($status['stopsig'])
+ $this->exit=-$status['stopsig'];
+ else
+ // This should never happen
+ $this->exit=-128;
+ } else
+ $this->exit=$status['exitcode'];
break;
}
}
@@ -103,19 +123,29 @@ class sql_task extends sql_row_obj {
$this->exit=proc_close($p);
}
$this->write();
- if ($this->exit == 0) {
+ if ($this->exit == 0)
log_msg(color('[success]', 'green'));
- } else {
+ elseif ($this->exit > 0) {
log_msg(color('[exit code '.$this->exit.']', 'red'));
- if ($fatal) {
+ if ($fatal)
throw_exception($this->command.' returned with exit status '.$this->exit);
- }
+ } elseif ($this->exit == -128) {
+ log_msg(color('[received unknown signal]', 'red'));
+ if ($fatal)
+ throw_exception($this->command.' received an unknown signal');
+ } else {
+ log_msg(color('[received signal '.-$this->exit.']', 'red'));
+ if ($fatal)
+ throw_exception($this->command.' received signal '.-$this->exit);
}
return $this->exit;
}
static function execute_task($command, $build, $fatal=true, $path=null, $env=null) {
+ global $task;
$task=new sql_task(null, is_object($build)?$build->id:$build, $command);
- return $task->execute($fatal, $path, $env);
+ $result=$task->execute($fatal, $path, $env);
+ unset($task);
+ return $result;
}
}
?>
diff --git a/shared/classes/user.php b/shared/classes/user.php
index 49c84c0..91a7a46 100644
--- a/shared/classes/user.php
+++ b/shared/classes/user.php
@@ -35,5 +35,8 @@ class sql_user extends sql_row_obj {
)
);
+ public function hasflag($flag) {
+ return (strpos($this->flags, $flag) !== false);
+ }
}
?>
diff --git a/shared/include/dbinit.php b/shared/include/dbinit.php
index 49b5864..3b19689 100644
--- a/shared/include/dbinit.php
+++ b/shared/include/dbinit.php
@@ -1,5 +1,7 @@
<?php
require_once(dirname(__FILE__).'/../config.php'); // Use __DIR__ in 5.3.0
-$S['pdo']=new pdo_debug('mysql:dbname='.$conf['sqldb'].';host='.$conf['sqlhost'], $conf['sqluser'], $conf['sqlpass']);
+$pdoclass=(class_exists('pdo_debug')?'pdo_debug':'PDO');
+$S['pdo']=new $pdoclass('mysql:dbname='.$conf['sqldb'].';host='.$conf['sqlhost'], $conf['sqluser'], $conf['sqlpass']);
+unset($pdoclass);
sql_row_obj::set_pdo_obj($S['pdo']);
?>