From 7cefe598e9f4fcb2411f9d8f9742c02b35fe1f46 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 5 Dec 2020 14:36:29 +0100 Subject: [PATCH] Don't use KERN_PROC_PATHNAME on NetBSD This returns the wrong thing and breaks the tests. Since it's not super important anyway, just disable it and go back to /proc, that works. --- src/common.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common.cpp b/src/common.cpp index d7b981d2b..95caaf62a 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -1901,10 +1901,12 @@ std::string get_executable_path(const char *argv0) { // https://opensource.apple.com/source/adv_cmds/adv_cmds-163/ps/print.c uint32_t buffSize = sizeof buff; if (_NSGetExecutablePath(buff, &buffSize) == 0) return std::string(buff); -#elif defined(__BSD__) && defined(KERN_PROC_PATHNAME) +#elif defined(__BSD__) && defined(KERN_PROC_PATHNAME) && !defined(__NetBSD__) // BSDs do not have /proc by default, (although it can be mounted as procfs via the Linux // compatibility layer). We can use sysctl instead: per sysctl(3), passing in a process ID of -1 // returns the value for the current process. + // + // (this is broken on NetBSD, while /proc works, so we use that) size_t buff_size = sizeof buff; int name[] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; int result = sysctl(name, sizeof(name) / sizeof(int), buff, &buff_size, nullptr, 0);