From nobody Tue Jul 7 01:57:22 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 4gvPVq3K0Vz6kd9m for ; Tue, 07 Jul 2026 01:57: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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gvPVq04Qfz3VKn for ; Tue, 07 Jul 2026 01:57:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1783389443; 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=RoHHAP4PKgPDX7lNwrRl9V37RZUJyb1vhJVnow1hqU0=; b=VhAcnaxxAAQfMyeGr5bRtNF8czJm7WUOBLyrNhqiVyBEfM96LGk9FuWKpNs7hgxYZjcFtd sIWvivUGMtdgmgCwTNw3kOC7JCkUb7wXkuKTnq6ID12uhOyLBNPrE6jLcBdwDN4uO4xp0z R/NQtvqqT2dCDiZEN3TjlxQINvCG8hnIkx9Lckm1Q8LBj64Mtx054UaNn9HKzERG73dwjp qhA49MuZcvJxhjOb+NF1k6tMB4qqgijuNBka1sAt4WQOy5Db/FJ+Oc64r/pCyPniXOhzma WtyH5IG8B81hNZWmnO08EagORd+ciV1yZgKyqsWzndq0YqooYcKdUQ//ETmBuA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1783389443; a=rsa-sha256; cv=none; b=uoDdsUF9OVkQ7PTd6I3WUNoSuY4YUZkX3mRaKWRQZrnA7+dA9//2u+8hz8q9TsFVe/+mux XMx5usH4AsflSMWjM8MGw++nk7e9ikVny6OenqjrvnTfH8yqInybD35aXQxWSw8YlKqW3k Yk5Wf60ShePozaLWerh0gV1Vq8XDc2K2s9D/sf837Tj6RPWQ2pkxwFv9IidmRhR/cSWwio EhLFzQW9k3u9fm9cQCPeQyLCRdVf8ANWqq6tUj/0QgSsBhK47BmMjGwBNc96yE2CCM4Hop 7uG9nJBombi+d1/shhz+rpzjrZSgDLtkZZaEeh/KXP9jOtFi3jRP/fVu9XSCqg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1783389443; 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=RoHHAP4PKgPDX7lNwrRl9V37RZUJyb1vhJVnow1hqU0=; b=O0qJqseVL/q2nndU5PEtHYzFTcLrgXgJxLSIpi9pOnZ8nsKH45+uUNh09enCMY6E9PZQTZ rBecIeSO5HGvvQpND+F8M2ATvDHuLh9XRoz8v1f3DUWJ/sWQhVR3Uzn5UCArP3CbrHHgsK cjCv7F5w/no2ewte2jE9rI8W38dFOkyJtZ/lLKrFbAedALbBZtURakADwwsQVejrSmWh2G NNgPyvS5Y48KSYu64uAXNVNFAHKA3sJBIGuilsHoepWqE99V3k6b42PGPgR/hkbvpkzhEs VWK3BV27qp6Sv23292BIuY4UZYgtkg0x3JLzvdPmRCBFHa2v+AdhJB1yaeJTKQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gvPVp600mzFR for ; Tue, 07 Jul 2026 01:57:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3f33d by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 07 Jul 2026 01:57:22 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 3e8b68c26e2b - main - pdfork.2: document pdopenpid(2) 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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: 3e8b68c26e2b108dac96517ef8fd26fe7dce5bcd Auto-Submitted: auto-generated Date: Tue, 07 Jul 2026 01:57:22 +0000 Message-Id: <6a4c5d02.3f33d.7156f525@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=3e8b68c26e2b108dac96517ef8fd26fe7dce5bcd commit 3e8b68c26e2b108dac96517ef8fd26fe7dce5bcd Author: Konstantin Belousov AuthorDate: 2026-05-21 17:33:43 +0000 Commit: Konstantin Belousov CommitDate: 2026-07-07 01:27:16 +0000 pdfork.2: document pdopenpid(2) Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D57124 --- lib/libsys/Makefile.sys | 1 + lib/libsys/pdfork.2 | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/lib/libsys/Makefile.sys b/lib/libsys/Makefile.sys index 76855e0ae54d..c362258b89f4 100644 --- a/lib/libsys/Makefile.sys +++ b/lib/libsys/Makefile.sys @@ -497,6 +497,7 @@ MLINKS+=open.2 openat.2 MLINKS+=pathconf.2 fpathconf.2 MLINKS+=pathconf.2 lpathconf.2 MLINKS+=pdfork.2 pdgetpid.2 \ + pdfork.2 pdopenpid.2 \ pdfork.2 pdkill.2 \ pdfork.2 pdrfork.2 \ pdfork.2 pdwait.2 diff --git a/lib/libsys/pdfork.2 b/lib/libsys/pdfork.2 index 6ebab24ff180..9099edebaa2a 100644 --- a/lib/libsys/pdfork.2 +++ b/lib/libsys/pdfork.2 @@ -36,6 +36,7 @@ .Sh NAME .Nm pdfork , .Nm pdrfork , +.Nm pdopenpid , .Nm pdgetpid , .Nm pdkill , .Nm pdwait @@ -49,6 +50,8 @@ .Ft pid_t .Fn pdrfork "int *fdp" "int pdflags" "int rfflags" .Ft int +.Fn pdopenpid "pid_t pid" "int pdflags" +.Ft int .Fn pdgetpid "int fd" "pid_t *pidp" .Ft int .Fn pdkill "int fd" "int signum" @@ -128,6 +131,28 @@ flags, or .Va RFSPAWN flag are specified. .Pp +.Fn pdopenpid +opens the process descriptor for the process specified by the argument +.Fa pid . +It takes the same flags in the +.Fa pdflags +argument as +.Fn pdfork . +The caller must have permission to debug the target process in order for +.Fn pdopenpid +to succeed. +Zombie processes cannot be opened. +.Pp +There might be more that one file descriptor referencing the process. +But only one caller of +.Fn pdwait +gets the exit status. +After the zombie is reaped, calls to +.Fn pdwait +specifying any file descriptors for the same process fail with the +.Er ESRCH +error. +.Pp .Fn pdgetpid queries the process ID (PID) in the process descriptor .Fa fd . @@ -198,6 +223,7 @@ return a PID, 0 or -1, as .Xr fork 2 does. .Pp +.Fn pdopenpid , .Fn pdgetpid , .Fn pdkill , and @@ -244,6 +270,40 @@ The function is called with reserved bits set in .Fa options . .El +.Pp +The +.Fn pdopenpid +might return the same errors as +.Xr open 2 , +related to the file descriptor allocation problems, as well as the +following specific errors: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa flags +argument has reserved bits set. +.It Bq Er ECAPMODE +.Fn pdopenpid +is called by the process in capability mode. +.It Bq Er EBUSY +The process specified by the +.Fa pid +argument already terminated. +.It Bq Er ESRCH +The process specified by the +.Fa pid +argument does not exist, or the caller does not have enough privileges +to open the process. +.It Bq Er EMFILE +The calling process already reached its limit for open file descriptors. +.Pp +Current implementation installs the opened process descriptor into the +calling process's file descriptors table. +If the descriptor cannot be installed, the process descriptor is closed, +which executes all actions performed by +.Xr close 2 +on it. +.El .Sh SEE ALSO .Xr close 2 , .Xr fork 2 , @@ -268,6 +328,10 @@ and .Fn pdwait system calls first appeared in .Fx 15.1 . +The +.Fn pdopenpid +system call first appeared in +.Fx 16.0 . .Pp Support for process descriptors mode was developed as part of the .Tn TrustedBSD @@ -288,3 +352,7 @@ functions were developed by .An Konstantin Belousov Aq Mt kib@FreeBSD.org with input from .An Alan Somers Aq Mt asomers@FreeBSD.org . +The +.Fn pdopenpid +function was developed by +.An Konstantin Belousov Aq Mt kib@FreeBSD.org .