OSDN Git Service

am 7b5b1667: am d3548a38: Merge "Add e4crypt_set_user_crypto_policies, calls vdc...
[android-x86/system-extras.git] / simpleperf / environment.cpp
index f4e98e6..e139b03 100644 (file)
@@ -401,3 +401,15 @@ bool GetValidThreadsFromThreadString(const std::string& tid_str, std::set<pid_t>
   }
   return true;
 }
+
+bool GetExecPath(std::string* exec_path) {
+  char path[PATH_MAX];
+  ssize_t path_len = readlink("/proc/self/exe", path, sizeof(path));
+  if (path_len <= 0 || path_len >= static_cast<ssize_t>(sizeof(path))) {
+    PLOG(ERROR) << "readlink failed";
+    return false;
+  }
+  path[path_len] = '\0';
+  *exec_path = path;
+  return true;
+}