From nobody Tue Aug 12 21:20:04 2025 X-Original-To: dev-commits-src-branches@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 4c1ktF0xFYz646Dp; Tue, 12 Aug 2025 21:20:05 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4c1ktF08Pvz3k0C; Tue, 12 Aug 2025 21:20:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755033605; 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=hTsVhAsX1SC6JoMfkjWr1hGNzUo5O3C/SMDDaMhPbdc=; b=M6sTenaVIQb0Q995nS0D0RftP2953BRvq5pqRU+OZNnnduDm64Cgd5SMmY0XFA2ZG1tkLl M/FjWgpkrcXncchn6Pf9lM4dGIoJmUTZQ2dWAjKDRRB3bOH96Cgkp+pQgVtKb7+ZILtaoM +2ZDDHAkGL5pGfWHZkOESQvlCBPLT39Tm61LpfDQdP5x0Cnl3rV3XUewtrzqJrIa3Fmnsi RFYI3P8n3DZJHMb0pN03FuANu/siTa1cy1wKLeWpM0NljYHZync8qXgnhBj+4oSQBqmIGI qoDVlTB7N4F7c6P1E5v7/oeRjaaK1h/Qo70yWmTYmVSZkWK0Nv+FK3d0mg4QnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755033605; 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=hTsVhAsX1SC6JoMfkjWr1hGNzUo5O3C/SMDDaMhPbdc=; b=P4oX3tGNsbEosBBE901pAhtJr5JGKud3/gy/xyURvZfEMHRue78nNRYAJJq7eHPIGKpBVe JEIWJm8JZ/ZYbbq0T3J7F4Lpe9rizVRC/noYjXyuRK9GDUQ8QbX+NfB/suBaKG64eecT05 zCc44XLf02l0Can5p3DiC2KTfaBTxci2nC+yPMb++3QU1y8W03yYYuC9bXH3hhhvhurZ41 1kb84x+KHhyFd6yuzbPmixf9WxRXsPoBSXL/s82ndTdc2hmqImGZuSzTfO2mYw9YyPNle1 6cs+zcAuu/n1uBx5+dBTPAP3XupVzLN0R3fEeHOmmfegd3ixkG3BPPa1lApjqQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1755033605; a=rsa-sha256; cv=none; b=c0qsbo5n1LseYXaId9oXkYRt+AcfQWUIISzjmBP1iaImWLac4hbM6+J6Bg+YXG/zJSnjXy vvCyZjJx0l7VxhlrLjf15fXeJFBMD9KEOvvj6cVhP2S4eb7Kk2/oBu40oDjjRo4ftqCxgj 1+vHCqfe5oCM5aE1IqZM0vIR9o5Kd3JNf074CWsEn5thkO6EyT8nsrYOGkyKkEhd8PVxCM H2EAzgSn4573L78jxVGH0QwT+M9rqjegHos6sUZ1iKKIcOE9TDIGvZg6rFgOehu4at7fYQ Z606rMf0tEf6KAHh+YveY04mR++ZJEgW1CnsA0TX4Sowu/YWRRxLbK1gBhtBVw== 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 4c1ktD6sCszvm9; Tue, 12 Aug 2025 21:20:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 57CLK4B0041112; Tue, 12 Aug 2025 21:20:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57CLK4wS041107; Tue, 12 Aug 2025 21:20:04 GMT (envelope-from git) Date: Tue, 12 Aug 2025 21:20:04 GMT Message-Id: <202508122120.57CLK4wS041107@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jilles Tjoelker Subject: git: 5c37f7d22fa7 - stable/14 - wordexp(3): Handle ECHILD from waitpid List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jilles X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 5c37f7d22fa7edd03b6cd012cb73fa6cac0880ad Auto-Submitted: auto-generated The branch stable/14 has been updated by jilles: URL: https://cgit.FreeBSD.org/src/commit/?id=5c37f7d22fa7edd03b6cd012cb73fa6cac0880ad commit 5c37f7d22fa7edd03b6cd012cb73fa6cac0880ad Author: Kenny Levinsen AuthorDate: 2025-04-21 12:13:43 +0000 Commit: Jilles Tjoelker CommitDate: 2025-08-12 21:18:42 +0000 wordexp(3): Handle ECHILD from waitpid If the calling process has used SIG_IGN as handler or set the SA_NOCLDWAIT flag for SIGCHLD, processes will be automatically reaped on exit and calls to waitpid(3) will therefore fail with ECHILD. We waitpid primarily to reap our child so that the caller does not have to worry about it. ECHILD indicates that there is no child to reap, so we can just treat that as a success and move on. Signed-off-by: Kenny Levinsen Tested by: Jan Beich Pull Request: https://github.com/freebsd/freebsd-src/pull/1675 (cherry picked from commit da9e73e5d483c47e67b3094356dd4b640749849e) --- lib/libc/gen/wordexp.c | 10 +++++++++- lib/libc/tests/gen/wordexp_test.c | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/libc/gen/wordexp.c b/lib/libc/gen/wordexp.c index f1437e30bbe2..f8080c20d121 100644 --- a/lib/libc/gen/wordexp.c +++ b/lib/libc/gen/wordexp.c @@ -265,7 +265,15 @@ cleanup: errno = serrno; return (error); } - if (wpid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) + /* + * Check process exit status, but ignore ECHILD as the child may have + * been automatically reaped if the process had set SIG_IGN or + * SA_NOCLDWAIT for SIGCHLD, and our reason for waitpid was just to + * reap our own child on behalf of the calling process. + */ + if (wpid < 0 && errno != ECHILD) + return (WRDE_NOSPACE); /* abort for unknown reason */ + if (wpid >= 0 && (!WIFEXITED(status) || WEXITSTATUS(status) != 0)) return (WRDE_NOSPACE); /* abort for unknown reason */ /* diff --git a/lib/libc/tests/gen/wordexp_test.c b/lib/libc/tests/gen/wordexp_test.c index 909097fbf51e..a8b9d5509633 100644 --- a/lib/libc/tests/gen/wordexp_test.c +++ b/lib/libc/tests/gen/wordexp_test.c @@ -292,6 +292,31 @@ ATF_TC_BODY(with_SIGCHILD_handler_test, tc) ATF_REQUIRE(r == 0); } +ATF_TC_WITHOUT_HEAD(with_SIGCHILD_ignore_test); +ATF_TC_BODY(with_SIGCHILD_ignore_test, tc) +{ + struct sigaction sa; + wordexp_t we; + int r; + + /* With SIGCHLD set to ignore so that the kernel auto-reaps zombies. */ + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sa.sa_handler = SIG_IGN; + r = sigaction(SIGCHLD, &sa, NULL); + ATF_REQUIRE(r == 0); + r = wordexp("hello world", &we, 0); + ATF_REQUIRE(r == 0); + ATF_REQUIRE(we.we_wordc == 2); + ATF_REQUIRE(strcmp(we.we_wordv[0], "hello") == 0); + ATF_REQUIRE(strcmp(we.we_wordv[1], "world") == 0); + ATF_REQUIRE(we.we_wordv[2] == NULL); + wordfree(&we); + sa.sa_handler = SIG_DFL; + r = sigaction(SIGCHLD, &sa, NULL); + ATF_REQUIRE(r == 0); +} + ATF_TC_WITHOUT_HEAD(with_unused_non_default_IFS_test); ATF_TC_BODY(with_unused_non_default_IFS_test, tc) { @@ -350,6 +375,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, WRDE_BADCHAR_test); ATF_TP_ADD_TC(tp, WRDE_SYNTAX_test); ATF_TP_ADD_TC(tp, with_SIGCHILD_handler_test); + ATF_TP_ADD_TC(tp, with_SIGCHILD_ignore_test); ATF_TP_ADD_TC(tp, with_unused_non_default_IFS_test); ATF_TP_ADD_TC(tp, with_used_non_default_IFS_test);