From 98dbd01a96fd1d715794c0fe8ad82392882a8129 Mon Sep 17 00:00:00 2001 From: Greg V Date: Thu, 9 Apr 2020 01:41:00 +0300 Subject: [PATCH] util: make util_get_process_exec_path work on FreeBSD w/o procfs sysctl is the correct way of getting the current executable's path. procfs is not mounted by default. Reviewed-by: Samuel Pitoiset Reviewed-by: Eric Engestrom Cc: mesa-stable Part-of: --- src/util/u_process.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/util/u_process.c b/src/util/u_process.c index af808c7b196..2965e46a436 100644 --- a/src/util/u_process.c +++ b/src/util/u_process.c @@ -44,6 +44,11 @@ #include #endif +#if DETECT_OS_FREEBSD +#include +#include +#endif + #if defined(__linux__) && defined(HAVE_PROGRAM_INVOCATION_NAME) static char *path = NULL; @@ -202,6 +207,13 @@ util_get_process_exec_path(char* process_path, size_t len) int result = _NSGetExecutablePath(process_path, &bufSize); return (result == 0) ? strlen(process_path) : 0; +#elif DETECT_OS_FREEBSD + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; + + (void) sysctl(mib, 4, process_path, &len, NULL, 0); + process_path[len - 1] = '\0'; + + return len; #elif DETECT_OS_UNIX ssize_t r;