From patchwork Thu Mar 25 21:07:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Lock X-Patchwork-Id: 48598 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C34A9B7C98 for ; Fri, 26 Mar 2010 09:17:50 +1100 (EST) Received: from localhost ([127.0.0.1]:43950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NuvN5-0004Ai-Md for incoming@patchwork.ozlabs.org; Thu, 25 Mar 2010 18:17:47 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NuuoJ-0006IS-J5 for qemu-devel@nongnu.org; Thu, 25 Mar 2010 17:41:51 -0400 Received: from [140.186.70.92] (port=42675 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NuuoH-0006H9-LX for qemu-devel@nongnu.org; Thu, 25 Mar 2010 17:41:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NuuoF-0005xK-Vp for qemu-devel@nongnu.org; Thu, 25 Mar 2010 17:41:49 -0400 Received: from gelbbaer.kn-bremen.de ([78.46.108.116]:41695 helo=smtp.kn-bremen.de) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NuuoF-0005x0-OJ for qemu-devel@nongnu.org; Thu, 25 Mar 2010 17:41:47 -0400 Received: by smtp.kn-bremen.de (Postfix, from userid 10) id 9CF351E00178; Thu, 25 Mar 2010 22:41:46 +0100 (CET) Received: from triton8.kn-bremen.de (noident@localhost [127.0.0.1]) by triton8.kn-bremen.de (8.14.3/8.14.3) with ESMTP id o2PL7DeJ052532 for ; Thu, 25 Mar 2010 22:07:13 +0100 (CET) (envelope-from nox@triton8.kn-bremen.de) Received: (from nox@localhost) by triton8.kn-bremen.de (8.14.3/8.14.3/Submit) id o2PL7Doc052531 for qemu-devel@nongnu.org; Thu, 25 Mar 2010 22:07:13 +0100 (CET) (envelope-from nox) From: Juergen Lock Date: Thu, 25 Mar 2010 22:07:12 +0100 To: qemu-devel@nongnu.org Message-ID: <20100325210712.GA52370@triton8.kn-bremen.de> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH] Use sysctl instead of /proc to find executable path on FreeBSD X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org ..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; } }