]> git.cworth.org Git - apitrace/commitdiff
Fallback to /proc/self/cmdline on setuid processes.
authorJosé Fonseca <jfonseca@vmware.com>
Thu, 14 Jul 2011 17:32:01 +0000 (18:32 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 14 Jul 2011 20:23:14 +0000 (21:23 +0100)
os_posix.cpp

index fdcaca9aa80685837efeccd1c2e9f1b5820d53a1..bf8d1908b5003f70a6cba035c241cc438d527931 100644 (file)
@@ -77,6 +77,15 @@ GetProcessName(char *str, size_t size)
     ssize_t len;
     len = readlink("/proc/self/exe", szProcessPath, sizeof(szProcessPath) - 1);
     if (len == -1) {
+        // /proc/self/exe is not available on setuid processes, so fallback to
+        // /proc/self/cmdline.
+        int fd = open("/proc/self/cmdline", O_RDONLY);
+        if (fd >= 0) {
+            len = read(fd, szProcessPath, sizeof(szProcessPath) - 1);
+            close(fd);
+        }
+    }
+    if (len <= 0) {
         snprintf(str, size, "%i", (int)getpid());
         return true;
     }