From d79ec039a42feea4e4c059eca29f64b40aa8583a Mon Sep 17 00:00:00 2001 From: nharmata Date: Wed, 6 Mar 2019 14:54:15 -0800 Subject: [PATCH] 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 --- src/main/cpp/blaze_util_linux.cc | 17 ++++------------- src/main/cpp/blaze_util_platform.h | 3 ++- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main/cpp/blaze_util_linux.cc b/src/main/cpp/blaze_util_linux.cc index 11047e2ec30828..cd12524033bd35 100644 --- a/src/main/cpp/blaze_util_linux.cc +++ b/src/main/cpp/blaze_util_linux.cc @@ -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() { diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h index 707d7d16e79aae..832bfe0eca8065 100644 --- a/src/main/cpp/blaze_util_platform.h +++ b/src/main/cpp/blaze_util_platform.h @@ -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.