diff options
author | Lennart Poettering <lennart@poettering.net> | 2006-07-14 00:17:31 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2006-07-14 00:17:31 +0000 |
commit | 881d4ddd397a829930b6800f1ecc438439cdc766 (patch) | |
tree | 27f600c787d605927ed0cbdad181ebe576224a9f /src/pulse | |
parent | 55296041473306ca4aa346197b60545814dfebe8 (diff) |
* fall back to prctl(PR_GET_NAME) in pa_get_binary_name() if readlink() fails
* call pa_path_get_filename() in all cases before returning in pa_get_binary_name(). We already did so on Win32, but didn't on Linux.
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1077 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/pulse')
-rw-r--r-- | src/pulse/util.c | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/src/pulse/util.c b/src/pulse/util.c index 338607c41..b041fec80 100644 --- a/src/pulse/util.c +++ b/src/pulse/util.c @@ -49,6 +49,10 @@ #include <windows.h> #endif +#ifdef HAVE_SYS_PRCTL_H +#include <sys/prctl.h> +#endif + #include "../pulsecore/winsock.h" #include <pulsecore/core-error.h> @@ -152,28 +156,51 @@ char *pa_get_home_dir(char *s, size_t l) { char *pa_get_binary_name(char *s, size_t l) { -#ifdef HAVE_READLINK - char path[PATH_MAX]; - int i; - assert(s && l); + assert(s); + assert(l); - /* This works on Linux only */ +#if defined(OS_IS_WIN32) + { + char path[PATH_MAX]; + + if (GetModuleFileName(NULL, path, PATH_MAX)) + return pa_strlcpy(s, pa_path_get_filename(path), l); + } +#endif - snprintf(path, sizeof(path), "/proc/%u/exe", (unsigned) getpid()); - if ((i = readlink(path, s, l-1)) < 0) - return NULL; +#ifdef HAVE_READLINK + { + int i; + char path[PATH_MAX]; + /* This works on Linux only */ + + if ((i = readlink("/proc/self/exe", path, sizeof(path)-1)) >= 0) { + path[i] = 0; + return pa_strlcpy(s, pa_path_get_filename(path), l); + } + } + +#endif + +#if defined(HAVE_SYS_PRCTL_H) && defined(PR_GET_NAME) + { - s[i] = 0; - return s; -#elif defined(OS_IS_WIN32) - char path[PATH_MAX]; - if (!GetModuleFileName(NULL, path, PATH_MAX)) - return NULL; - pa_strlcpy(s, pa_path_get_filename(path), l); - return s; -#else - return NULL; + #ifndef TASK_COMM_LEN + /* Actually defined in linux/sched.h */ + #define TASK_COMM_LEN 16 + #endif + + char tcomm[TASK_COMM_LEN+1]; + memset(tcomm, 0, sizeof(tcomm)); + + /* This works on Linux only */ + if (prctl(PR_GET_NAME, (unsigned long) tcomm, 0, 0, 0) == 0) + return pa_strlcpy(s, tcomm, l); + + } #endif + + return NULL; } const char *pa_path_get_filename(const char *p) { |