Skip to contentSkip to conversation

util/cutils: Use getexecpath() on OpenBSD for qemu_init_exec_dir()

PATCH In review Brad Smith 2 participants 3 messages Sep 15 – Oct 26 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

Brad Smith

author
#0 lore raw

PATCH 1/1 util/cutils: Use getexecpath() on OpenBSD for qemu_init_exec_dir()

util/cutils: Use getexecpath() on OpenBSD for qemu_init_exec_dir()

OpenBSD has introduced a function getexecpath() to be able to retrieve the executable name and path.

---
 meson.build   | 8 ++++++++
 util/cutils.c | 6 ++++++
 2 files changed, 14 insertions(+)
meson.build +8 -0
index cfac634cf1..0e07138b0c 100644
@@ -3034,6 +3034,14 @@ config_host_data.set('CONFIG_ELF_AUX_INFO', cc.links(osdep_prefix + '''
     return hwcap;
   }'''))
 
+config_host_data.set('CONFIG_GETEXECPATH', cc.links(osdep_prefix + '''
+  #include <limits.h>
+  #include <unistd.h>
+  int main(void) {
+    char buf[PATH_MAX];
+    getexecpath(buf, sizeof(buf));
+  }'''))
+
 config_host_data.set('CONFIG_USBFS', have_linux_user and cc.compiles('''
   #include <linux/usbdevice_fs.h>
 
util/cutils.c +6 -0
index 91ddadfd15..b5d1d13e24 100644
@@ -1091,6 +1091,12 @@ void qemu_init_exec_dir(const char *argv0)
             p = buf;
         }
     }
+#elif defined(__OpenBSD__) && defined(CONFIG_GETEXECPATH)
+    {
+        if (getexecpath(buf, sizeof(buf)) == 0) {
+            p = buf;
+        }
+    }
 #elif defined(__APPLE__)
     {
         char fpath[PATH_MAX];
Signature · 1 line
2.55.0
author
#1 lore raw

ping.

Quoted 47 lines · Brad Smith

util/cutils: Use getexecpath() on OpenBSD for qemu_init_exec_dir()

OpenBSD has introduced a function getexecpath() to be able to retrieve the executable name and path.

---
  meson.build   | 8 ++++++++
  util/cutils.c | 6 ++++++
  2 files changed, 14 insertions(+)
meson.build +8 -0
index cfac634cf1..0e07138b0c 100644
@@ -3034,6 +3034,14 @@ config_host_data.set('CONFIG_ELF_AUX_INFO', cc.links(osdep_prefix + '''
      return hwcap;
    }'''))
 
+config_host_data.set('CONFIG_GETEXECPATH', cc.links(osdep_prefix + '''
+  #include <limits.h>
+  #include <unistd.h>
+  int main(void) {
+    char buf[PATH_MAX];
+    getexecpath(buf, sizeof(buf));
+  }'''))
+
  config_host_data.set('CONFIG_USBFS', have_linux_user and cc.compiles('''
    #include <linux/usbdevice_fs.h>
 
util/cutils.c +6 -0
index 91ddadfd15..b5d1d13e24 100644
@@ -1091,6 +1091,12 @@ void qemu_init_exec_dir(const char *argv0)
              p = buf;
          }
      }
+#elif defined(__OpenBSD__) && defined(CONFIG_GETEXECPATH)
+    {
+        if (getexecpath(buf, sizeof(buf)) == 0) {
+            p = buf;
+        }
+    }
  #elif defined(__APPLE__)
      {
          char fpath[PATH_MAX];
Reviewed-by on v1 1/1
#2 lore raw
In reply to Brad Smith
Quoted 10 lines · Brad Smith

util/cutils: Use getexecpath() on OpenBSD for qemu_init_exec_dir()

OpenBSD has introduced a function getexecpath() to be able to retrieve the executable name and path.

---
 meson.build   | 8 ++++++++
 util/cutils.c | 6 ++++++
 2 files changed, 14 insertions(+)

I'll include this if no one else picks it up before my next misc pull request

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|