From 0de081d80de3eca9b5fb6c2bea58342ee4acc61e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 14 Jul 2011 18:32:01 +0100 Subject: [PATCH] Fallback to /proc/self/cmdline on setuid processes. --- os_posix.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) 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; } -- 2.45.2