Merge pull request #8020 from edolstra/no-such-process

Make findRuntimeRoots() more resilient to disappearing processes
This commit is contained in:
Eelco Dolstra 2023-03-09 19:57:47 +01:00 committed by GitHub
commit 523913d091
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -371,6 +371,7 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor)
while (errno = 0, ent = readdir(procDir.get())) { while (errno = 0, ent = readdir(procDir.get())) {
checkInterrupt(); checkInterrupt();
if (std::regex_match(ent->d_name, digitsRegex)) { if (std::regex_match(ent->d_name, digitsRegex)) {
try {
readProcLink(fmt("/proc/%s/exe" ,ent->d_name), unchecked); readProcLink(fmt("/proc/%s/exe" ,ent->d_name), unchecked);
readProcLink(fmt("/proc/%s/cwd", ent->d_name), unchecked); readProcLink(fmt("/proc/%s/cwd", ent->d_name), unchecked);
@ -393,7 +394,6 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor)
} }
fdDir.reset(); fdDir.reset();
try {
auto mapFile = fmt("/proc/%s/maps", ent->d_name); auto mapFile = fmt("/proc/%s/maps", ent->d_name);
auto mapLines = tokenizeString<std::vector<std::string>>(readFile(mapFile), "\n"); auto mapLines = tokenizeString<std::vector<std::string>>(readFile(mapFile), "\n");
for (const auto & line : mapLines) { for (const auto & line : mapLines) {