Bug 267110 - xargs return incorrect exit code when run in parallel mode
Summary: xargs return incorrect exit code when run in parallel mode
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Mateusz Guzik
URL:
Keywords:
: 267111 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-10-16 05:07 UTC by Du Liu
Modified: 2022-11-10 22:46 UTC (History)
3 users (show)

See Also:


Attachments
patch to xargs and tests (2.04 KB, patch)
2022-10-16 05:32 UTC, Du Liu
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Du Liu 2022-10-16 05:07:41 UTC
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
```
Comment 1 Du Liu 2022-10-16 05:23:17 UTC
*** Bug 267111 has been marked as a duplicate of this bug. ***
Comment 2 Du Liu 2022-10-16 05:32:48 UTC
Created attachment 237367 [details]
patch to xargs and tests

This is the patch to fix the issue
Comment 3 Du Liu 2022-10-16 05:33:43 UTC
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
Comment 4 commit-hook freebsd_committer freebsd_triage 2022-10-17 10:40:55 UTC
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(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2022-11-10 22:45:11 UTC
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(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2022-11-10 22:46:12 UTC
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(-)