[Toybox] [PATCH] xargs: add --max-args synonym, -o option, and fix -p.

Rob Landley rob at landley.net
Mon Aug 26 19:55:16 PDT 2019


On 8/26/19 12:30 PM, enh wrote:
> ping?

Um! Right. Where was I on this... it's not _generally_ safe to call
perror_exit() from vfork() context, both because it calls our builtin atexit
function list (none here), and because it does a flush() to potentially the
wrong filehandles. That PROBABLY won't cause a problem here, since we only
changed stdin and that's readonly?

Sigh, this is why I wrote xrun(), to handle all this corner case weirdness in
one place. I should switch this to use that.

Ok, question: if we can't open /dev/tty or /dev/null what's the correct thing to
do? This is a "should never fail" case (means your environment is bonkers),
but... what should we DO about it? Kill the whole xargs()? We're going to
repeatedly fail to call each child here. Or we could call it and hope for the
best, but it might misbehave. A real-world case is a chroot with no /dev, in
which case it'll _probably_ work?

That's why I didn't handle the error: continuing seemed to be the best option?
(I tried to make _toybox_ handle "we were called with no stdin" gracefully,
except notstdio() is just gonna open /dev/null to consume filehandles under 3
and error_exit() if it can't, so again crazy environment will drive it nuts...

Now what I _could_ do is call pipe() to get a NOP filehandle. Those are created
in pairs, but I could presumably close the second... Hmmm...

Anyway, I should apply your patch, change it to open the filehandle _first_ and
use xrun(), error_exit() for the tty failure but use pipe() instead of /dev/null
to consume a NOP filehandle (that can only really fail running out of
filehandles, which is definitely error_exit() time...)

Rob



More information about the Toybox mailing list