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 1778F385781D for ; Wed, 10 Mar 2021 20:10:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1778F385781D Received: by mail-qt1-x835.google.com with SMTP id h26so9696746qtm.5 for ; Wed, 10 Mar 2021 12:10:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=BpJ1vN87QVZoSoOmbBm+ur8KEcTDfhTqBBc5EbPKCvM=; b=GlduwwheYqkCoM5HVBTOE4tKQks7JpTL2wFOUA3M3sYCrLC+iv0RKVgraz+9pY/cNE uwY2mvVyzIFZgrwm+Hgj3wJpQkFGqPzeiQeYrSivdPPbYyjMEvE/i3jKscUQApY7w6qJ KWw7/frTi6OzS8uG2GGZxWS/NxTYCHbOaglFwcghN/JU5dVfWIl9UTEywG6rXrFIQQa1 Sr1Xa5Y+SwySgFqCdnvHxnCAUyCnUWDbGX0xN+AIvHKRQAiJx+E5+rh5HYUsqker4Nin O3sLo4LYKN5JvWxNXPaTRklyDPMWwcihMT+yMTE8D6CDWvo59Gj8J4XxEYuyFc5qsHnr 5tJA== X-Gm-Message-State: AOAM532TgnY1gxPZFB+/brCmtYhsVo89K4M417WQlFLlmWy0DZGKPt8V wlwKTzkyC19WUu2KW2UUP9cL1Ak/jgHR06LD X-Google-Smtp-Source: ABdhPJxzkkaDwEQRCHRbnok7pDCtaU5l5LJouLNtrWbE6McMgB13eDSiPzY6t0cs7Bw2xfo7ggPxtA== X-Received: by 2002:ac8:4e8f:: with SMTP id 15mr4296347qtp.317.1615407038406; Wed, 10 Mar 2021 12:10:38 -0800 (PST) Received: from [192.168.1.4] ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id m25sm215746qtq.59.2021.03.10.12.10.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Mar 2021 12:10:38 -0800 (PST) To: Florian Weimer , 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> From: Adhemerval Zanella Subject: Re: [PATCH 5/8] posix: Do not clobber errno by atfork handlers Message-ID: <09b94a9b-905d-db39-3566-767c097f4348@linaro.org> Date: Wed, 10 Mar 2021 17:10:35 -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: <87o8fs4mm9.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit 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: Wed, 10 Mar 2021 20:10:40 -0000 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. > > I wonder if this should be part of __run_fork_handlers, so that fork > handlers always observe the original errno value. I am not sure about it, checking the errno without actually calling a function that might setting it is error-prone imho.