From owner-freebsd-hackers@FreeBSD.ORG Sun Aug 20 21:05:50 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 6A28916A4DF for ; Sun, 20 Aug 2006 21:05:50 +0000 (UTC) (envelope-from mwm-keyword-freebsdhackers2.e313df@mired.org) Received: from mired.org (vpn.mired.org [66.92.153.74]) by mx1.FreeBSD.org (Postfix) with SMTP id B2E2D43D5D for ; Sun, 20 Aug 2006 21:05:47 +0000 (GMT) (envelope-from mwm-keyword-freebsdhackers2.e313df@mired.org) Received: (qmail 86846 invoked by uid 1001); 20 Aug 2006 21:05:39 -0000 Received: by bhuda.mired.org (tmda-sendmail, from uid 1001); Sun, 20 Aug 2006 17:05:39 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17640.52899.432083.511555@bhuda.mired.org> Date: Sun, 20 Aug 2006 17:05:39 -0400 To: "Reko Turja" In-Reply-To: <017601c6c486$6477c370$0a0aa8c0@rivendell> References: <017601c6c486$6477c370$0a0aa8c0@rivendell> X-Mailer: VM 7.17 under 21.4 (patch 19) "Constant Variable" XEmacs Lucid X-Primary-Address: mwm@mired.org X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`; h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ X-Delivery-Agent: TMDA/1.0.3 (Seattle Slew) From: Mike Meyer Cc: 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: Sun, 20 Aug 2006 21:05:50 -0000 In <017601c6c486$6477c370$0a0aa8c0@rivendell>, Reko Turja typed: > I've been playing with Open Watcom for a bit in FreeBSD and for a > while there's been one stumblim block for further advancement. Watcom > uses a method for storing program messages etc. where these messages > are stored as a "resource file" inside the executable itself. As the > commands are usually invoked without the canonical path, the tools > cannot find the resource portion stored inside. > > This far I've been looking for some solutions from which none seem to > work too well. vn_fullpath (9) is running only inside kernel I think, > and with the approach using kvm_openfiles and kvm_getprocs I can only > get the command without the path (there are vnode etc. structures > inside the kinfo_proc structure, but those seem to be unavailable from > user space). Of course /proc might help in here, but I rather kept the > code compilable on very vanilla system. > > Any pointers on how to proceed would be welcome. In general, what you're asking can't be done on Unix. The vn_fullpath man page notes this by pointing out that it makes a "best effort", and giving a list of reasons why it isn't reliable. Many of those apply in your case as well. 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. http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information.