From owner-freebsd-questions Tue Sep 21 18:44:20 1999 Delivered-To: freebsd-questions@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id 629D5150D2 for ; Tue, 21 Sep 1999 18:44:17 -0700 (PDT) (envelope-from bright@wintelcom.net) Received: from localhost (bright@localhost) by fw.wintelcom.net (8.9.3/8.9.3) with ESMTP id TAA24670; Tue, 21 Sep 1999 19:00:37 -0700 (PDT) Date: Tue, 21 Sep 1999 19:00:35 -0700 (PDT) From: Alfred Perlstein To: Laurence Berland Cc: Ben Smithurst , "Oleg V. Volkov" , freebsd-questions@FreeBSD.ORG Subject: Re: How to find absolute name of running binary? In-Reply-To: <37E83100.F6CBC126@confusion.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, 21 Sep 1999, Laurence Berland wrote: > So how do programs like gzip/gunzip do it? Where running gunzip is the > same as gzip -d? because no one is going out of thier way to decieve the program of the argv[0]. It wouldn't be standard practive to do so, but it can be done: #include int main (void) { char *spam[] = { "spam", NULL }; execve("./t/tt", spam, NULL); } the program ./t/tt will see argv[0] as "spam" instead of "./t/tt" most exec wrappers don't do this, so it would have to be intentional. -Alfred > > Ben Smithurst wrote: > > > > Alfred Perlstein wrote: > > > > > On Tue, 21 Sep 1999, Oleg V. Volkov wrote: > > > > > >> Well subject says it all. How could i find absolute name of my running > > >> binary from inside it? References to man or C examples welcome. > > > > > > I think some permutation of getcwd(3) and argv[0] should help, perhaps > > > with lstat (to check if you were run via a symlink) > > > > That won't do much if people give the program crap in argv[0], e.g. > > execlp("foo", "ha ha, fooled you!", "-x", "-y", "z", NULL), will > > it? There's some about this in some FAQ somewhere (comp.unix.programmer > > FAQ maybe, I'm not sure), and it basically boils down to "don't > > do it". I'd like to know what Oleg is doing and why he needs this > > information. > > > > -- > > Ben Smithurst | PGP: 0x99392F7D > > ben@scientia.demon.co.uk | key available from keyservers and > > | ben+pgp@scientia.demon.co.uk > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > > with "unsubscribe freebsd-questions" in the body of the message > > -- > Laurence Berland, Stuyvesant HS Debate > <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> > Windows 98: n. > useless extension to a minor patch release for > 32-bit extensions and a graphical shell for a > 16-bit patch to an 8-bit operating system > originally coded for a 4-bit microprocessor, > written by a 2-bit company that can't stand for > 1 bit of competition. > http://stuy.debate.net > icq #7434346 aol imer E1101 > The above email Copyright (C) 1999 Laurence Berland > All rights reserved > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-questions" in the body of the message > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message