From nobody Tue Jul 08 21:39:22 2025 X-Original-To: dev-commits-src-main@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 4bcDyg3ZYzz60ZVt; Tue, 08 Jul 2025 21:39:23 +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 4bcDyg0ZkXz3GYc; Tue, 08 Jul 2025 21:39:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752010763; 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=6xBwA9FzQm702+Ld2EvaKENmyyCiopsxWpeP4QGudNQ=; b=J7U16WYvQWvGkrrrmuCs6QNK76sukNwUDTay9aMemCWnEHa6QS3r7h0kdpkwQmXj4eJy47 LEuM1uBP0vWF0d+r5KZGW2YyyQhVluA8QQCCi+B95zaiGKRPJG9D8N4ue4Y/v+miMA31p6 +QmIAcHsNXiVyPSMNpNgb5aCe1hdHv08TgshPT/iFcu1b4kC7JXTRGOGCVY0SJgzU3vR0X 8CaEZb2c83qUw2NmtiN82y/poQSZhjheJjdvcdq4SZdqoEcEE/7cncKGf8HbybSosPCYeR 1P+Q9aQHTF7RXOdHHavJDYi/zqZwMgibDJ0UNnIrBI7jC/VI0K/u/zNZLcAXHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752010763; 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=6xBwA9FzQm702+Ld2EvaKENmyyCiopsxWpeP4QGudNQ=; b=Ot/7XLx3WAjBJRSF+kSNmMM31U/0R4/ceyr/fA4RLpAgV5tbnDAlTqW/B8TZEg3sEbM4zR wLDj7S31ag45JXURQWEMZH2rX9b+5tjsRvy0RfLpEXTdpEg++/kKgQcr8qBpVNvhZM1ZXb p8hfnuK9tZS2zesuYkvLnruaOzW1GsnEUO02ahMmPKvMP8n4e4vzm5mDgZ37bWm8gZ0GGe dqUG0nBBuB+0ltyj0e1ZfSTnNP3HTzVGeZkMtoKKNkqAUZrdmiOoAuVDXLNLpa8rsVah22 Z18sMBCwxBKCwb732pUiWtq7zX8q8SmC9JSNLpTeRZ/lH2975BdhpNajB/BGDg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1752010763; a=rsa-sha256; cv=none; b=PrdnGaT4k5YJK2gQXhukLDsO7VW9J9b+XxyvoulUQFADEzOFp7j7AofdSd62aLxf+8kKAP WJmdPCJPUDZQOcaOsB/oyhX2Nsybqih26YN4NKa+g6c6NvZipmxaBPOSGU40dwUhgnyRby 2uBe42MW28KjvDOUEZM2zB2hAv2t3uv5KNgHG7LOcB8Jcy4H9Q0BYMswPNn7KTXb0EhnH4 hCI7HkFCM6Mku+3c3SaYUueatuAII1GYZV/dgLhuGN8xuVdXwlFmDVGi0yzC/raRNpSvFK Uic7t9iL62G52UFJLjQFmEaCPlRfLopZV17sq5BDh0565/pBMIpy0VhK+z4agA== 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 4bcDyf70f2zv43; Tue, 08 Jul 2025 21:39:22 +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 568LdMhr067625; Tue, 8 Jul 2025 21:39:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 568LdMaW067622; Tue, 8 Jul 2025 21:39:22 GMT (envelope-from git) Date: Tue, 8 Jul 2025 21:39:22 GMT Message-Id: <202507082139.568LdMaW067622@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jilles Tjoelker Subject: git: da9e73e5d483 - main - wordexp(3): Handle ECHILD from waitpid List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: da9e73e5d483c47e67b3094356dd4b640749849e Auto-Submitted: auto-generated The branch main has been updated by jilles: URL: https://cgit.FreeBSD.org/src/commit/?id=da9e73e5d483c47e67b3094356dd4b640749849e commit da9e73e5d483c47e67b3094356dd4b640749849e Author: Kenny Levinsen AuthorDate: 2025-04-21 12:13:43 +0000 Commit: Jilles Tjoelker CommitDate: 2025-07-08 21:27:33 +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 --- 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);