[Toybox] [PATCH] ls.c: match coreutils exit status.

enh enh at google.com
Sun Nov 3 21:18:32 PST 2019


On Sun, Nov 3, 2019 at 5:13 PM Rob Landley <rob at landley.net> wrote:
>
> On 10/31/19 11:50 AM, enh via Toybox wrote:
> > Andrew Ilijic noticed that our ls exit status differs from coreutils
> > while writing tests. From coreutils' `ls --help`:
> >
> >  0  if OK,
> >  1  if minor problems (e.g., cannot access subdirectory),
> >  2  if serious trouble (e.g., cannot access command-line argument).
> >
> > Invalid/unknown command-line arguments count as 2.
>
> I agree it's a difference, but what is the impact? Did any script anywhere use
> this, or are we changing it just because we can? What is the rule for what the
> return codes mean? (Are we switching from posix to the man pages as our standard?)
>
> As for _this_ one, what's the definition of "minor" vs "serious"? If we "ls *"
> and there's 300 things, one of which is a subdirectory we can't access, this is
> both minor and serious. And we're adding behavior that we care about enough to
> test but not mentioning it in the help output, not that I _want_ to make
> multiple commands' help output bigger...
>
> It's not a big change, I just don't understand what the motivation for it is.

andrew was trying to write tests, and having trouble because of this
difference. he asked me off-list what we've done about exit statuses
in the past, and i said basically "in the past we've changed toybox to
match the existing tools _but_ in the past it's always because we've
had a real-world existing user --- so this is a new case where
currently the only known user would be a toybox test". to which he
asked "so what should we do?" and, since i'd already written this
patch to show him _how_ to do the ARGFAIL thing, i basically said
let's suck it and see --- if rob takes the patch, go with `$?`, if he
doesn't like it, go with `|| echo`.

looks like we're on the `|| echo` path.

> It's an increase (2 new lines and a macro) in code complexity rather than an
> equivalent substitution, and it's the half-dozenth return to this topic so far
> over an 8 month period, and I'd like to be able to enunciate what we're trying
> to accomplish here and put it in design.html or something.

for me personally "existing scripts in the wild are making use of the
distinctions [as with timeout(1) or xargs(1)]" is 100% legit. and
"we've only seen this on the man page and can't imagine a use for it"
is the opposite end of the spectrum.

this one is particularly weird because on the one hand "helps testing"
is good, but on the other hand, the fact that "the reference
implementation is ridiculous" is bad. (a) because the difference
between "minor" and "serious" seems completely arbitrary and (b)
because i'm really struggling to imagine a situation where it would
actually be useful. (well, i can probably guess that this was for
autotools, so they could recognize a GNU ls? but until we hit that
case in practice...)

> Rob


More information about the Toybox mailing list