From patchwork Thu Mar 25 21:07:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Use sysctl instead of /proc to find executable path on FreeBSD From: Juergen Lock X-Patchwork-Id: 48598 Message-Id: <20100325210712.GA52370@triton8.kn-bremen.de> To: qemu-devel@nongnu.org Date: Thu, 25 Mar 2010 22:07:12 +0100 ..since /proc usually isn't mounted on FreeBSD. Signed-off-by: Juergen Lock --- a/vl.c +++ b/vl.c @@ -52,6 +52,7 @@ #include #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) #include +#include #else #include #endif @@ -3368,10 +3369,13 @@ static char *find_datadir(const char *ar } #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; } }