From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id F39CD3858D20 for ; Mon, 22 May 2023 10:12:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F39CD3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684750344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ieqs6w1TC7cXXaNttbfvvvrgUIDg9+6aPm0izjmxVB0=; b=c17mo8JT73ZKemSjqJeblqC4z9NdmA1rDFXrEaGrjpB+3cKfL/pnir1zrzZk4Y25+bgyD8 37ljo0Rq5498Nvs9Hovk4LSB6VN9fJWiZcJLNyhCpldyDjQuMzubOg8fAkTghIAbeBxO1+ jk7czwo4esEeISsMUuLxpGpUDHMTnjc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-642-KtPRqCySOp2ubEqzMvo7XQ-1; Mon, 22 May 2023 06:12:20 -0400 X-MC-Unique: KtPRqCySOp2ubEqzMvo7XQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E5830185A791; Mon, 22 May 2023 10:12:19 +0000 (UTC) Received: from oldenburg3.str.redhat.com (unknown [10.39.195.128]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD18A1121314; Mon, 22 May 2023 10:12:18 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, Luca Boccassi , Philip Withnall Subject: Re: [PATCH v4 2/3] posix: Add pidfd_fork References: <20230517173516.1988283-1-adhemerval.zanella@linaro.org> <20230517173516.1988283-3-adhemerval.zanella@linaro.org> Date: Mon, 22 May 2023 12:12:16 +0200 In-Reply-To: <20230517173516.1988283-3-adhemerval.zanella@linaro.org> (Adhemerval Zanella's message of "Wed, 17 May 2023 14:35:15 -0300") Message-ID: <877ct065fj.fsf@oldenburg3.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: * 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 as fork, and store the FD through an int * argument? The documentaiton should discuss if SIGCHLD is sent for such processes, and if the PID can be used in waitpid etc. Ideally we'd have test cases 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. > diff --git a/posix/fork-internal.c b/posix/fork-internal.c > new file mode 100644 > index 0000000000..be0d3219af > --- /dev/null > +++ b/posix/fork-internal.c > +void > +__fork_pos (int state, uint64_t lastrun, bool multiple_threads, > + struct nss_database_data *nss_database_data) Maybe __fork_post, with a t? > diff --git a/posix/fork-internal.h b/posix/fork-internal.h > new file mode 100644 > index 0000000000..3814d851c4 > --- /dev/null > +++ b/posix/fork-internal.h > +uint64_t __fork_pre (bool, struct nss_database_data *) attribute_hidden; > +void __fork_pos (int, uint64_t, bool, struct nss_database_data *) > + attribute_hidden; I suggest to put the arguments into a struct, with struct nss_database_data as a non-pointer member. It makes it easier to document the meaning of the arguments. And we may have to add more things in the future. > diff --git a/sysdeps/unix/sysv/linux/pidfd_fork.c b/sysdeps/unix/sysv/linux/pidfd_fork.c > new file mode 100644 > index 0000000000..a3ef48ce77 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/pidfd_fork.c > +static int > +forkfd (void) > +{ > + /* The kernel should not change the pidfd for the child, and the returning > + value on the parent is always larger than 0 (since a new file descriptor > + is always opened with CLONE_PIDFD is the kernel supports it. */ Missing ). Thanks, Florian