* [PATCH v1] util: OpenBSD build fix
@ 2020-07-14 19:43 David CARLIER
2020-07-14 20:52 ` Peter Maydell
0 siblings, 1 reply; 2+ messages in thread
From: David CARLIER @ 2020-07-14 19:43 UTC (permalink / raw)
To: qemu-devel, QEMU Trivial
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] util: OpenBSD build fix
2020-07-14 19:43 [PATCH v1] util: OpenBSD build fix David CARLIER
@ 2020-07-14 20:52 ` Peter Maydell
0 siblings, 0 replies; 2+ messages in thread
From: Peter Maydell @ 2020-07-14 20:52 UTC (permalink / raw)
To: David CARLIER; +Cc: QEMU Trivial, qemu-devel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-07-14 20:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-14 19:43 [PATCH v1] util: OpenBSD build fix David CARLIER
2020-07-14 20:52 ` Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).