From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11344 Path: news.gmane.org!.POSTED!not-for-mail From: mzpqnxow Newsgroups: gmane.linux.lib.musl.general Subject: Re: Question about setting argv[0] when manually using dynamic linker Date: Wed, 17 May 2017 21:15:05 +0000 Message-ID: References: <20170517070115.GL6320@example.net> <20170517162428.GH17319@brightrain.aerifal.cx> <20170517190705.GM6320@example.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c063c88e012ca054fbec8ba" X-Trace: blaine.gmane.org 1495055729 20019 195.159.176.226 (17 May 2017 21:15:29 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 17 May 2017 21:15:29 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-11359-gllmg-musl=m.gmane.org@lists.openwall.com Wed May 17 23:15:25 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 1dB6I0-00058h-ME for gllmg-musl@m.gmane.org; Wed, 17 May 2017 23:15:24 +0200 Original-Received: (qmail 32093 invoked by uid 550); 17 May 2017 21:15:28 -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 32072 invoked from network); 17 May 2017 21:15:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mzpqnxow-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=l0BY5ixkOqa2gmyK9D6MU2ju82ix40M7Bi4yj87/ut8=; b=tUGj0z5qwmtFvnxlfTN+o0g94LmB6/bTH3HcG1CPmgIIoSAOq/oO1uXC/ep+gGrbRx 6QmdldYf5RjX1fLVYSUu8E/yHlnVtjh0hfM5JABGVGvzQ1keZ236xNZaG1/uoabltdIz E+yRPu6XGj1V++yx1LXcjNqI3req4HgvpRkq1VO8hs/ArWcJJ5FOqMkWMP5ofR3DRjxW Kn0yGEV6PxDrdu5WToZhgxeWE++neZIqZ4itxbfHYgULS4WMBlAadugMsNQCNlIAhrEf 8DoYr7bF2DTR3qI1JXLStwtqsVJjbr1ycdoaq4WNsKXsugeUZ9PDOczFM96jUQqdGNzn prkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=l0BY5ixkOqa2gmyK9D6MU2ju82ix40M7Bi4yj87/ut8=; b=fLujJFYST0QFbo5qODyZsJSLkk2XkHYTvgHM/a7j7mLhTP6txXczaxjJiw5OfSj/rE gywO63txUqu+nCjtUWdot1Bf3UN9tjppGX+ompj8/OrXa6gGRVahmzw3cWqzgWUEsP3O 0Ao2VsV/jeyJRyLWNp5K5rutIHvl5y4M6RzXUM8KWwLB5BLxPCy+BpEtfRbBeCARbeWc l+UE64yDefqYTZNYw8Ybp5b6GwTUiycC66p7ysSvc/m4rBqm0D48Ueg3ElgavhL3/WT/ yDyIqtkEZAcnZnfcWv0XUJE5rQmkH0oxXkpzEzGw57VaGFbFM8fLCRQbppYoLsZIpWIn 8tiw== X-Gm-Message-State: AODbwcCAu91Wp0eHFSKr8d57vHWY8k3botwa661LVcg415L5hswYxLDz /iPtsiDimvLBo9HW/cwY5IV8OMyqLIDy7DQ= X-Received: by 10.55.165.196 with SMTP id o187mr790757qke.88.1495055716038; Wed, 17 May 2017 14:15:16 -0700 (PDT) In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:11344 Archived-At: --94eb2c063c88e012ca054fbec8ba Content-Type: text/plain; charset="UTF-8" Does the shell built-in "exec" -a app1 /bah/dynamic-loader.so /path/to/app1" work or it has the same problem with argv[0] getting reset? On Wed, May 17, 2017 at 15:16 John Regan wrote: > > On Wed, May 17, 2017 at 2:07 PM, wrote: > >> On Wed, May 17, 2017 at 12:24:28PM -0400, Rich Felker 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. >> >> > > >>> 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. >> >> > > >>> Rune >> >> > 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 >> >> We do deploy dynamic linked apps without any dependencies on the libraries >> on the host. It works just fine with musl-as-it-is, including the >> questionably designed applications like busybox and gcc who >> analyze argv[0]. >> >> > at this time. Perhaps adding an option like --argv0=foo would be >> > appropriate. >> >> What would be the justification for adding the supporting code (to every >> instance of the dynamic loader)? >> >> It looks like --argv0=foo is meant to overcome a specific limitation in >> bourne shell, in a specific context where the task can be solved easily >> and generally better without involving the bourne shell in the first hand. >> >> I would like to see an example of a situation where a wrapper in C (or >> any language allowing setting of argv[0]) is less appropriate? >> >> If one really has a reason to express the wrapper in sh, a one-liner in >> C and an extra exec from the shell (much cheaper than starting the >> shell itself was) is sufficient to make it work. >> >> Rune >> >> Hi Rune - would you mind sharing some tips on doing that? > > I wrote and compiled a short program that just dumps the elements in argv, > then a wrapper program that figures out the needed paths for libc, real > binary, etc, but it seems like argv[0] gets reset by the dynamic loader. > > I'm calling execve with the path to the libc.so, and argv is somenthing > like: > > argv[0] - desired process name > argv[1] - full path to the real binary > argv[2...] arguments > > The 'real' binary is loaded and ran, but winds up printing out: > > argv[0] - full path to the real binary > argv[1...] arguments > --94eb2c063c88e012ca054fbec8ba Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Does the shell built-in "exec" -a app1 /bah/dynamic-loader.s= o /path/to/app1" work or it has the same problem with argv[0] getting = reset?

On Wed, May 17, 2017 a= t 15:16 John Regan <saxindust= ries@gmail.com> wrote:
=

On Wed, May 17, 2= 017 at 2:07 PM, <u-uy74@aetey.se> wrote:
Hi Rune - would you mind sharing some = tips on doing that?

I wrote and compiled a short progra= m that just dumps the elements in argv, then a wrapper program that figures= out the needed paths for libc, real binary, etc, but it seems like argv[0]= gets reset by the dynamic loader.

I'm calling exec= ve with the path to the libc.so, and argv is somenthing like:

argv[0] - desired process name
argv[1] - full path t= o the real binary
argv[2...] arguments

=
= The 'real' binary is loaded and ran, but winds up printing out:
=
argv[0] - full path to the real binary
arg= v[1...] arguments
--94eb2c063c88e012ca054fbec8ba--