Returns the path to the running executable. N.B. Derived from //knowledge/smalltalk/background_kb.cc Arg: strip_exe: if true, remove the name of the executable itself from the returned string. Example: calling this from /usr/bin/foo would return /usr/bin.
| 215 | // returned string. Example: calling this from /usr/bin/foo |
| 216 | // would return /usr/bin. |
| 217 | static string GetBinaryDir(bool strip_exe) { |
| 218 | char exe_path[PATH_MAX] = {0}; |
| 219 | PCHECK(readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1) != -1); |
| 220 | // Make sure it's null-terminated: |
| 221 | exe_path[sizeof(exe_path) - 1] = 0; |
| 222 | |
| 223 | if (strip_exe) { |
| 224 | // The exe is the last component of the path, so remove one component. |
| 225 | string ret = exe_path; |
| 226 | std::vector<string> components = absl::StrSplit(exe_path, '/'); |
| 227 | components.pop_back(); |
| 228 | return absl::StrJoin(components, "/"); |
| 229 | } |
| 230 | return exe_path; |
| 231 | } |
| 232 | |
| 233 | port::Status GpuExecutor::GetKernel(const MultiKernelLoaderSpec& spec, |
| 234 | KernelBase* kernel) { |