about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-03-01T16·36+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-03-01T16·36+0000
commitd822bf32e470e46a3634638fee3c4b1472d2cd26 (patch)
tree031d79cc5f4bd420d3a601ab8de923d351b59766
parentfa95f4be3f4df6ebe4d49ec57a66129f645e36c7 (diff)
* Close the database before the destructor runs.
-rw-r--r--src/libmain/shared.cc3
-rw-r--r--src/libstore/db.cc2
-rw-r--r--src/libstore/store.cc7
-rw-r--r--src/libstore/store.hh3
4 files changed, 15 insertions, 0 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index a832344c9c49..1e48a6365220 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -14,6 +14,7 @@ extern "C" {
 
 #include "globals.hh"
 #include "gc.hh"
+#include "store.hh"
 #include "shared.hh"
 
 #include "config.h"
@@ -213,6 +214,8 @@ static void initAndRun(int argc, char * * argv)
     RemoveTempRoots removeTempRoots; /* unused variable - don't remove */
 
     run(remaining);
+
+    closeDB(); /* it's fine if the DB isn't actually open */
 }
 
 
diff --git a/src/libstore/db.cc b/src/libstore/db.cc
index 448b70e6ccbc..667951ae7b84 100644
--- a/src/libstore/db.cc
+++ b/src/libstore/db.cc
@@ -278,6 +278,8 @@ void Database::close()
     } catch (DbException e) { rethrow(e); }
 
     delete env;
+
+    env = 0;
 }
 
 
diff --git a/src/libstore/store.cc b/src/libstore/store.cc
index 94c992f22936..e792fd28cedc 100644
--- a/src/libstore/store.cc
+++ b/src/libstore/store.cc
@@ -136,6 +136,13 @@ void initDB()
 }
 
 
+void closeDB()
+{
+    /* If the database isn't open, this is a NOP. */
+    nixDB.close();
+}
+
+
 void createStoreTransaction(Transaction & txn)
 {
     Transaction txn2(nixDB);
diff --git a/src/libstore/store.hh b/src/libstore/store.hh
index c617585bab96..a170c69e7477 100644
--- a/src/libstore/store.hh
+++ b/src/libstore/store.hh
@@ -49,6 +49,9 @@ void openDB(bool reserveSpace = true);
 /* Create the required database tables. */
 void initDB();
 
+/* Close the database. */
+void closeDB();
+
 /* Get a transaction object. */
 void createStoreTransaction(Transaction & txn);