From owner-freebsd-hackers@FreeBSD.ORG Mon Aug 21 10:43:49 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 66C4216A4DE for ; Mon, 21 Aug 2006 10:43:49 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.FreeBSD.org (Postfix) with ESMTP id C57C143D58 for ; Mon, 21 Aug 2006 10:43:48 +0000 (GMT) (envelope-from des@des.no) Received: from tim.des.no (localhost [127.0.0.1]) by spam.des.no (Postfix) with ESMTP id 9824D20A5; Mon, 21 Aug 2006 12:43:44 +0200 (CEST) X-Spam-Tests: AWL X-Spam-Learn: disabled X-Spam-Score: 0.0/3.0 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on tim.des.no Received: from xps.des.no (des.no [80.203.243.180]) by tim.des.no (Postfix) with ESMTP id 7C7F62084; Mon, 21 Aug 2006 12:43:44 +0200 (CEST) Received: by xps.des.no (Postfix, from userid 1001) id 486B433C24; Mon, 21 Aug 2006 12:43:44 +0200 (CEST) From: des@des.no (Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?=) To: Mike Meyer References: <017601c6c486$6477c370$0a0aa8c0@rivendell> <17640.52899.432083.511555@bhuda.mired.org> Date: Mon, 21 Aug 2006 12:43:44 +0200 In-Reply-To: <17640.52899.432083.511555@bhuda.mired.org> (Mike Meyer's message of "Sun, 20 Aug 2006 17:05:39 -0400") Message-ID: <86sljqnzbz.fsf@xps.des.no> User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Reko Turja , freebsd-hackers@freebsd.org Subject: Re: Aqcuiring full path to running process from outside the kernel X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Aug 2006 10:43:49 -0000 Mike Meyer writes: > However, you can also make a best effort. Check argv[0] to see if you > have an absolute path. If not, do what the shell would do to find the > executable - look for it on $PATH. Once you've found it, call > realpath(3) to canonicalize the path. You got it the wrong way around. First pass argv[0] to realpath(3), fall back to using $PATH only if realpath(3) fails (which it shouldn't unless you've called chdir(2), chroot(2) or jail(2) earlier in the process, or the executable was moved or removed) DES --=20 Dag-Erling Sm=F8rgrav - des@des.no