From e2103b86b031ab74ff4c8dd0a3944cb488c9333e Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen@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 <devnexen@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
On Tue, 14 Jul 2020 at 20:45, David CARLIER <devnexen@gmail.com> wrote: > > From e2103b86b031ab74ff4c8dd0a3944cb488c9333e Mon Sep 17 00:00:00 2001 > From: David Carlier <devnexen@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. Hi; thanks for the patch. These look like two separate changes, so they should be in separate patches, please. It would be useful to have a comment in the code documenting what the limitations of the OpenBSD call are, and when it's better than just using realpath() on the argv[0] that we already have. (ie, in which cases is the argv[0] which we get back via KERN_PROC_ARGV something other than the argv[0] that was passed to the process?) > Signed-off-by: David Carlier <devnexen@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 you want to use malloc() you need to check the return value. But better to use g_malloc(), which can't return a failure value. > + 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]. */ > -- thanks -- PMM
© 2016 - 2024 Red Hat, Inc.