From nobody Sun Jan 25 15:56:54 2026 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 4dzbrk4KbNz6PjPS for ; Sun, 25 Jan 2026 15:56:54 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dzbrk1qPsz47xn for ; Sun, 25 Jan 2026 15:56:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769356614; 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=uY6kAKzLt09CiEo+3L+/Nn0/N13+QGJjEx71jewoZdY=; b=AmWN2xUo+FSbOavldZVuz2VaroScw89lW2ala05hogjTUeYmEtXCpMebE5bxnCa8zt0bxZ UWU25yNBhhkKuTTSjENYzLcN2owhitb7AWNAUA2Z+lLLD8j8dfHd+UbdjjKE0CunSj8bjO RFDUo7JoZV+0H/L68R7ZEPzpGdO5spRE7tL/4U8v3CSDhCpKzy5b2UbL5/KqSh4jOnQI/y TvCK16Zn2qbr6iNYsRFrdvYWL0TmGD2q3PCa71c8R9JI6NnUXfdlEbiJ13TXy7o4yAo/k5 ZTGWUeScMjpgqF/XAGFEayv6y2dA5Or1rIXOV1g8w2YV95QSR91qE8E7/3Itdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769356614; 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=uY6kAKzLt09CiEo+3L+/Nn0/N13+QGJjEx71jewoZdY=; b=fnJLS/9yU5QPQU7GnaXR+ycNfQm3i33Evks/x5E14HdqlnVqc6qiSj8/jhke6mlx6bouQW 5GEjU3Pi/X+IYZE+1FyoaDypVopEmvmMEe0PnW6gm2CdNo0isk9laaTin+6jxSDK+0xBIj 798hHoITAe+imr7rE0wrW0Kp2CSBu8/u9SYJuTA03bQ6JQkO0qwOrBy0h3kPsAbWaBY1A2 ECEfojGIQ2dMPfVJYnRXfF5/0R8kZT4+zmjo48jW/kFYWREersnB2L6gOuRATa3gecB4XC ux0k/jCVz3hIcmuqN6hq3ikODLkiT+rGDjHQqRtoo30qi59fugBPWzuO0mR7VA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1769356614; a=rsa-sha256; cv=none; b=rb3rfnSKkuWLnkaASU9/WTCXzsvvtkUfv4x2O0HY7cNVH+Zk29tZQwG96pzwCQzGdXvEQV U2MJa7WPP2KfHdhd7ed56yMA+fwDSKvq9PKBDdUyLqzA2VMgwmS5v4ZU06AFcFguiY1oOD xryJR23cY71xUgIWEUzW1PsK28nb2BXkA1aGSRuUcm1i+lqqfZsyHoNvgR2xBcL7+dLQeq rqpLYDdlia5s2zplqzZvG+Fs6b0yzhjfYTySDSmSoyuTtJrZfvDGApuhv9j0vh6nlA6z4l 1pa3DYhjfubERqyBFGXP90nCJCIxx/0yVTuggfAeWsafhB9yLDBeiEJfI+vKVw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dzbrk1P5szhxL for ; Sun, 25 Jan 2026 15:56:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 31d71 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 25 Jan 2026 15:56:54 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 7fe33d58a826 - main - kern/kern_exit.c: extract wait6_check_alive() helper 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7fe33d58a82680fcb75de7deea5a071998830b35 Auto-Submitted: auto-generated Date: Sun, 25 Jan 2026 15:56:54 +0000 Message-Id: <69763d46.31d71.564d702@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=7fe33d58a82680fcb75de7deea5a071998830b35 commit 7fe33d58a82680fcb75de7deea5a071998830b35 Author: Konstantin Belousov AuthorDate: 2026-01-08 04:50:03 +0000 Commit: Konstantin Belousov CommitDate: 2026-01-25 15:53:36 +0000 kern/kern_exit.c: extract wait6_check_alive() helper Reviewed by: asomers, markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54592 --- sys/kern/kern_exit.c | 96 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 2b22e3a0a23b..53225bcfd425 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1283,7 +1283,6 @@ report_alive_proc(struct thread *td, struct proc *p, siginfo_t *siginfo, } if (status != NULL) *status = cont ? SIGCONT : W_STOPCODE(p->p_xsig); - td->td_retval[0] = p->p_pid; PROC_UNLOCK(p); } @@ -1307,6 +1306,62 @@ wait6_checkopt(int options) return (0); } +/* + * Checks and reports status for alive process, according to the + * options. Returns true if the process fits one of the requested + * options and its status was updated in siginfo. + * + * If the process was reported (the function result is true), both the + * process and proctree locks are unlocked. + */ +static bool +wait6_check_alive(struct thread *td, int options, struct proc *p, int *status, + siginfo_t *siginfo) +{ + bool report; + + PROC_LOCK_ASSERT(p, MA_OWNED); + sx_assert(&proctree_lock, SA_XLOCKED); + + if ((options & WTRAPPED) != 0 && (p->p_flag & P_TRACED) != 0) { + PROC_SLOCK(p); + report = (p->p_flag & (P_STOPPED_TRACE | P_STOPPED_SIG)) && + p->p_suspcount == p->p_numthreads && + (p->p_flag & P_WAITED) == 0; + PROC_SUNLOCK(p); + if (report) { + CTR4(KTR_PTRACE, + "wait: returning trapped pid %d status %#x (xstat %d) xthread %d", + p->p_pid, W_STOPCODE(p->p_xsig), p->p_xsig, + p->p_xthread != NULL ? + p->p_xthread->td_tid : -1); + report_alive_proc(td, p, siginfo, status, + options, CLD_TRAPPED); + return (true); + } + } + + if ((options & WUNTRACED) != 0 && (p->p_flag & P_STOPPED_SIG) != 0) { + PROC_SLOCK(p); + report = p->p_suspcount == p->p_numthreads && + (p->p_flag & P_WAITED) == 0; + PROC_SUNLOCK(p); + if (report) { + report_alive_proc(td, p, siginfo, status, options, + CLD_STOPPED); + return (true); + } + } + + if ((options & WCONTINUED) != 0 && (p->p_flag & P_CONTINUED) != 0) { + report_alive_proc(td, p, siginfo, status, options, + CLD_CONTINUED); + return (true); + } + + return (false); +} + int kern_wait6(struct thread *td, idtype_t idtype, id_t id, int *status, int options, struct __wrusage *wrusage, siginfo_t *siginfo) @@ -1314,7 +1369,6 @@ kern_wait6(struct thread *td, idtype_t idtype, id_t id, int *status, struct proc *p, *q; pid_t pid; int error, nfound, ret; - bool report; AUDIT_ARG_VALUE((int)idtype); /* XXX - This is likely wrong! */ AUDIT_ARG_PID((pid_t)id); /* XXX - This may be wrong! */ @@ -1367,43 +1421,11 @@ loop_locked: nfound++; PROC_LOCK_ASSERT(p, MA_OWNED); - if ((options & WTRAPPED) != 0 && - (p->p_flag & P_TRACED) != 0) { - PROC_SLOCK(p); - report = - ((p->p_flag & (P_STOPPED_TRACE | P_STOPPED_SIG)) && - p->p_suspcount == p->p_numthreads && - (p->p_flag & P_WAITED) == 0); - PROC_SUNLOCK(p); - if (report) { - CTR4(KTR_PTRACE, - "wait: returning trapped pid %d status %#x (xstat %d) xthread %d", - p->p_pid, W_STOPCODE(p->p_xsig), p->p_xsig, - p->p_xthread != NULL ? - p->p_xthread->td_tid : -1); - report_alive_proc(td, p, siginfo, status, - options, CLD_TRAPPED); - return (0); - } - } - if ((options & WUNTRACED) != 0 && - (p->p_flag & P_STOPPED_SIG) != 0) { - PROC_SLOCK(p); - report = (p->p_suspcount == p->p_numthreads && - ((p->p_flag & P_WAITED) == 0)); - PROC_SUNLOCK(p); - if (report) { - report_alive_proc(td, p, siginfo, status, - options, CLD_STOPPED); - return (0); - } - } - if ((options & WCONTINUED) != 0 && - (p->p_flag & P_CONTINUED) != 0) { - report_alive_proc(td, p, siginfo, status, options, - CLD_CONTINUED); + if (wait6_check_alive(td, options, p, status, siginfo)) { + td->td_retval[0] = pid; return (0); } + PROC_UNLOCK(p); }