From nobody Tue Aug 12 21:20:45 2025 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 4c1kv125xYz645wD; Tue, 12 Aug 2025 21:20:45 +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 4c1kv11W4lz3k3q; Tue, 12 Aug 2025 21:20:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755033645; 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=jDnFVm+NYNvDsfgNbsHeMmMVW+RQA8n/+mod3MKGr14=; b=FzQa6L4yxe1JasPTSi/PvirMgTLo2YNxJmZNn7wq1xZ0f1DBW5lent71pVzvxbsF5uI39t gJmQqARjTx6r4Us4CcnADmXFk+AvDR13Gz2AVXzxcGfXl+aSpd4kMC/R/tCN5dOW54uFBe Gz0reoeM55t3IWeceLwDqR+G3LKpZdln0aseCxv5NsXaaD6NkKS930RVp+f/GH3g1LnsWX D2o41ETYNeAKrVRtxvEUU5XdO8Vlyd6ddXGHlfl5BgIXglhlOq9Wz97cP5LJUKOa7u0hiC teb0FSc0j7CBA45JDtu5T+rrHtOu/Zv/37dbAEYn49/aALXfqW/yOOPdaJdRfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755033645; 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=jDnFVm+NYNvDsfgNbsHeMmMVW+RQA8n/+mod3MKGr14=; b=kuWDX8hYLjpqlLP1tTiVILvOAY8svlozFffTwKqGbe3H9OvLUialOTDHDe+2rCJSdnTXGl K6yMJwX5W9rs7//uK5s7lSC5Gn7HSn2phJegAGze+l7KX1CFSsR0tcpQOLGdzH9I6EEtPM hW9r5YOSWXnPoSTo/I/OtWl+XVw1dDpvVhe7nNhRSpNvTJ8gaoCUvSSvhofPTQIrh+M7z9 knnBCZTPZCdy7B6wD6PPvLrjsRurn+ISSo3ADaRGtVLfTI/L0q/0zKAfJdJLdd5fxzzmmW 8b8D4bvm6OieUX1LLU8CV2H0khypGGukSSdBv4GHkCAbeEFNwh4dBNoaQ9+Ucw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1755033645; a=rsa-sha256; cv=none; b=izTm7Y9ZEZ5UjXtaYpu73JNFBH5fl3ezHne3ubjdzDudBWOebZ+HEHqefXGtOJNEkXQHrv DvDL4T5IPEzQgnGmW2zjYt0XNRh9k9MSCiNMhWkNCHC2uXroqwJ8O3EWB94zNXuDsVTvdG bJypyU6+FJ0CFoSHDEIzWnRLrVqCaMNrWMXnMuCwaec4mRFKhlpdZp/OMFRFZlGWRABYAG hd9ZE5zMSZSavQ0MT0Fjo2l0Uy1YfF67T2VAgYcjmKNTBMQDYW8JE7q27+pU4eROdqABlF +Lh+7XDLbiJKC9MsQ67h6m5xjnYRwY6AWeOGEjQ8ZpG7xRIN753zzbrkEvWZew== 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 4c1kv1102PzvTg; Tue, 12 Aug 2025 21:20:45 +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 57CLKjOY047454; Tue, 12 Aug 2025 21:20:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57CLKjtb047451; Tue, 12 Aug 2025 21:20:45 GMT (envelope-from git) Date: Tue, 12 Aug 2025 21:20:45 GMT Message-Id: <202508122120.57CLKjtb047451@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: 01bb889cc1b1 - stable/13 - wordexp(3): Handle ECHILD from waitpid 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/13 X-Git-Reftype: branch X-Git-Commit: 01bb889cc1b1863798ae65f95769c227bae297c3 Auto-Submitted: auto-generated The branch stable/13 has been updated by jilles: URL: https://cgit.FreeBSD.org/src/commit/?id=01bb889cc1b1863798ae65f95769c227bae297c3 commit 01bb889cc1b1863798ae65f95769c227bae297c3 Author: Kenny Levinsen AuthorDate: 2025-04-21 12:13:43 +0000 Commit: Jilles Tjoelker CommitDate: 2025-08-12 21:20:24 +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 0902814eb04f..fe23e563c3f5 100644 --- a/lib/libc/gen/wordexp.c +++ b/lib/libc/gen/wordexp.c @@ -266,7 +266,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 ea8dc3d37828..f7e94b02697a 100644 --- a/lib/libc/tests/gen/wordexp_test.c +++ b/lib/libc/tests/gen/wordexp_test.c @@ -293,6 +293,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) { @@ -351,6 +376,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);