From nobody Thu Nov 10 22:45:35 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4N7cPC4cqCz4dDyh; Thu, 10 Nov 2022 22:45:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4N7cPC48ZSz4QYG; Thu, 10 Nov 2022 22:45:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668120335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=a/Ky1lJzxF3Xjg6z5Z1utGbnt6SE9yB5yLASCdUcG/o=; b=CNYcaTvvSGZGTkRo/mHx/glBfpZ2kA0xstSQAOiz3Wc8kIx+lrfZ3i7r9XShoJ1+y7lmf/ /8qfb8mb25sCxWQihZEWpQ/VMnx6Gi3qQa9A6EqhqOAFpyjfRFRu1BTMjKzk4wcwxo19g3 vc5cPfwttZv/D47fwFGbTKfB2g+RdAseEfkGhdTi8Pj8qvYiMBsCqvWUZn0xV3ovEWtjzj puDRXFvcO7kriOsR5B1AhKlTfvvElfgv1qiqAFLiS4We9zmnbpv2Iba7/ZsjKRi0AlwF1t UuJ5LewrnxGeSpDvdzhuTcRkquY42W8sHvyNIK9c/MKUX206H8qzmlclHIHl+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668120335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=a/Ky1lJzxF3Xjg6z5Z1utGbnt6SE9yB5yLASCdUcG/o=; b=p4C/sDXqMax+tfHf+bQ453jud2bSIxNaJyjE3WmaS7Jqi9NC7BQLljB5OI0dnzoMiz5A3n Lmu1s0IO1vRxuiBLU8bonG9mAiXZNfAQC0dBKxbryKjgtkuXR7hZ49cfhQvitagsjqjd5B TTxqoDEvXH98hqxT52QOJ+dy44TLW5iOj6JzLKFrjSMlptt0vek4xQRpG3ma1bFT1udKzt WFxrrM+Bln7IEpQWFmfvvqar4qUd8ytcCXb3SDuK6htZtpyVl3/3CYZ1T9YyC1JW76Ahwo WmpeIWIa6cWO+t4XTKzGdblMF+t9MpNhGA3ts6sWjoJQPot9AGrzppVR2xbO/g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668120335; a=rsa-sha256; cv=none; b=b7gNQqoQTv2FQKxw59VDHER3guLihhVQpvPVBSGU9B4lmU6lJQ3Kg8Wv0Jaof48po/RvER sVXNiEwuRcEMmvyoOUJyrbBwZSSaUvkgP/WWNkmTq+LBIroCjSqFwE/rMjAOvuCwvp97Z5 8MjQU8oAVsWCrGmE4uGW9jrddktLJNpbbVYImJ0FPG+h+Em66ZT8zZqrlU9ROpbMzAQsvy tExt6pDbqqKP/5Z0d00zU5Zb39XZIeOA01IvkHiA/eMct/9bjvgkmkukKfBhSPPg9rdCar JpwFkdFarV/56b9nq7lC1O1NsmlJqgUGn5NdZrmtkg7jfup9W4WGGRHe4H18pw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4N7cPC3C0szJmx; Thu, 10 Nov 2022 22:45:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2AAMjZc3000087; Thu, 10 Nov 2022 22:45:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AAMjZVr000086; Thu, 10 Nov 2022 22:45:35 GMT (envelope-from git) Date: Thu, 10 Nov 2022 22:45:35 GMT Message-Id: <202211102245.2AAMjZVr000086@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 2abbb9dd7802 - stable/12 - xargs: fix exit code when using -P List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 2abbb9dd7802c4408922104e1b961603008fde2e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=2abbb9dd7802c4408922104e1b961603008fde2e commit 2abbb9dd7802c4408922104e1b961603008fde2e Author: liu-du AuthorDate: 2022-10-16 03:41:54 +0000 Commit: Mateusz Guzik 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(-) 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 2825a26f4dfa..6520d43dae50 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -314,8 +314,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': @@ -405,8 +407,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;