From nobody Sun Jan 25 15:56:53 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 4dzbrk1Gvtz6PjXN 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 4dzbrj1KgXz480r for ; Sun, 25 Jan 2026 15:56:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769356613; 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=/+4+Q43jjooq1EWntlCdUL8i+2PKwFFWK1trkAlLIXE=; b=Ktv6T4rmrglE8M2Ma69y46utL9EHCvZV0ea5eTvId6PSq3RSZKVnHaNcxm0QB3N7T7tDhl sgD/yuJhDs5tVqkqTRxJjQU8FX2zQ2CZGoT8vos4AIYDj2pgGrnZR+gu7hV4hPZDVJy4D0 F3I3+yGaY3nZxQmKD0c6ifzzthKEhR1wr2LgRzW9tKG1Nnm1qa4mbNHKitBSduuSdCVs7p NAlf24AA9gxRlSlJrjqZPFxtvtAnu0/p6Rax7/KBGOWty03HNmNcC/UA+hRe2cSiclP8yl c56knxq3LN/qHIOJjBbVX6hK8vKPyoazrKS/Xly1oYByQ0fGL8W8QAIoR51zRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769356613; 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=/+4+Q43jjooq1EWntlCdUL8i+2PKwFFWK1trkAlLIXE=; b=O/0sS8VT7UAu91ypI1Lxl2qnuRms8onH+QZgKamczZkddSXWjSytugV0E0NX4lXuFNLAph 8Y3oMW4TP0SElrhFJuURxt8P0b0BK3098ImK6axp8kx2oeSIQjMQD69CVooQi55GIQ022d DrIcal5VT3QOyoKcW1ADo8WcZrzcsFjm8N5xKbgEIv1OzB5F20Nkp+ZJTIReKbhj9YMmeo sbw9kyh4plDfB36UUsGoJeRSkJ+GjtwG/IV84YctWOwtIgW8yTjBRAJwxSF2Q148e1Vv4w 8NGdkQor451YG7DmoiG7Iri6BIYkjKhlii/ZaKUHIMtJWZiDDpD+vnWEK7k5iA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1769356613; a=rsa-sha256; cv=none; b=UDY9ZznUfupIKsGKDuuVwdfPPN5BTtQD9J9uS4zKXhPySuw+gZUuc6FeNFBmr54eEN+3M4 Bt1zGt5Pi+DVqu6vTjBEkYH6eZ2lVTacJ/ML1OyaJtvUH/vfC0F8bUZaChklh89bTbSirX YNyrXjKqTKqG916N8qA4As6A4xu9cfMwXUMnpXaRCXi5gF/m9JAnDHlqwEVSpQ1MMpP+DQ Ugo5D8LJCgcDQLN9j4PSfBJJyhFYWist1Mm1vgkKPSXK0g+LB9KyW3/0tqnZg51Xf+9vhB avAgwPwP1DKsP23vyxf3q9zvbdQGyo81e03nlhaKLoQt5BlJtitjD2dj+z0NAQ== 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 4dzbrj0c76zhQk for ; Sun, 25 Jan 2026 15:56:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 33a27 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 25 Jan 2026 15:56:53 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 2b67cfa39d83 - main - kern/kern_exit.c: extract some helpers from proc_to_reap() 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: 2b67cfa39d8367a021d165681a1e7f54c6020470 Auto-Submitted: auto-generated Date: Sun, 25 Jan 2026 15:56:53 +0000 Message-Id: <69763d45.33a27.7dcb772a@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=2b67cfa39d8367a021d165681a1e7f54c6020470 commit 2b67cfa39d8367a021d165681a1e7f54c6020470 Author: Konstantin Belousov AuthorDate: 2026-01-08 04:19:04 +0000 Commit: Konstantin Belousov CommitDate: 2026-01-25 15:53:30 +0000 kern/kern_exit.c: extract some helpers from proc_to_reap() 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 | 116 +++++++++++++++++++++++++++++---------------------- 1 file changed, 66 insertions(+), 50 deletions(-) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index db6e91f00534..2b22e3a0a23b 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1042,13 +1042,75 @@ proc_reap(struct thread *td, struct proc *p, int *status, int options) atomic_add_int(&nprocs, -1); } +static void +wait_fill_siginfo(struct proc *p, siginfo_t *siginfo) +{ + PROC_LOCK_ASSERT(p, MA_OWNED); + + if (siginfo == NULL) + return; + + bzero(siginfo, sizeof(*siginfo)); + siginfo->si_errno = 0; + + /* + * SUSv4 requires that the si_signo value is always + * SIGCHLD. Obey it despite the rfork(2) interface allows to + * request other signal for child exit notification. + */ + siginfo->si_signo = SIGCHLD; + + /* + * This is still a rough estimate. We will fix the cases + * TRAPPED, STOPPED, and CONTINUED later. + */ + if (WCOREDUMP(p->p_xsig)) { + siginfo->si_code = CLD_DUMPED; + siginfo->si_status = WTERMSIG(p->p_xsig); + } else if (WIFSIGNALED(p->p_xsig)) { + siginfo->si_code = CLD_KILLED; + siginfo->si_status = WTERMSIG(p->p_xsig); + } else { + siginfo->si_code = CLD_EXITED; + siginfo->si_status = p->p_xexit; + } + + siginfo->si_pid = p->p_pid; + siginfo->si_uid = p->p_ucred->cr_uid; + + /* + * The si_addr field would be useful additional detail, but + * apparently the PC value may be lost when we reach this + * point. bzero() above sets siginfo->si_addr to NULL. + */ +} + +static void +wait_fill_wrusage(struct proc *p, struct __wrusage *wrusage) +{ + struct rusage *rup; + + PROC_LOCK_ASSERT(p, MA_OWNED); + + if (wrusage == NULL) + return; + + rup = &wrusage->wru_self; + *rup = p->p_ru; + PROC_STATLOCK(p); + calcru(p, &rup->ru_utime, &rup->ru_stime); + PROC_STATUNLOCK(p); + + rup = &wrusage->wru_children; + *rup = p->p_stats->p_cru; + calccru(p, &rup->ru_utime, &rup->ru_stime); +} + static int proc_to_reap(struct thread *td, struct proc *p, idtype_t idtype, id_t id, int *status, int options, struct __wrusage *wrusage, siginfo_t *siginfo, int check_only) { - struct rusage *rup; - sx_assert(&proctree_lock, SA_XLOCKED); PROC_LOCK(p); @@ -1133,60 +1195,14 @@ proc_to_reap(struct thread *td, struct proc *p, idtype_t idtype, id_t id, return (0); } - if (siginfo != NULL) { - bzero(siginfo, sizeof(*siginfo)); - siginfo->si_errno = 0; - - /* - * SUSv4 requires that the si_signo value is always - * SIGCHLD. Obey it despite the rfork(2) interface - * allows to request other signal for child exit - * notification. - */ - siginfo->si_signo = SIGCHLD; - - /* - * This is still a rough estimate. We will fix the - * cases TRAPPED, STOPPED, and CONTINUED later. - */ - if (WCOREDUMP(p->p_xsig)) { - siginfo->si_code = CLD_DUMPED; - siginfo->si_status = WTERMSIG(p->p_xsig); - } else if (WIFSIGNALED(p->p_xsig)) { - siginfo->si_code = CLD_KILLED; - siginfo->si_status = WTERMSIG(p->p_xsig); - } else { - siginfo->si_code = CLD_EXITED; - siginfo->si_status = p->p_xexit; - } - - siginfo->si_pid = p->p_pid; - siginfo->si_uid = p->p_ucred->cr_uid; - - /* - * The si_addr field would be useful additional - * detail, but apparently the PC value may be lost - * when we reach this point. bzero() above sets - * siginfo->si_addr to NULL. - */ - } + wait_fill_siginfo(p, siginfo); /* * There should be no reason to limit resources usage info to * exited processes only. A snapshot about any resources used * by a stopped process may be exactly what is needed. */ - if (wrusage != NULL) { - rup = &wrusage->wru_self; - *rup = p->p_ru; - PROC_STATLOCK(p); - calcru(p, &rup->ru_utime, &rup->ru_stime); - PROC_STATUNLOCK(p); - - rup = &wrusage->wru_children; - *rup = p->p_stats->p_cru; - calccru(p, &rup->ru_utime, &rup->ru_stime); - } + wait_fill_wrusage(p, wrusage); if (p->p_state == PRS_ZOMBIE && !check_only) { proc_reap(td, p, status, options);