about summary refs log tree commit diff
path: root/posix/fork.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-01-21 10:20:54 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-06-24 10:04:13 -0300
commitd0c40833862f5cfe4d03d9130d79c1d93f284af0 (patch)
tree71ceace106baf9f2f930b71058fe3445d94ad3fb /posix/fork.c
parent9a7565403758f65c07fe3705e966381d9cfd35b6 (diff)
downloadglibc-d0c40833862f5cfe4d03d9130d79c1d93f284af0.tar.gz
glibc-d0c40833862f5cfe4d03d9130d79c1d93f284af0.tar.xz
glibc-d0c40833862f5cfe4d03d9130d79c1d93f284af0.zip
posix: Do not clobber errno by atfork handlers
Checked on x86_64-linux-gnu.
Diffstat (limited to 'posix/fork.c')
-rw-r--r--posix/fork.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/posix/fork.c b/posix/fork.c
index 44caf8d166..940d6a0955 100644
--- a/posix/fork.c
+++ b/posix/fork.c
@@ -103,6 +103,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)
 	{
@@ -115,6 +118,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;