diff options
author | Felipe Sateler <fsateler@debian.org> | 2014-10-11 01:34:23 -0300 |
---|---|---|
committer | David Henningsson <david.henningsson@canonical.com> | 2014-10-16 15:57:21 +0200 |
commit | 93c698c9fc8f67a941fbfa028c6fb362eaa5fb77 (patch) | |
tree | 6e0e551e9cd8d95811fb66bd2834aa2ac8a45254 | |
parent | c45c0b149065af0f0ed6b07da83075a022030403 (diff) |
util: Try finding out application name using dladdr if available
This fixes getting the binary name in the Hurd, or any other port using
the GNU C library, but only in the case where the library is directly
linked to. Opening with dlopen will not work.
Change in v3: reorder header includes and definitions
Change in v2: use a weak reference to main, so that we
don't crash when main cannot be found.
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/pulse/util.c | 23 |
2 files changed, 25 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index f13ddb08c..74bea71e8 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 ace698c03..d672f5350 100644 --- a/src/pulse/util.c +++ b/src/pulse/util.c @@ -64,6 +64,15 @@ #include "util.h" +#if defined(HAVE_DLADDR) && defined(PA_GCC_WEAKREF) +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif +#include <dlfcn.h> + +static int _main() PA_GCC_WEAKREF(main); +#endif + char *pa_get_user_name(char *s, size_t l) { const char *p; char *name = NULL; @@ -218,6 +227,20 @@ char *pa_get_binary_name(char *s, size_t l) { } #endif +#if defined(HAVE_DLADDR) && defined(PA_GCC_WEAKREF) + { + Dl_info info; + if(_main) { + int err = dladdr(&_main, &info); + if (err != 0) { + char *p = pa_realpath(info.dli_fname); + if (p) + return p; + } + } + } +#endif + #if defined(HAVE_SYS_PRCTL_H) && defined(PR_GET_NAME) { |