include cleanups: remove unused headers and add feature test macros
[musl] / src / process / fork.c
1 #include <unistd.h>
2 #include <string.h>
3 #include "syscall.h"
4 #include "libc.h"
5 #include "pthread_impl.h"
6
7 static void dummy(int x)
8 {
9 }
10
11 weak_alias(dummy, __fork_handler);
12
13 pid_t fork(void)
14 {
15         pid_t ret;
16         sigset_t set;
17         __fork_handler(-1);
18         __block_all_sigs(&set);
19         ret = syscall(SYS_fork);
20         if (libc.main_thread && !ret) {
21                 pthread_t self = __pthread_self();
22                 self->tid = self->pid = syscall(SYS_getpid);
23                 memset(&self->robust_list, 0, sizeof self->robust_list);
24                 libc.threads_minus_1 = 0;
25                 libc.main_thread = self;
26         }
27         __restore_sigs(&set);
28         __fork_handler(!ret);
29         return ret;
30 }