Bug 11381 - Wrong exit code in xargs
Summary: Wrong exit code in xargs
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: 1.28.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-05 12:38 UTC by Masar
Modified: 2018-10-30 13:42 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Masar 2018-10-05 12:38:58 UTC

    
Comment 1 Masar 2018-10-05 12:54:42 UTC
Here is a sample command that shows the problem:
   
   echo "1 2 3" | busybox xargs -n 1 -I '{}' sh -c "exit 255" ; echo $?

This command shoud print '124' as exit code, but in newer versions it returns '0'

I tested on varioius linux systems and with docker:
   1.29: ERROR
   1.28: ERROR
   1.27: OK
   1.26: OK

DOCKER: latest
   docker run -ti --rm busybox:latest
   / # echo 1 2 3 | /bin/busybox xargs -n 1 -I '{}' sh -c 'exit 255' ; echo $?
   xargs: sh: exited with status 255; aborting
   0

DOCKER: 1.29
   docker run -ti --rm busybox:1.29
   / # echo 1 2 3 | /bin/busybox xargs -n 1 -I '{}' sh -c 'exit 255' ; echo $?
   xargs: sh: exited with status 255; aborting
   0

DOCKER: 1.28
   docker run -ti --rm busybox:1.28
   / # echo 1 2 3 | /bin/busybox xargs -n 1 -I '{}' sh -c 'exit 255' ; echo $?
   xargs: sh: exited with status 255; aborting
   0

DOCKER: 1.27
   docker run -ti --rm busybox:1.27
   / # echo 1 2 3 | /bin/busybox xargs -n 1 -I '{}' sh -c 'exit 255' ; echo $?
   xargs: sh: exited with status 255; aborting
   124

DOCKER: 1.26
   docker run -ti --rm busybox:1.26
   / # echo 1 2 3 | /bin/busybox xargs -n 1 -I '{}' sh -c 'exit 255' ; echo $?
   xargs: sh: exited with status 255; aborting
   124
Comment 2 Denys Vlasenko 2018-10-30 13:41:59 UTC
Fixed in git:

commit f3e2838fc4e6bd0713d7ee5a17e752a19870a0f8
Date:   Tue Oct 30 14:40:17 2018 +0100

    xargs: fix exit code if command exits nonzero, closes 11381