[Mesa-dev] [PATCH 4/4] util: Get program name based on path when possible

Timothy Arceri tarceri at itsqueeze.com
Wed Sep 12 04:26:42 UTC 2018


On 12/9/18 2:24 am, Nicholas Kazlauskas wrote:
> 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 change breaks the detection of Wine applications. Can you give an 
example of the string in program_invocation_name for Chromium? Can we 
not remove the arguments from the string?

> 
> 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 | 17 ++++++++++++++---
>   1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/src/util/u_process.c b/src/util/u_process.c
> index 5e5927678d..ca4d0770cb 100644
> --- a/src/util/u_process.c
> +++ b/src/util/u_process.c
> @@ -29,6 +29,7 @@
>   #include <string.h>
>   #include <errno.h>
>   #include <stdlib.h>
> +#include <stdio.h>
>   
>   #undef GET_PROGRAM_NAME
>   
> @@ -36,22 +37,32 @@
>   #    if !defined(__GLIBC__) || (__GLIBC__ < 2)
>   /* These aren't declared in any libc5 header */
>   extern char *program_invocation_name, *program_invocation_short_name;
> +extern char *__progname;
>   #    endif
>   static const char *
>   __getProgramName()
>   {
> -   char * arg = strrchr(program_invocation_name, '/');
> +   static char * actual_path;
> +   char * path = NULL;
> +   char * arg = NULL;
> +
> +   if (!actual_path)
> +      actual_path = realpath("/proc/self/exe", NULL);
> +
> +   path = actual_path ? actual_path : program_invocation_name;
> +
> +   arg = strrchr(path, '/');
>      if (arg)
>         return arg+1;
>   
>      /* If there was no '/' at all we likely have a windows like path from
>       * a wine application.
>       */
> -   arg = strrchr(program_invocation_name, '\\');
> +   arg = strrchr(path, '\\');
>      if (arg)
>         return arg+1;
>   
> -   return program_invocation_name;
> +   return path;
>   }
>   #    define GET_PROGRAM_NAME() __getProgramName()
>   #elif defined(__CYGWIN__)
> 


More information about the mesa-dev mailing list