diff mbox series

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

Message ID 20210202151134.2123748-5-adhemerval.zanella@linaro.org
State Under Review
Delegated to: Florian Weimer
Headers show
Series [1/8] posix: Consolidate register-atfork | expand

Commit Message

Adhemerval Zanella Feb. 2, 2021, 3:11 p.m. UTC
Checked on x86_64-linux-gnu.
---
 posix/fork.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

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)