>From e2103b86b031ab74ff4c8dd0a3944cb488c9333e Mon Sep 17 00:00:00 2001 From: David Carlier <devne...@gmail.com> Date: Tue, 14 Jul 2020 21:34:59 +0100 Subject: [PATCH] util: OpenBSD build fix.
thread id implementation, using getthrid syscall. qemu_exec_dir implementation as beast as we can as path is not always possible to resolve this on this platform. Signed-off-by: David Carlier <devne...@gmail.com> --- util/oslib-posix.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 72907d4d7f..4a0cce15b4 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -56,6 +56,10 @@ #include <lwp.h> #endif +#ifdef __OpenBSD__ +#include <sys/sysctl.h> +#endif + #ifdef __APPLE__ #include <mach-o/dyld.h> #endif @@ -100,6 +104,8 @@ int qemu_get_thread_id(void) return (int)tid; #elif defined(__NetBSD__) return _lwp_self(); +#elif defined(__OpenBSD__) + return getthrid(); #else return getpid(); #endif @@ -408,6 +414,23 @@ void qemu_init_exec_dir(const char *argv0) } } } +#elif defined(__OpenBSD__) + { + + char **args; + size_t len; + int mib[4] = {CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV}; + + *buf = 0; + if (!sysctl(mib, ARRAY_SIZE(mib), NULL, &len, NULL, 0)) { + args = malloc(len); + if (!sysctl(mib, ARRAY_SIZE(mib), args, &len, NULL, 0)) { + p = realpath(*args, buf); + } + + free(args); + } + } #endif /* If we don't have any way of figuring out the actual executable location then try argv[0]. */ -- 2.27.0