From: Juergen Lock Date: Thu, 25 Mar 2010 21:07:12 +0000 (+0100) Subject: Use sysctl instead of /proc to find executable path on FreeBSD X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=92c0e6579c045916ec592ceef7caf868ff310cfa;p=qemu.git Use sysctl instead of /proc to find executable path on FreeBSD ..since /proc usually isn't mounted on FreeBSD. Signed-off-by: Juergen Lock Signed-off-by: Blue Swirl --- diff --git a/vl.c b/vl.c index 7c0a825a5f..6768cf1251 100644 --- a/vl.c +++ b/vl.c @@ -52,6 +52,7 @@ #include #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) #include +#include #else #include #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; } }