]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
posix: Do not clobber errno by atfork handlers
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 21 Jan 2021 13:20:54 +0000 (10:20 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 24 Jun 2021 13:04:13 +0000 (10:04 -0300)
Checked on x86_64-linux-gnu.

posix/fork.c

index 44caf8d16633fc83ad7b90325cfbb535f7590e3a..940d6a095564df8e7bd1384a30f4e2c2724d61ef 100644 (file)
@@ -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;