From: Brad Smith <[email protected]>

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.

Signed-off-by: Brad Smith <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
Signed-off-by: Daniel P. Berrangé <[email protected]>
---
 meson.build   | 8 ++++++++
 util/cutils.c | 6 ++++++
 2 files changed, 14 insertions(+)

diff --git a/meson.build b/meson.build
index 71f135f0530..1b1523c5917 100644
--- a/meson.build
+++ b/meson.build
@@ -3040,6 +3040,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>
 
diff --git a/util/cutils.c b/util/cutils.c
index d8a04ead5a4..2996baa677c 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -1097,6 +1097,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];
-- 
2.56.0


Reply via email to