about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-09-14T13·02+0200
committerEelco Dolstra <edolstra@gmail.com>2017-09-14T13·02+0200
commit308ecf63611c858327f163a154a3216fd6195ed9 (patch)
treeced86271a6d757c5537702089dfbc40ef4bfd7a7
parentda1e4fdfb54e0a69dd145180cae1eb7a0afd1b26 (diff)
Show the pid of temporary roots
-rw-r--r--src/libstore/gc.cc25
-rw-r--r--src/libstore/local-store.hh2
2 files changed, 16 insertions, 11 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index fbc96f583efc..ab2c5ca0274c 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -196,17 +196,17 @@ void LocalStore::addTempRoot(const Path & path)
 }
 
 
-PathSet LocalStore::readTempRoots(FDs & fds)
+std::set<std::pair<pid_t, Path>> LocalStore::readTempRoots(FDs & fds)
 {
-    PathSet tempRoots;
+    std::set<std::pair<pid_t, Path>> tempRoots;
 
     /* Read the `temproots' directory for per-process temporary root
        files. */
-    DirEntries tempRootFiles = readDirectory(tempRootsDir);
-
-    for (auto & i : tempRootFiles) {
+    for (auto & i : readDirectory(tempRootsDir)) {
         Path path = tempRootsDir + "/" + i.name;
 
+        pid_t pid = std::stoi(i.name);
+
         debug(format("reading temporary root file '%1%'") % path);
         FDPtr fd(new AutoCloseFD(open(path.c_str(), O_CLOEXEC | O_RDWR, 0666)));
         if (!*fd) {
@@ -247,9 +247,9 @@ PathSet LocalStore::readTempRoots(FDs & fds)
 
         while ((end = contents.find((char) 0, pos)) != string::npos) {
             Path root(contents, pos, end - pos);
-            debug(format("got temporary root '%1%'") % root);
+            debug("got temporary root '%s'", root);
             assertStorePath(root);
-            tempRoots.insert(root);
+            tempRoots.emplace(pid, root);
             pos = end + 1;
         }
 
@@ -347,9 +347,13 @@ Roots LocalStore::findRoots()
     Roots roots = findRootsNoTemp();
 
     FDs fds;
+    pid_t prev = -1;
     size_t n = 0;
-    for (auto & root : readTempRoots(fds))
-        roots[fmt("{temp:%d}", n++)] = root;
+    for (auto & root : readTempRoots(fds)) {
+        if (prev != root.first) n = 0;
+        prev = root.first;
+        roots[fmt("{temp:%d:%d}", root.first, n++)] = root.second;
+    }
 
     return roots;
 }
@@ -756,7 +760,8 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
        per-process temporary root files.  So after this point no paths
        can be added to the set of temporary roots. */
     FDs fds;
-    state.tempRoots = readTempRoots(fds);
+    for (auto & root : readTempRoots(fds))
+        state.tempRoots.insert(root.second);
     state.roots.insert(state.tempRoots.begin(), state.tempRoots.end());
 
     /* After this point the set of roots or temporary roots cannot
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index 62a11a94a5e4..0a3841133e5d 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -176,7 +176,7 @@ private:
     typedef std::shared_ptr<AutoCloseFD> FDPtr;
     typedef list<FDPtr> FDs;
 
-    PathSet readTempRoots(FDs & fds);
+    std::set<std::pair<pid_t, Path>> readTempRoots(FDs & fds);
 
 public: