[Mesa-dev] [PATCH 1/3] gallium/os: add os_get_process_cmd_line

Marek Olšák maraeo at gmail.com
Sat Jul 30 15:22:43 UTC 2016


From: Marek Olšák <marek.olsak at amd.com>

for debugging
---
 src/gallium/auxiliary/os/os_process.c | 37 +++++++++++++++++++++++++++++++++++
 src/gallium/auxiliary/os/os_process.h |  2 ++
 2 files changed, 39 insertions(+)

diff --git a/src/gallium/auxiliary/os/os_process.c b/src/gallium/auxiliary/os/os_process.c
index 332e195..3ee30b1 100644
--- a/src/gallium/auxiliary/os/os_process.c
+++ b/src/gallium/auxiliary/os/os_process.c
@@ -30,6 +30,10 @@
 #include "os/os_process.h"
 #include "util/u_memory.h"
 
+#if defined(PIPE_OS_UNIX)
+#include <stdio.h>
+#endif
+
 #if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
 #  include <windows.h>
 #elif defined(__GLIBC__) || defined(__CYGWIN__)
@@ -108,3 +112,36 @@ os_get_process_name(char *procname, size_t size)
       return FALSE;
    }
 }
+
+bool
+os_get_process_cmd_line(char *result, size_t size)
+{
+#if defined(PIPE_OS_UNIX)
+   char ps[256];
+   int len;
+   FILE *p;
+
+   /* Execute the ps command. */
+   snprintf(ps, sizeof(ps), "ps --pid %i -o args --no-headers", getpid());
+
+   p = popen(ps, "r");
+   if (!p)
+      return false;
+
+   result = fgets(result, size, p);
+   pclose(p);
+
+   if (!result)
+      return false;
+
+   /* Remove the newline character. */
+   len = strlen(result);
+   if (result[len - 1] == '\n')
+      result[len - 1] = 0;
+
+   return true;
+
+#else
+   return false;
+#endif
+}
diff --git a/src/gallium/auxiliary/os/os_process.h b/src/gallium/auxiliary/os/os_process.h
index 0d50ddc..3965a8b 100644
--- a/src/gallium/auxiliary/os/os_process.h
+++ b/src/gallium/auxiliary/os/os_process.h
@@ -36,5 +36,7 @@
 extern boolean
 os_get_process_name(char *str, size_t size);
 
+extern bool
+os_get_process_cmd_line(char *result, size_t size);
 
 #endif /* OS_PROCESS_H */
-- 
2.7.4



More information about the mesa-dev mailing list