Date: Mon, 17 Oct 2022 10:40:04 GMT From: Mateusz Guzik <mjg@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 0ca740d9a639 - main - xargs: fix exit code when using -P Message-ID: <202210171040.29HAe4k8035247@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by mjg: 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(-) diff --git a/usr.bin/xargs/tests/regress.sh b/usr.bin/xargs/tests/regress.sh index 72458a42d774..e79bfd4352fa 100644 --- a/usr.bin/xargs/tests/regress.sh +++ b/usr.bin/xargs/tests/regress.sh @@ -1,6 +1,6 @@ # $FreeBSD$ -echo 1..16 +echo 1..20 REGRESSION_START($1) @@ -21,4 +21,9 @@ REGRESSION_TEST(`0L', `xargs -0 -L2 echo <${SRCDIR}/regress.0.in') REGRESSION_TEST(`0P1', `xargs -0 -P1 echo <${SRCDIR}/regress.0.in') REGRESSION_TEST(`quotes', `xargs -n1 echo <${SRCDIR}/regress.quotes.in') +REGRESSION_TEST_FREEFORM(`parallel1', `echo /var/empty /var/empty | xargs -n1 -P2 test -d; [ $? = 0 ]') +REGRESSION_TEST_FREEFORM(`parallel2', `echo /var/empty /var/empty/nodir | xargs -n1 -P2 test -d; [ $? = 1 ]') +REGRESSION_TEST_FREEFORM(`parallel3', `echo /var/empty/nodir /var/empty | xargs -n1 -P2 test -d; [ $? = 1 ]') +REGRESSION_TEST_FREEFORM(`parallel4', `echo /var/empty/nodir /var/empty/nodir | xargs -n1 -P2 test -d; [ $? = 1 ]') + REGRESSION_END() diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c index 7b664cfde1cc..21455e7be26e 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -315,8 +315,10 @@ parse_input(int argc, char *argv[]) switch (ch = getchar()) { case EOF: /* No arguments since last exec. */ - if (p == bbp) - xexit(*av, rval); + if (p == bbp) { + waitchildren(*av, 1); + exit(rval); + } goto arg1; case ' ': case '\t': @@ -406,8 +408,10 @@ arg2: *xp++ = *avj; } prerun(argc, av); - if (ch == EOF || foundeof) - xexit(*av, rval); + if (ch == EOF || foundeof) { + waitchildren(*av, 1); + exit(rval); + } p = bbp; xp = bxp; count = 0;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202210171040.29HAe4k8035247>