From f57ceec7a2828362bf779ad1165b1c611de7978c Mon Sep 17 00:00:00 2001 From: Greg V Date: Thu, 2 Apr 2020 18:49:58 +0300 Subject: [PATCH] util: implement pa_get_binary_name on FreeBSD without procfs requirement procfs is not mounted by default, sysctl offers a bulletproof way of requesting this information. Part-of: --- src/pulse/util.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pulse/util.c b/src/pulse/util.c index 0b30abaf4..d1bb3863b 100644 --- a/src/pulse/util.c +++ b/src/pulse/util.c @@ -91,6 +91,10 @@ static int _main() PA_GCC_WEAKREF(main); #include #endif +#ifdef __FreeBSD__ +#include +#endif + #ifdef HAVE_DBUS #include #endif @@ -224,7 +228,7 @@ char *pa_get_binary_name(char *s, size_t l) { } #endif -#if defined(__linux__) || defined(__FreeBSD_kernel__) +#if defined(__linux__) || (defined(__FreeBSD_kernel__) && !defined(__FreeBSD__)) { char *rp; /* This works on Linux and Debian/kFreeBSD */ @@ -239,11 +243,12 @@ char *pa_get_binary_name(char *s, size_t l) { #ifdef __FreeBSD__ { - char *rp; + char path[PATH_MAX + 1]; + size_t len = PATH_MAX; + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; - if ((rp = pa_readlink("/proc/curproc/file"))) { - pa_strlcpy(s, pa_path_get_filename(rp), l); - pa_xfree(rp); + if (sysctl(mib, 4, &path, &len, NULL, 0) == 0) { + pa_strlcpy(s, pa_path_get_filename(path), l); return s; } }