diff options
author | Juergen Lock <nox@jelal.kn-bremen.de> | 2010-03-25 22:07:12 +0100 |
---|---|---|
committer | Blue Swirl <blauwirbel@gmail.com> | 2010-03-30 17:44:38 +0000 |
commit | 92c0e6579c045916ec592ceef7caf868ff310cfa (patch) | |
tree | 4b47f37df7fb4277cdba7a51aad6d4ca5527de06 | |
parent | 2b5eb3712350d65d3eacb3ae468aae5e846b27b3 (diff) |
Use sysctl instead of /proc to find executable path on FreeBSD
..since /proc usually isn't mounted on FreeBSD.
Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
-rw-r--r-- | vl.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -52,6 +52,7 @@ #include <sys/stat.h> #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) #include <libutil.h> +#include <sys/sysctl.h> #else #include <util.h> #endif @@ -2276,10 +2277,13 @@ static char *find_datadir(const char *argv0) } #elif defined(__FreeBSD__) { - int len; - len = readlink("/proc/curproc/file", buf, sizeof(buf) - 1); - if (len > 0) { - buf[len] = 0; + static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; + size_t len = sizeof(buf) - 1; + + *buf = '\0'; + if (!sysctl(mib, sizeof(mib)/sizeof(*mib), buf, &len, NULL, 0) && + *buf) { + buf[sizeof(buf) - 1] = '\0'; p = buf; } } |