aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/helpers.c24
-rw-r--r--CMakeLists.txt1
-rw-r--r--config.h.in3
3 files changed, 28 insertions, 0 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c
index e5545492..f7adfba0 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -39,6 +39,9 @@
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif
+#ifdef HAVE_PROC_PIDPATH
+#include <libproc.h>
+#endif
#ifdef __FreeBSD__
#include <sys/types.h>
@@ -755,6 +758,27 @@ void GetProcBinary(al_string *path, al_string *fname)
pathname[pathlen] = 0;
}
#endif
+#ifdef HAVE_PROC_PIDPATH
+ if(!pathname)
+ {
+ const pid_t pid = getpid();
+ char procpath[PROC_PIDPATHINFO_MAXSIZE];
+ int ret;
+
+ ret = proc_pidpath(pid, procpath, sizeof(procpath));
+ if(ret < 1)
+ {
+ WARN("proc_pidpath(%d, ...) failed: %s\n", pid, strerror(errno));
+ free(pathname);
+ pathname = NULL;
+ }
+ else
+ {
+ pathlen = strlen(procpath);
+ pathname = strdup(procpath);
+ }
+ }
+#endif
if(!pathname)
{
const char *selfname;
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 883c43d2..4f41f4c3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -507,6 +507,7 @@ CHECK_SYMBOL_EXISTS(sysconf unistd.h HAVE_SYSCONF)
CHECK_SYMBOL_EXISTS(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
CHECK_SYMBOL_EXISTS(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
+CHECK_SYMBOL_EXISTS(proc_pidpath libproc.h HAVE_PROC_PIDPATH)
CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
CHECK_SYMBOL_EXISTS(modff math.h HAVE_MODFF)
CHECK_SYMBOL_EXISTS(log2f math.h HAVE_LOG2F)
diff --git a/config.h.in b/config.h.in
index 5768e345..1ff64fe4 100644
--- a/config.h.in
+++ b/config.h.in
@@ -23,6 +23,9 @@
/* Define if we have the _aligned_malloc function */
#cmakedefine HAVE__ALIGNED_MALLOC
+/* Define if we have the proc_pidpath function */
+#cmakedefine HAVE_PROC_PIDPATH
+
/* Define if we have the getopt function */
#cmakedefine HAVE_GETOPT