Truncate 64bit int status, error on db failure.
authorAndrew Dunstan <andrew@dunslane.net>
Fri, 17 Feb 2012 18:35:17 +0000 (10:35 -0800)
committerAndrew Dunstan <andrew@dunslane.net>
Fri, 17 Feb 2012 18:35:17 +0000 (10:35 -0800)
Problems noted by Tom Lane, diagnosed and fixed by me.

cgi-bin/pgstatus.pl

index 57a60eddf23e3423f38968d59364852e5cc8ee90..bfe50ce1eb2b368fc91082e176fb1c8c25f04b6e 100755 (executable)
@@ -317,6 +317,8 @@ EOSQL
 # just for the duration of the transaction. That turns off logging the
 # bind params, so all the logs don't get stuffed on the postgres logs
 
+
+my $sqlres;
 $db->begin_work;
 $db->do("select set_local_error_terse()");
 
@@ -341,42 +343,59 @@ $sth->bind_param(14,$scmurl);
 $sth->bind_param(15,$githeadref);
 $sth->bind_param(16,$frozen_sconf,{ pg_type => DBD::Pg::PG_BYTEA });
 
-$sth->execute;
-$sth->finish;
+$sqlres = $sth->execute;
 
+if ($sqlres)
+{
 
+       $sth->finish;
 
-my $logst2 = <<EOSQL;
+       my $logst2 = q{
 
-  insert into build_status_log 
-    (sysname, snapshot, branch, log_stage, log_text, stage_duration)
-    values (?, ?, ?, ?, ?, ?)
+         insert into build_status_log 
+               (sysname, snapshot, branch, log_stage, log_text, stage_duration)
+               values (?, ?, ?, ?, ?, ?)
 
-EOSQL
-    ;
+    };
+
+       $sth = $db->prepare($logst2);
+
+       $/=undef;
+
+       my $stage_start = $ts;
 
-$sth = $db->prepare($logst2);
+       foreach my $log_file( @log_file_names )
+       {
+               next if $log_file =~ /^githead/;
+               my $handle;
+               open($handle,"$dirname/$log_file");
+               my $mtime = (stat $handle)[9];
+               my $stage_interval = $mtime - $stage_start;
+               $stage_start = $mtime;
+               my $ltext = <$handle>;
+               close($handle);
+               $ltext =~ s/\x00/\\0/g;
+               $sqlres = $sth->execute($animal,$dbdate,$branch,$log_file,$ltext, 
+                         "$stage_interval seconds");
+               last unless $sqlres;
+       }
 
-$/=undef;
+       $sth->finish unless $sqlres;
 
-my $stage_start = $ts;
+}
 
-foreach my $log_file( @log_file_names )
+if (! $sqlres)
 {
-    next if $log_file =~ /^githead/;
-    my $handle;
-    open($handle,"$dirname/$log_file");
-    my $mtime = (stat $handle)[9];
-    my $stage_interval = $mtime - $stage_start;
-    $stage_start = $mtime;
-    my $ltext = <$handle>;
-    close($handle);
-    $ltext =~ s/\x00/\\0/g;
-    $sth->execute($animal,$dbdate,$branch,$log_file,$ltext, 
-                 "$stage_interval seconds");
+
+       print "Status: 462 database failure\nContent-Type: text/plain\n\n";
+       print "Your report generated a database failure:\n", 
+              $db->errstr, 
+                        "\n";
+       $db->rollback;
+       $db->disconnect;
+       exit;
 }
 
-$sth->finish;
 
 $db->commit;