From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id CADDD3888014; Thu, 24 Jun 2021 20:53:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CADDD3888014 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc] posix: Do not clobber errno by atfork handlers X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/master X-Git-Oldrev: 9a7565403758f65c07fe3705e966381d9cfd35b6 X-Git-Newrev: d0c40833862f5cfe4d03d9130d79c1d93f284af0 Message-Id: <20210624205350.CADDD3888014@sourceware.org> Date: Thu, 24 Jun 2021 20:53:50 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jun 2021 20:53:50 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d0c40833862f5cfe4d03d9130d79c1d93f284af0 commit d0c40833862f5cfe4d03d9130d79c1d93f284af0 Author: Adhemerval Zanella Date: Thu Jan 21 10:20:54 2021 -0300 posix: Do not clobber errno by atfork handlers Checked on x86_64-linux-gnu. Diff: --- posix/fork.c | 6 ++++++ 1 file changed, 6 insertions(+) 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;