Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set argv0= to allow multi-executable binaries #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matthewbauer
Copy link
Contributor

Some binaries use $0 sniffing to determine what mode to use. So, we
want to propagate the argv0 we are using so we can use these programs.

A good example is “coreutils” which uses this method:

$ tree /nix/store/...-coreutils-8.31
.
├── bin
│   ├── [ -> coreutils
│   ├── b2sum -> coreutils
│   ├── base32 -> coreutils
│   ├── base64 -> coreutils
│   ├── basename -> coreutils
│   ├── basenc -> coreutils
│   ├── cat -> coreutils
│   ├── chcon -> coreutils
│   ├── chgrp -> coreutils
│   ├── chmod -> coreutils
│   ├── chown -> coreutils
│   ├── chroot -> coreutils
│   ├── cksum -> coreutils
│   ├── comm -> coreutils
│   ├── coreutils
│   ├── cp -> coreutils
│   ├── csplit -> coreutils
│   ├── cut -> coreutils
│   ├── date -> coreutils
│   ├── dd -> coreutils
│   ├── df -> coreutils
│   ├── dir -> coreutils
│   ├── dircolors -> coreutils
│   ├── dirname -> coreutils
│   ├── du -> coreutils
│   ├── echo -> coreutils
│   ├── env -> coreutils
│   ├── expand -> coreutils
│   ├── expr -> coreutils
│   ├── factor -> coreutils
│   ├── false -> coreutils
│   ├── fmt -> coreutils
│   ├── fold -> coreutils
│   ├── groups -> coreutils
│   ├── head -> coreutils
│   ├── hostid -> coreutils
│   ├── id -> coreutils
│   ├── install -> coreutils
│   ├── join -> coreutils
│   ├── kill -> coreutils
│   ├── link -> coreutils
│   ├── ln -> coreutils
│   ├── logname -> coreutils
│   ├── ls -> coreutils
│   ├── md5sum -> coreutils
│   ├── mkdir -> coreutils
│   ├── mkfifo -> coreutils
│   ├── mknod -> coreutils
│   ├── mktemp -> coreutils
│   ├── mv -> coreutils
│   ├── nice -> coreutils
│   ├── nl -> coreutils
│   ├── nohup -> coreutils
│   ├── nproc -> coreutils
│   ├── numfmt -> coreutils
│   ├── od -> coreutils
│   ├── paste -> coreutils
│   ├── pathchk -> coreutils
│   ├── pinky -> coreutils
│   ├── pr -> coreutils
│   ├── printenv -> coreutils
│   ├── printf -> coreutils
│   ├── ptx -> coreutils
│   ├── pwd -> coreutils
│   ├── readlink -> coreutils
│   ├── realpath -> coreutils
│   ├── rm -> coreutils
│   ├── rmdir -> coreutils
│   ├── runcon -> coreutils
│   ├── seq -> coreutils
│   ├── sha1sum -> coreutils
│   ├── sha224sum -> coreutils
│   ├── sha256sum -> coreutils
│   ├── sha384sum -> coreutils
│   ├── sha512sum -> coreutils
│   ├── shred -> coreutils
│   ├── shuf -> coreutils
│   ├── sleep -> coreutils
│   ├── sort -> coreutils
│   ├── split -> coreutils
│   ├── stat -> coreutils
│   ├── stdbuf -> coreutils
│   ├── stty -> coreutils
│   ├── sum -> coreutils
│   ├── sync -> coreutils
│   ├── tac -> coreutils
│   ├── tail -> coreutils
│   ├── tee -> coreutils
│   ├── test -> coreutils
│   ├── timeout -> coreutils
│   ├── touch -> coreutils
│   ├── tr -> coreutils
│   ├── true -> coreutils
│   ├── truncate -> coreutils
│   ├── tsort -> coreutils
│   ├── tty -> coreutils
│   ├── uname -> coreutils
│   ├── unexpand -> coreutils
│   ├── uniq -> coreutils
│   ├── unlink -> coreutils
│   ├── uptime -> coreutils
│   ├── users -> coreutils
│   ├── vdir -> coreutils
│   ├── wc -> coreutils
│   ├── who -> coreutils
│   ├── whoami -> coreutils
│   └── yes -> coreutils
└── libexec
└── coreutils
└── libstdbuf.so

3 directories, 108 files

It needs argv0 to be set to the real name of the utility. Before it was something like /tmp/tmpx-20190509T191742Z-4f90c6f0/dat/../run

Some binaries use $0 sniffing to determine what mode to use. So, we
want to propagate the argv0 we are using so we can use these programs.

A good example is “coreutils” which uses this method:

$ tree /nix/store/...-coreutils-8.31
.
├── bin
│   ├── [ -> coreutils
│   ├── b2sum -> coreutils
│   ├── base32 -> coreutils
│   ├── base64 -> coreutils
│   ├── basename -> coreutils
│   ├── basenc -> coreutils
│   ├── cat -> coreutils
│   ├── chcon -> coreutils
│   ├── chgrp -> coreutils
│   ├── chmod -> coreutils
│   ├── chown -> coreutils
│   ├── chroot -> coreutils
│   ├── cksum -> coreutils
│   ├── comm -> coreutils
│   ├── coreutils
│   ├── cp -> coreutils
│   ├── csplit -> coreutils
│   ├── cut -> coreutils
│   ├── date -> coreutils
│   ├── dd -> coreutils
│   ├── df -> coreutils
│   ├── dir -> coreutils
│   ├── dircolors -> coreutils
│   ├── dirname -> coreutils
│   ├── du -> coreutils
│   ├── echo -> coreutils
│   ├── env -> coreutils
│   ├── expand -> coreutils
│   ├── expr -> coreutils
│   ├── factor -> coreutils
│   ├── false -> coreutils
│   ├── fmt -> coreutils
│   ├── fold -> coreutils
│   ├── groups -> coreutils
│   ├── head -> coreutils
│   ├── hostid -> coreutils
│   ├── id -> coreutils
│   ├── install -> coreutils
│   ├── join -> coreutils
│   ├── kill -> coreutils
│   ├── link -> coreutils
│   ├── ln -> coreutils
│   ├── logname -> coreutils
│   ├── ls -> coreutils
│   ├── md5sum -> coreutils
│   ├── mkdir -> coreutils
│   ├── mkfifo -> coreutils
│   ├── mknod -> coreutils
│   ├── mktemp -> coreutils
│   ├── mv -> coreutils
│   ├── nice -> coreutils
│   ├── nl -> coreutils
│   ├── nohup -> coreutils
│   ├── nproc -> coreutils
│   ├── numfmt -> coreutils
│   ├── od -> coreutils
│   ├── paste -> coreutils
│   ├── pathchk -> coreutils
│   ├── pinky -> coreutils
│   ├── pr -> coreutils
│   ├── printenv -> coreutils
│   ├── printf -> coreutils
│   ├── ptx -> coreutils
│   ├── pwd -> coreutils
│   ├── readlink -> coreutils
│   ├── realpath -> coreutils
│   ├── rm -> coreutils
│   ├── rmdir -> coreutils
│   ├── runcon -> coreutils
│   ├── seq -> coreutils
│   ├── sha1sum -> coreutils
│   ├── sha224sum -> coreutils
│   ├── sha256sum -> coreutils
│   ├── sha384sum -> coreutils
│   ├── sha512sum -> coreutils
│   ├── shred -> coreutils
│   ├── shuf -> coreutils
│   ├── sleep -> coreutils
│   ├── sort -> coreutils
│   ├── split -> coreutils
│   ├── stat -> coreutils
│   ├── stdbuf -> coreutils
│   ├── stty -> coreutils
│   ├── sum -> coreutils
│   ├── sync -> coreutils
│   ├── tac -> coreutils
│   ├── tail -> coreutils
│   ├── tee -> coreutils
│   ├── test -> coreutils
│   ├── timeout -> coreutils
│   ├── touch -> coreutils
│   ├── tr -> coreutils
│   ├── true -> coreutils
│   ├── truncate -> coreutils
│   ├── tsort -> coreutils
│   ├── tty -> coreutils
│   ├── uname -> coreutils
│   ├── unexpand -> coreutils
│   ├── uniq -> coreutils
│   ├── unlink -> coreutils
│   ├── uptime -> coreutils
│   ├── users -> coreutils
│   ├── vdir -> coreutils
│   ├── wc -> coreutils
│   ├── who -> coreutils
│   ├── whoami -> coreutils
│   └── yes -> coreutils
└── libexec
    └── coreutils
        └── libstdbuf.so

3 directories, 108 files
@solidsnack
Copy link
Owner

solidsnack commented May 10, 2019

Thanks for making this change. I'm not sure we can use this method -- -a ... is a Bash-ism -- but I'm sure we can do something.

It sounds like you're not calling including the binary in the tarball and calling it with a script, but rather inlining the binary, using arx -e <path/to/binary>. While we sort out setting $0, would putting the binary in the tarball work?

@matthewbauer
Copy link
Contributor Author

Thanks for making this change. I'm not sure we can use this method -- -a ... is a Bash-ism -- but I'm sure we can do something.

Oops didn't consider that! It's definitely good to avoid that.

It sounds like you're not calling including the binary in the tarball and calling it with a script, but rather inlining the binary, using arx -e <path/to/binary>. While we sort out setting $0, would putting the binary in the tarball work?

The binary is still in the tarball. The problem is I don't want to hardcode the binary name into it. So for instance, I would like to be able to make a symlink on the outer arx script so that it propagates to the inner "$0". Here is a good way to show what happens without using -a:

$ arx tmpx // echo '$0' > exe && chmod +x exe && ./exe
/tmp/tmpx-20190510T174337Z-81443be2/dat/../run

I'd like it to show ./exe and also allow me to make a symlink so that:

$ ln -s exe exe2 && ./exe2
./exe2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants