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]> --- meson.build | 8 ++++++++ util/cutils.c | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/meson.build b/meson.build index cfac634cf1..0e07138b0c 100644 --- a/meson.build +++ b/meson.build @@ -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> diff --git a/util/cutils.c b/util/cutils.c index 91ddadfd15..b5d1d13e24 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -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]; -- 2.55.0
