public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@linux-m68k.org>
To: Florian Weimer via Libc-alpha <libc-alpha@sourceware.org>
Cc: Florian Weimer <fweimer@redhat.com>
Subject: Re: [PATCH v2 5/8] posix: Do not clobber errno by atfork handlers
Date: Thu, 11 Mar 2021 23:21:22 +0100	[thread overview]
Message-ID: <87eeglmivx.fsf@igel.home> (raw)
In-Reply-To: <871rclbdwa.fsf@oldenburg.str.redhat.com> (Florian Weimer via Libc-alpha's message of "Thu, 11 Mar 2021 22:04:37 +0100")

On Mär 11 2021, Florian Weimer via Libc-alpha wrote:

> * 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.

But I think it wouldn't be bad to make that unconditional.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

  reply	other threads:[~2021-03-11 22:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11 19:52 [PATCH v2 1/8] posix: Consolidate register-atfork Adhemerval Zanella
2021-03-11 19:52 ` [PATCH v2 2/8] linux: Use __libc_single_threaded on fork Adhemerval Zanella
2021-03-11 20:18   ` Florian Weimer
2021-03-11 19:52 ` [PATCH v2 3/8] posix: Consolidate fork implementation Adhemerval Zanella
2021-03-11 19:52 ` [PATCH v2 4/8] nptl: Move fork into libc Adhemerval Zanella
2021-03-11 20:16   ` Florian Weimer
2021-03-11 21:41   ` Florian Weimer
2021-03-11 19:52 ` [PATCH v2 5/8] posix: Do not clobber errno by atfork handlers Adhemerval Zanella
2021-03-11 21:04   ` Florian Weimer
2021-03-11 22:21     ` Andreas Schwab [this message]
2021-03-11 22:31       ` Florian Weimer
2021-03-11 19:52 ` [PATCH v2 6/8] Consolidate pthread_atfork Adhemerval Zanella
2021-03-11 19:52 ` [PATCH v2 7/8] support: Add xpthread_kill Adhemerval Zanella
2021-03-11 20:19   ` Florian Weimer
2021-03-11 19:52 ` [PATCH v2 8/8] posix: Add _Fork [BZ #4737] Adhemerval Zanella
2021-03-11 21:05 ` [PATCH v2 1/8] posix: Consolidate register-atfork Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87eeglmivx.fsf@igel.home \
    --to=schwab@linux-m68k.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).