about summary refs log tree commit diff
path: root/src/libstore/gc.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-01-31T22·01+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-01-31T22·01+0000
commit89c9bc11abc02cc746838bfef101e5fecc59a6c5 (patch)
treeff3f905443476b0c41be7560851cd90b2823b8df /src/libstore/gc.cc
parent207bdcbe86bac5fb9e650d26b22ae33c667151e4 (diff)
* Add a test for a more subtle race: a process starting after the
  temporary root files have been read but creating outputs before the
  store directory has been read.

Diffstat (limited to 'src/libstore/gc.cc')
-rw-r--r--src/libstore/gc.cc22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index af40e0b928..c89f7a8a1e 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -12,10 +12,24 @@
 #include <unistd.h>
 
 
+/* Acquire the global GC lock. */
+static AutoCloseFD openGCLock(LockType lockType)
+{
+#if 0
+    Path fnGCLock = (format("%1%/%2%/%3%")
+        % nixStateDir % tempRootsDir % getpid()).str();
+        
+    fdTempRoots = open(fnTempRoots.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0600);
+    if (fdTempRoots == -1)
+        throw SysError(format("opening temporary roots file `%1%'") % fnTempRoots);
+#endif
+}
+
+
 static string tempRootsDir = "temproots";
 
 /* The file to which we write our temporary roots. */
-Path fnTempRoots;
+static Path fnTempRoots;
 static AutoCloseFD fdTempRoots;
 
 
@@ -213,6 +227,10 @@ void collectGarbage(const PathSet & roots, GCAction action,
         else
             tempRootsClosed.insert(*i);
 
+    /* For testing - see tests/gc-concurrent.sh. */
+    if (getenv("NIX_DEBUG_GC_WAIT"))
+        sleep(2);
+    
     /* After this point the set of roots or temporary roots cannot
        increase, since we hold locks on everything.  So everything
        that is not currently in in `livePaths' or `tempRootsClosed'
@@ -231,7 +249,7 @@ void collectGarbage(const PathSet & roots, GCAction action,
     /* !!! when we have multiple output paths per derivation, this
        will not work anymore because we get cycles. */
     storePaths = topoSort(storePaths2);
-    
+
     for (Paths::iterator i = storePaths.begin(); i != storePaths.end(); ++i) {
 
         debug(format("considering deletion of `%1%'") % *i);