From 3f071a90a4313749b348a7d98284c005e5d87537 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 24 Mar 2018 08:25:58 -0700 Subject: Use proc_pidpath to get the process path on macOS when available --- Alc/helpers.c | 24 ++++++++++++++++++++++++ CMakeLists.txt | 1 + config.h.in | 3 +++ 3 files changed, 28 insertions(+) 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 #endif +#ifdef HAVE_PROC_PIDPATH +#include +#endif #ifdef __FreeBSD__ #include @@ -754,6 +757,27 @@ void GetProcBinary(al_string *path, al_string *fname) sysctl(mib, 3, (void*)pathname, &pathlen, NULL, 0); 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) { 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 -- cgit v1.2.3