Skip to content

Commit

Permalink
Bazel linux client: Have GetSelfPath always return "/proc/self/exe" -…
Browse files Browse the repository at this point in the history
…- don't do any symlink resolution.

The eager symlink resolution is unnecessary.

RELNOTES:
PiperOrigin-RevId: 237126043
  • Loading branch information
haxorz authored and copybara-github committed Mar 6, 2019
1 parent 566040e commit d79ec03
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
17 changes: 4 additions & 13 deletions src/main/cpp/blaze_util_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,10 @@ void WarnFilesystemType(const string& output_base) {
}

string GetSelfPath() {
char buffer[PATH_MAX] = {};
ssize_t bytes = readlink("/proc/self/exe", buffer, sizeof(buffer));
if (bytes == sizeof(buffer)) {
// symlink contents truncated
bytes = -1;
errno = ENAMETOOLONG;
}
if (bytes == -1) {
BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
<< "error reading /proc/self/exe: " << GetLastErrorString();
}
buffer[bytes] = '\0'; // readlink does not NUL-terminate
return string(buffer);
// The file to which this symlink points could change contents or go missing
// concurrent with execution of the Bazel client, so we don't eagerly resolve
// it.
return "/proc/self/exe";
}

uint64_t GetMillisecondsMonotonic() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/cpp/blaze_util_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ void SigPrintf(const char *format, ...);

std::string GetProcessIdAsString();

// Get the absolute path to the binary being executed.
// Get an absolute path to the binary being executed that is guaranteed to be
// readable.
std::string GetSelfPath();

// Returns the directory Bazel can use to store output.
Expand Down

0 comments on commit d79ec03

Please sign in to comment.