From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by sourceware.org (Postfix) with ESMTPS id E95673858D35 for ; Mon, 22 May 2023 12:44:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E95673858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 59B6F6183B; Mon, 22 May 2023 12:44:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62174C433EF; Mon, 22 May 2023 12:44:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684759475; bh=9R1INbaAugNQQ7IhVHmz98cCzp1vefM5itqCyOouuGg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UDiL6VkG6ZESbnENXY2mwJn/b5z7d/LUIIaHbD7NdOOOpvdNWx9DqaIT61XoEZdV3 BuRioVJ4aZJ8gAsImZ8ECoLyJLVX2RoJzRZVk6dzsww7AbRUbm0gzXFIol1JCZYd29 1Px6p4qb8KPFB7ODyHH+NnfoikA+lpY4bi2bDW2RPYsc912UPo8/o9dkMxI1TWIg1X h+zL80Shy3MQTOH9KlMkHFotLsrXmeRBLE3h36V9R2TYWi12a6VnI2jkHnXp0AX2uq S8fNTwmDZNwm66oXknaZqHjh0/7IbiLwcPas++9Srs8uD3MFlprsbffjufyTdngqN8 61wg8zVy57dnQ== Date: Mon, 22 May 2023 14:44:31 +0200 From: Christian Brauner To: Florian Weimer Cc: Adhemerval Zanella , libc-alpha@sourceware.org, Luca Boccassi , Philip Withnall Subject: Re: [PATCH v4 2/3] posix: Add pidfd_fork Message-ID: <20230522-balken-leiden-004cc9c6674b@brauner> References: <20230517173516.1988283-1-adhemerval.zanella@linaro.org> <20230517173516.1988283-3-adhemerval.zanella@linaro.org> <877ct065fj.fsf@oldenburg3.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <877ct065fj.fsf@oldenburg3.str.redhat.com> X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, May 22, 2023 at 12:12:16PM +0200, Florian Weimer via Libc-alpha wrote: > * Adhemerval Zanella: > > > +@deftypefun int pidfd_fork (unsigned int @var{flags}) > > +@standards{GNU, sys/pidfd.h} > > +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} > > +The @code{fork} function is similar to @code{fork} but return a file > > +descriptor instead of process ID. > > + > > +If the operation is sucessful, there are both parent and child processes > > +and both see @code{pidfd_fork} return, but with different values: it return > > +a value of @code{0} in the child process and returns a file descriptor to > > +child's process int the parent process. Although the value of @code{0} clashes > > +with @code{STDIN_FILENO}, it also assumed that stardand input is always > > +available so a conformant application will never see a the @code{0} stream > > +being returned to parent as a valid file descriptor. > > I think this is a bit ugly. Maybe pidfd_fork should return the PID/zero I agree. We went through some pain to ensure that 0 can be used as a valid fd value. Imho, it'd be better to use a return argument. It would also align with how CLONE_PIDFD with legacy clone() works. > as fork, and store the FD through an int * argument? > > The documentaiton should discuss if SIGCHLD is sent for such processes, Depends on whether you set exit_signal. I would expect pidfd_fork() to very closely mirror the semantics of fork(). So I would expect SIGCHLD to be delivered. But that's not how I understand this patchset just from glancing at it. > and if the PID can be used in waitpid etc. Ideally we'd have test cases The pid can be used with waitpid(). I don't understand why it wouldn't. > for this behavior, too. 8-) > > I think it would be valuable to support creating subprocesses without > ever sending SIGCHLD on their termination. Not sure if this should be > the default behavior, or something enabled with a flag. Best behind a flag. If you name it pidfd_fork() then it might be best if you default to delivering SIGCHLD and provide an opt-out through a flag.