Skip to content

Commit

Permalink
oslib-posix: Use sysctl(2) call to resolve exec_dir on NetBSD
Browse files Browse the repository at this point in the history
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 <[email protected]>
Message-id: [email protected]
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
krytarowski authored and pm215 committed Nov 2, 2017
1 parent fa73e14 commit 094611b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion util/oslib-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
#include <libutil.h>
#endif

#ifdef __NetBSD__
#include <sys/sysctl.h>
#endif

#include "qemu/mmap-alloc.h"

#ifdef CONFIG_DEBUG_STACK_USAGE
Expand Down Expand Up @@ -250,9 +254,14 @@ void qemu_init_exec_dir(const char *argv0)
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};
#else
static int mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME};
#endif
size_t len = sizeof(buf) - 1;

*buf = '\0';
Expand Down

0 comments on commit 094611b

Please sign in to comment.