mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
fix reintroduction of errno clobbering by atfork handlers
commitbd153422f2
reintroduced the bug fixed inc21051e90c
by refactoring the __syscall_ret into _Fork where it once again runs before the atfork handlers are called. since _Fork is a public interface that sets errno, this can't be fixed the way it was fixed last time without making new internal interfaces. instead, just save errno, and restore it only on error to ensure that a value of 0 is never restored.
This commit is contained in:
parent
2d0bbe6c78
commit
3437e478ba
1 changed files with 3 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "libc.h"
|
||||
|
||||
static void dummy(int x) { }
|
||||
|
@ -8,6 +9,8 @@ pid_t fork(void)
|
|||
{
|
||||
__fork_handler(-1);
|
||||
pid_t ret = _Fork();
|
||||
int errno_save = errno;
|
||||
__fork_handler(!ret);
|
||||
if (ret<0) errno = errno_save;
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue