[Toybox] bug: commands with no options silently allow all options

Rob Landley rob at landley.net
Fri Mar 17 09:28:26 PDT 2017

On 03/16/2017 12:08 PM, enh wrote:
> commands with options are fine:
> $ ./toybox df -z
> ...
> df: Unknown option z
> but any command with no options silently ignores any options:
> $ ./toybox uptime -z
>  10:07:34 up 34 days, 30 min,  6 users,  load average: 4.44, 2.28, 1.46
> $ ./toybox uptime -z g
>  10:08:26 up 34 days, 31 min,  6 users,  load average: 3.65, 2.46, 1.57
> $ ./toybox uptime g
>  10:08:28 up 34 days, 31 min,  6 users,  load average: 3.65, 2.46, 1.57

Um, yeah. That was intentional. (Postel's law is a bug now?)

When you NULL out the optstr of the NEWTOY() macro the option parsing
infrastructure doesn't get called (and can actually drop out at compile
time if nothing uses it, see the NEED_OPTIONS in main.c). Instead
main(argv) gets put straight into toys.argv[] and if the command wants
to parse stuff itself it can.

You can get a similar effect with the "?" prefix to optstr (as find.c
and kill.c do so "find -depth" and "kill -stop" aren't intercepted as

I also added a flag to skip the --help and --version parsing for "false"
and "true" because paying _any_ attention to their arguments was
considered a bug by somebody (I forget who, there was a complaint).

It's easy to change the behavior, but... could you clarify what you want?

If you change the NULL to ">0", it goes:

  $ ./uptime -z
  usage: uptime

  Tell how long the system has been running and the system load
  averages for the past 1, 5 and 15 minutes.

  uptime: Unknown option z
  $ ./uptime
   10:53:24 up 122 days, 22:01,  269 users,  load average: 1.67, 1.71,

I see that the gnu/dammit stuff has grown checking for this over the
past decade (along with systemd). Circa Red Hat 9 a lot of stuff with no
options ignored them. Now everything has lots and lots of options even
when it does nothing. (Good grief, "help cd" produces 33 lines of
output, and that's despite popd/pushd being separate commands.)

If you're going to police this you may also want to do stuff like "nproc
one two three four five" which happily ignores the extraneous garbage
and produces its output. I'm guessing it should _not_ work?


More information about the Toybox mailing list