Skip to content

Commit

Permalink
Fix bug that threw an error while searching for linux headers through…
Browse files Browse the repository at this point in the history
… a symlink (#1821)

Summary: This PR removes a condition which checks to see if a host path
exists in the filesystem of a process when trying to resolve symlinks.

The function `fs::Exists()` returned false for a broken symlink when the
expectation was to return true because the path existed although it was
a broken symlink. This function would later on fix the broken symlink
path by reading its target host and converting the broken path into the
actual path. This makes the code removal safe as the next check:
`is_symlink` will return an error code if there is no file.

Type of change: /kind bug

Test Plan: Existing tests pass and deployed the PEM with the updated fix
and saw that the Linux header files were found.

---------

Signed-off-by: Kartik Pattaswamy <[email protected]>
  • Loading branch information
kpattaswamy authored Feb 16, 2024
1 parent 561ec31 commit e633c50
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/stirling/utils/linux_headers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,12 @@ Status FindLinuxHeadersDirectory(const std::filesystem::path& lib_modules_dir) {
}

StatusOr<std::filesystem::path> ResolvePossibleSymlinkToHostPath(const std::filesystem::path p) {
// The rest of this won't work if "p" does not exist. Go ahead and error out early if needed.
if (!fs::Exists(p)) {
return error::NotFound(absl::Substitute("Did not find host headers at path: $0.", p.string()));
}

// Check if "p" is a symlink.
std::error_code ec;
const bool is_symlink = std::filesystem::is_symlink(p, ec);
if (ec) {
return error::Internal(ec.message());
return error::NotFound(absl::Substitute("Did not find the host headers at path: $0, $1.",
p.string(), ec.message()));
}

if (!is_symlink) {
Expand Down

0 comments on commit e633c50

Please sign in to comment.