about summary refs log tree commit diff
path: root/src/libstore/gc.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-07-20T12·17+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-07-20T12·17+0000
commitc15f544356dfebf6d08887e73fa156d4e70e2bbc (patch)
treefad9d05cb72330af8e96538e160d896b54fd0ca0 /src/libstore/gc.cc
parentebcccbd3581d34d7fefb975c0255a39a3e39e122 (diff)
* Call find-runtime-roots.pl from the garbage collector to prevent
  running applications etc. from being garbage collected.

Diffstat (limited to 'src/libstore/gc.cc')
-rw-r--r--src/libstore/gc.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index 484a5f2bec..3831de4408 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -316,6 +316,31 @@ static void findRoots(const Path & path, bool recurseSymlinks,
 }
 
 
+static void addAdditionalRoots(PathSet & roots)
+{
+    Path rootFinder = getEnv("NIX_ROOT_FINDER",
+        "/nix/libexec/nix/find-runtime-roots.pl"); /* !!! */
+
+    if (rootFinder.empty()) return;
+    
+    printMsg(lvlDebug, format("executing `%1%' to find additional roots") % rootFinder);
+
+    string result = runProgram(rootFinder);
+
+    Strings paths = tokenizeString(result, "\n");
+    
+    for (Strings::iterator i = paths.begin(); i != paths.end(); ++i) {
+        if (isInStore(*i)) {
+            Path path = toStorePath(*i);
+            if (roots.find(path) == roots.end()) {
+                debug(format("found additional root `%1%'") % path);
+                roots.insert(path);
+            }
+        }
+    }
+}
+
+
 static void dfsVisit(const PathSet & paths, const Path & path,
     PathSet & visited, Paths & sorted)
 {
@@ -370,6 +395,12 @@ void collectGarbage(GCAction action, const PathSet & pathsToDelete,
     if (!ignoreLiveness)
         findRoots(rootsDir, true, roots);
 
+    /* Add additional roots returned by the program specified by the
+       NIX_ROOT_FINDER environment variable.  This is typically used
+       to add running programs to the set of roots (to prevent them
+       from being garbage collected). */
+    addAdditionalRoots(roots);
+
     if (action == gcReturnRoots) {
         result = roots;
         return;