watchdog fix

svn path=/trunk/boinc/; revision=1099
This commit is contained in:
David Anderson 2003-03-25 19:16:54 +00:00
parent 842aadcf0f
commit 1b94875dd7
1 changed files with 18 additions and 7 deletions

View File

@ -22,18 +22,26 @@ function read_count_file() {
}
$lines = file("nresults");
if (!$lines) return false;
return $lines[0];
return $lines;
}
function write_count_file($n) {
function write_count_file($n,$m) {
$f = fopen("nresults", "w");
if (!$f) return false;
$x = sprintf("%d", $n);
$x = sprintf("%d\n%d", $n, $m);
fwrite($f, $x);
fclose($f);
return true;
}
function get_working_count_from_db() {
$result = mysql_query("select count(*) from result where server_state = 4");
if (!$result) return false;
$count = mysql_fetch_array($result);
mysql_free_result($result);
return $count[0];
}
function get_count_from_db() {
$result = mysql_query("select count(*) from result");
if (!$result) return false;
@ -50,15 +58,18 @@ function get_count_from_db() {
if ($m == false) {
fail("Can't get result count from DB\n");
}
$p = get_working_count_from_db();
if ($p == false) {
fail("Can't get working result count from DB\n");
}
$n = read_count_file();
if ($n == false) {
write_count_file($m);
write_count_file($m,$p);
exit();
}
if ($n == $m) {
//echo "fail\n";
if (trim($n[0]) == $m && trim($n[1]) == $p) {
fail("Result count hasn't changed\n");
}
write_count_file($m);
write_count_file($m,$p);
?>