qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David CARLIER <devnexen@gmail.com>
To: qemu-devel <qemu-devel@nongnu.org>,
	QEMU Trivial <qemu-trivial@nongnu.org>
Subject: [PATCH v1] util: OpenBSD build fix
Date: Tue, 14 Jul 2020 20:43:55 +0100	[thread overview]
Message-ID: <CA+XhMqwMKk1eCNg-T15KRAa_e1-r0cmZ49f-135sppTFWpTerQ@mail.gmail.com> (raw)

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


             reply	other threads:[~2020-07-14 19:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-14 19:43 David CARLIER [this message]
2020-07-14 20:52 ` [PATCH v1] util: OpenBSD build fix Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+XhMqwMKk1eCNg-T15KRAa_e1-r0cmZ49f-135sppTFWpTerQ@mail.gmail.com \
    --to=devnexen@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).