From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by sourceware.org (Postfix) with ESMTPS id 3D5623AAA008 for ; Thu, 24 Jun 2021 11:05:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3D5623AAA008 Received: by mail-qv1-xf29.google.com with SMTP id f16so3042789qvs.7 for ; Thu, 24 Jun 2021 04:05:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=PSvYntWSY9HFlnEuu4M3dpS4+O5uBW3lDnjR3LxFKGw=; b=KMHMajoUMiEyouZpqsUui06FXrBsEHqsAIszVrec+Pu+aZYj36H/zakeV+3GrYGP7G GWl85GcrAcfVfzpat6B4Co5mwLZvZNhcT9u+juYQz8pWMV48EOd49fIFAlnWD7o/8ax3 6Pl2xLWkZol3NG067cViqKA+BiPng8BndsKWw1GvpkpVJN3m51jz/JH7aGtxV0NnqRdf n4Pb1xWhVG7pT6U0xTwgTTIIPuqON+jZqIUFSVNzx0+r8M/QCL6tYo4up0TIh54aDvOE NfnGSH6mxD/pg3OVCFkwvsZF8TuhS7XOB6wagL2lpDwwtoF4rn/Z+Wfz7X2tcCboLyS6 PdXg== X-Gm-Message-State: AOAM530W0xaYeaqgG1RjKv9CbO7AliqxMVD+bjTL7B4a+a1DK0F2qR1/ 5coqRvUN5RKeADwOKjs2Aj0sX8+XWwAVkg== X-Google-Smtp-Source: ABdhPJzkmURsCANYyBK18Ig4dabN2b/Mnp3QVCdoKl/zTrMIH+EBUNsD951KNVxMgRx+VSrMNhqI8A== X-Received: by 2002:a0c:f750:: with SMTP id e16mr4688598qvo.47.1624532757643; Thu, 24 Jun 2021 04:05:57 -0700 (PDT) Received: from [192.168.1.108] ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id 6sm2324462qks.0.2021.06.24.04.05.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 04:05:57 -0700 (PDT) Subject: Re: [PATCH v4 2/4] posix: Do not clobber errno by atfork handlers To: Florian Weimer , Adhemerval Zanella via Libc-alpha References: <20210623184354.395316-1-adhemerval.zanella@linaro.org> <20210623184354.395316-3-adhemerval.zanella@linaro.org> <877dijn097.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Message-ID: <30080b5b-33ae-27a8-3031-2785022a17c9@linaro.org> Date: Thu, 24 Jun 2021 08:05:54 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <877dijn097.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, 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 11:05:59 -0000 On 24/06/2021 05:19, Florian Weimer wrote: > * Adhemerval Zanella via Libc-alpha: > >> Checked on x86_64-linux-gnu. >> --- >> posix/fork.c | 5 +++++ >> 1 file changed, 5 insertions(+) >> >> diff --git a/posix/fork.c b/posix/fork.c >> index 44caf8d166..9340511198 100644 >> --- a/posix/fork.c >> +++ b/posix/fork.c >> @@ -103,6 +103,9 @@ __libc_fork (void) >> } >> else >> { >> + /* If _Fork failed, preserve its errno value. */ >> + int save_errno = errno; >> + >> /* Release acquired locks in the multi-threaded case. */ >> if (multiple_threads) >> { >> @@ -115,6 +118,8 @@ __libc_fork (void) >> >> /* Run the handlers registered for the parent. */ >> __run_fork_handlers (atfork_run_parent, multiple_threads); >> + >> + __set_errno (save_errno); > > I think you should restrict the __set_errno call to pid < 0, so that > errno is not 0 after a different value has been observed by the fork > handlers. OK, I can change it back. From the previous review iteration I understood you were ok with making it unconditional [1]. [1] https://sourceware.org/pipermail/libc-alpha/2021-March/123729.html