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 ESMTP id 1C52A385482F for ; Thu, 24 Jun 2021 08:47:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1C52A385482F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-422--ovs_nTwOKOtMAaSZNHZoA-1; Thu, 24 Jun 2021 04:47:24 -0400 X-MC-Unique: -ovs_nTwOKOtMAaSZNHZoA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88253800D55; Thu, 24 Jun 2021 08:47:23 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-228.ams2.redhat.com [10.36.112.228]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD1F95D6A1; Thu, 24 Jun 2021 08:47:22 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella via Libc-alpha Subject: Re: [PATCH v4 4/4] posix: Add _Fork [BZ #4737] References: <20210623184354.395316-1-adhemerval.zanella@linaro.org> <20210623184354.395316-5-adhemerval.zanella@linaro.org> Date: Thu, 24 Jun 2021 10:47:20 +0200 In-Reply-To: <20210623184354.395316-5-adhemerval.zanella@linaro.org> (Adhemerval Zanella via Libc-alpha's message of "Wed, 23 Jun 2021 15:43:54 -0300") Message-ID: <87y2azlkdj.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.7 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jun 2021 08:47:27 -0000 * Adhemerval Zanella via Libc-alpha: > +@deftypefun pid_t _Fork (void) > +@standards{GNU, unistd.h} > +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} > +The @code{_Fork} function is similar to @code{fork} but does not issue > +any atfork callback registered with @code{pthread_atfork} neither reset > +any internal state or locks (such as the malloc one) and only setup a > +minimal state required to call async-signal-safe functions (such as raise > +or execve). Maybe: +The @code{_Fork} function is similar to @code{fork}, but it does not invoke +any callbacks registered with @code{pthread_atfork}, nor does it reset +any internal state or locks (such as the @code{malloc} locks). In the +new subprocess, only async-signal-safe functions may be called, such as +@code{dup2} or @code{execve}. + +The @code{_Fork} function is an async-signal-safe replacement of @code{fork}. +It is a GNU extension. > diff --git a/posix/tst-_Fork.c b/posix/tst-_Fork.c > new file mode 100644 > index 0000000000..f14da12d5a > --- /dev/null > +++ b/posix/tst-_Fork.c > +/* _Fork is async-signal-safe, so check if it can successfully issue > + a new process in a signal handler. */ > +static int > +singlethread_signal_test (void) > +{ > + xsignal (SIGUSR1, &sigusr1_handler); > + /* Assume synchronous signal handling. */ > + xraise (SIGUSR1); > + TEST_COMPARE (sigusr1_handler_ran, 1); This test tests using a synchronous signal, so it doesn't add much value in my opinion. > +/* Different than fork, _Fork does not execute any pthread_atfork > + handlers. */ > +static int > +singlethread_atfork_test (void) > +{ > + pthread_atfork (atfork_prepare, atfork_parent, atfork_child); > + singlethread_test (); > + TEST_COMPARE (atfork_prepare_var, false); > + TEST_COMPARE (atfork_parent_var, false); > + TEST_COMPARE (atfork_child_var, false); Use TEST_VERIFY (!atfork_child_var) etc.? > diff --git a/posix/unistd.h b/posix/unistd.h > index d9d8929f71..fa06c890ba 100644 > --- a/posix/unistd.h > +++ b/posix/unistd.h > @@ -781,6 +781,13 @@ extern __pid_t fork (void) __THROWNL; > extern __pid_t vfork (void) __THROW; > #endif /* Use misc or XPG < 7. */ > > +#ifdef __USE_GNU > +/* This is similar to fork, however it does not run the atfork handlers > + neither reinitialize any internal locks in multithread case. > + Different than fork, _Fork is async-signal-safe. */ > +extern __pid_t _Fork (void) __THROWNL; > +#endif Should this be _THROW (no callbacks)? Do we have to specify the returns_twice attribute? Thanks, Florian