From owner-freebsd-hackers@FreeBSD.ORG Tue Aug 22 12:04:43 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 D5C9E16A4E7 for ; Tue, 22 Aug 2006 12:04:43 +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 6127E43D80 for ; Tue, 22 Aug 2006 12:04:32 +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 4788620A5; Tue, 22 Aug 2006 14:04:28 +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 2EC452084; Tue, 22 Aug 2006 14:04:28 +0200 (CEST) Received: by xps.des.no (Postfix, from userid 1001) id F0F1933C24; Tue, 22 Aug 2006 14:04:27 +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> <86sljqnzbz.fsf@xps.des.no> <17642.8303.746281.383448@bhuda.mired.org> Date: Tue, 22 Aug 2006 14:04:27 +0200 In-Reply-To: <17642.8303.746281.383448@bhuda.mired.org> (Mike Meyer's message of "Mon, 21 Aug 2006 17:06:55 -0400") Message-ID: <8664glnfhw.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: Tue, 22 Aug 2006 12:04:43 -0000 Mike Meyer writes: > In <86sljqnzbz.fsf@xps.des.no>, Dag-Erling Sm=F8rgrav typed: > > 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) > No, I got it the right way 'round. If the shell walks the PATH, then > calling realpath(3) on argv[0] is the wrong thing to do, as it'll > resolve the path relative to the pwd. but argv[0] is either an absolute path or a path relative to pwd, unless your shell is broken. des@xps ~% cat >bin/foo #!/bin/sh echo $0 $@ des@xps ~% chmod a+rx bin/foo des@xps ~% ./bin/foo ./bin/foo des@xps ~% foo /home/des/bin/foo DES --=20 Dag-Erling Sm=F8rgrav - des@des.no