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 <samuel.pitoiset@gmail.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/1598>
(cherry picked from commit 98dbd01a96)
This commit is contained in:
Greg V 2020-04-09 01:41:00 +03:00 committed by Eric Engestrom
parent 00fcc6c6ae
commit b255dbcdd9
2 changed files with 13 additions and 1 deletions

View file

@ -1093,7 +1093,7 @@
"description": "util: make util_get_process_exec_path work on FreeBSD w/o procfs",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null
},

View file

@ -44,6 +44,11 @@
#include <mach-o/dyld.h>
#endif
#if DETECT_OS_FREEBSD
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#if defined(__linux__) && defined(HAVE_PROGRAM_INVOCATION_NAME)
static char *path = NULL;
@ -211,6 +216,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;