X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fprocess%2Ffork.c;h=fb42478ae709a3e11619740a11b7a344cb63655a;hb=1ef37aa00ea830dfda76e04e3d941cafa74d8b76;hp=bcd47c97a6e117e16c9c4bf534a26b56edc6aec8;hpb=9080cc153cc2b09881c3245becbd68534db18d7c;p=musl diff --git a/src/process/fork.c b/src/process/fork.c index bcd47c97..fb42478a 100644 --- a/src/process/fork.c +++ b/src/process/fork.c @@ -1,18 +1,37 @@ #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.threaded && !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; + self->next = self->prev = self; + __thread_list_lock = 0; libc.threads_minus_1 = 0; } - if (libc.fork_handler) libc.fork_handler(!ret); - return ret; + __restore_sigs(&set); + __fork_handler(!ret); + return __syscall_ret(ret); }