From d139924bf583dbc217ecec488096eeb02ab86c1d Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 8 Feb 2019 22:01:12 +0000 Subject: [PATCH] vm: Use the old FreeBSD os-freebsd.cpp so we don't need procfs installed (it's not mounted by default). --- vm/os-freebsd.cpp | 60 ++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/vm/os-freebsd.cpp b/vm/os-freebsd.cpp index 5acf07fb13..4948c053c7 100644 --- a/vm/os-freebsd.cpp +++ b/vm/os-freebsd.cpp @@ -1,33 +1,45 @@ #include "master.hpp" +#include +#include + namespace factor { char *vm_saved_path; -/* - FreeBSD needs proc mounted for this function to work. - "mount -t procfs proc /proc" -*/ - -const char* vm_executable_path(){ - ssize_t bufsiz = 4096; - while (true) { - char* buf = new char [bufsiz + 1]; - ssize_t size = readlink("/proc/curproc/file", buf, bufsiz); - if (size < 0) { - fatal_error("Cannot read /proc/curproc/file", errno); - } - else { - if (size < bufsiz) { - buf[size] = '\0'; - const char* ret = safe_strdup(buf); - delete[] buf; - return ret; - } else { - delete[] buf; - bufsiz *= 2; - } - } + + +/* From SBCL */ +const char *vm_executable_path() +{ + char path[PATH_MAX + 1]; + + if (getosreldate() >= 600024) + { + /* KERN_PROC_PATHNAME is available */ + size_t len = PATH_MAX + 1; + int mib[4]; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; + if (sysctl(mib, 4, &path, &len, NULL, 0) != 0) + return NULL; } + else + { + int size; + size = readlink("/proc/curproc/file", path, sizeof(path) - 1); + if (size < 0) + return NULL; + path[size] = '\0'; + } + + if(strcmp(path, "unknown") == 0) + return NULL; + + return safe_strdup(path); } + } -- 2.34.1