[Bug: Busybox 1.22.1] false return 0 instead of 1 with '--help' switch.
Joshua Judson Rosen
jrosen at harvestai.com
Tue Sep 2 20:17:51 UTC 2014
On 2014-09-02 14:22, Harald Becker wrote:
> Hi Joshua !
>
>> It's also interesting that busybox "false --help" behaves completely
>> differently
>> depending on whether it's invoked from within a busybox shell or not:
>
> This is wrong!
Hi Harald--
It might be wrong, but it's nonetheless true and not a mistake on my part. ;)
> You called different versions, not Busybox false.
>
>> * invoking "false" as an ash builtin bypasses the "--help" check,
>> does not print the usage message, and exits with EXIT_FAILURE
>> per false_main().
>
> Here you probably used a shell function, which overrides the applet in Busybox.
>
> Look in your profile or sourced scripts, anywhere there I expect a definition
> like: "false() { return 1; }"
Sorry, I meant falsecmd(), not false_main().
Look in ash.c, where you'll see these definitions:
static int FAST_FUNC
falsecmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
return 1;
}
[...]
/* Keep these in proper order since it is searched via bsearch() */
static const struct builtincmd builtintab[] = {
[...]
{ BUILTIN_REGULAR "false" , falsecmd },
[...]
}
> This case is not concerned with the question which Busybox false shall return.
> The maintainer of your profile script is inquestion, for what your shell
> function does.
I'm saying I was surprised that there are two different implementations of
"busybox false", and that their behaviors disagree with each other.
If you want to verify this experimentally, look at this:
jrosen at bz:~/src/busybox$ ./busybox false --help; echo $?
BusyBox v1.23.0.git (2014-09-02 13:43:43 EDT) multi-call binary.
Usage: false
Return an exit code of FALSE (1)
0
jrosen at bz:~/src/busybox$ ln -svfn busybox false
`false' -> `busybox'
jrosen at bz:~/src/busybox$ ./false --help; echo $?
BusyBox v1.23.0.git (2014-09-02 13:43:43 EDT) multi-call binary.
Usage: false
Return an exit code of FALSE (1)
0
jrosen at bz:~/src/busybox$ ./busybox sh -c './false --help; echo $?'
BusyBox v1.23.0.git (2014-09-02 13:43:43 EDT) multi-call binary.
Usage: false
Return an exit code of FALSE (1)
0
jrosen at bz:~/src/busybox$ ./busybox sh -c 'type false; false --help; echo $?'
false is a shell builtin
1
jrosen at bz:~/src/busybox$
Please, don't take my word for it--or Bastian's. Try it yourself.
>> * invoking "false" directly as "/bin/false" or "busybox false"
>> bypasses false_main(), prints the usage message, and exits
>> with 0 per run_applet_no_and_exit().
>
> This is due to common handling of --help in Busybox. The common code displays
> the usage message and exits.
Yes. That's what I said. ;)
If you want to approach this via code inspection, the "false --help returns 0"
change
was efd0698f74caab0a0c8a51228b923ee142e8e278 in git, and that change affects only
the `false binary', not the "false command" in busybox ash.
Did you look at my patch? It brings the two "false" commands into alignment with
each other--as well as into alignment with both POSIX and GNU coreutils "false".
--
"'tis an ill wind that blows no minds."
More information about the busybox
mailing list