[PATCH 1/2] Prefer process title over executable path on Android

Alexander Monakov amonakov at ispras.ru
Mon Jul 1 23:38:08 PDT 2013


---
 common/os_posix.cpp |  4 +++-
 wrappers/trace.cpp  | 24 ++++++------------------
 2 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/common/os_posix.cpp b/common/os_posix.cpp
index 9e8580f..c270da5 100644
--- a/common/os_posix.cpp
+++ b/common/os_posix.cpp
@@ -77,8 +77,10 @@ getProcessName(void)
     }
     len = strlen(buf);
 #else
-    ssize_t len;
+    ssize_t len = 0;
+#ifndef ANDROID
     len = readlink("/proc/self/exe", buf, size - 1);
+#endif
     if (len <= 0) {
         // /proc/self/exe is not available on setuid processes, so fallback to
         // /proc/self/cmdline.
diff --git a/wrappers/trace.cpp b/wrappers/trace.cpp
index 33b5cf1..66db1ff 100644
--- a/wrappers/trace.cpp
+++ b/wrappers/trace.cpp
@@ -49,30 +49,18 @@ namespace trace {
 static bool
 isZygoteProcess(void)
 {
-    os::String proc_name;
-
-    proc_name = os::getProcessName();
-    proc_name.trimDirectory();
-
-    return strcmp(proc_name, "app_process") == 0;
-}
-
-static os::String
-getZygoteProcessName(void)
-{
     os::String path;
     size_t size = PATH_MAX;
     char *buf = path.buf(size);
     ssize_t len;
 
-    int fd = open("/proc/self/cmdline", O_RDONLY);
+    len = readlink("/proc/self/exe", buf, size - 1);
 
-    assert(fd >= 0);
-    len = read(fd, buf, size - 1);
-    close(fd);
-    path.truncate();
+    if (len <= 0)
+        return false;
+    path.truncate(len);
 
-    return path;
+    return strcmp(path, "/system/bin/app_process") == 0;
 }
 
 bool
@@ -97,7 +85,7 @@ isTracingEnabled(void)
     char target_proc_name[PROP_VALUE_MAX] = "";
     os::String proc_name;
 
-    proc_name = getZygoteProcessName();
+    proc_name = os::getProcessName();
 
     __system_property_get("debug.apitrace.procname", target_proc_name);
     enabled = !strcmp(target_proc_name, proc_name);
-- 
1.8.2.1



More information about the apitrace mailing list