[Mesa-dev] [PATCH v2 1/4] util: Get program name based on path when possible
Nicholas Kazlauskas
nicholas.kazlauskas at amd.com
Mon Sep 24 18:18:36 UTC 2018
Some programs start with the path and command line arguments in
argv[0] (program_invocation_name). Chromium is an example of
an application using mesa that does this.
This tries to query the real path for the symbolic link /proc/self/exe
to find the program name instead.
Signed-off-by: Nicholas Kazlauskas <nicholas.kazlauskas at amd.com>
---
src/util/u_process.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/util/u_process.c b/src/util/u_process.c
index 5e5927678d..4cae6f6dee 100644
--- a/src/util/u_process.c
+++ b/src/util/u_process.c
@@ -41,8 +41,22 @@ static const char *
__getProgramName()
{
char * arg = strrchr(program_invocation_name, '/');
- if (arg)
+ if (arg) {
+ /* This is likely part of a Linux file path.
+ * Try to get the program name without any command line arguments. */
+ static char * full_path;
+
+ if (!full_path)
+ full_path = realpath("/proc/self/exe", NULL);
+
+ if (full_path) {
+ char * res = strrchr(full_path, '/');
+ if (res)
+ return res+1;
+ }
+
return arg+1;
+ }
/* If there was no '/' at all we likely have a windows like path from
* a wine application.
--
2.19.0
More information about the mesa-dev
mailing list