[PATCH 5/8] posix: Do not clobber errno by atfork handlers

Adhemerval Zanella adhemerval.zanella@linaro.org
Thu Mar 11 15:29:00 GMT 2021



On 11/03/2021 11:25, Florian Weimer wrote:
> * Andreas Schwab:
> 
>> On Mär 11 2021, Adhemerval Zanella via Libc-alpha wrote:
>>
>>> 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.  */
>>
>> Perhaps: "If _Fork failed, preserve its errno value."

Ack.

>>
>>>   if (pid < 0)
>>>     __set_errno (save_errno)
> 
> Agreed.  And then it's clear it should be moved to the parent branch of
> the if statement above.
> 

But moving it before __run_fork_handlers in the the previous if (which
handles the pid != 0) will both 1. reset the errno even for success
(pid > 0) and 2. not fixing the issue since __run_fork_handlers will
be issue later. What I am missing in your suggestion? 


More information about the Libc-alpha mailing list