Track whether we think the connection is open in dbopen.

It is now therefore OK to call db-ensure-open and db-ensure-closed in
other contexts.

Signed-off-by: Ian Jackson <ian.jack...@eu.citrix.com>
---
 tcl/JobDB-Executive.tcl | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tcl/JobDB-Executive.tcl b/tcl/JobDB-Executive.tcl
index da9b7e9..1763b69 100644
--- a/tcl/JobDB-Executive.tcl
+++ b/tcl/JobDB-Executive.tcl
@@ -79,6 +79,7 @@ proc set-flight {} {
 }
 
 variable dbusers 0
+variable dbopen 0 ;# 1 means known to be open and good; 0 might mean broken
 
 proc db-open {} {
     variable dbusers
@@ -96,6 +97,11 @@ proc db-close {} {
     db-ensure-closed
 }
 proc db-ensure-open {} {
+    variable dbopen
+
+    if {$dbopen} return
+    catch { db-ensure-closed } ;# clean up any detritus
+
     set pl {
        use Osstest;
        use Osstest::Executive;
@@ -109,8 +115,12 @@ proc db-ensure-open {} {
     # is whitespace-separated.
     regsub -all {;} $db_pg_dsn { } conninfo
     pg_connect -conninfo $conninfo -connhandle dbh
+
+    set dbopen 1
 }
 proc db-ensure-closed {} {
+    variable dbopen
+    set dbopen 0
     pg_disconnect dbh
 }
 
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

Reply via email to