From: John Regan <saxindustries@gmail.com>
To: musl@lists.openwall.com
Subject: Re: Question about setting argv[0] when manually using dynamic linker
Date: Wed, 17 May 2017 14:16:09 -0500 [thread overview]
Message-ID: <CACBMf30uisSGHfAbLi+G_=rEFSGJy1M7LPRhxhggm9Jc6rVmvg@mail.gmail.com> (raw)
In-Reply-To: <20170517190705.GM6320@example.net>
[-- Attachment #1: Type: text/plain, Size: 2405 bytes --]
On Wed, May 17, 2017 at 2:07 PM, <u-uy74@aetey.se> 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
[-- Attachment #2: Type: text/html, Size: 3841 bytes --]
next prev parent reply other threads:[~2017-05-17 19:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-17 0:38 John Regan
2017-05-17 9:01 ` u-uy74
2017-05-17 11:00 ` mzpqnxow
2017-05-17 16:07 ` mzpqnxow
2017-05-17 16:16 ` John Regan
2017-05-17 16:24 ` Rich Felker
2017-05-17 19:07 ` u-uy74
2017-05-17 19:16 ` John Regan [this message]
2017-05-17 21:10 ` u-uy74
2017-05-17 21:15 ` mzpqnxow
2017-05-17 21:22 ` John Regan
2017-07-02 17:36 ` u-uy74
2017-07-04 20:58 ` Rich Felker
2017-07-05 6:01 ` u-uy74
2017-07-09 9:23 ` u-uy74
2017-07-09 12:23 ` Rich Felker
2017-07-09 14:04 ` u-uy74
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACBMf30uisSGHfAbLi+G_=rEFSGJy1M7LPRhxhggm9Jc6rVmvg@mail.gmail.com' \
--to=saxindustries@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).