]> git.proxmox.com Git - qemu.git/commitdiff
Use sysctl instead of /proc to find executable path on FreeBSD
authorJuergen Lock <nox@jelal.kn-bremen.de>
Thu, 25 Mar 2010 21:07:12 +0000 (22:07 +0100)
committerBlue Swirl <blauwirbel@gmail.com>
Tue, 30 Mar 2010 17:44:38 +0000 (17:44 +0000)
..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>
vl.c

diff --git a/vl.c b/vl.c
index 7c0a825a5f37626260f796544c5a41d06a9c9ebb..6768cf125185aa0c67932cb56cc41f05f090b4fe 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -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;
         }
     }