oslib-posix: Use sysctl(2) call to resolve exec_dir on NetBSD

NetBSD 8.0(beta) ships with KERN_PROC_PATHNAME in sysctl(2).
Older NetBSD versions can use argv[0] parsing fallback.

This code section is partly shared with FreeBSD.

Signed-off-by: Kamil Rytarowski <n54@gmx.com>
Message-id: 20171028194833.23858-1-n54@gmx.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Kamil Rytarowski 2017-10-28 21:48:33 +02:00 committed by Peter Maydell
parent fa73e14625
commit 094611b426

View File

@ -49,6 +49,10 @@
#include <libutil.h> #include <libutil.h>
#endif #endif
#ifdef __NetBSD__
#include <sys/sysctl.h>
#endif
#include "qemu/mmap-alloc.h" #include "qemu/mmap-alloc.h"
#ifdef CONFIG_DEBUG_STACK_USAGE #ifdef CONFIG_DEBUG_STACK_USAGE
@ -250,9 +254,14 @@ void qemu_init_exec_dir(const char *argv0)
p = buf; p = buf;
} }
} }
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__) \
|| (defined(__NetBSD__) && defined(KERN_PROC_PATHNAME))
{ {
#if defined(__FreeBSD__)
static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
#else
static int mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME};
#endif
size_t len = sizeof(buf) - 1; size_t len = sizeof(buf) - 1;
*buf = '\0'; *buf = '\0';