From: José Fonseca Date: Thu, 14 Jul 2011 17:32:01 +0000 (+0100) Subject: Fallback to /proc/self/cmdline on setuid processes. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=0de081d80de3eca9b5fb6c2bea58342ee4acc61e;p=apitrace Fallback to /proc/self/cmdline on setuid processes. --- diff --git a/os_posix.cpp b/os_posix.cpp index fdcaca9..bf8d190 100644 --- a/os_posix.cpp +++ b/os_posix.cpp @@ -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; }