Skip to content

Commit

Permalink
return original name if link resolution fails
Browse files Browse the repository at this point in the history
  • Loading branch information
peadar committed Mar 6, 2024
1 parent 5991040 commit 2a201d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 0 additions & 1 deletion elf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::map<std::string, size_t>>();
size_t idx = 0;
for (auto sym : syms->array)
Expand Down
9 changes: 7 additions & 2 deletions fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand Down

0 comments on commit 2a201d7

Please sign in to comment.