[v3,2/4] posix: Do not clobber errno by atfork handlers
Commit Message
Changes from v2:
* Set/restore errno unconditionally.
Changes from v1:
* Move the errno set/restore to parent branch.
---
Checked on x86_64-linux-gnu.
---
posix/fork.c | 5 +++++
1 file changed, 5 insertions(+)
@@ -99,6 +99,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)
{
@@ -111,6 +114,8 @@ __libc_fork (void)
/* Run the handlers registered for the parent. */
__run_fork_handlers (atfork_run_parent, multiple_threads);
+
+ __set_errno (save_errno);
}
return pid;