From nobody Thu Jan 08 07:14:59 2026 X-Original-To: freebsd-hackers@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 4dmx4j5FFjz5hwSJ; Thu, 08 Jan 2026 07:15:17 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4dmx4j09z7z3Xvm; Thu, 08 Jan 2026 07:15:16 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 6087Exd7056542; Thu, 8 Jan 2026 09:15:02 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 6087Exd7056542 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 6087ExeA056541; Thu, 8 Jan 2026 09:14:59 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 8 Jan 2026 09:14:59 +0200 From: Konstantin Belousov To: Alan Somers Cc: Rob Norris , FreeBSD Hackers , arch@freebsd.org Subject: Re: Is anybody working on extending procdesc support to rfork? Message-ID: References: <01AC8C85-DE8E-44F9-85FD-6E2514DDE96B@FreeBSD.org> <8fa41730-7659-4038-a5e2-fae13e96d410@app.fastmail.com> List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.2 X-Spam-Checker-Version: SpamAssassin 4.0.2 (2025-08-27) on tom.home X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 4dmx4j09z7z3Xvm On Wed, Jan 07, 2026 at 08:42:59PM -0700, Alan Somers wrote: > On Wed, Jan 7, 2026 at 8:02 PM Rob Norris wrote: > > > > On Thu, 8 Jan 2026, at 1:40 PM, Konstantin Belousov wrote: > > > > That's fair. The bug report references discussion at > > https://lists.cam.ac.uk/pipermail/cl-capsicum-discuss/2015-May/msg00012.html > > which seems to be no longer available. Does anybody have a pointer > > to it? > > > > > > Looks like a change to the mailing list archive software. I guess this or something in the same thread. > > > > https://lists.cam.ac.uk/sympa/arc/cl-capsicum-discuss/2015-05/msg00012.html > > > > Thanks for finding that! There's two important pieces of information there: > > * "we reserve the PID until all of its PDs had been closed". If > that's true, then it's possible to use wait4 with process descriptors > race-free. That would be good enough for my current purposes. A > proper pdwait4() would still be useful for capability-mode processes, > however. > > * Ed Shouten already wrote a pdwait(3) on top of kqueue (though the > link is dead). I might be able to use that. > > I'll investigate both of the above points tomorrow. I added some version of pdwait(2) as well. Mine does not reap the referenced child, it is the job of close(). More, this allows more than one process to pdwait() and get the expected results. I do not return pid from pdwait(), I see no point in mimicking wait(2) there. It worked for me with the following simple test program: /* $Id: pdrfork.c,v 1.6 2026/01/08 07:00:36 kostik Exp kostik $ */ #include #include #include #include #include #include #include #include #include #ifndef SYS_pdrfork #define SYS_pdrfork 600 static int pdrfork(int *fdp, int pdflags, int rfflags) { return (syscall(SYS_pdrfork, fdp, pdflags, rfflags)); } #endif #ifndef SYS_pdwait #define SYS_pdwait 601 static pid_t pdwait(int fd, int options, int *status, struct __wrusage *wrp, siginfo_t *sip) { return (syscall(SYS_pdwait, fd, options, status, wrp, sip)); } #endif int main(void) { struct __wrusage wr; siginfo_t si; int error, fd, pid, pid1, status; fd = -1; pid = pdrfork(&fd, 0, RFPROC | RFPROCDESC); if (pid == -1) err(1, "pdrfork"); if (pid == 0) { sleep(1); _exit(12); } error = pdgetpid(fd, &pid1); if (error != 0) err(1, "pdgetpid"); printf("fd %d pid %d getpid %d\n", fd, pid, pid1); status = -1; error = pdwait(fd, WEXITED, &status, &wr, &si); if (error != 0) err(1, "pdwait"); printf("status %#x\n", status); close(fd); return (0); }