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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id AD2F33860C2E for ; Thu, 11 Mar 2021 21:04:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AD2F33860C2E 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-216-NB-LOMK9NpS5x41D3dMvxw-1; Thu, 11 Mar 2021 16:04:31 -0500 X-MC-Unique: NB-LOMK9NpS5x41D3dMvxw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6CFEF196634E; Thu, 11 Mar 2021 21:04:27 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-77.ams2.redhat.com [10.36.112.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 88E8B10013D6; Thu, 11 Mar 2021 21:04:26 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella via Libc-alpha Subject: Re: [PATCH v2 5/8] posix: Do not clobber errno by atfork handlers References: <20210311195210.3153729-1-adhemerval.zanella@linaro.org> <20210311195210.3153729-5-adhemerval.zanella@linaro.org> Date: Thu, 11 Mar 2021 22:04:37 +0100 In-Reply-To: <20210311195210.3153729-5-adhemerval.zanella@linaro.org> (Adhemerval Zanella via Libc-alpha's message of "Thu, 11 Mar 2021 16:52:07 -0300") Message-ID: <871rclbdwa.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.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_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, 11 Mar 2021 21:04:36 -0000 * Adhemerval Zanella via Libc-alpha: > Changes from v1: > * Move the errno set/restore to parent branch. > --- > Checked on x86_64-linux-gnu. > --- > posix/fork.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/posix/fork.c b/posix/fork.c > index cc1bdc1232..a4fdd44e1e 100644 > --- a/posix/fork.c > +++ b/posix/fork.c > @@ -68,7 +68,6 @@ __libc_fork (void) > } > > pid_t pid = _Fork (); > - > if (pid == 0) > { > fork_system_setup (); > @@ -99,6 +98,11 @@ __libc_fork (void) > } > else > { > + /* If _Fork failed, preserve its errno value. */ > + int save_errno; > + if (pid < 0) > + save_errno = errno; > + > /* Release acquired locks in the multi-threaded case. */ > if (multiple_threads) > { > @@ -111,6 +115,9 @@ __libc_fork (void) > > /* Run the handlers registered for the parent. */ > __run_fork_handlers (atfork_run_parent, multiple_threads); > + > + if (pid < 0) > + __set_errno (save_errno); > } > > return pid; This is okay. GCC does not warn about the uninitialized save_errno here; I checked with build-many-glibcs.py. Apparently the middle-end is smart enough to detect that the conditions match. Thanks, Florian