[PATCH] util: Try finding out application name using dladdr if available

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Felipe,

it would be good to describe what the patch is for;
I assume fixing hurd?

dladdr() is a GNU extension; the manpage does

#define _GNU_SOURCE
#include <dlfcn.h>

p.

> ---
>  configure.ac     |  2 ++
>  src/pulse/util.c | 18 ++++++++++++++++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/configure.ac b/configure.ac
> index 837e81e..2b011fb 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -580,6 +580,8 @@ AC_SYS_LARGEFILE
>  # Check for open64 to know if the current system does have open64() and similar functions
>  AC_CHECK_FUNCS_ONCE([open64])
>  
> +AC_SEARCH_LIBS([dladdr], [dl], [HAVE_DLADDR=1], [HAVE_DLADDR=0])
> +AC_DEFINE(HAVE_DLADDR, [1], [Have dladdr?])
>  
>  ###################################
>  #      External libraries         #
> diff --git a/src/pulse/util.c b/src/pulse/util.c
> index ace698c..67e23dc 100644
> --- a/src/pulse/util.c
> +++ b/src/pulse/util.c
> @@ -32,6 +32,7 @@
>  #include <time.h>
>  #include <unistd.h>
>  #include <sys/types.h>
> +#include <dlfcn.h>
>  
>  #ifdef HAVE_PWD_H
>  #include <pwd.h>
> @@ -64,6 +65,10 @@
>  
>  #include "util.h"
>  
> +#ifdef HAVE_DLADDR
> +extern int main(int, char*[]);
> +#endif
> +
>  char *pa_get_user_name(char *s, size_t l) {
>      const char *p;
>      char *name = NULL;
> @@ -218,6 +223,19 @@ char *pa_get_binary_name(char *s, size_t l) {
>      }
>  #endif
>  
> +#ifdef HAVE_DLADDR
> +    {
> +        Dl_info DLInfo;
> +        int err = dladdr(&main, &DLInfo);
> +        if (err != 0) {
> +            char *p = pa_realpath(DLInfo.dli_fname);
> +            if (p) {
> +                return p;
> +            }
> +        }
> +    }
> +#endif
> +
>  #if defined(HAVE_SYS_PRCTL_H) && defined(PR_GET_NAME)
>      {
>  
> 

-- 

Peter Meerwald
+43-664-2444418 (mobile)


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux