X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fprocess%2Ffork.c;h=da074ae9c9b958be06cc0e6bbd4f0daa27524cbc;hb=2fae10f887b48b809bac56e4ff8a5c3fd4525de3;hp=a04e8929a70e10ce7e32e3e44834ebb9ab51e049;hpb=870cc679771f776333953b2a990a107393d9d0fd;p=musl diff --git a/src/process/fork.c b/src/process/fork.c index a04e8929..da074ae9 100644 --- a/src/process/fork.c +++ b/src/process/fork.c @@ -1,19 +1,35 @@ #include +#include +#include #include "syscall.h" #include "libc.h" #include "pthread_impl.h" +static void dummy(int x) +{ +} + +weak_alias(dummy, __fork_handler); + pid_t fork(void) { pid_t ret; - if (libc.fork_handler) libc.fork_handler(-1); - ret = syscall(SYS_fork); - if (libc.main_thread && !ret) { + sigset_t set; + __fork_handler(-1); + __block_all_sigs(&set); +#ifdef SYS_fork + ret = __syscall(SYS_fork); +#else + ret = __syscall(SYS_clone, SIGCHLD, 0); +#endif + if (!ret) { pthread_t self = __pthread_self(); - self->tid = self->pid = syscall(SYS_getpid); + self->tid = __syscall(SYS_gettid); + self->robust_list.off = 0; + self->robust_list.pending = 0; libc.threads_minus_1 = 0; - libc.main_thread = self; } - if (libc.fork_handler) libc.fork_handler(!ret); - return ret; + __restore_sigs(&set); + __fork_handler(!ret); + return __syscall_ret(ret); }