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 9A881388C017 for ; Thu, 11 Mar 2021 13:25:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9A881388C017 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-450-b-zdwJfRNw-clQGe4WZgmQ-1; Thu, 11 Mar 2021 08:25:19 -0500 X-MC-Unique: b-zdwJfRNw-clQGe4WZgmQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1633593923; Thu, 11 Mar 2021 13:25:18 +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 3C5065C23E; Thu, 11 Mar 2021 13:25:17 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella Cc: Adhemerval Zanella via Libc-alpha Subject: Re: [PATCH 5/8] posix: Do not clobber errno by atfork handlers References: <20210202151134.2123748-1-adhemerval.zanella@linaro.org> <20210202151134.2123748-5-adhemerval.zanella@linaro.org> <87o8fs4mm9.fsf@oldenburg.str.redhat.com> <09b94a9b-905d-db39-3566-767c097f4348@linaro.org> Date: Thu, 11 Mar 2021 14:25:27 +0100 In-Reply-To: <09b94a9b-905d-db39-3566-767c097f4348@linaro.org> (Adhemerval Zanella's message of "Wed, 10 Mar 2021 17:10:35 -0300") Message-ID: <87eeglizzs.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.79 on 10.5.11.16 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 13:25:25 -0000 * Adhemerval Zanella: > On 09/03/2021 08:01, Florian Weimer wrote: >> * Adhemerval Zanella via Libc-alpha: >> >>> Checked on x86_64-linux-gnu. >>> --- >>> posix/fork.c | 4 +++- >>> 1 file changed, 3 insertions(+), 1 deletion(-) >>> >>> diff --git a/posix/fork.c b/posix/fork.c >>> index 4c9e60f187..7f27fb8338 100644 >>> --- a/posix/fork.c >>> +++ b/posix/fork.c >>> @@ -68,7 +68,7 @@ __libc_fork (void) >>> } >>> >>> pid_t pid = _Fork (); >>> - >>> + int save_errno = errno; >>> if (pid == 0) >>> { >>> /* Reset the lock state in the multi-threaded case. */ >>> @@ -107,6 +107,8 @@ __libc_fork (void) >>> __run_fork_handlers (pid == 0 ? atfork_run_child : atfork_run_parent, >>> multiple_threads); >>> >>> + if (pid < 0) >>> + __set_errno (save_errno); >>> return pid; >>> } >>> weak_alias (__libc_fork, __fork) >> >> Why is this condition correct? Shouldn't it be pid >= 0? > > But pid >= 0 is a valid call which should not set errno. The idea is > to return the _Fork error value even if some atfork handler in the > parent does clobber it. Then maybe move that into the else part for the parent (on fork error there is no subprocess) and add a comment? Thanks, Florian