From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11337 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Question about setting argv[0] when manually using dynamic linker Date: Wed, 17 May 2017 12:24:28 -0400 Message-ID: <20170517162428.GH17319@brightrain.aerifal.cx> References: <20170517070115.GL6320@example.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1495038285 31938 195.159.176.226 (17 May 2017 16:24:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 17 May 2017 16:24:45 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11352-gllmg-musl=m.gmane.org@lists.openwall.com Wed May 17 18:24:37 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dB1ka-00086t-Gy for gllmg-musl@m.gmane.org; Wed, 17 May 2017 18:24:36 +0200 Original-Received: (qmail 11422 invoked by uid 550); 17 May 2017 16:24:40 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 11404 invoked from network); 17 May 2017 16:24:39 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11337 Archived-At: On Wed, May 17, 2017 at 11:16:51AM -0500, John Regan wrote: > On Wed, May 17, 2017 at 11:07 AM, mzpqnxow wrote: > > > BTW, the shell built-in "exec" has -a which can be used to set argv[0] > > > > Again though, I'm not entire sure I understand your use, so ignore this if > > it's irrelevant :> > > > > On Wed, May 17, 2017 at 07:00 mzpqnxow wrote: > > > >> Is there any reason you want to avoid simply statically linking the > >> program(s) so that it needs no libc or other shared objects at all? > >> > >> Or did I misunderstand what you're trying to do? > >> > >> On Wed, May 17, 2017 at 05:05 wrote: > >> > >>> On Tue, May 16, 2017 at 08:38:56PM -0400, John Regan wrote: > >>> > Hi there - I was wondering if it's possible to somehow set argv[0] when > >>> > calling the dynamic linker to load a program. > >>> ... > >>> > I'd like to retain whatever was actually typed on the command line (in > >>> this > >>> > case, set argv[0] to "app"), since many apps look at argv[0] to change > >>> > behavior, ie - gzip vs gunzip. > >>> > > >>> > I tried seeing if there was some switch I could pass to the linker, > >>> etc - > >>> > as far as I can tell, there's no easy way to do this. > >>> > >>> Set argv[0] to whatever you need when you exec*() the dynamic loader, > >>> which is straightforward with a binary wrapper (not with a shell). > >>> > >>> A binary wrapper also adds less overhead then going through a shell. > >>> > >>> There is imho hardly any incentive to put such functionalty into the > >>> loader. I say this even though we are dependent here on such tricks, > >>> to work around programs which insist on guessing things when not asked > >>> to. > >>> > >>> Regards, > >>> Rune > >>> > >>> > Well, if I statically link I'm unable to dynamically load modules (at least > I'm pretty sure that's the case). There's some cases where that might be > useful. > > Right now, I'm really just trying to see "is this doable?". It'd be > interesting to be able to distribute a program with its own libc, > libraries, etc, and still have the ability to dynamically load modules. You're right about static linking and dlopen, and what you're doing is a completely reasonable and recommended way for deploying dynamic linked apps in a self-contained way that doesn't depend on musl libc on the host. Unfortunately there's no way to set argv[0] like you want at this time. Perhaps adding an option like --argv0=foo would be appropriate. Rich