From 89c9bc11abc02cc746838bfef101e5fecc59a6c5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 31 Jan 2005 22:01:55 +0000 Subject: * 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. --- src/libstore/gc.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/libstore/gc.cc') diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index af40e0b9286a..c89f7a8a1ee4 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -12,10 +12,24 @@ #include +/* 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); -- cgit 1.4.1