mirror of
https://git.musl-libc.org/git/musl
synced 2025-03-19 00:52:55 +03:00
prevent fork's errno from being clobbered by atfork handlers
If the syscall fails, errno must be set correctly for the caller. There's no guarantee that the handlers registered with pthread_atfork won't clobber errno, so we need to ensure it gets set after they are called.
This commit is contained in:
parent
a39f20bf9f
commit
c21051e90c
@ -18,9 +18,9 @@ pid_t fork(void)
|
||||
__fork_handler(-1);
|
||||
__block_all_sigs(&set);
|
||||
#ifdef SYS_fork
|
||||
ret = syscall(SYS_fork);
|
||||
ret = __syscall(SYS_fork);
|
||||
#else
|
||||
ret = syscall(SYS_clone, SIGCHLD, 0);
|
||||
ret = __syscall(SYS_clone, SIGCHLD, 0);
|
||||
#endif
|
||||
if (!ret) {
|
||||
pthread_t self = __pthread_self();
|
||||
@ -31,5 +31,5 @@ pid_t fork(void)
|
||||
}
|
||||
__restore_sigs(&set);
|
||||
__fork_handler(!ret);
|
||||
return ret;
|
||||
return __syscall_ret(ret);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user