From d0c40833862f5cfe4d03d9130d79c1d93f284af0 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Thu, 21 Jan 2021 10:20:54 -0300 Subject: [PATCH] posix: Do not clobber errno by atfork handlers Checked on x86_64-linux-gnu. --- posix/fork.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/posix/fork.c b/posix/fork.c index 44caf8d..940d6a0 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; -- 2.7.4