when xargs runs in parallel mode (using -P flag), it may sometimes return incorrect exit code. The following code shows current (incorrect) behaviour: /bin directory exists, /foo directory does not exist. `echo /bin /foo | xargs -n1 -P2 test -d` sometimes return 0 sometimes return 1: ``` root@freebsd:~ # test -d /bin root@freebsd:~ # echo $? 0 root@freebsd:~ # test -d /foo root@freebsd:~ # echo $? 1 root@freebsd:~ # echo /bin /foo | xargs -n1 -P2 test -d root@freebsd:~ # echo $? 0 root@freebsd:~ # echo /bin /foo | xargs -n1 -P2 test -d root@freebsd:~ # echo $? 1 root@freebsd:~ # echo /bin /foo | xargs -n1 -P2 test -d root@freebsd:~ # echo $? 0 ```
*** Bug 267111 has been marked as a duplicate of this bug. ***
Created attachment 237367 [details] patch to xargs and tests This is the patch to fix the issue
Not sure which is the perferred way to send fixes, I also raised a PR in github: https://github.com/freebsd/freebsd-src/pull/618
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=0ca740d9a639ab635f5a28be9051d0124a9544a1 commit 0ca740d9a639ab635f5a28be9051d0124a9544a1 Author: liu-du <duliujimmy@hotmail.com> AuthorDate: 2022-10-16 03:41:54 +0000 Commit: Mateusz Guzik <mjg@FreeBSD.org> CommitDate: 2022-10-17 10:39:04 +0000 xargs: fix exit code when using -P currently when xargs runs in parallel mode (e.g. -P2), it somtimes incorrectly returns zero exit code. this commit fix it and also adds tests. Reviewed by: mjg PR: 267110 usr.bin/xargs/tests/regress.sh | 7 ++++++- usr.bin/xargs/xargs.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=6c49b65d6da24cc50409418b26a2df1bdbdb672e commit 6c49b65d6da24cc50409418b26a2df1bdbdb672e Author: liu-du <duliujimmy@hotmail.com> AuthorDate: 2022-10-16 03:41:54 +0000 Commit: Mateusz Guzik <mjg@FreeBSD.org> CommitDate: 2022-11-10 22:43:58 +0000 xargs: fix exit code when using -P currently when xargs runs in parallel mode (e.g. -P2), it somtimes incorrectly returns zero exit code. this commit fix it and also adds tests. Reviewed by: mjg PR: 267110 (cherry picked from commit 0ca740d9a639ab635f5a28be9051d0124a9544a1) usr.bin/xargs/tests/regress.sh | 7 ++++++- usr.bin/xargs/xargs.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-)
A commit in branch stable/12 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=2abbb9dd7802c4408922104e1b961603008fde2e commit 2abbb9dd7802c4408922104e1b961603008fde2e Author: liu-du <duliujimmy@hotmail.com> AuthorDate: 2022-10-16 03:41:54 +0000 Commit: Mateusz Guzik <mjg@FreeBSD.org> CommitDate: 2022-11-10 22:45:24 +0000 xargs: fix exit code when using -P currently when xargs runs in parallel mode (e.g. -P2), it somtimes incorrectly returns zero exit code. this commit fix it and also adds tests. Reviewed by: mjg PR: 267110 (cherry picked from commit 0ca740d9a639ab635f5a28be9051d0124a9544a1) usr.bin/xargs/tests/regress.sh | 7 ++++++- usr.bin/xargs/xargs.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-)