From: Adhemerval Zanella Date: Thu, 21 Jan 2021 13:20:54 +0000 (-0300) Subject: posix: Do not clobber errno by atfork handlers X-Git-Tag: glibc-2.34~222 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0c40833862f5cfe4d03d9130d79c1d93f284af0;p=thirdparty%2Fglibc.git posix: Do not clobber errno by atfork handlers Checked on x86_64-linux-gnu. --- diff --git a/posix/fork.c b/posix/fork.c index 44caf8d1663..940d6a09556 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;