landley / toybox

toybox
http://landley.net/toybox
BSD Zero Clause License
2.44k stars 340 forks source link

xargs has non-conforming behavior (failing to exit) when a child exits with exit status 255 #483

Closed GabrielRavier closed 8 months ago

GabrielRavier commented 9 months ago

An invocation of xargs such as echo $(seq 1 100) | ./toybox-x86_64 xargs -n1 sh -c 'sleep "$0"; echo "$0"; exit 255' results in the following:

$ echo $(seq 1 6) | ./toybox-x86_64 xargs -n1 sh -c 'sleep "$0"; echo "$0"; exit 255'
1
xargs: sh: exited with status 255; aborting
2
xargs: sh: exited with status 255; aborting
3
xargs: sh: exited with status 255; aborting
4
xargs: sh: exited with status 255; aborting
5
xargs: sh: exited with status 255; aborting
6
xargs: sh: exited with status 255; aborting
$ echo $?
124
$ 

even though the POSIX standard states that:

If [...] an invocation of the utility exits with exit status 255, the xargs utility shall write a diagnostic message and exit without processing any remaining input.

...meaning that Toybox should have exited after printing the first diagnostic, without processing the rest of the input.

landley commented 9 months ago

Commit b89c8914513e

landley commented 8 months ago

Assuming in the absence of objection that the above commit fixed it.

GabrielRavier commented 8 months ago

Can confirm it seems fixed on my end too.