diff options
author | Greg V <greg@unrelenting.technology> | 2020-04-02 18:49:58 +0300 |
---|---|---|
committer | PulseAudio Marge Bot <pulseaudio-maintainers@lists.freedesktop.org> | 2021-01-18 16:33:53 +0000 |
commit | f57ceec7a2828362bf779ad1165b1c611de7978c (patch) | |
tree | 57684aade3de77cf64e473e0bf611ddc2fcee960 | |
parent | e6560becf13879cf85b541e1da7ed635e5e9b7a4 (diff) |
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: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/277>
-rw-r--r-- | src/pulse/util.c | 15 |
1 files 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 <sys/sysctl.h> #endif +#ifdef __FreeBSD__ +#include <sys/sysctl.h> +#endif + #ifdef HAVE_DBUS #include <pulsecore/rtkit.h> #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; } } |