diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-03-14T12·27+0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-03-14T12·30+0100 |
commit | a3f37d87eabcfb5dc581abcfa46e5e7d387dfa8c (patch) | |
tree | 926932c125326ce08609e9cce338051ec256ffe5 /src/libstore | |
parent | 115e2c8c67a949d3fa78fda450186803cd713958 (diff) |
findRuntimeRoots: Simplify/fix handling of /proc files
Scanning of /proc/<pid>/{exe,cwd} was broken because '{memory:' was prepended twice. Also, get rid of the whole '{memory:...}' thing because it's unnecessary, we can just list the file in /proc directly.
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/gc.cc | 26 | ||||
-rw-r--r-- | src/libstore/store-api.hh | 3 |
2 files changed, 14 insertions, 15 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 2a314035436f..8c3607f66149 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -362,8 +362,7 @@ try_again: } if (res > 0 && buf[0] == '/') roots[std::string(static_cast<char *>(buf), res)] - .emplace((format("{memory:%1%") % file).str()); - return; + .emplace(file); } static string quoteRegexChars(const string & raw) @@ -395,10 +394,10 @@ void LocalStore::findRuntimeRoots(Roots & roots) while (errno = 0, ent = readdir(procDir.get())) { checkInterrupt(); if (std::regex_match(ent->d_name, digitsRegex)) { - readProcLink((format("{memory:/proc/%1%/exe}") % ent->d_name).str(), unchecked); - readProcLink((format("{memory:/proc/%1%/cwd}") % ent->d_name).str(), unchecked); + readProcLink(fmt("/proc/%s/exe" ,ent->d_name), unchecked); + readProcLink(fmt("/proc/%s/cwd", ent->d_name), unchecked); - auto fdStr = (format("/proc/%1%/fd") % ent->d_name).str(); + auto fdStr = fmt("/proc/%s/fd", ent->d_name); auto fdDir = AutoCloseDir(opendir(fdStr.c_str())); if (!fdDir) { if (errno == ENOENT || errno == EACCES) @@ -407,9 +406,8 @@ void LocalStore::findRuntimeRoots(Roots & roots) } struct dirent * fd_ent; while (errno = 0, fd_ent = readdir(fdDir.get())) { - if (fd_ent->d_name[0] != '.') { - readProcLink((format("%1%/%2%") % fdStr % fd_ent->d_name).str(), unchecked); - } + if (fd_ent->d_name[0] != '.') + readProcLink(fmt("%s/%s", fdStr, fd_ent->d_name), unchecked); } if (errno) { if (errno == ESRCH) @@ -419,19 +417,19 @@ void LocalStore::findRuntimeRoots(Roots & roots) fdDir.reset(); try { - auto mapFile = (format("/proc/%1%/maps") % ent->d_name).str(); + auto mapFile = fmt("/proc/%s/maps", ent->d_name); auto mapLines = tokenizeString<std::vector<string>>(readFile(mapFile, true), "\n"); - for (const auto& line : mapLines) { + for (const auto & line : mapLines) { auto match = std::smatch{}; if (std::regex_match(line, match, mapRegex)) - unchecked[match[1]].emplace((format("{memory:%1%}") % mapFile).str()); + unchecked[match[1]].emplace(mapFile); } - auto envFile = (format("/proc/%1%/environ") % ent->d_name).str(); + auto envFile = fmt("/proc/%s/environ", ent->d_name); auto envString = readFile(envFile, true); auto env_end = std::sregex_iterator{}; for (auto i = std::sregex_iterator{envString.begin(), envString.end(), storePathRegex}; i != env_end; ++i) - unchecked[i->str()].emplace((format("{memory:%1%}") % envFile).str()); + unchecked[i->str()].emplace(envFile); } catch (SysError & e) { if (errno == ENOENT || errno == EACCES || errno == ESRCH) continue; @@ -451,7 +449,7 @@ void LocalStore::findRuntimeRoots(Roots & roots) for (const auto & line : lsofLines) { std::smatch match; if (std::regex_match(line, match, lsofRegex)) - unchecked[match[1]].emplace((format("{memory:%1%}" % LSOF).str()); + unchecked[match[1]].emplace("{lsof}"); } } catch (ExecError & e) { /* lsof not installed, lsof failed */ diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index b4e5f5511599..bb16659765f4 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -11,6 +11,7 @@ #include <atomic> #include <limits> #include <map> +#include <unordered_set> #include <memory> #include <string> @@ -47,7 +48,7 @@ const size_t storePathHashLen = 32; // i.e. 160 bits const uint32_t exportMagic = 0x4558494e; -typedef std::map<Path, std::set<std::string>> Roots; +typedef std::unordered_map<Path, std::unordered_set<std::string>> Roots; struct GCOptions |