Skip to content

Commit d79ec03

Browse files
haxorzcopybara-github
authored andcommitted
Bazel linux client: Have GetSelfPath always return "/proc/self/exe" -- don't do any symlink resolution.
The eager symlink resolution is unnecessary. RELNOTES: PiperOrigin-RevId: 237126043
1 parent 566040e commit d79ec03

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/main/cpp/blaze_util_linux.cc

+4-13
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,10 @@ void WarnFilesystemType(const string& output_base) {
8282
}
8383

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

10091
uint64_t GetMillisecondsMonotonic() {

src/main/cpp/blaze_util_platform.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ void SigPrintf(const char *format, ...);
9595

9696
std::string GetProcessIdAsString();
9797

98-
// Get the absolute path to the binary being executed.
98+
// Get an absolute path to the binary being executed that is guaranteed to be
99+
// readable.
99100
std::string GetSelfPath();
100101

101102
// Returns the directory Bazel can use to store output.

0 commit comments

Comments
 (0)