From d0c40833862f5cfe4d03d9130d79c1d93f284af0 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Thu, 21 Jan 2021 10:20:54 -0300 Subject: posix: Do not clobber errno by atfork handlers Checked on x86_64-linux-gnu. --- posix/fork.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'posix/fork.c') 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; -- cgit 1.4.1