Mesa (staging/21.3): util: make util_get_process_exec_path work on FreeBSD w/o procfs
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Nov 1 19:36:40 UTC 2021
Module: Mesa
Branch: staging/21.3
Commit: 435d6c4e63754370db4ad4f33718d9e66a3a7f7f
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=435d6c4e63754370db4ad4f33718d9e66a3a7f7f
Author: Greg V <greg at unrelenting.technology>
Date: Thu Apr 9 01:41:00 2020 +0300
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 at gmail.com>
Reviewed-by: Eric Engestrom <eric at engestrom.ch>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/1598>
(cherry picked from commit 98dbd01a96fd1d715794c0fe8ad82392882a8129)
---
.pick_status.json | 2 +-
src/util/u_process.c | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/.pick_status.json b/.pick_status.json
index abe63c5c592..17b0eaacf8b 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -571,7 +571,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
},
diff --git a/src/util/u_process.c b/src/util/u_process.c
index 231286061b0..678f3a06736 100644
--- a/src/util/u_process.c
+++ b/src/util/u_process.c
@@ -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;
More information about the mesa-commit
mailing list