From 2a201d763a0fb75422522e1f0500701fd6665342 Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Wed, 6 Mar 2024 17:13:29 +0000 Subject: [PATCH] return original name if link resolution fails --- elf.cc | 1 - fs.cc | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/elf.cc b/elf.cc index 7d169e1..6821572 100644 --- a/elf.cc +++ b/elf.cc @@ -532,7 +532,6 @@ Object::findDebugSymbol(const string &name) // auto syms = debugSymbols(); if (!cachedSymbols) { - std::clog << "caching symbols for " << io->filename() << "\n"; cachedSymbols = std::make_unique>(); size_t idx = 0; for (auto sym : syms->array) diff --git a/fs.cc b/fs.cc index 87f78de..7cce2ef 100644 --- a/fs.cc +++ b/fs.cc @@ -32,11 +32,16 @@ std::string linkResolve(std::string name) { char buf[1024]; + std::string orig = name; int rc; for (;;) { rc = readlink(name.c_str(), buf, sizeof buf - 1); - if (rc == -1) - break; + // some files in /proc are links, but report "(deleted)" in the name if + // the original has gone away. Opening such files works, and uses the + // in-core inode, so use that if we can + if (rc == -1) { + return errno == EINVAL ? name : orig; + } buf[rc] = 0; if (buf[0] != '/') { auto lastSlash = name.rfind('/');