News for hackers. Stuff that matters.
Re:Why bother with argv[0]? by blenderob on Tuesday September 03, 2024 @11:54AM (#41436161)
What about compiled binaries that for one reason or another is doing an execve() on "/usr/bin/cmp" or some such thing? Do you propose changing every script and every binary on earth that expects Busybox to be a POSIXy, Unixy environment?
Re:Why bother with argv[0]? by pzmarzly on Tuesday September 03, 2024 @12:06PM (#41436308)
On Unixes it doesn't matter if /usr/bin/cmp is a script or a compiled binary. If the script has correct shebang, kernel takes care of executing it.
Re:Why bother with argv[0]? by oguz-ismail on Tuesday September 03, 2024 @12:51PM (#41436741)
Shebangs are not part of the UNIX specification. What happens if an executable starts with `#!' is implementation-defined.
Re:Why bother with argv[0]? by immibis on Wednesday September 04, 2024 @08:12AM (#41444734)
is being able to run busybox part of that specification? Linux ELF files are tagged for Linux OS, not generic Unix OS.
Re:Why bother with argv[0]? by blenderob on Wednesday September 04, 2024 @08:20AM (#41444786)
> is being able to run busybox part of that specification?

It's the other way round. This is like asking if running RHEL is part of the specification? Obviously not. But RHEL provides an environment that is quite close to the specification.

So is running a busybox part of the specification? Obviously not. But Busybox provides an environment that is close to the speficiation.

Re:Why bother with argv[0]? by immibis on Wednesday September 04, 2024 @11:49AM (#41447185)
Then it would be busybox's responsibility to make busybox work.
Re:Why bother with argv[0]? by account42 on Thursday September 05, 2024 @06:52AM (#41455388)
UNIX/POSIX doesn't specify an executable format at all
Re:Why bother with argv[0]? by sophacles on Tuesday September 03, 2024 @12:22PM (#41436478)
No you make this script:

   #!/bin/sh
   exec /bin/busybox cmp
And place it at /usr/bin/cmp
Re:Why bother with argv[0]? by teddyh on Tuesday September 03, 2024 @12:49PM (#41436728)
Surely you mean

  #!/bin/sh
  exec /bin/busybox cmp "$@"
Re:Why bother with argv[0]? by oguz-ismail on Tuesday September 03, 2024 @12:53PM (#41436762)
`#!/bin/sh' makes this less portable than it could be, if /bin/sh doesn't exists on my system it won't work, for example. Remove that line and it'll work everywhere.
Re:Why bother with argv[0]? by teddyh on Tuesday September 03, 2024 @01:01PM (#41436858)
If /bin/sh does not exist, what in the world is executing the shell script?
Re:Why bother with argv[0]? by oguz-ismail on Tuesday September 03, 2024 @01:08PM (#41436935)
The shell, of course. It just might not be (because it doesn't have to be) located in /bin.
Re:Why bother with argv[0]? by teddyh on Tuesday September 03, 2024 @01:11PM (#41436969)
I’m pretty sure that /bin/sh is mandated by POSIX.
Re:Why bother with argv[0]? by oguz-ismail on Tuesday September 03, 2024 @01:45PM (#41437258)
It's not. See https://pubs.opengroup.org/onlinepubs/9799919799/utilities/s...

    Applications should note that the standard PATH to the shell cannot be assumed to be either /bin/sh or /usr/bin/sh, and should be determined by interrogation of the PATH returned by getconf PATH, ensuring that the returned pathname is an absolute pathname and not a shell built-in.
Re:Why bother with argv[0]? by alerighi on Tuesday September 03, 2024 @02:47PM (#41437822)
So now to execute a program that could have been a direct run you have to fire up a shell, have it parse the file, and execute the instruction? Not really a great thing...

Plus, you have to know the absolute path of the executable busybox, not something you always know in advance.

Re:Why bother with argv[0]? by sophacles on Tuesday September 03, 2024 @03:13PM (#41438129)
You're not wrong about the extra execution of shell, although a lightweight shell like ash or dash doesn't have a huge overhead.

But realistically, the only people that need to worry about the actual location of the busybox executable are the people who write the install script - it would take that as an argument or variable and spit out all the little scripts as an automated process. The current installer already has to do most of this work as part of setting up the relevant links anyway.