From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by sourceware.org (Postfix) with ESMTPS id E6EEB388A42B for ; Thu, 11 Mar 2021 14:07:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E6EEB388A42B Received: by mail-qt1-x835.google.com with SMTP id 94so1176248qtc.0 for ; Thu, 11 Mar 2021 06:07:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=iONln8ADZ8PBNrDpABQ3vCCz/Ho4pr/3mH1CFkScPps=; b=O5FAEQLFE4/0QwCL71ZAV0xSEOXTWwxZ0nOpKmUz992jyhkg2lsCwwusOFwLIeoWcb 9fd4klRF951aUDFf7YVnIYf5+bhHB29t+JeBCTmX5db6OeNa9ywhLlhYy3jCVssL9sU8 3qWqxJry9ZuLFocvDoIzUYUyEKnRNQ38EFqOn0RD756e+Y1nkDjDIUxGmOtqJXZ9PqBN e3gkiVDzlumxysRoG7XgAo4GaTUJB+UMUlKZkrCnMkHnuZpSneLowE69M72vX0wvFQfy aKmW+vlA1wjiUwWOZ4snjN5AA8mi+J41csLJFsIgtcVoZ3BI60BZcGTIcP2Jr996Y0eI 0amQ== X-Gm-Message-State: AOAM533UwkVCkUHfZqoB2uxH0xHxTH/kVCGh/Y3/cZCcxB6+iho3lPRy e2FyO/1fnTo0S5HGRRaNLXT9spfGYtupXNii X-Google-Smtp-Source: ABdhPJx51TvYgmxm+szNGwpBURRXdqES+ZJvc52c8m7kHEKj2KAVq9F+g3uJ/H2PoS2/X3eWYFUBlQ== X-Received: by 2002:aed:3a83:: with SMTP id o3mr7309946qte.349.1615471623344; Thu, 11 Mar 2021 06:07:03 -0800 (PST) Received: from [192.168.1.4] ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id z89sm1868352qtd.5.2021.03.11.06.07.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Mar 2021 06:07:03 -0800 (PST) Subject: Re: [PATCH 5/8] posix: Do not clobber errno by atfork handlers To: Florian Weimer Cc: Adhemerval Zanella via Libc-alpha 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> <87eeglizzs.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Message-ID: <13c1767e-a4b5-788f-611e-3c660fbceef6@linaro.org> Date: Thu, 11 Mar 2021 11:07:00 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <87eeglizzs.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=-13.5 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, 11 Mar 2021 14:07:05 -0000 On 11/03/2021 10:25, Florian Weimer wrote: > * 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? But we need to restore it *after* __run_fork_handlers calls. I will add the comment to make it explicit: /* Restore the errno value even if some atfork handler in the parent clobber it. */ if (pid < 0) __set_errno (save_errno)